public virtual bool ChangeSizeWindow() { if (dragIndex >= 0) { Vector2 lastPos = currRect.position; transform.SetAsLastSibling(); Vector2 delta = UIScreenTool.ScreenToUIPos(canvas, new Vector2(Input.mousePosition.x, Input.mousePosition.y)) - UIScreenTool.ScreenToUIPos(canvas, lastSizePos); if (dragIndex == 0 || dragIndex == 2 || dragIndex == 4) { if (currRect.rect.width - 20 > delta.x * 1 / currRect.transform.lossyScale.x) //currRect.anchoredPosition.x + delta.x >= 0) { currRect.position += delta.x * Vector3.right * (1 - currRect.pivot.x); currSize -= delta.x * Vector2.right * 1 / currRect.transform.lossyScale.x; } } else if (dragIndex == 1 || dragIndex == 3 || dragIndex == 5) { //currRect.anchoredPosition += delta.x * Vector2.right; if (currRect.rect.width - 20 > -delta.x * 1 / currRect.transform.lossyScale.x) //currRect.anchoredPosition.x + currRect.sizeDelta.x + delta.x < 1080) { currRect.position += delta.x * Vector3.right * (1 - currRect.pivot.x); currSize += delta.x * Vector2.right * 1 / currRect.transform.lossyScale.x; } } if (dragIndex == 0 || dragIndex == 1 || dragIndex == 6) { if (currRect.rect.height - 50 > -delta.y * 1 / currRect.transform.lossyScale.y) //currRect.anchoredPosition.y + currRect.sizeDelta.y + delta.y < 1080) { currRect.position += delta.y * Vector3.up * (1 - currRect.pivot.y); currSize += delta.y * Vector2.up * 1 / currRect.transform.lossyScale.y; } } else if (dragIndex == 2 || dragIndex == 3 || dragIndex == 7) { if (currRect.rect.height - 50 > delta.y * 1 / currRect.transform.lossyScale.y) //currRect.anchoredPosition.y + delta.y >= 0) { currRect.position += delta.y * Vector3.up * (1 - currRect.pivot.y); currSize -= delta.y * Vector2.up * 1 / currRect.transform.lossyScale.y; } } if (currSize.x < minSize.x) { currSize.x = minSize.x; } if (currSize.y < minSize.y) { currSize.y = minSize.y; } currRect.sizeDelta = currSize; lastSizePos = Input.mousePosition; return(true); } return(false); }
void Start() { if (PlayerPrefs.HasKey("RuleElem_" + id + "_x")) { Rect screenRect = new Rect(PlayerPrefs.GetFloat("RuleElem_" + id + "_x"), PlayerPrefs.GetFloat("RuleElem_" + id + "_y"), PlayerPrefs.GetFloat("RuleElem_" + id + "_width"), PlayerPrefs.GetFloat("RuleElem_" + id + "_height")); screenRect.height *= 1f * Screen.width / Screen.height; UIScreenTool.ScreenToUIRect(canvas, screenRect, GetComponent <RectTransform>(), true); } }
private void SaveCoord() { Rect rect = UIScreenTool.UIToScreenRect(canvas, currRect); rect.height = rect.height * Screen.height / Screen.width; PlayerPrefs.SetFloat("RuleElem_" + id + "_x", rect.x); PlayerPrefs.SetFloat("RuleElem_" + id + "_y", rect.y); PlayerPrefs.SetFloat("RuleElem_" + id + "_width", rect.width); PlayerPrefs.SetFloat("RuleElem_" + id + "_height", rect.height); }
public virtual void Update() { ChangeSizeBorder(); Move(); ChangeSizeWindow(); if (isRotate) { Rect rect = UIScreenTool.UIToScreenRect(canvas, currRect); transform.rotation = new Quaternion((rect.y + rect.height / 2 - 0.5f) / 4, (rect.x + rect.width / 2 - 0.5f) / 2, 0, 1); } }
public static Rect UIToScreenRect(Canvas canvas, RectTransform rectTrans) { Vector2 pos = UIScreenTool.UIToScreenPos(canvas, rectTrans.position); Vector2 size = rectTrans.rect.size;// new Vector2(rectTrans.rect.width, rectTrans.rect.height); size = new Vector2(size.x * canvas.transform.lossyScale.x, size.y * canvas.transform.lossyScale.y); size = UIScreenTool.UIToScreenPos(canvas, pos + size) - UIScreenTool.UIToScreenPos(canvas, pos); pos = new Vector2(pos.x - rectTrans.pivot.x * size.x, pos.y - rectTrans.pivot.y * size.y); return(new Rect(pos.x / Screen.width, pos.y / Screen.height, size.x / Screen.width, size.y / Screen.height)); }
public virtual bool Move() { if (isDrag && dragIndex == -1) { transform.SetAsLastSibling(); Vector3 delta = UIScreenTool.ScreenToUIPos(canvas, new Vector2(Input.mousePosition.x, Input.mousePosition.y)) - UIScreenTool.ScreenToUIPos(canvas, lastMovePos); if (true /*currRect.anchoredPosition.x + delta.x >= 0 && currRect.anchoredPosition.y + delta.y >= 0 && * currRect.anchoredPosition.x + currRect.sizeDelta.x + delta.x < 1080 && * currRect.anchoredPosition.y + currRect.sizeDelta.y + delta.y < 1080*/) { currRect.position += delta; } lastMovePos = Input.mousePosition; return(true); } return(false); }