using UnityEngine; /// <summary> /// UIWidget 型の拡張メソッドを管理するクラス /// </summary> public static class UIWidgetExt { /// <summary> /// UIRoot の子オブジェクトのグローバル座標を返します /// </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; } }
var pos = uiWidget.GetGlobalPosition();