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 code; public string[] typeOptions; public UI_MachineKPI machineKPI; public Sprite previewImage; public Vector3 centerPos; public Animator animator; public HighLighter highLighter; public float animSpeed; public override void AfterAwake() { if (!gameObject.activeSelf) return; GetComponentInParent().machines.Add(this); centerPos = transform.GetMeshGroupCenter(); animator = GetComponentInChildren(); highLighter = GetComponentInChildren(true); } public void SetAnimationSpeed() { if (machineKPI != null) { float.TryParse(machineKPI.data.eorate, out var eorate); animSpeed = eorate / 100f; 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(); if (myFloor != null) { return myFloor.floorIndex; } currentParent = currentParent.parent; } return 0; } } }