CalculateAbsoluteWidgetBounds() static public method

Calculate the combined bounds of all widgets attached to the specified game object or its children (in world space).
static public CalculateAbsoluteWidgetBounds ( Transform trans ) : Bounds
trans Transform
return Bounds
    /// <summary>
    /// Calculate the bounds of all widgets under this game object.
    /// </summary>

    public void Press(bool isPressed)
    {
        if (isPressed)
        {
            mDragStarted = false;
        }

        if (rootForBounds != null)
        {
            mPressed = isPressed;

            if (isPressed)
            {
                // Update the bounds
                mBounds = NGUIMath.CalculateAbsoluteWidgetBounds(rootForBounds);

                // Remove all momentum on press
                mMomentum = Vector2.zero;
                mScroll   = 0f;

                // Disable the spring movement
                SpringPosition sp = GetComponent <SpringPosition>();
                if (sp != null)
                {
                    sp.enabled = false;
                }
            }
            else if (dragEffect == UIDragObject.DragEffect.MomentumAndSpring)
            {
                ConstrainToBounds(false);
            }
        }
    }
示例#2
0
        static protected Vector3 GetCenterInWorldSpace(GameObject go)
        {
            Bounds  curBounds = NGUIMath.CalculateAbsoluteWidgetBounds(go.transform);
            Vector3 center    = (curBounds.min + curBounds.max) * 0.5f;

            return(center);
        }
示例#3
0
        private void Recenter()
        {
            if (this.direction != Direction.None)
            {
                Vector3 boundsCenter = NGUIMath.CalculateAbsoluteWidgetBounds(this.transform).center;

                if (this.direction == Direction.Horizontal || this.direction == Direction.Both)
                {
                    float differenceHorizontal = this.transform.position.x - boundsCenter.x;

                    foreach (Transform child in this.transform)
                    {
                        child.Translate(differenceHorizontal, 0f, 0f, Space.World);
                    }
                }

                if (this.direction == Direction.Vertical || this.direction == Direction.Both)
                {
                    float differenceVertical = this.transform.position.y - boundsCenter.y;

                    foreach (Transform child in this.transform)
                    {
                        child.Translate(0f, differenceVertical, 0f, Space.World);
                    }
                }
            }
        }
示例#4
0
 public void Press(bool isPressed)
 {
     if (isPressed)
     {
         mDragStarted = false;
     }
     if (!(rootForBounds != null))
     {
         return;
     }
     mPressed = isPressed;
     if (isPressed)
     {
         mBounds   = NGUIMath.CalculateAbsoluteWidgetBounds(rootForBounds);
         mMomentum = Vector2.zero;
         mScroll   = 0f;
         SpringPosition component = GetComponent <SpringPosition>();
         if (component != null)
         {
             component.enabled = false;
         }
     }
     else if (dragEffect == UIDragObject.DragEffect.MomentumAndSpring)
     {
         ConstrainToBounds(immediate: false);
     }
 }
示例#5
0
 // Token: 0x0600308B RID: 12427 RVA: 0x000EE320 File Offset: 0x000EC720
 public void Press(bool isPressed)
 {
     if (isPressed)
     {
         this.mDragStarted = false;
     }
     if (this.rootForBounds != null)
     {
         this.mPressed = isPressed;
         if (isPressed)
         {
             this.mBounds   = NGUIMath.CalculateAbsoluteWidgetBounds(this.rootForBounds);
             this.mMomentum = Vector2.zero;
             this.mScroll   = 0f;
             SpringPosition component = base.GetComponent <SpringPosition>();
             if (component != null)
             {
                 component.enabled = false;
             }
         }
         else if (this.dragEffect == UIDragObject.DragEffect.MomentumAndSpring)
         {
             this.ConstrainToBounds(false);
         }
     }
 }
 public void Press(bool isPressed)
 {
     //IL_0032: Unknown result type (might be due to invalid IL or missing references)
     //IL_0037: Unknown result type (might be due to invalid IL or missing references)
     //IL_003d: Unknown result type (might be due to invalid IL or missing references)
     //IL_0042: Unknown result type (might be due to invalid IL or missing references)
     if (isPressed)
     {
         mDragStarted = false;
     }
     if (rootForBounds != null)
     {
         mPressed = isPressed;
         if (isPressed)
         {
             mBounds   = NGUIMath.CalculateAbsoluteWidgetBounds(rootForBounds);
             mMomentum = Vector2.get_zero();
             mScroll   = 0f;
             SpringPosition component = this.GetComponent <SpringPosition>();
             if (component != null)
             {
                 component.set_enabled(false);
             }
         }
         else if (dragEffect == UIDragObject.DragEffect.MomentumAndSpring)
         {
             ConstrainToBounds(false);
         }
     }
 }
