Files
EnglewoodLAB/Assets/Scripts/Objects/Machine.cs
SOOBEEN HAN f1894889ee <refactor> Octopus Twin 템플릿 적용
- 기능 외 UI 구조만 적용
- 프로젝트에 걸맞는 UI는 재작업 필요
2026-02-23 18:20:09 +09:00

128 lines
3.0 KiB
C#

using System;
using UnityEngine;
using EnglewoodLAB.Extensions;
using EnglewoodLAB.UI;
using Cysharp.Threading.Tasks;
namespace EnglewoodLAB
{
[Serializable]
public class Machine : MonoBehaviour
{
public string machineName;
public string code;
public string[] typeOptions;
public MachineInfoItem machineKPI;
public Sprite previewImage;
public Vector3 centerPos;
public Vector3 originScale;
public Animator[] animators;
public float animSpeed;
public float focusDistance;
public float focusAzimuth;
public float focusElevation;
private void Start()
{
animators = GetComponentsInChildren<Animator>();
ReleaseAnimators();
}
public async UniTask Init()
{
centerPos = transform.GetMeshCenter();
originScale = gameObject.transform.localScale;
AssignAnimators();
await UniTask.CompletedTask;
}
public void AssignAnimators()
{
if (animators == null) return;
foreach (var animator in animators)
{
if (animator != null) animator.enabled = true;
}
SetAnimationSpeed();
}
public void ReleaseAnimators()
{
if (animators == null) return;
foreach (var animator in animators)
{
if (animator != null) animator.enabled = false;
}
}
public void SetAnimationSpeed()
{
if (animators.Length == 0)
return;
if (machineKPI != null)
{
if (machineKPI.data.statusnm == null)
{
animSpeed = 0f;
}
if (machineKPI.data.statusnm == "가동중")
{
animSpeed = UnityEngine.Random.Range(0.7f, 1.5f);
}
else
{
animSpeed = 0f;
}
foreach (var animator in animators)
{
animator.speed = animSpeed;
}
}
}
//public void ActiveHighLighter()
//{
// if (highLighter == null)
// return;
// highLighter.gameObject.SetActive(true);
//}
//public void DeactiveHighLighter()
//{
// if (highLighter == null)
// return;
// highLighter.gameObject.SetActive(false);
//}
public int GetMachineFloorIndex()
{
Transform currentParent = transform.parent;
while (currentParent != null)
{
Floor myFloor = currentParent.GetComponent<Floor>();
if (myFloor != null)
{
return myFloor.index;
}
currentParent = currentParent.parent;
}
return 0;
}
}
}