FairyGUI.DisplayObject.GlobalToLocal C# (CSharp) Method

GlobalToLocal() public method

将舞台坐标转换为本地坐标
public GlobalToLocal ( Vector2 point ) : Vector2
point UnityEngine.Vector2
return UnityEngine.Vector2
        public Vector2 GlobalToLocal(Vector2 point)
        {
            Container wsc = this.worldSpaceContainer;

            if (wsc != null)//I am in a world space
            {
                Camera cam = wsc.GetRenderCamera();
                Vector3 worldPoint;
                Vector3 direction;
                Vector3 screenPoint = new Vector3();
                screenPoint.x = point.x;
                screenPoint.y = Screen.height - point.y;

                if (wsc.hitArea is MeshColliderHitTest)
                {
                    if (((MeshColliderHitTest)wsc.hitArea).ScreenToLocal(cam, screenPoint, ref point))
                    {
                        worldPoint = Stage.inst.cachedTransform.TransformPoint(point.x, -point.y, 0);
                        direction = Vector3.back;
                    }
                    else //当射线没有击中模型时,无法确定本地坐标
                        return new Vector2(float.NaN, float.NaN);
                }
                else
                {
                    screenPoint.z = cam.WorldToScreenPoint(this.cachedTransform.position).z;
                    worldPoint = cam.ScreenToWorldPoint(screenPoint);
                    Ray ray = cam.ScreenPointToRay(screenPoint);
                    direction = Vector3.zero - ray.direction;
                }

                return this.WorldToLocal(worldPoint, direction);
            }
            else //I am in stage space
            {
                Vector3 worldPoint = Stage.inst.cachedTransform.TransformPoint(point.x, -point.y, 0);
                return this.WorldToLocal(worldPoint, Vector3.back);
            }
        }

Usage Example

 static public int GlobalToLocal(IntPtr l)
 {
     try {
         FairyGUI.DisplayObject self = (FairyGUI.DisplayObject)checkSelf(l);
         UnityEngine.Vector2    a1;
         checkType(l, 2, out a1);
         var ret = self.GlobalToLocal(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }