Commit 12b7ef47 authored by 17김현학's avatar 17김현학

the velocity in path UI can be changed by VelocitySlider

parent 33986f26
...@@ -2267,8 +2267,8 @@ RectTransform: ...@@ -2267,8 +2267,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -79.45001, y: -10.799988} m_AnchoredPosition: {x: -39.634995, y: -10.799988}
m_SizeDelta: {x: 99.9, y: 30} m_SizeDelta: {x: 179.53, y: 30}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1034884447 --- !u!114 &1034884447
MonoBehaviour: MonoBehaviour:
...@@ -2630,8 +2630,8 @@ RectTransform: ...@@ -2630,8 +2630,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -79.45, y: 19.2} m_AnchoredPosition: {x: -39.635002, y: 19.199997}
m_SizeDelta: {x: 99.9, y: 30} m_SizeDelta: {x: 179.53, y: 30}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1165269553 --- !u!114 &1165269553
MonoBehaviour: MonoBehaviour:
......
...@@ -10,7 +10,6 @@ public class LogScaleSlider : MonoBehaviour ...@@ -10,7 +10,6 @@ public class LogScaleSlider : MonoBehaviour
Scrollbar slider; Scrollbar slider;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
...@@ -28,4 +27,9 @@ public class LogScaleSlider : MonoBehaviour ...@@ -28,4 +27,9 @@ public class LogScaleSlider : MonoBehaviour
text.text = GetLogScaleValue() + "c"; text.text = GetLogScaleValue() + "c";
} }
public void UpdateValuebyVelocity(float v)
{
slider.value = Mathf.Log10(1 - v) * -0.2f;
}
} }
...@@ -25,4 +25,9 @@ public class Square : FlatLandObject ...@@ -25,4 +25,9 @@ public class Square : FlatLandObject
{ {
return pathList[n+1]; return pathList[n+1];
} }
public float GetPathVeclocity(int n)
{
return pathVelocity[n + 1];
}
} }
\ No newline at end of file
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine.EventSystems;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System; using System;
...@@ -11,6 +12,8 @@ public class UIManager : MonoBehaviour ...@@ -11,6 +12,8 @@ public class UIManager : MonoBehaviour
Square square; Square square;
[SerializeField] [SerializeField]
Camera playercamera; Camera playercamera;
[SerializeField]
LogScaleSlider velocityslider;
public Canvas canvas; public Canvas canvas;
public Text mytime; public Text mytime;
...@@ -21,18 +24,28 @@ public class UIManager : MonoBehaviour ...@@ -21,18 +24,28 @@ public class UIManager : MonoBehaviour
public Text wintext; public Text wintext;
public GameObject _pathUI; public GameObject _pathUI;
public LevelManager Levelmanager; public LevelManager Levelmanager;
private int prevSelectPathNum = -1; private int prevSelectPathNum = -1;
private Text pathName; private Text pathName;
private Text pathVeclocity;
private Vector3 middlePoint; private Vector3 middlePoint;
private Vector3 canvasSize; private Vector3 canvasSize;
private int sliderflag = 0;
GraphicRaycaster gr;
PointerEventData ped;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
_pathUI.SetActive(false); _pathUI.SetActive(false);
pathName = _pathUI.transform.Find("Name").GetComponent<Text>(); pathName = _pathUI.transform.Find("Name").GetComponent<Text>();
pathVeclocity = _pathUI.transform.Find("Velocity").GetComponent<Text>();
middlePoint = _pathUI.transform.position; middlePoint = _pathUI.transform.position;
canvasSize = new Vector3(Screen.width, Screen.height, 0); canvasSize = new Vector3(Screen.width, Screen.height, 0);
gr = canvas.GetComponent<GraphicRaycaster>();
ped = new PointerEventData(null);
} }
// Update is called once per frame // Update is called once per frame
...@@ -47,59 +60,105 @@ public class UIManager : MonoBehaviour ...@@ -47,59 +60,105 @@ public class UIManager : MonoBehaviour
} }
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0))
{ {
RaycastHit hit1; ped.position = Input.mousePosition;
RaycastHit hit2; List<RaycastResult> results = new List<RaycastResult>();
var ray = Camera.main.ScreenPointToRay(Input.mousePosition); gr.Raycast(ped, results);
if (results.Count != 0)
if (Physics.Raycast(ray, out hit1))
{ {
ray = playercamera.ViewportPointToRay(hit1.textureCoord); GameObject obj = results[0].gameObject;
if (Physics.Raycast(ray, out hit2))
if(obj.tag == "VelocitySlider")
{ {
var obj = hit2.collider.gameObject; sliderflag = 1;
if (_pathUI.activeSelf == true && prevSelectPathNum != -1)
{
square.pathVelocity[prevSelectPathNum + 1] = velocityslider.GetLogScaleValue();
pathVeclocity.text = "Velocity: " + square.GetPathVeclocity(prevSelectPathNum).ToString() + "c";
}
}
}
else
{
RaycastHit hit1;
RaycastHit hit2;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (obj.tag == "path") if (Physics.Raycast(ray, out hit1))
{
ray = playercamera.ViewportPointToRay(hit1.textureCoord);
if (Physics.Raycast(ray, out hit2))
{ {
int pathNum = int.Parse(obj.name.Substring(13)); var obj = hit2.collider.gameObject;
if (pathNum != prevSelectPathNum) if (obj.tag == "path")
{ {
pathName.text = obj.name; int pathNum = int.Parse(obj.name.Substring(13));
var tmp = Camera.main.WorldToScreenPoint(hit1.point);
var mouseClickPosition = tmp - canvasSize * 0.5f + middlePoint; if (pathNum != prevSelectPathNum)
{
var hitVector1 = mouseClickPosition - middlePoint; updatePathInfo(obj, pathNum);
hitVector1.z = 0;
var hitVector2 = new Vector3(hit2.point.x, hit2.point.z, 0.0f); var mouseClickPosition = getMouseClickPosition(hit1);
Debug.Log(hitVector1 + "test"); var v = getDestVector(mouseClickPosition - middlePoint, new Vector3(hit2.point.x, hit2.point.z, 0.0f), pathNum);
Debug.Log(hitVector2 + "test");
var k = hitVector1.magnitude / hitVector2.magnitude; _pathUI.transform.position = mouseClickPosition + v;
Debug.Log(k + "test"); _pathUI.SetActive(true);
var v = square.GetDestPoint(pathNum) - hitVector2;
v.z = 0; prevSelectPathNum = pathNum;
}
_pathUI.transform.position = mouseClickPosition + k * v; else
_pathUI.SetActive(true); {
prevSelectPathNum = pathNum; _pathUI.SetActive(false);
prevSelectPathNum = -1;
sliderflag = 0;
}
} }
else else
{ {
_pathUI.SetActive(false); _pathUI.SetActive(false);
prevSelectPathNum = -1; prevSelectPathNum = -1;
sliderflag = 0;
} }
} }
else
{
_pathUI.SetActive(false);
prevSelectPathNum = -1;
}
} }
} }
} }
else if(sliderflag == 1 && Input.GetMouseButton(0))
{
if (_pathUI.activeSelf == true && prevSelectPathNum != -1)
{
square.pathVelocity[prevSelectPathNum + 1] = velocityslider.GetLogScaleValue();
pathVeclocity.text = "Velocity: " + square.GetPathVeclocity(prevSelectPathNum).ToString() + "c";
}
}
else if (Input.GetMouseButtonDown(1)) else if (Input.GetMouseButtonDown(1))
{ {
_pathUI.SetActive(false); _pathUI.SetActive(false);
prevSelectPathNum = -1; prevSelectPathNum = -1;
sliderflag = 0;
} }
} }
private Vector3 getMouseClickPosition(RaycastHit hit)
{
var tmp = Camera.main.WorldToScreenPoint(hit.point);
return tmp - canvasSize * 0.5f + middlePoint;
}
private Vector3 getDestVector(Vector3 hitVector1, Vector3 hitVector2, int pathNum)
{
hitVector1.z = 0;
var v = square.GetDestPoint(pathNum) - hitVector2;
var k = hitVector1.magnitude / hitVector2.magnitude;
return k * v;
}
private void updatePathInfo(GameObject obj, int pathNum)
{
pathName.text = obj.name;
pathVeclocity.text = "Velocity: " + square.GetPathVeclocity(pathNum).ToString() + "c";
velocityslider.UpdateValuebyVelocity(square.GetPathVeclocity(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