コード例 #1
0
ファイル: RG_Utils.cs プロジェクト: clime57/Stars
        /// <summary>
        /// 将UI上的某个世界坐标转换成UI根节点上的本地坐标
        /// </summary>
        /// <param name="pos">UI对象世界坐标</param>
        /// <returns>UI根节点上的本地坐标</returns>
        public static Vector3 getNGUIPosition(Vector3 pos)
        {
            Vector3 newPos = UICamera.mainCamera.WorldToScreenPoint(pos);

            newPos.x -= Screen.width / 2;
            newPos.y -= Screen.height / 2;
            //newPos.x *= 640 / (float)Screen.height;
            if (UIWindowManager.getInstance().getUIRoot().scalingStyle == UIRoot.Scaling.Constrained ||
                UIWindowManager.getInstance().getUIRoot().scalingStyle == UIRoot.Scaling.ConstrainedOnMobiles)
            {
                float curScreenHeight = Screen.height * UICamera.mainCamera.rect.height;
                newPos.x *= (960.0f / (float)curScreenHeight);
                newPos.y *= (960.0f / (float)curScreenHeight);
            }
            return(newPos);
        }
コード例 #2
0
ファイル: RG_Utils.cs プロジェクト: clime57/Stars
        public static Vector2 getCurMouseOrTouchNGUIPosition()
        {
#if UNITY_EDITOR
            Vector3 newPos = Input.mousePosition;
#else
            Vector3 newPos = Input.GetTouch(0).position;
#endif
            newPos.x -= Screen.width / 2;
            newPos.y -= Screen.height / 2;
            if (UIWindowManager.getInstance().getUIRoot().scalingStyle == UIRoot.Scaling.Constrained ||
                UIWindowManager.getInstance().getUIRoot().scalingStyle == UIRoot.Scaling.ConstrainedOnMobiles)
            {
                float curScreenHeight = Screen.height * UICamera.mainCamera.rect.height;
                newPos.x *= (960.0f / (float)curScreenHeight);
                newPos.y *= (960.0f / (float)curScreenHeight);
            }
            return(newPos);
        }
コード例 #3
0
 public void setScale()
 {
     if (UIWindowManager.getInstance() != null)
     {
         if (UIWindowManager.getInstance().getUIRoot().scalingStyle == UIRoot.Scaling.Constrained ||
             UIWindowManager.getInstance().getUIRoot().scalingStyle == UIRoot.Scaling.ConstrainedOnMobiles)
         {
             Vector3 newVec;
             float   myRatio  = (float)Screen.width / (float)Screen.height;
             float   maxRatio = 1708.0f / 960.0f;
             float   minRatio = 1280.0f / 960.0f;
             newVec.x             = Mathf.Lerp(_scaleof_960_640.x, _scaleof_1136_640.x, (myRatio - minRatio) / (maxRatio - minRatio));
             newVec.y             = _scaleof_960_640.y;
             newVec.z             = _scaleof_960_640.z;
             transform.localScale = newVec;
         }
         else if ((float)Screen.width / (float)Screen.height < 1.4f)
         {
             transform.localScale = _scaleof_1024_768;
         }
     }
 }
コード例 #4
0
 public UIWindowManager()
 {
     instance_ = this;
     _resReleaseSw.Start();
 }