Commit 4cd68997 authored by 18김민수's avatar 18김민수

Seperated "Square.cs" and "PathRenderer.cs".

parent 7c42f50b
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class PathRenderer : MonoBehaviour
{
[SerializeField]
Square square;
LineRenderer _pathRenderer;
float _zPosition => square.transform.position.z;
// Start is called before the first frame update
void Start()
{
_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))
{
Debug.Log("asdf");
_DrawMorePath(hit.point);
}
else
{
_DrawOnePath(hit.point);
}
}
}
}
private void _DrawOnePath(Vector3 point)
{
_ResetPaths();
point.z = _zPosition;
square.pathList[0] = transform.position;
square.pathList[1] = point;
_pathRenderer.SetPositions(square.pathList.ToArray());
}
private void _ResetPaths()
{
_pathRenderer.positionCount = 2;
square.pathList.Clear();
square.pathList.Add(transform.position);
square.pathList.Add(new Vector3(0, 0, _zPosition));
_pathRenderer.SetPositions(square.pathList.ToArray());
}
private void _DrawMorePath(Vector3 point)
{
point.z = _zPosition;
square.pathList.Add(point);
_pathRenderer.positionCount = square.pathList.Count();
_pathRenderer.SetPositions(square.pathList.ToArray());
}
}
fileFormatVersion: 2
guid: 8f30fcfb85a9c704291c91129b0b8f0c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,61 +6,6 @@ using System.Linq;
public class Square : FlatLandObject
{
public LineRenderer pathRenderer; // About drawing paths.
public List<Vector3> pathList = new List<Vector3>();
private float _zPosition => transform.position.z;
private void Awake()
{
_ResetPaths();
}
private 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))
{
Debug.Log("asdf");
_DrawMorePath(hit.point);
}
else
{
_DrawOnePath(hit.point);
}
}
}
}
private void _DrawOnePath(Vector3 point)
{
_ResetPaths();
point.z = _zPosition;
pathList[0] = transform.position;
pathList[1] = point;
pathRenderer.SetPositions(pathList.ToArray());
}
private void _ResetPaths()
{
pathRenderer.positionCount = 2;
pathList.Clear();
pathList.Add(transform.position);
pathList.Add(new Vector3(0, 0, _zPosition));
pathRenderer.SetPositions(pathList.ToArray());
}
private void _DrawMorePath(Vector3 point)
{
point.z = _zPosition;
pathList.Add(point);
pathRenderer.positionCount = pathList.Count();
pathRenderer.SetPositions(pathList.ToArray());
}
}
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