UI 부품에 안내선 표시

8459 단어 Unity
디자이너는 포토샵 같은 가이드가 없나요?그래서 해봤어요.
    void OnDrawGizmos ()
    {
        RectTransform rectTransform = transform as RectTransform;

        float xOffset = transform.position.x - transform.localPosition.x;
        float yOffset = transform.position.y - transform.localPosition.y;

       //左端x
        float x1 = (transform.localPosition.x - (rectTransform.sizeDelta.x * rectTransform.pivot.x) * transform.lossyScale.x) + xOffset;
       //右端x        
        float x2 = (transform.localPosition.x + (rectTransform.sizeDelta.x * (1f - rectTransform.pivot.x) * transform.lossyScale.x))+ xOffset;
       //上端y    
       float y1 = (transform.localPosition.y - (rectTransform.sizeDelta.y  * rectTransform.pivot.y) * transform.lossyScale.y) + yOffset;
    //下端y
        float y2 = (transform.localPosition.y + (rectTransform.sizeDelta.y  * (1f - rectTransform.pivot.y) * transform.lossyScale.y)) + yOffset;


        float max = 100000f;
        float min = -100000f;

        Gizmos.color = new Color32(255,0,0,100);
        Gizmos.DrawLine(new Vector3(x1,min,0f), new Vector3(x1,max,0f));
        Gizmos.DrawLine(new Vector3(x2,min,0f), new Vector3(x2,max,0f));
        Gizmos.DrawLine(new Vector3(min,y1,0f), new Vector3(max,y1,0f));
        Gizmos.DrawLine(new Vector3(min,y2,0f), new Vector3(max,y2,0f));
    }
하고 있는 일
RectTransform의 4점 좌표를 계산하여 월드 좌표로 변경한 후Gism로 그리기
결국 이런 느낌.

좋은 웹페이지 즐겨찾기