87 lines
2.3 KiB
C#
87 lines
2.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
|
|
namespace CHN
|
|
{
|
|
|
|
public class Machine : MonoBehaviour
|
|
{
|
|
public string code;
|
|
public string[] typeOptions;
|
|
public UI_MachineKPI machineKPI;
|
|
public Sprite previewImage;
|
|
public Vector3 centerPos;
|
|
|
|
Renderer[] renderers;
|
|
Dictionary<Renderer, Material[]> originMaterials = new();
|
|
|
|
public Material translucentMat;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
if (!gameObject.activeSelf)
|
|
return;
|
|
GetComponentInParent<Floor>().machines.Add(this);
|
|
centerPos = transform.GetMeshGroupCenter();
|
|
renderers = GetComponentsInChildren<Renderer>();
|
|
CachingOriginMat();
|
|
|
|
translucentMat = Resources.Load<Material>("MAT_Translucent");
|
|
}
|
|
|
|
void CachingOriginMat()
|
|
{
|
|
foreach (Renderer renderer in renderers)
|
|
{
|
|
Material[] originMat = renderer.materials;
|
|
originMaterials.Add(renderer, originMat);
|
|
}
|
|
}
|
|
|
|
public void ActivateTranslucent()
|
|
{
|
|
foreach (Renderer renderer in renderers)
|
|
{
|
|
Material[] newMats = renderer.sharedMaterials;
|
|
|
|
for (int i = 0; i < newMats.Length; i++)
|
|
{
|
|
newMats[i] = translucentMat;
|
|
}
|
|
|
|
renderer.sharedMaterials = newMats;
|
|
}
|
|
}
|
|
|
|
public void DeactivateTranslucent()
|
|
{
|
|
foreach (Renderer renderer in renderers)
|
|
{
|
|
Material[] originMat = originMaterials[renderer];
|
|
renderer.sharedMaterials = originMat;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |