using System; using System.Collections.Generic; using UnityEngine; public interface IPointManagerView { } public class PointManagerView : MonoBehaviour, IPointManagerView { [SerializeField] private GameObject pointPrefab; private List activePoints = new List(); [SerializeField] public GameObject movingAlert; [SerializeField] [Tooltip("¹ÝÅõ¸í ·Îº¿ ¸ðµ¨ÀÇ IK")] public HybridInverseKinematicsNode kinematicsNode; void Start() { movingAlert.SetActive(false); } 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 CreatePoint(RobotData pose, int index) { Vector3 position = ConvertRobotDataToVector3(pose); GameObject pointObj = Instantiate(pointPrefab, position, Quaternion.identity, this.transform); activePoints.Add(pointObj); RobotPoint pointComponent = pointObj.GetComponent(); if (pointComponent != null) { pointComponent.pointIndex = activePoints.Count - 1; } else { Debug.LogError("pointÇÁ¸®ÆÕ¿¡ RobotPoint½ºÅ©¸³Æ®°¡ ¾øÀ½"); } } public void UpdatePointPosition(int index, Vector3 pose) { if (index < 0 || index >= activePoints.Count) return; activePoints[index].transform.position = pose; } public void DeletePoint(int index) { if (index < 0 || index >= activePoints.Count) return; Destroy(activePoints[index]); activePoints.RemoveAt(index); } public void RedrawPoints(List poses) { foreach (var point in activePoints) Destroy(point); activePoints.Clear(); if (poses == null) return; for (int i= 0; i < poses.Count; i++) CreatePoint(poses[i], i); } }