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:
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: -79.45001, y: -10.799988}
m_SizeDelta: {x: 99.9, y: 30}
m_AnchoredPosition: {x: -39.634995, y: -10.799988}
m_SizeDelta: {x: 179.53, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1034884447
MonoBehaviour:
......@@ -2630,8 +2630,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: -79.45, y: 19.2}
m_SizeDelta: {x: 99.9, y: 30}
m_AnchoredPosition: {x: -39.635002, y: 19.199997}
m_SizeDelta: {x: 179.53, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1165269553
MonoBehaviour:
......
......@@ -10,7 +10,6 @@ public class LogScaleSlider : MonoBehaviour
Scrollbar slider;
// Start is called before the first frame update
void Start()
{
......@@ -28,4 +27,9 @@ public class LogScaleSlider : MonoBehaviour
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
{
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.Generic;
using UnityEngine.EventSystems;
using UnityEngine;
using UnityEngine.UI;
using System;
......@@ -11,6 +12,8 @@ public class UIManager : MonoBehaviour
Square square;
[SerializeField]
Camera playercamera;
[SerializeField]
LogScaleSlider velocityslider;
public Canvas canvas;
public Text mytime;
......@@ -21,18 +24,28 @@ public class UIManager : MonoBehaviour
public Text wintext;
public GameObject _pathUI;
public LevelManager Levelmanager;
private int prevSelectPathNum = -1;
private Text pathName;
private Text pathVeclocity;
private Vector3 middlePoint;
private Vector3 canvasSize;
private int sliderflag = 0;
GraphicRaycaster gr;
PointerEventData ped;
// Start is called before the first frame update
void Start()
{
_pathUI.SetActive(false);
pathName = _pathUI.transform.Find("Name").GetComponent<Text>();
pathVeclocity = _pathUI.transform.Find("Velocity").GetComponent<Text>();
middlePoint = _pathUI.transform.position;
canvasSize = new Vector3(Screen.width, Screen.height, 0);
gr = canvas.GetComponent<GraphicRaycaster>();
ped = new PointerEventData(null);
}
// Update is called once per frame
......@@ -47,59 +60,105 @@ public class UIManager : MonoBehaviour
}
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit1;
RaycastHit hit2;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit1))
ped.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
gr.Raycast(ped, results);
if (results.Count != 0)
{
ray = playercamera.ViewportPointToRay(hit1.textureCoord);
if (Physics.Raycast(ray, out hit2))
GameObject obj = results[0].gameObject;
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;
var tmp = Camera.main.WorldToScreenPoint(hit1.point);
var mouseClickPosition = tmp - canvasSize * 0.5f + middlePoint;
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;
int pathNum = int.Parse(obj.name.Substring(13));
if (pathNum != prevSelectPathNum)
{
updatePathInfo(obj, pathNum);
var mouseClickPosition = getMouseClickPosition(hit1);
var v = getDestVector(mouseClickPosition - middlePoint, new Vector3(hit2.point.x, hit2.point.z, 0.0f), pathNum);
_pathUI.transform.position = mouseClickPosition + v;
_pathUI.SetActive(true);
prevSelectPathNum = pathNum;
}
else
{
_pathUI.SetActive(false);
prevSelectPathNum = -1;
sliderflag = 0;
}
}
else
{
_pathUI.SetActive(false);
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))
{
_pathUI.SetActive(false);
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