mouse event 처리 중
This commit is contained in:
81
Assets/Scripts/UVC/Factory/Alarm/AlarmManager.cs
Normal file
81
Assets/Scripts/UVC/Factory/Alarm/AlarmManager.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UVC.Factory;
|
||||
using UVC.Factory.Component;
|
||||
|
||||
namespace UVC.Factory.Alarm
|
||||
{
|
||||
public class AlarmManager : MonoBehaviour
|
||||
{
|
||||
public static AlarmManager Instance { get; private set; }
|
||||
|
||||
public GameObject alarmUIPrefab; // 알람 UI 프리팹 (아래에서 설명)
|
||||
private Dictionary<string, AlarmUIController> activeAlarmUIs = new Dictionary<string, AlarmUIController>();
|
||||
|
||||
// FactoryDataManager에서 찾을 수 있도록 참조를 저장
|
||||
private FactoryObjectManager dataManager;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
dataManager = FactoryObjectManager.Instance;
|
||||
// 예시: FactoryDataManager의 알람 이벤트에 구독
|
||||
// dataManager.OnAlarmReceived += HandleNewAlarm;
|
||||
// dataManager.OnAlarmCleared += HandleClearedAlarm;
|
||||
}
|
||||
|
||||
public void HandleNewAlarm(AlarmData data)
|
||||
{
|
||||
// 이미 해당 설비에 알람 UI가 떠 있는지 확인
|
||||
if (activeAlarmUIs.TryGetValue(data.objectId, out AlarmUIController uiController))
|
||||
{
|
||||
// 있으면 기존 UI에 알람 정보만 추가
|
||||
uiController.AddAlarm(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 없으면 새로 생성
|
||||
FactoryObject targetObject = dataManager.FindById(data.objectId);
|
||||
if (targetObject != null)
|
||||
{
|
||||
GameObject newUIObject = Instantiate(alarmUIPrefab, transform); // 매니저 하위에 생성
|
||||
AlarmUIController newUiController = newUIObject.GetComponent<AlarmUIController>();
|
||||
newUiController.Initialize(targetObject, data);
|
||||
|
||||
activeAlarmUIs.Add(data.objectId, newUiController);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleClearedAlarm(AlarmData data)
|
||||
{
|
||||
if (activeAlarmUIs.TryGetValue(data.objectId, out AlarmUIController uiController))
|
||||
{
|
||||
uiController.RemoveAlarm(data);
|
||||
if (uiController.GetAlarmCount() == 0)
|
||||
{
|
||||
activeAlarmUIs.Remove(data.objectId);
|
||||
Destroy(uiController.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 알람 데이터 전달용 클래스
|
||||
public class AlarmData
|
||||
{
|
||||
public string objectId;
|
||||
public string alarmId; // 각 알람의 고유 ID
|
||||
public string message;
|
||||
// ... 심각도, 시간 등 기타 정보
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/UVC/Factory/Alarm/AlarmManager.cs.meta
Normal file
2
Assets/Scripts/UVC/Factory/Alarm/AlarmManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6765c5d969530e44cbe4fc91d5e52ca1
|
||||
126
Assets/Scripts/UVC/Factory/Alarm/AlarmUIController.cs
Normal file
126
Assets/Scripts/UVC/Factory/Alarm/AlarmUIController.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UVC.Factory.Component;
|
||||
|
||||
namespace UVC.Factory.Alarm
|
||||
{
|
||||
public class AlarmUIController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject clusterView;
|
||||
[SerializeField] private TextMeshProUGUI alarmCountText;
|
||||
[SerializeField] private GameObject expandedView;
|
||||
[SerializeField] private GameObject singleAlarmIconPrefab; // 개별 알람 아이콘
|
||||
|
||||
private Transform targetObject;
|
||||
private List<AlarmData> alarms = new List<AlarmData>();
|
||||
private bool isExpanded = false;
|
||||
|
||||
public void Initialize(FactoryObject target, AlarmData initialAlarm)
|
||||
{
|
||||
this.targetObject = target.transform;
|
||||
AddAlarm(initialAlarm);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
// 빌보드 효과: 항상 카메라를 바라보도록 하고, 타겟 오브젝트를 따라다님
|
||||
transform.position = targetObject.position + Vector3.up * 2.0f; // 예시: 머리 위 2미터
|
||||
transform.rotation = Camera.main.transform.rotation;
|
||||
}
|
||||
|
||||
public void AddAlarm(AlarmData alarm)
|
||||
{
|
||||
alarms.Add(alarm);
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
public void RemoveAlarm(AlarmData alarm)
|
||||
{
|
||||
// 실제로는 alarmId로 찾아서 지워야 함
|
||||
alarms.Remove(alarm);
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
private void UpdateView()
|
||||
{
|
||||
if (isExpanded)
|
||||
{
|
||||
// 확장된 상태라면 개별 아이콘들을 다시 그림
|
||||
ExpandCluster();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 일반 상태
|
||||
if (alarms.Count > 1)
|
||||
{
|
||||
clusterView.SetActive(true);
|
||||
expandedView.SetActive(false); // 단일 뷰도 꺼야 함
|
||||
alarmCountText.text = alarms.Count.ToString();
|
||||
}
|
||||
else if (alarms.Count == 1)
|
||||
{
|
||||
clusterView.SetActive(false);
|
||||
expandedView.SetActive(false);
|
||||
// 여기에 단일 알람 아이콘을 보여주는 로직 추가
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick() // 이 함수를 Event Trigger 등으로 호출
|
||||
{
|
||||
if (isExpanded)
|
||||
{
|
||||
CollapseCluster();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alarms.Count > 1)
|
||||
{
|
||||
// 클러스터 확장
|
||||
CameraController.Instance.FocusOnTarget(transform, 5.0f); // 예시: 5미터 거리로 줌
|
||||
ExpandCluster();
|
||||
}
|
||||
else if (alarms.Count == 1)
|
||||
{
|
||||
// 단일 알람 클릭
|
||||
CameraController.Instance.FocusOnTarget(targetObject, 3.0f);
|
||||
// 추가로 알람 상세 정보 UI를 띄울 수 있음
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExpandCluster()
|
||||
{
|
||||
isExpanded = true;
|
||||
clusterView.SetActive(false);
|
||||
expandedView.SetActive(true);
|
||||
|
||||
// 기존 아이콘들 삭제
|
||||
foreach (Transform child in expandedView.transform)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
// 원형으로 아이콘 배치
|
||||
for (int i = 0; i < alarms.Count; i++)
|
||||
{
|
||||
float angle = i * Mathf.PI * 2f / alarms.Count;
|
||||
Vector3 pos = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0) * 0.5f; // 0.5f는 반지름
|
||||
|
||||
GameObject iconObj = Instantiate(singleAlarmIconPrefab, expandedView.transform);
|
||||
iconObj.transform.localPosition = pos;
|
||||
// iconObj의 SingleAlarmIcon 스크립트에 알람 데이터 전달
|
||||
iconObj.GetComponent<SingleAlarmIcon>().SetData(alarms[i], targetObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void CollapseCluster()
|
||||
{
|
||||
isExpanded = false;
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
public int GetAlarmCount() => alarms.Count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 773fa02b59601044b8be752f78f63e55
|
||||
25
Assets/Scripts/UVC/Factory/Alarm/SingleAlarmIcon.cs
Normal file
25
Assets/Scripts/UVC/Factory/Alarm/SingleAlarmIcon.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UVC.Factory.Alarm
|
||||
{
|
||||
public class SingleAlarmIcon : MonoBehaviour
|
||||
{
|
||||
private AlarmData myAlarmData;
|
||||
private Transform equipmentTransform;
|
||||
|
||||
public void SetData(AlarmData data, Transform equipment)
|
||||
{
|
||||
myAlarmData = data;
|
||||
equipmentTransform = equipment;
|
||||
// 아이콘 모양이나 색을 알람 심각도에 따라 변경 가능
|
||||
}
|
||||
|
||||
public void OnPointerClick()
|
||||
{
|
||||
// 클릭 시 해당 설비로 카메라 포커스
|
||||
CameraController.Instance.FocusOnTarget(equipmentTransform, 3.0f);
|
||||
Debug.Log($"알람 [{myAlarmData.message}]이 발생한 설비로 이동합니다.");
|
||||
// 여기서 알람 상세정보 패널을 띄워도 좋음
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Factory/Alarm/SingleAlarmIcon.cs.meta
Normal file
2
Assets/Scripts/UVC/Factory/Alarm/SingleAlarmIcon.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd395cde180b3094a91d87699139bbcf
|
||||
Reference in New Issue
Block a user