Commit ada94d32 authored by 17김현학's avatar 17김현학

PathUI is placed at destination of patH

parent 9159b7bc
......@@ -3076,8 +3076,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 42}
m_SizeDelta: {x: 86.75, y: 30}
m_AnchoredPosition: {x: 0, y: 41.199997}
m_SizeDelta: {x: 100.26, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1335777782
MonoBehaviour:
......@@ -3195,9 +3195,9 @@ RectTransform:
m_Father: {fileID: 1193230061}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 164, y: 105}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -156.13002, y: -66.28998}
m_SizeDelta: {x: 312.26, y: 132.57999}
m_Pivot: {x: 0, y: 0}
--- !u!1 &1661408487
......
......@@ -24,6 +24,7 @@ public class UIManager : MonoBehaviour
private int prevSelectPathNum = -1;
private Text pathName;
private Vector3 middlePoint;
private Vector3 canvasSize;
// Start is called before the first frame update
void Start()
......@@ -31,6 +32,7 @@ public class UIManager : MonoBehaviour
_pathUI.SetActive(false);
pathName = _pathUI.transform.Find("Name").GetComponent<Text>();
middlePoint = _pathUI.transform.position;
canvasSize = new Vector3(Screen.width, Screen.height, 0);
}
// Update is called once per frame
......@@ -63,15 +65,20 @@ public class UIManager : MonoBehaviour
if (pathNum != prevSelectPathNum)
{
pathName.text = obj.name;
//_pathUI.transform.position = middlePoint;
var tmp = Camera.main.WorldToScreenPoint(hit1.point);
float width = Screen.width * _pathUI.GetComponent<RectTransform>().anchorMin.x;
float height = Screen.height * _pathUI.GetComponent<RectTransform>().anchorMin.y;
var mouseClickPosition = tmp - canvasSize * 0.5f + middlePoint;
_pathUI.GetComponent<RectTransform>().anchoredPosition = new Vector2(tmp.x - width, tmp.y - height);
// see for reference: https://sushanta1991.blogspot.com/2016/04/how-to-move-unity-ui-using-mouse.html
// Also try using Camera.WorldtoViewportPoint() and Camera.WorldtoScreenPoint() to convert world coordinates to
// normalized viewport (x,y) or pixel coordinates)
var hitVector1 = mouseClickPosition - middlePoint;
hitVector1.z = 0;
var hitVector2 = new Vector3(hit2.point.x, hit2.point.z, 0.0f);
Debug.Log(hitVector1 + "test");
Debug.Log(hitVector2 + "test");
var k = hitVector1.magnitude / hitVector2.magnitude;
Debug.Log(k + "test");
var v = square.GetDestPoint(pathNum) - hitVector2;
v.z = 0;
_pathUI.transform.position = mouseClickPosition + k * v;
_pathUI.SetActive(true);
prevSelectPathNum = pathNum;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment