2021-12-02 00:42:24 -08:00
|
|
|
|
using System.Collections.Generic;
|
2021-03-18 13:35:11 +00:00
|
|
|
|
using System.Linq;
|
2021-12-02 00:42:24 -08:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using QSB.WorldSync;
|
2020-12-24 15:57:25 +00:00
|
|
|
|
using UnityEngine.UI;
|
2020-12-23 22:43:05 +00:00
|
|
|
|
|
2020-12-31 12:10:55 +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
|
|
|
|
{
|
2021-03-18 13:35:11 +00:00
|
|
|
|
public List<QSBQuantumState> QuantumStates { get; private set; }
|
2020-12-24 15:57:25 +00:00
|
|
|
|
public Text DebugBoxText;
|
2021-10-16 23:35:45 +01:00
|
|
|
|
public int CurrentState => AttachedObject._stateIndex;
|
2020-12-24 10:06:17 +00:00
|
|
|
|
|
2021-02-10 20:37:42 +00:00
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
|
|
|
|
base.OnRemoval();
|
2021-02-19 21:25:17 +00:00
|
|
|
|
if (DebugBoxText != null)
|
|
|
|
|
{
|
|
|
|
|
UnityEngine.Object.Destroy(DebugBoxText.gameObject);
|
|
|
|
|
}
|
2021-02-10 20:37:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 22:43:05 +00:00
|
|
|
|
public override void Init(MultiStateQuantumObject attachedObject, int id)
|
|
|
|
|
{
|
|
|
|
|
ObjectId = id;
|
|
|
|
|
AttachedObject = attachedObject;
|
2021-10-16 23:35:45 +01:00
|
|
|
|
|
2021-11-25 22:44:15 +00:00
|
|
|
|
if (QSBCore.ShowQuantumDebugBoxes)
|
2020-12-24 15:57:25 +00:00
|
|
|
|
{
|
2021-10-16 23:35:45 +01:00
|
|
|
|
DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Multistate\r\nid:{id}\r\nstate:{CurrentState}").GetComponent<Text>();
|
2020-12-24 15:57:25 +00:00
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-01-26 17:08:02 +00:00
|
|
|
|
base.Init(attachedObject, id);
|
2021-10-16 23:35:45 +01:00
|
|
|
|
|
2021-12-02 00:42:24 -08:00
|
|
|
|
StartDelayedReady();
|
|
|
|
|
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllAdded, () =>
|
2021-10-16 23:35:45 +01:00
|
|
|
|
{
|
2021-12-02 00:42:24 -08:00
|
|
|
|
FinishDelayedReady();
|
|
|
|
|
|
|
|
|
|
QuantumStates = AttachedObject._states.Select(QSBWorldSync.GetWorldFromUnity<QSBQuantumState>).ToList();
|
|
|
|
|
|
|
|
|
|
if (QuantumStates.Any(x => x == null))
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error - {AttachedObject.name} has one or more null QSBQuantumStates assigned!", OWML.Common.MessageType.Error);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-10-16 23:35:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 17:04:57 +00:00
|
|
|
|
public void ChangeState(int newStateIndex)
|
2021-01-26 14:07:17 +00:00
|
|
|
|
{
|
2021-03-17 17:04:57 +00:00
|
|
|
|
if (CurrentState != -1)
|
2021-01-26 14:07:17 +00:00
|
|
|
|
{
|
2021-03-17 17:04:57 +00:00
|
|
|
|
QuantumStates[CurrentState].SetVisible(false);
|
2021-01-26 14:07:17 +00:00
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-03-17 17:04:57 +00:00
|
|
|
|
QuantumStates[newStateIndex].SetVisible(true);
|
2021-10-16 23:35:45 +01:00
|
|
|
|
AttachedObject._stateIndex = newStateIndex;
|
2021-11-25 22:44:15 +00:00
|
|
|
|
if (QSBCore.ShowQuantumDebugBoxes)
|
2021-01-26 14:07:17 +00:00
|
|
|
|
{
|
2021-10-16 23:35:45 +01:00
|
|
|
|
DebugBoxText.text = $"Multistate\r\nid:{ObjectId}\r\nstate:{CurrentState}";
|
2021-01-26 14:07:17 +00:00
|
|
|
|
}
|
2020-12-23 22:43:05 +00:00
|
|
|
|
}
|
2020-12-23 11:26:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|