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

Adding Path UI (use dummy image)

parent 525b88d4
# ===========================
# Default Collab Ignore Rules
# ===========================
# OS Generated
# ============
.DS_Store
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
[Tt]humbs.db
[Dd]esktop.ini
# Visual Studio / MonoDevelop generated
# =====================================
[Ee]xported[Oo]bj/
*.userprefs
*.csproj
*.pidb
*.suo
*.sln
*.user
*.unityproj
*.booproj
# Unity generated
# ===============
[Oo]bj/
[Bb]uild
sysinfo.txt
*.stackdump
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6021508400235234101
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6021508400235234100}
- component: {fileID: 6021508400235234098}
- component: {fileID: 6021508400235234099}
m_Layer: 5
m_Name: PathUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6021508400235234100
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6021508400235234101}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
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: 0}
m_SizeDelta: {x: 5, y: 5}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6021508400235234098
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6021508400235234101}
m_CullTransparentMesh: 0
--- !u!114 &6021508400235234099
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6021508400235234101}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0.392}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 21300000, guid: 0905f15ba4c169d478723617ce3c4ad1, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
fileFormatVersion: 2
guid: db6831d28b87b2745b9eff23a7e565c8
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System;
public class PathRenderer : MonoBehaviour
{
[SerializeField]
Square square;
[SerializeField]
GameObject PathColliderPrefab;
LineRenderer _pathRenderer;
float _originalPathColliderY;
// Start is called before the first frame update
void Start()
{
_originalPathColliderY = PathColliderPrefab.transform.localScale.y;
_pathRenderer = GetComponent<LineRenderer>();
_ResetPaths();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(1))
{
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKey(KeyCode.LeftShift))
{
_DrawMorePath(hit.point);
}
else
{
_DrawOnePath(hit.point);
}
}
}
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
Debug.Log(hit.collider.gameObject.name);
}
}
}
private void _DrawOnePath(Vector3 point)
{
_ResetPaths();
square.pathList[0] = transform.position;
square.pathList[1] = point;
_pathRenderer.SetPositions(square.pathList.ToArray());
_InstantiatePathCollider(0);
}
private void _ResetPaths()
{
_pathRenderer.positionCount = 2;
square.pathList.Clear();
square.pathList.Add(transform.position);
square.pathList.Add(new Vector3(0, 0, 0));
_pathRenderer.SetPositions(square.pathList.ToArray());
for (int i = 0; i < transform.childCount; i++)
Destroy(transform.GetChild(i).gameObject);
}
private void _DrawMorePath(Vector3 point)
{
square.pathList.Add(point);
_pathRenderer.positionCount = square.pathList.Count();
_pathRenderer.SetPositions(square.pathList.ToArray());
_InstantiatePathCollider(square.pathList.Count() - 2);
}
private void _InstantiatePathCollider(int n)
{
var _pathCollider = Instantiate(PathColliderPrefab, transform);
_pathCollider.name = "PathCollider-" + n;
_pathCollider.transform.localScale = new Vector3(2, _originalPathColliderY, 0);
_pathCollider.transform.eulerAngles = new Vector3(0, 0,
(float)Constants.RadianToDegree(Mathf.PI / 2 +
Mathf.Atan
(square.GetTangent(
square.GetNthPath(n)))));
float _newY = square.GetNthPath(n).magnitude;
_pathCollider.transform.localScale = new Vector3(2, _newY * _originalPathColliderY, 0);
_pathCollider.transform.position = (square.pathList[n] + square.pathList[n + 1]) / 2;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.UI;
using System;
public class PathRenderer : MonoBehaviour
{
[SerializeField]
Square square;
[SerializeField]
GameObject PathColliderPrefab;
public GameObject canvas;
public GameObject pathUIPrefab;
LineRenderer _pathRenderer;
float _originalPathColliderY;
// Start is called before the first frame update
void Start()
{
_originalPathColliderY = PathColliderPrefab.transform.localScale.y;
_pathRenderer = GetComponent<LineRenderer>();
_ResetPaths();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(1))
{
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (Input.GetKey(KeyCode.LeftShift))
{
_DrawMorePath(hit.point);
}
else
{
_DrawOnePath(hit.point);
}
}
}
}
private void _DrawOnePath(Vector3 point)
{
_ResetPaths();
square.pathList[0] = transform.position;
square.pathList[1] = point;
_pathRenderer.SetPositions(square.pathList.ToArray());
_InstantiatePathCollider(0);
_InstantiatePathUI(0, point/2);
}
private void _ResetPaths()
{
_pathRenderer.positionCount = 2;
square.pathList.Clear();
square.pathList.Add(transform.position);
square.pathList.Add(new Vector3(0, 0, 0));
_pathRenderer.SetPositions(square.pathList.ToArray());
for (int i = 0; i < transform.childCount; i++)
{
Destroy(transform.GetChild(i).gameObject);
string str = "PathUI-" + i;
GameObject t = canvas.transform.FindChild(str).gameObject;
Destroy(t);
}
}
private void _DrawMorePath(Vector3 point)
{
square.pathList.Add(point);
_pathRenderer.positionCount = square.pathList.Count();
_pathRenderer.SetPositions(square.pathList.ToArray());
_InstantiatePathCollider(square.pathList.Count() - 2);
_InstantiatePathUI(square.pathList.Count() - 2, (point + square.pathList[square.pathList.Count() - 2])/2);
}
private void _InstantiatePathCollider(int n)
{
var _pathCollider = Instantiate(PathColliderPrefab, transform);
_pathCollider.name = "PathCollider-" + n;
_pathCollider.tag = "path";
_pathCollider.transform.localScale = new Vector3(2, _originalPathColliderY, 0);
_pathCollider.transform.eulerAngles = new Vector3(0, 0,
(float)Constants.RadianToDegree(Mathf.PI / 2 +
Mathf.Atan
(square.GetTangent(
square.GetNthPath(n)))));
float _newY = square.GetNthPath(n).magnitude;
_pathCollider.transform.localScale = new Vector3(2, _newY * _originalPathColliderY, 0);
_pathCollider.transform.position = (square.pathList[n] + square.pathList[n + 1]) / 2;
}
private void _InstantiatePathUI(int n, Vector3 point)
{
var _pathUI = Instantiate(pathUIPrefab);
_pathUI.transform.SetParent(canvas.transform);
_pathUI.transform.position += point;
_pathUI.name = "PathUI-" + n;
_pathUI.tag = "pathui";
_pathUI.SetActive(false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIManager : MonoBehaviour
{
public GameObject canvas;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
var obj = hit.collider.gameObject;
if (obj.tag == "path")
{
int pathNum = int.Parse(obj.name.Substring(13));
string str = "PathUI-" + pathNum;
GameObject t = canvas.transform.FindChild(str).gameObject;
if (t.activeSelf == true)
{
t.SetActive(false);
}
else
{
t.SetActive(true);
}
}
}
}
}
}
fileFormatVersion: 2
guid: 1f0e97ee5297ee342a4167b4fc9896dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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