示例#7
0
    /// <summary>
    /// 设置展示面板的位置 by吴江
    /// </summary>
    /// <param name="_tooltipObj"></param>
    /// <param name="_triggerObj"></param>
    protected static void SetEquipTooltipPostion(GameObject _tooltipObj, GameObject _triggerObj)
    {
        Transform tooltipTrans = _tooltipObj.transform;
        Transform tiggerTrans  = _triggerObj.transform;

        if (_triggerObj != null)
        {
            Bounds triBounds  = NGUIMath.CalculateAbsoluteWidgetBounds(_triggerObj.transform);
            Bounds descBounds = NGUIMath.CalculateAbsoluteWidgetBounds(tooltipTrans);
            float  lx         = tooltipTrans.position.x - descBounds.max.x + triBounds.min.x;
            float  rx         = tooltipTrans.position.x - descBounds.min.x + triBounds.max.x;
            float  y          = tooltipTrans.position.y;
            float  xMin       = descBounds.min.x - descBounds.max.x + triBounds.min.x;

            Vector3 BottomLeftPosition = UICamera.currentCamera.ViewportToWorldPoint(new Vector3(0, 0, 0));
            if (xMin < BottomLeftPosition.x)
            {
                _tooltipObj.transform.position = new Vector3(rx, y, tiggerTrans.position.z - 1);
            }
            else
            {
                _tooltipObj.transform.position = new Vector3(lx, y, tiggerTrans.position.z - 1);
            }
            //以本地坐标修正一次z轴
            _tooltipObj.transform.localPosition = new Vector3(tooltipTrans.localPosition.x, tooltipTrans.localPosition.y, -300f);//解决IOS上,引导和界面层级问题  by邓成
        }
        else
        {
            _tooltipObj.transform.localPosition = new Vector3(0f, 0f, -300f);
        }
    }
示例#8
0
    private void Update()
    {
        textWidthInPixels = NGUIMath.CalculateAbsoluteWidgetBounds(transform).size.x / LegacyEditorData.instance.transform.localScale.x;

        if (UICamera.hoveredObject == null)
        {
            DisplayTooltip("", null);
        }

        if (textWidthInPixels > scrollWidth)
        {
            hoveredTime += Time.deltaTime;
            if (hoveredTime >= timeToStartScrolling)
            {
                float xPos = transform.localPosition.x - (scrollSpeed * Time.deltaTime);
                //Since xPos will start to be negative, we need to see if it's already fully on screen before we actually move it
                if ((xPos + textWidthInPixels) > scrollWidth)
                {
                    transform.localPosition = new Vector3(xPos, transform.localPosition.y, transform.localPosition.z);
                }
                else
                {
                    //If we hit the end, wait for a few seconds and then reset the scrolling
                    Invoke("resetTimeAndPosition", timeToResetScrolling);
                }
            }
        }
    }
