-
Notifications
You must be signed in to change notification settings - Fork 1
Release 0.6.7 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release 0.6.7 #14
Conversation
📝 WalkthroughWalkthroughThe pull request introduces a new feature called UnityObjectExtensions by adding a new file that provides extension methods for Unity UI components. The changelog is updated for version 0.6.7 to document this addition. A metadata file for the newly added script is introduced, and the package version in package.json is incremented accordingly. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer
participant RT as RectTransform
participant Ext as UnityObjectsExtensions
Dev->>RT: Call GetWorldCornersArray()
RT->>Ext: Invoke GetLocalCornersArray() to compute local corners
Ext-->>RT: Return local corners array
Ext->>RT: Transform corners using localToWorldMatrix
RT-->>Dev: Return world corners array
sequenceDiagram
participant Dev as Developer
participant GR as GraphicRaycaster
participant Ext as UnityObjectsExtensions
Dev->>GR: Call RaycastPoint(screenPoint)
GR->>Ext: Create PointerEventData for the raycast
Ext->>GR: Perform raycast and populate results list
GR-->>Dev: Return raycast result (boolean) and results list
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (2)
- CHANGELOG.md (1)
- Runtime/UnityObjectsExtensions.cs (1)
Files ignored due to filter (2)
- Runtime/UnityObjectsExtensions.cs.meta
- package.json
Files not summarized due to errors (2)
- Runtime/UnityObjectsExtensions.cs (nothing obtained from openai)
- CHANGELOG.md (nothing obtained from openai)
Files not reviewed due to errors (2)
- CHANGELOG.md (no response)
- Runtime/UnityObjectsExtensions.cs (no response)
Review comments generated (0)
- Review: 0
- LGTM: 0
Tips
Chat with
CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
CHANGELOG.md
(1 hunks)Runtime/UnityObjectsExtensions.cs
(1 hunks)Runtime/UnityObjectsExtensions.cs.meta
(1 hunks)package.json
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: review
🔇 Additional comments (4)
Runtime/UnityObjectsExtensions.cs.meta (1)
1-11
: LGTM!The meta file is correctly formatted with all required fields for Unity to track this new asset.
Runtime/UnityObjectsExtensions.cs (1)
6-8
: Good use of nullable reference types and suppression directiveEnabling nullable reference types enhances type safety, and the ReSharper directive appropriately addresses namespace organization.
package.json (1)
5-5
: LGTM!Version increment follows semantic versioning properly for a feature addition.
CHANGELOG.md (1)
7-11
: LGTM!The changelog entry follows the established format and properly documents the new feature.
public static Vector3[] GetLocalCornersArray(this RectTransform transform) | ||
{ | ||
var corners = new Vector3[4]; | ||
var rect = transform.rect; | ||
var x = rect.x; | ||
var y = rect.y; | ||
var xMax = rect.xMax; | ||
var yMax = rect.yMax; | ||
|
||
corners[0] = new Vector3(x, y, 0f); | ||
corners[1] = new Vector3(x, yMax, 0f); | ||
corners[2] = new Vector3(xMax, yMax, 0f); | ||
corners[3] = new Vector3(xMax, y, 0f); | ||
|
||
return corners; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add null parameter validation
The extension method should validate the transform parameter to avoid NullReferenceException.
public static Vector3[] GetLocalCornersArray(this RectTransform transform)
{
+ if (transform == null)
+ {
+ throw new System.ArgumentNullException(nameof(transform));
+ }
var corners = new Vector3[4];
var rect = transform.rect;
var x = rect.x;
var y = rect.y;
var xMax = rect.xMax;
var yMax = rect.yMax;
corners[0] = new Vector3(x, y, 0f);
corners[1] = new Vector3(x, yMax, 0f);
corners[2] = new Vector3(xMax, yMax, 0f);
corners[3] = new Vector3(xMax, y, 0f);
return corners;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public static Vector3[] GetLocalCornersArray(this RectTransform transform) | |
{ | |
var corners = new Vector3[4]; | |
var rect = transform.rect; | |
var x = rect.x; | |
var y = rect.y; | |
var xMax = rect.xMax; | |
var yMax = rect.yMax; | |
corners[0] = new Vector3(x, y, 0f); | |
corners[1] = new Vector3(x, yMax, 0f); | |
corners[2] = new Vector3(xMax, yMax, 0f); | |
corners[3] = new Vector3(xMax, y, 0f); | |
return corners; | |
} | |
public static Vector3[] GetLocalCornersArray(this RectTransform transform) | |
{ | |
if (transform == null) | |
{ | |
throw new System.ArgumentNullException(nameof(transform)); | |
} | |
var corners = new Vector3[4]; | |
var rect = transform.rect; | |
var x = rect.x; | |
var y = rect.y; | |
var xMax = rect.xMax; | |
var yMax = rect.yMax; | |
corners[0] = new Vector3(x, y, 0f); | |
corners[1] = new Vector3(x, yMax, 0f); | |
corners[2] = new Vector3(xMax, yMax, 0f); | |
corners[3] = new Vector3(xMax, y, 0f); | |
return corners; | |
} |
public static Vector3[] GetWorldCornersArray(this RectTransform transform) | ||
{ | ||
var corners = transform.GetLocalCornersArray(); | ||
var matrix4x = transform.localToWorldMatrix; | ||
for (int i = 0; i < 4; i++) | ||
{ | ||
corners[i] = matrix4x.MultiplyPoint(corners[i]); | ||
} | ||
|
||
return corners; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve variable naming and add null validation
The variable matrix4x
could have a more descriptive name, and null validation should be added.
public static Vector3[] GetWorldCornersArray(this RectTransform transform)
{
+ if (transform == null)
+ {
+ throw new System.ArgumentNullException(nameof(transform));
+ }
var corners = transform.GetLocalCornersArray();
- var matrix4x = transform.localToWorldMatrix;
+ var worldMatrix = transform.localToWorldMatrix;
for (int i = 0; i < 4; i++)
{
- corners[i] = matrix4x.MultiplyPoint(corners[i]);
+ corners[i] = worldMatrix.MultiplyPoint(corners[i]);
}
return corners;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public static Vector3[] GetWorldCornersArray(this RectTransform transform) | |
{ | |
var corners = transform.GetLocalCornersArray(); | |
var matrix4x = transform.localToWorldMatrix; | |
for (int i = 0; i < 4; i++) | |
{ | |
corners[i] = matrix4x.MultiplyPoint(corners[i]); | |
} | |
return corners; | |
} | |
public static Vector3[] GetWorldCornersArray(this RectTransform transform) | |
{ | |
if (transform == null) | |
{ | |
throw new System.ArgumentNullException(nameof(transform)); | |
} | |
var corners = transform.GetLocalCornersArray(); | |
var worldMatrix = transform.localToWorldMatrix; | |
for (int i = 0; i < 4; i++) | |
{ | |
corners[i] = worldMatrix.MultiplyPoint(corners[i]); | |
} | |
return corners; | |
} |
public static bool RaycastPoint(this GraphicRaycaster raycaster, Vector2 screenPoint, out List<RaycastResult> results) | ||
{ | ||
var eventData = new PointerEventData(EventSystem.current) | ||
{ | ||
position = screenPoint, | ||
displayIndex = 0 | ||
}; | ||
|
||
results = new List<RaycastResult>(); | ||
|
||
raycaster.Raycast(eventData, results); | ||
|
||
return results.Count > 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for null EventSystem.current
The method assumes EventSystem.current
is not null, which might cause a NullReferenceException if no event system exists in the scene.
public static bool RaycastPoint(this GraphicRaycaster raycaster, Vector2 screenPoint, out List<RaycastResult> results)
{
+ if (raycaster == null)
+ {
+ throw new System.ArgumentNullException(nameof(raycaster));
+ }
+
+ if (EventSystem.current == null)
+ {
+ results = new List<RaycastResult>();
+ return false;
+ }
var eventData = new PointerEventData(EventSystem.current)
{
position = screenPoint,
displayIndex = 0
};
results = new List<RaycastResult>();
raycaster.Raycast(eventData, results);
return results.Count > 0;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public static bool RaycastPoint(this GraphicRaycaster raycaster, Vector2 screenPoint, out List<RaycastResult> results) | |
{ | |
var eventData = new PointerEventData(EventSystem.current) | |
{ | |
position = screenPoint, | |
displayIndex = 0 | |
}; | |
results = new List<RaycastResult>(); | |
raycaster.Raycast(eventData, results); | |
return results.Count > 0; | |
} | |
public static bool RaycastPoint(this GraphicRaycaster raycaster, Vector2 screenPoint, out List<RaycastResult> results) | |
{ | |
if (raycaster == null) | |
{ | |
throw new System.ArgumentNullException(nameof(raycaster)); | |
} | |
if (EventSystem.current == null) | |
{ | |
results = new List<RaycastResult>(); | |
return false; | |
} | |
var eventData = new PointerEventData(EventSystem.current) | |
{ | |
position = screenPoint, | |
displayIndex = 0 | |
}; | |
results = new List<RaycastResult>(); | |
raycaster.Raycast(eventData, results); | |
return results.Count > 0; | |
} |
New:
Summary by CodeRabbit
New Features
Chores