bad-piggies-0.1.3-porting/Assets/Scripts/Assembly-CSharp/PartCounter.cs

45 lines
955 B
C#
Raw Normal View History

2024-02-24 22:40:44 -05:00
using UnityEngine;
public class PartCounter : MonoBehaviour
{
public BasePart.PartType m_partType;
private TextMesh m_textMesh;
private void Awake()
{
m_textMesh = GetComponent<TextMesh>();
EventManager.Connect<PartCountChanged>(ReceivePartCountChangedEvent);
}
private void OnDestroy()
{
EventManager.Disconnect<PartCountChanged>(ReceivePartCountChangedEvent);
}
private void ReceivePartCountChangedEvent(PartCountChanged data)
{
if (data.partType != m_partType)
{
return;
}
m_textMesh.text = data.count.ToString();
if (data.count == 0)
{
GameObject icon = base.transform.parent.GetComponent<DraggableButton>().Icon;
if ((bool)icon)
{
icon.renderer.material.color = new Color(0.4f, 0.4f, 0.4f, 0.4f);
}
}
else
{
GameObject icon2 = base.transform.parent.GetComponent<DraggableButton>().Icon;
if ((bool)icon2)
{
icon2.renderer.material.color = new Color(1f, 1f, 1f, 1f);
}
}
}
}