示例#9
0
    private void Update()
    {
        float deltaTime = UpdateRealTimeDelta();

        if (mPressed)
        {
            SpringPosition component = GetComponent <SpringPosition>();
            if (component != null)
            {
                component.enabled = false;
            }
            mScroll = 0f;
        }
        else
        {
            mMomentum += scale * (mScroll * 20f);
            mScroll    = NGUIMath.SpringLerp(mScroll, 0f, 20f, deltaTime);
            if (mMomentum.magnitude > 0.01f)
            {
                mTrans.localPosition += (Vector3)NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
                mBounds = NGUIMath.CalculateAbsoluteWidgetBounds(rootForBounds);
                if (!ConstrainToBounds(dragEffect == UIDragObject.DragEffect.None))
                {
                    SpringPosition component2 = GetComponent <SpringPosition>();
                    if (component2 != null)
                    {
                        component2.enabled = false;
                    }
                }
                return;
            }
            mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
    }
示例#10
0
    // Token: 0x060001F7 RID: 503 RVA: 0x000176A8 File Offset: 0x000158A8
    private void Update()
    {
        float deltaTime = RealTime.deltaTime;

        if (this.mPressed)
        {
            SpringPosition component = base.GetComponent <SpringPosition>();
            if (component != null)
            {
                component.enabled = false;
            }
            this.mScroll = 0f;
        }
        else
        {
            this.mMomentum += this.scale * (this.mScroll * 20f);
            this.mScroll    = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, deltaTime);
            if (this.mMomentum.magnitude > 0.01f)
            {
                this.mTrans.localPosition += NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
                this.mBounds = NGUIMath.CalculateAbsoluteWidgetBounds(this.rootForBounds);
                if (!this.ConstrainToBounds(this.dragEffect == UIDragObject.DragEffect.None))
                {
                    SpringPosition component2 = base.GetComponent <SpringPosition>();
                    if (component2 != null)
                    {
                        component2.enabled = false;
                    }
                }
                return;
            }
            this.mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
    }
示例#11
0
    public void RelayoutImmediately()
    {
        Vector2 startPosition = this.m_Parent.transform.position;

        List <Transform> children = new List <Transform>();

        for (int i = 0; i < this.m_Parent.childCount; i++)
        {
            children.Add(this.m_Parent.GetChild(i));
        }
        children.Sort((x, y) => { return(string.Compare(x.name, y.name)); });

        for (int i = 0; i < children.Count; i++)
        {
            Transform needLayoutTransform = children[i];
            if (this.m_IntervalDistance.Equals(Vector2.zero))
            {
                this.m_IntervalDistance = this.m_Arrangement == UIGrid.Arrangement.Horizontal ?
                                          new Vector2(NGUIMath.CalculateAbsoluteWidgetBounds(needLayoutTransform).size.x + this.m_WidgetsDistance, 0) :
                                          new Vector2(0, NGUIMath.CalculateAbsoluteWidgetBounds(needLayoutTransform).size.y + this.m_WidgetsDistance);

                Vector2 anchorPosition = new Vector2(this.m_AnchorObject.position.x, this.m_AnchorObject.position.y);
                startPosition = this.m_AnchorPoint == AnchorPoint.MinMost ? anchorPosition :
                                this.m_AnchorPoint == AnchorPoint.MaxMost ? anchorPosition - this.m_IntervalDistance * (this.m_Parent.childCount - 1)
                                                :  anchorPosition - this.m_IntervalDistance * (this.m_Parent.childCount - 1) / 2;
            }

            Vector2 calculatedPosition = startPosition + i * this.m_IntervalDistance;

            needLayoutTransform.transform.position = new Vector3(calculatedPosition.x, calculatedPosition.y, needLayoutTransform.transform.position.z);
        }
    }
示例#12
0
    /// <summary>
    /// Set up everything necessary to preview a UI object.
    /// </summary>

    static bool SetupPreviewForUI(Camera cam, GameObject root, GameObject child, UISnapshotPoint point)
    {
        if (child.GetComponentInChildren <UIRect>() == null)
        {
            return(false);
        }

        if (child.GetComponent <UIPanel>() == null)
        {
            root.AddComponent <UIPanel>();
        }

        Bounds  bounds  = NGUIMath.CalculateAbsoluteWidgetBounds(child.transform);
        Vector3 size    = bounds.extents;
        float   objSize = size.magnitude;

        cam.transform.position = bounds.center;
        cam.cullingMask        = (1 << root.layer);

        if (point != null)
        {
            SetupSnapshotCamera(child, cam, point);
        }
        else
        {
            SetupSnapshotCamera(child, cam, objSize, Mathf.RoundToInt(Mathf.Max(size.x, size.y)), -100f, 100f);
        }
        NGUITools.ImmediatelyCreateDrawCalls(root);
        return(true);
    }
示例#13
0
        void SetAnchor(Vector2 screenPos)
        {
            var     t           = controller.transform.GetChild(0);
            Vector3 worldPos    = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(Mathf.Clamp(screenPos.x, Bg.GetComponent <UIWidget>().width *((float)Screen.width / (float)UIRoot.list[0].manualWidth) / 2, (Screen.width - Bg.GetComponent <UIWidget>().width *((float)Screen.width / (float)UIRoot.list[0].manualWidth) / 2)), screenPos.y));
            Bounds  abs         = NGUIMath.CalculateAbsoluteWidgetBounds(t);
            float   aspect      = (float)Screen.width / (float)Screen.height;
            Vector4 worldMargin = Margin * 2.0f / (float)UIRoot.list[0].manualHeight;

            worldPos.x = Mathf.Clamp(worldPos.x, -aspect + worldMargin.x, aspect - worldMargin.y);
            Vector3 currentPos = t.position;

            currentPos.x = worldPos.x;

            /*if (worldPos.y >= 1f - worldMargin.w - abs.size.y - 0.2f)
             * {
             *  currentPos.y = worldPos.y - abs.size.y / 2 - 0.1f;
             * }
             * else
             * {
             *  currentPos.y = worldPos.y + abs.size.y / 2 + 0.1f;
             * }*/

            t.position      = currentPos;
            t.localPosition = new Vector2(t.localPosition.x, 0);
        }
