GetSpriteRendererRect() public static method

Returns the size of the sprite renderer.
public static GetSpriteRendererRect ( SpriteRenderer sr ) : Vector2
sr SpriteRenderer
return Vector2
コード例 #1
0
        /* Functions */

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

            Vector2 cursorRect = JCS_Util.GetSpriteRendererRect(mSpriteRenderer);

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

            mSpriteRenderer.sortingOrder = mOrderLayer;

#if (UNITY_EDITOR)
            mShowCursor = true;
#endif
        }
コード例 #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_Util.GetSpriteRendererRect(checkTrans);

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

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

            RectTransform appRect = JCS_Canvas.GuessCanvas().AppRect;

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

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

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

            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);
        }