Files
ChunilENG/Assets/Scripts/Machine.cs
2025-04-24 08:36:29 +09:00

78 lines
2.0 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 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<Floor>().machines.Add(this);
centerPos = transform.GetMeshGroupCenter();
animator = GetComponentInChildren<Animator>();
highLighter = GetComponentInChildren<HighLighter>(true);
}
public void SetAnimationSpeed()
{
if (machineKPI != null)
{
if (machineKPI.data.kpiDataInfo.eorate == null)
return;
float.TryParse(machineKPI.data.kpiDataInfo.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<Floor>();
if (myFloor != null)
{
return myFloor.floorIndex;
}
currentParent = currentParent.parent;
}
return 0;
}
}
}