示例#14
0
 void Start()
 {//Set up things on the start method
     uICamera    = GameObject.Find("UICamera").GetComponent <Camera>();
     bounds      = NGUIMath.CalculateAbsoluteWidgetBounds(constraintArea.transform);
     targetPoint = target.transform.position; //get target's coords
     transform.LookAt(targetPoint);           //makes the camera look to it
     distanceToTarget = Vector3.Distance(targetPoint, transform.position);
 }
示例#15
0
    /// <summary>
    /// Computes a menu position that will avoid obscuring a hierarchy
    /// of NGUI UI widgets.
    /// </summary>
    /// <returns>
    /// The menu position.
    /// </returns>
    /// <param name='menu'>
    /// The Context Menu.
    /// </param>
    /// <param name='uiObject'>
    /// The game object that is the parent for one or more NGUI UI widgets.
    /// </param>
    public static Vector3 ComputeMenuPosition(CtxMenu menu, GameObject uiObject)
    {
        Bounds   bounds = NGUIMath.CalculateAbsoluteWidgetBounds(uiObject.transform);
        UICamera uiCam  = UICamera.FindCameraForLayer(uiObject.layer);
        Rect     rect   = ComputeScreenSpaceBounds(bounds, uiCam.cachedCamera);

        return(ComputeMenuPosition(menu, rect, true));
    }
示例#16
0
 private void OnPressForeground(GameObject go, bool isPressed)
 {
     if (isPressed)
     {
         this.mCam = UICamera.currentCamera;
         AABBox aABBox = NGUIMath.CalculateAbsoluteWidgetBounds(this.mFG.cachedTransform);
         this.mScreenPos = this.mCam.WorldToScreenPoint(aABBox.center);
     }
 }
示例#17
0
    /// <summary>
    /// Save the position of the foreground on press.
    /// </summary>

    void OnPressForeground(GameObject go, bool isPressed)
    {
        if (isPressed)
        {
            mCam = UICamera.currentCamera;
            Bounds b = NGUIMath.CalculateAbsoluteWidgetBounds(mFG.cachedTransform);
            mScreenPos = mCam.WorldToScreenPoint(b.center);
        }
    }
