File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Assets/JCSUnity/Scripts/Util
docs/ScriptReference/Util Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,36 @@ public static bool IsUnityDefinedUI(Component comp)
5252 comp . GetComponent < TMP_InputField > ( ) ) ;
5353 }
5454
55+ /// <summary>
56+ /// Return the bounds of the UI element.
57+ /// </summary>
58+ public static Bounds GetBounds ( Transform transform )
59+ {
60+ var min = Vector3 . positiveInfinity ;
61+ var max = Vector3 . negativeInfinity ;
62+
63+ RectTransform [ ] rts = transform . GetComponentsInChildren < RectTransform > ( ) ;
64+
65+ foreach ( RectTransform rt in rts )
66+ {
67+ // Get the 4 corners in world coordinates
68+ var v = new Vector3 [ 4 ] ;
69+ rt . GetWorldCorners ( v ) ;
70+
71+ // update min and max
72+ foreach ( var vector3 in v )
73+ {
74+ min = Vector3 . Min ( min , vector3 ) ;
75+ max = Vector3 . Max ( max , vector3 ) ;
76+ }
77+ }
78+
79+ var bounds = new Bounds ( ) ;
80+ bounds . SetMinMax ( min , max ) ;
81+
82+ return bounds ;
83+ }
84+
5585 #region EVENT
5686
5787 /// <summary>
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ User interface related utilities functions.
77| Name | Description |
88| :---------------------------------| :--------------------------------------------------------------------------|
99| IsUnityDefinedUI | Return true if GameObject contains built-in UI components. |
10+ | GetBounds | Return the bounds of the UI element. |
1011| AddEventTriggerEvent | Add an event to EventTrigger component from Unity API. |
1112| SetLangText | Set text by system language and language data. |
1213| SetText | Set the text with data. |
You can’t perform that action at this time.
0 commit comments