/// <summary>
        /// Make a canvas space object to a world space position.
        ///
        /// NOTE(jenchieh): Make UI object (canvas space) on top of the
        /// world space game object.
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public Vector3 CastToScreen(Vector3 pos)
        {
            JCS_Camera   jcsCam   = JCS_Camera.main;
            JCS_ResizeUI resizeUI = JCS_ResizeUI.instance;

            Vector3 positionOffset = mPositionOffset;

            if (mPanelRoot != null)
            {
                positionOffset.x /= mPanelRoot.PanelDeltaWidthRatio;
                positionOffset.y /= mPanelRoot.PanelDeltaHeightRatio;
            }

            switch (GetObjectType())
            {
            case JCS_UnityObjectType.TEXT:
            case JCS_UnityObjectType.UI:
            {
                Vector2 worldToCanvasSpace = jcsCam.WorldToCanvasSpace(pos);

                float targetScale = resizeUI.TargetScale;

                if (targetScale != 0.0f)
                {
                    worldToCanvasSpace.x /= resizeUI.TargetScale;
                    worldToCanvasSpace.y /= resizeUI.TargetScale;
                }

                this.LocalPosition = worldToCanvasSpace + (Vector2)positionOffset;
            }
            break;
            }

            return(this.LocalPosition);
        }
Esempio n. 2
0
        /* Functions */

        private void Awake()
        {
            this.mAppRect = this.GetComponent <RectTransform>();
            this.mCanvas  = this.GetComponent <Canvas>();

            if (JCS_UISettings.instance.RESIZE_UI)
            {
                // resizable UI in order to resize the UI correctly
                mResizeUI = JCS_Util.SpawnGameObject(RESIZE_UI_PATH).GetComponent <JCS_ResizeUI>();
                mResizeUI.transform.SetParent(this.transform);
            }

            JCS_UIManager.instance.AddCanvas(this);

            if (mDisplayOnAwake)
            {
                Show();
            }
            else
            {
                Hide();
            }
        }
Esempio n. 3
0
        //========================================
        //      Unity's function
        //------------------------------
        private void Awake()
        {
            this.mRect = this.GetComponent <RectTransform>();

            // if this is the root object set this as un destroyable
            this.gameObject.AddComponent <JCS_UniqueObject>();

            if (instance != null)
            {
                string black_screen_name = JCS_UISettings.BLACK_SCREEN_NAME;
                string white_screen_name = JCS_UISettings.WHITE_SCREEN_NAME;

                // Cuz the transform list will change while we set the
                // transform to this transform.
                List <Transform> readyToSetList = new List <Transform>();

                Transform tempTrans = instance.transform;
                for (int index = 0;
                     index < tempTrans.childCount;
                     ++index)
                {
                    Transform child = tempTrans.GetChild(index);
                    if (child.name == black_screen_name ||
                        child.name == (black_screen_name + "(Clone)"))
                    {
                        continue;
                    }

                    if (child.name == white_screen_name ||
                        child.name == (white_screen_name + "(Clone)"))
                    {
                        continue;
                    }

                    if (child.name == "JCS_IgnorePanel")
                    {
                        continue;
                    }

                    // TODO(JenChieh): optimize this?
                    if (child.GetComponent <JCS_IgnoreDialogueObject>() != null)
                    {
                        continue;
                    }

                    // add to set list ready to set to the new transform as parent
                    readyToSetList.Add(child);
                }

                // set to the new transform
                foreach (Transform trans in readyToSetList)
                {
                    // set parent to the new canvas in the new scene
                    trans.SetParent(this.transform);
                }

                // Delete the old one
                DestroyImmediate(instance.gameObject);
            }


            instance = this;

            JCS_Canvas.instance.SetResizeUI(this);
        }
Esempio n. 4
0
        /* Functions */

        private void Awake()
        {
            if (instance != null)
            {
                string black_screen_name = JCS_UISettings.BLACK_SCREEN_NAME;
                string white_screen_name = JCS_UISettings.WHITE_SCREEN_NAME;

                // cuz the transform list will change while we set the transform to
                // the transform,
                List <Transform> readyToSetList = new List <Transform>();

                Transform tempTrans = instance.transform;
                // so record all the transform
                for (int index = 0; index < tempTrans.childCount; ++index)
                {
                    Transform child = tempTrans.GetChild(index);
                    if (child.name == black_screen_name ||
                        child.name == (black_screen_name + "(Clone)"))
                    {
                        continue;
                    }

                    if (child.name == white_screen_name ||
                        child.name == (white_screen_name + "(Clone)"))
                    {
                        continue;
                    }

                    if (child.name == "JCS_IgnorePanel")
                    {
                        continue;
                    }

                    // TODO(JenChieh): optimize this?
                    if (child.GetComponent <JCS_IgnoreDialogueObject>() != null)
                    {
                        continue;
                    }

                    // add to set list ready to set to the new transform as parent
                    readyToSetList.Add(child);
                }

                // set to the new transform
                foreach (Transform trans in readyToSetList)
                {
                    // set parent to the new canvas in the new scene
                    trans.SetParent(this.transform);
                }

                // Delete the old one
                DestroyImmediate(instance.gameObject);
            }


            // attach the new one
            instance = this;

            this.mAppRect = this.GetComponent <RectTransform>();
            this.mCanvas  = this.GetComponent <Canvas>();

            if (JCS_UISettings.instance.RESIZE_UI)
            {
                // resizable UI in order to resize the UI correctly
                JCS_ResizeUI rui = JCS_Utility.SpawnGameObject(RESIZE_UI_PATH).GetComponent <JCS_ResizeUI>();
                rui.transform.SetParent(this.transform);
            }
        }
Esempio n. 5
0
 public void SetResizeUI(JCS_ResizeUI ui)
 {
     this.mResizeUI = ui;
 }