FairyGUI.GObject.LocalToRoot C# (CSharp) Method

LocalToRoot() public method

Transforms a point from the local coordinate system to GRoot coordinates.
public LocalToRoot ( Vector2 pt, GRoot r ) : Vector2
pt UnityEngine.Vector2
r GRoot
return UnityEngine.Vector2
        public Vector2 LocalToRoot(Vector2 pt, GRoot r)
        {
            pt = LocalToGlobal(pt);
            if (r == null || r == GRoot.inst)
            {
                //fast
                pt.x /= GRoot.contentScaleFactor;
                pt.y /= GRoot.contentScaleFactor;
            }
            else
                return r.GlobalToLocal(pt);

            return pt;
        }

Usage Example

Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="popup"></param>
        /// <param name="target"></param>
        /// <param name="downward"></param>
        /// <returns></returns>
        public Vector2 GetPoupPosition(GObject popup, GObject target, object downward)
        {
            Vector2 pos;
            Vector2 size = Vector2.zero;

            if (target != null)
            {
                pos  = target.LocalToRoot(Vector2.zero, this);
                size = target.LocalToRoot(target.size, this) - pos;
            }
            else
            {
                pos = this.GlobalToLocal(Stage.inst.touchPosition);
            }
            float xx, yy;

            xx = pos.x;
            if (xx + popup.width > this.width)
            {
                xx = xx + size.x - popup.width;
            }
            yy = pos.y + size.y;
            if ((downward == null && yy + popup.height > this.height) ||
                downward != null && (bool)downward == false)
            {
                yy = pos.y - popup.height - 1;
                if (yy < 0)
                {
                    yy  = 0;
                    xx += size.x / 2;
                }
            }

            return(new Vector2(Mathf.RoundToInt(xx), Mathf.RoundToInt(yy)));
        }
All Usage Examples Of FairyGUI.GObject::LocalToRoot