using UnityEngine;
<summary>
</summary>
public static class UIWidgetExt
{
<summary>
</summary>
public static Vector3 GetGlobalPosition( this Component self )
{
if ( self == null ) return Vector3.zero;
var transform = self.transform;
var pos = Vector3.zero;
while ( transform != null )
{
pos += transform.localPosition;
transform = transform.parent;
}
return pos;
}
<summary>
</summary>
public static void SetGlobalPosition( this Component self, float x, float y )
{
var globalPos = self.GetGlobalPosition();
var localPos = self.transform.localPosition;
var parentPos = globalPos - localPos;
var pos = self.transform.localPosition;
pos.x = -parentPos.x + x;
pos.y = -parentPos.y + y;
self.transform.localPosition = pos;
}
}
uiWidget.SetGlobalPosition( 0, 0 );