Files
ChunilENG/Assets/Scripts/Machine.cs
2025-11-21 13:07:13 +09:00

100 lines
2.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using WI;
namespace CHN
{
[Serializable]
public class Machine : MonoBehaviour
{
public string machineName;
public string code;
public string[] typeOptions;
public UI_MachineKPI machineKPI;
public Sprite previewImage;
public Vector3 centerPos;
public Vector3 originScale;
public Animator[] animators;
public HighLighter highLighter;
public float animSpeed;
public float focusDistance;
public float focusAzimuth;
public float focusElevation;
public override void AfterAwake()
{
if (!gameObject.activeSelf)
return;
GetComponentInParent<Floor>().machines.Add(this);
centerPos = transform.GetMeshGroupCenter();
animators = GetComponentsInChildren<Animator>();
highLighter = GetComponentInChildren<HighLighter>(true);
originScale = gameObject.transform.localScale;
}
public void SetAnimationSpeed()
{
if (animators.Length == 0)
return;
if (machineKPI != null)
{
if (machineKPI.data.machineInfo.statusnm == null)
{
animSpeed = 0f;
}
if (machineKPI.data.machineInfo.statusnm == "°¡µ¿Áß")
{
animSpeed = UnityEngine.Random.Range(0.7f, 1.5f);
}
else
{
animSpeed = 0f;
}
foreach(var animator in animators)
{
animator.speed = animSpeed;
}
}
}
public void ActiveHighLighter()
{
highLighter.gameObject.SetActive(true);
}
public void DeactiveHighLighter()
{
highLighter.gameObject.SetActive(false);
}
public int GetMachineFloorIndex()
{
Transform currentParent = transform.parent;
while (currentParent != null)
{
Floor myFloor = currentParent.GetComponent<Floor>();
if (myFloor != null)
{
return myFloor.floorIndex;
}
currentParent = currentParent.parent;
}
return 0;
}
}
}