quantum-space-buddies/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2020-12-24 10:06:17 +00:00
using OWML.Utils;
2020-12-24 15:57:25 +00:00
using QSB.Utility;
using UnityEngine.UI;
2020-12-23 22:43:05 +00:00
namespace QSB.QuantumSync.WorldObjects
2020-12-23 11:26:47 +00:00
{
2021-01-26 14:07:17 +00:00
internal class QSBMultiStateQuantumObject : QSBQuantumObject<MultiStateQuantumObject>
2020-12-23 11:26:47 +00:00
{
2020-12-24 10:06:17 +00:00
public QuantumState[] QuantumStates { get; private set; }
2020-12-24 15:57:25 +00:00
public Text DebugBoxText;
2020-12-24 10:06:17 +00:00
public override void OnRemoval()
{
base.OnRemoval();
if (DebugBoxText != null)
{
UnityEngine.Object.Destroy(DebugBoxText.gameObject);
}
}
2020-12-23 22:43:05 +00:00
public override void Init(MultiStateQuantumObject attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
2020-12-24 10:06:17 +00:00
QuantumStates = AttachedObject.GetValue<QuantumState[]>("_states");
2020-12-24 15:57:25 +00:00
if (QSBCore.DebugMode)
{
DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, AttachedObject.GetValue<int>("_stateIndex").ToString()).GetComponent<Text>();
}
2021-01-26 17:08:02 +00:00
base.Init(attachedObject, id);
2021-01-26 14:07:17 +00:00
}
public void ChangeState(int stateIndex)
{
var currentStateIndex = AttachedObject.GetValue<int>("_stateIndex");
if (currentStateIndex != -1)
{
QuantumStates[currentStateIndex].SetVisible(false);
}
QuantumStates[stateIndex].SetVisible(true);
AttachedObject.SetValue("_stateIndex", stateIndex);
if (QSBCore.DebugMode)
{
DebugBoxText.text = stateIndex.ToString();
}
2020-12-23 22:43:05 +00:00
}
2020-12-23 11:26:47 +00:00
}
}