示例#18
0
        //计算出NGUI某个UISprite或者UITexture或者 UILabel 在屏幕中占的矩形位置;
        private Rect NGUIObjectToRect(GameObject go)
        {
            Camera  camera = NGUITools.FindCameraForLayer(go.layer);
            Bounds  bounds = NGUIMath.CalculateAbsoluteWidgetBounds(go.transform);
            Vector3 min    = camera.WorldToScreenPoint(bounds.min);
            Vector3 max    = camera.WorldToScreenPoint(bounds.max);

            return(new Rect(min.x, min.y, max.x - min.x, max.y - min.y));
        }
示例#19
0
 public static Vector3 CalculateElementSize(UXElement element)
 {
     if (element.Root != null)
     {
         Bounds bounds = NGUIMath.CalculateAbsoluteWidgetBounds(element.Root.transform);
         return(new Vector3(element.UXCamera.ScaleColliderHorizontally(bounds.size.x), element.UXCamera.ScaleColliderVertically(bounds.size.y), 0f));
     }
     return(Vector3.zero);
 }
示例#20
0
 public UnityNode(GameObject obj)
 {
     gameObject = obj;
     camera     = GetCamera();
     bounds     = NGUIMath.CalculateAbsoluteWidgetBounds(gameObject.transform);
     rect       = BoundsToScreenSpace(bounds);
     objectPos  = WorldToGUIPoint(bounds.center);
     components = GameObjectAllComponents();
 }
示例#21
0
    public void setData(string txt, float delay)
    {
        tfText.text = "\n" + txt + "\n";
        gameObject.SetActive(true);

        _b = NGUIMath.CalculateAbsoluteWidgetBounds(tfText.transform);
        spTooltip.width  = Mathf.RoundToInt(_b.extents.x * 2.0f + 70.0f);
        spTooltip.height = Mathf.RoundToInt(_b.extents.y * 2.0f + 95.0f);
        _leftTime        = delay;

        visible = true;
    }
示例#22
0
    /// <summary>
    /// Save the position of the foreground on press.
    /// </summary>

    void OnPressForeground(GameObject go, bool isPressed)
    {
        if (isPressed)
        {
            mCam = UICamera.currentCamera;
            Bounds b = NGUIMath.CalculateAbsoluteWidgetBounds(mFG.cachedTransform);
            mScreenPos = mCam.WorldToScreenPoint(b.center);
        }
        else if (onDragFinished != null)
        {
            onDragFinished(UIDraggablePanel.DragonMode.None);
        }
    }
示例#23
0
 private void OnPressForeground(GameObject go, bool isPressed)
 {
     if (isPressed)
     {
         mCam = UICamera.currentCamera;
         var bounds = NGUIMath.CalculateAbsoluteWidgetBounds(mFG.cachedTransform);
         mScreenPos = mCam.WorldToScreenPoint(bounds.center);
     }
     else
     {
         onDragFinished?.Invoke();
     }
 }
示例#24
0
 private void OnPressForeground(GameObject go, bool isPressed)
 {
     if (isPressed)
     {
         this.mCam = UICamera.currentCamera;
         Bounds bounds = NGUIMath.CalculateAbsoluteWidgetBounds(this.mFG.cachedTransform);
         this.mScreenPos = this.mCam.WorldToScreenPoint(bounds.center);
     }
     else if (this.onDragFinished != null)
     {
         this.onDragFinished();
     }
 }
    public override Rect GetRect()
    {
        int w = Screen.width / 2;
        int h = Screen.height / 2;

        Bounds b = NGUIMath.CalculateAbsoluteWidgetBounds(uiTexture.transform);

        int rx = Mathf.RoundToInt(b.min.x * h + w);
        int ry = Mathf.RoundToInt((b.min.y + 1) * h);
        int rz = Mathf.RoundToInt(b.size.x * h);
        int rw = Mathf.RoundToInt(b.size.y * h);

        return(new Rect(rx, ry, rz, rw));
    }
