Files
HDRobotics/Assets/Scripts/View/PointManagerView.cs

71 lines
2.1 KiB
C#
Raw Normal View History

2025-11-06 20:14:27 +09:00
using System;
2025-10-30 09:31:05 +09:00
using System.Collections.Generic;
2025-11-06 20:14:27 +09:00
using UnityEditor.Experimental.GraphView;
2025-10-30 09:31:05 +09:00
using UnityEngine;
public interface IPointManagerView
{
}
public class PointManagerView : MonoBehaviour, IPointManagerView
{
2025-11-06 20:14:27 +09:00
[SerializeField] private GameObject pointPrefab;
2025-10-30 09:31:05 +09:00
private List<GameObject> activePoints = new List<GameObject>();
2025-11-06 20:14:27 +09:00
[SerializeField] public GameObject movingAlert;
[SerializeField]
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IK")]
public HybridInverseKinematicsNode kinematicsNode;
void Start()
{
movingAlert.SetActive(false);
}
2025-11-06 20:14:27 +09:00
private Vector3 ConvertRobotDataToVector3(RobotData pose)
2025-10-30 09:31:05 +09:00
{
2025-11-06 20:14:27 +09:00
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);
2025-10-30 09:31:05 +09:00
GameObject pointObj = Instantiate(pointPrefab, position, Quaternion.identity, this.transform);
activePoints.Add(pointObj);
2025-11-06 20:14:27 +09:00
RobotPoint pointComponent = pointObj.GetComponent<RobotPoint>();
if (pointComponent != null)
{
pointComponent.pointIndex = activePoints.Count - 1;
}
else
{
Debug.LogError("point<6E><74><EFBFBD><EFBFBD><EFBFBD>տ<EFBFBD> RobotPoint<6E><74>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD>");
}
2025-10-30 09:31:05 +09:00
}
public void UpdatePointPosition(int index, Vector3 pose)
2025-10-30 09:31:05 +09:00
{
if (index < 0 || index >= activePoints.Count) return;
activePoints[index].transform.position = pose;
2025-10-30 09:31:05 +09:00
}
public void DeletePoint(int index)
{
if (index < 0 || index >= activePoints.Count) return;
Destroy(activePoints[index]);
activePoints.RemoveAt(index);
}
public void RedrawPoints(List<RobotData> poses)
{
foreach (var point in activePoints) Destroy(point);
activePoints.Clear();
2025-11-06 20:14:27 +09:00
if (poses == null) return;
for (int i= 0; i < poses.Count; i++) CreatePoint(poses[i], i);
2025-10-30 09:31:05 +09:00
}
}