using System; using System.Collections.Generic; using System.Linq; using UnityEngine; // ÀÎÅÍÆäÀ̽º public interface IPathLineView { } [RequireComponent(typeof(LineRenderer))] public class PathLineView : MonoBehaviour, IPathLineView { private LineRenderer lineRenderer; void Awake() { lineRenderer = GetComponent(); // Line Renderer ±âº» ¼³Á¤ lineRenderer.startWidth = 0.01f; lineRenderer.endWidth = 0.01f; lineRenderer.material = new Material(Shader.Find("Legacy Shaders/Particles/Alpha Blended Premultiply")); lineRenderer.startColor = Color.cyan; lineRenderer.endColor = Color.cyan; } private Vector3 ConvertRobotDataToVector3(RobotData pose) { float x = Convert.ToSingle(pose.x / -1000.0); // mm -> m float y = Convert.ToSingle(pose.z / 1000.0); // Robot Z(mm) -> Unity Y(m) float z = Convert.ToSingle(pose.y / -1000.0); // Robot Y(mm) -> Unity Z(m) return new Vector3(x, y, z); } /// /// ÇÁ·Î±×·¥ÀÇ ¸ðµç Æ÷ÀÎÆ®¸¦ ¼ø¼­´ë·Î ÀÕ´Â ¼±À» ±×¸² /// public void DrawPath(List poses) { if (poses == null || poses.Count < 2) { lineRenderer.positionCount = 0; // Æ÷ÀÎÆ®°¡ 2°³ ¹Ì¸¸ÀÌ¸é ¼±À» Áö¿ò return; } Vector3[] positions = poses.Select(ConvertRobotDataToVector3).ToArray(); lineRenderer.positionCount = positions.Length; lineRenderer.SetPositions(positions); } // ½Ç½Ã°£ °æ·Î ±×¸®±â public void DrawPath(List poses, int modifiedIndex, RobotData tempPose) { if (poses == null || poses.Count < 2 || modifiedIndex < 0 || modifiedIndex >= poses.Count) { DrawPath(poses); return; } Vector3[] positions = poses.Select(ConvertRobotDataToVector3).ToArray(); positions[modifiedIndex] = ConvertRobotDataToVector3(tempPose); lineRenderer.positionCount = positions.Length; lineRenderer.SetPositions(positions); } }