Example #1
0
        /* Functions */

        private void Awake()
        {
            this.mSpriteRenderer = this.GetComponent <SpriteRenderer>();
            this.mAnimator       = this.GetComponent <Animator>();

            Vector2 cursorRect = JCS_Utility.GetSpriteRendererRect(mSpriteRenderer);

            mOffset.x = cursorRect.x / 2.0f;
            mOffset.y = cursorRect.y / 2.0f;

            mSpriteRenderer.sortingOrder = mOrderLayer;

#if (UNITY_EDITOR)
            mShowCursor = true;
#endif
        }
Example #2
0
        /// <summary>
        /// Check weather the "type" in the screen space. (Sprite Renderer)
        /// </summary>
        /// <param name="checkTrans"> sprite renderer to check. (Sprite width & height) </param>
        /// <returns>
        /// true: in screen space,
        /// false: not in screen space
        /// </returns>
        public bool CheckInScreenSpace(SpriteRenderer checkTrans)
        {
            Vector2 objectRect = JCS_Utility.GetSpriteRendererRect(checkTrans);

            Camera  cam    = JCS_Camera.main.GetCamera();
            Vector2 objPos = cam.WorldToViewportPoint(checkTrans.transform.position);
            Vector2 camPos = cam.WorldToViewportPoint(cam.transform.position);

            float objLeft  = objPos.x - (objectRect.x / 2);
            float objRight = objPos.x + (objectRect.x / 2);
            float objTop   = objPos.y + (objectRect.y / 2);
            float objBot   = objPos.y - (objectRect.y / 2);

            RectTransform appRect = JCS_Canvas.instance.GetAppRect();

            float camWidth  = appRect.sizeDelta.x;
            float camHeight = appRect.sizeDelta.y;

            float camLeft  = camPos.x - (camWidth / 2);
            float camRight = camPos.x + (camWidth / 2);
            float camTop   = camPos.y + (camHeight / 2);
            float camBot   = camPos.y - (camHeight / 2);

#if (UNITY_EDITOR)
            Vector3 topLeft  = new Vector3(objLeft, objTop, 0);
            Vector3 topRight = new Vector3(objRight, objTop, 0);
            Vector3 botRight = new Vector3(objRight, objBot, 0);
            Vector3 botLeft  = new Vector3(objLeft, objBot, 0);

            Debug.DrawLine(topLeft, topRight);
            Debug.DrawLine(topLeft, botLeft);
            Debug.DrawLine(botRight, botLeft);
            Debug.DrawLine(topRight, botRight);
#endif

            // TODO(JenChieh): Not done.

            if ((objRight < camLeft || objLeft > camRight) &&
                (objTop < camBot || objBot > camTop))
            {
                // out of screen.
                return(false);
            }

            return(true);
        }