示例#26
0
    public void TweenToggleOn()
    {
        var bounds = NGUIMath.CalculateAbsoluteWidgetBounds(tweenTrans);

        if (scrollPage != null && !scrollPage.IsVisible(bounds.min))
        {
            scrollPage.ScrollToBottom();
//			var panTrans = panel.transform;
//			var toPos = new Vector3(panTrans.localPosition.x, panTrans.localPosition.y + tableSize +10f, 0);
//			//Debug.Log("MOVE THE F**K " + panTrans.localPosition + " TO " + toPos);
//			SpringPanel.Begin(panel.gameObject, toPos, 10f);
        }
        tween.onFinished.Clear();
    }
示例#27
0
 static public int CalculateAbsoluteWidgetBounds_s(IntPtr l)
 {
     try {
         UnityEngine.Transform a1;
         checkType(l, 1, out a1);
         var ret = NGUIMath.CalculateAbsoluteWidgetBounds(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    void StartScale()
    {
        Bounds  dependBounds = NGUIMath.CalculateAbsoluteWidgetBounds(dependOnGameObject.transform);
        Vector3 bottomLeft   = new Vector3(dependBounds.center.x - dependBounds.extents.x, dependBounds.center.y - dependBounds.extents.y, dependBounds.center.z);
        Vector3 topRight     = new Vector3(dependBounds.center.x + dependBounds.extents.x, dependBounds.center.y + dependBounds.extents.y, dependBounds.center.z);

        Vector3 localBottomLeft = widgetTran.InverseTransformPoint(bottomLeft);
        Vector3 localTopRight   = widgetTran.InverseTransformPoint(topRight);

        float width  = localTopRight.x - localBottomLeft.x + sizeOffset.x;
        float height = localTopRight.y - localBottomLeft.y + sizeOffset.y;

        scaledWidget.Dimensions = new Vector2(width, height);
    }
示例#29
0
        static protected Vector3 GetCenterInScreenSpace(GameObject go)
        {
            UICamera cam       = UICamera.FindCameraForLayer(go.layer);
            Bounds   curBounds = NGUIMath.CalculateAbsoluteWidgetBounds(go.transform);

            if (cam != null)
            {
                Vector3 center = (curBounds.min + curBounds.max) * 0.5f;
                //获取屏幕空间的位置
                center   = cam.cachedCamera.WorldToScreenPoint(center);
                center.z = 0;
                return(center);
            }
            return(go.transform.position);
        }
    private void Update()
    {
        //IL_003d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0043: Unknown result type (might be due to invalid IL or missing references)
        //IL_0054: Unknown result type (might be due to invalid IL or missing references)
        //IL_0059: Unknown result type (might be due to invalid IL or missing references)
        //IL_005e: Unknown result type (might be due to invalid IL or missing references)
        //IL_009b: Unknown result type (might be due to invalid IL or missing references)
        //IL_00ac: Unknown result type (might be due to invalid IL or missing references)
        //IL_00b1: Unknown result type (might be due to invalid IL or missing references)
        //IL_00b6: Unknown result type (might be due to invalid IL or missing references)
        //IL_00c7: Unknown result type (might be due to invalid IL or missing references)
        //IL_00cc: Unknown result type (might be due to invalid IL or missing references)
        //IL_0117: Unknown result type (might be due to invalid IL or missing references)
        float deltaTime = RealTime.deltaTime;

        if (mPressed)
        {
            SpringPosition component = this.GetComponent <SpringPosition>();
            if (component != null)
            {
                component.set_enabled(false);
            }
            mScroll = 0f;
        }
        else
        {
            mMomentum += scale * (mScroll * 20f);
            mScroll    = NGUIMath.SpringLerp(mScroll, 0f, 20f, deltaTime);
            if (mMomentum.get_magnitude() > 0.01f)
            {
                Transform obj = mTrans;
                obj.set_localPosition(obj.get_localPosition() + Vector2.op_Implicit(NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime)));
                mBounds = NGUIMath.CalculateAbsoluteWidgetBounds(rootForBounds);
                if (!ConstrainToBounds(dragEffect == UIDragObject.DragEffect.None))
                {
                    SpringPosition component2 = this.GetComponent <SpringPosition>();
                    if (component2 != null)
                    {
                        component2.set_enabled(false);
                    }
                }
                return;
            }
            mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
    }