48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// 인터페이스
|
|
public interface IPointManagerView
|
|
{
|
|
void CreatePoint(RobotData pose);
|
|
void UpdatePointPosition(int index, RobotData pose);
|
|
void DeletePoint(int index);
|
|
void RedrawPoints(List<RobotData> poses); // (RobotProgram.Steps에서 변환)
|
|
}
|
|
|
|
public class PointManagerView : MonoBehaviour, IPointManagerView
|
|
{
|
|
[SerializeField] private GameObject pointPrefab; // 인스펙터에서 포인트 프리팹 연결
|
|
private List<GameObject> activePoints = new List<GameObject>();
|
|
|
|
public void CreatePoint(RobotData pose)
|
|
{
|
|
Vector3 position = new Vector3(pose.x, pose.y, pose.z);
|
|
GameObject pointObj = Instantiate(pointPrefab, position, Quaternion.identity, this.transform);
|
|
activePoints.Add(pointObj);
|
|
// (참고: 이 pointObj에 'InteractionView'가 감지할 수 있는 콜라이더와 스크립트가 있어야 함)
|
|
}
|
|
|
|
public void UpdatePointPosition(int index, RobotData pose)
|
|
{
|
|
if (index < 0 || index >= activePoints.Count) return;
|
|
activePoints[index].transform.position = new Vector3(pose.x, pose.y, pose.z);
|
|
}
|
|
|
|
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();
|
|
// 모든 포인트 새로 생성
|
|
foreach (var pose in poses) CreatePoint(pose);
|
|
}
|
|
}
|