2021-12-07 15:56:08 +00:00
|
|
|
|
using QSB.Utility;
|
2021-12-02 08:42:24 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-12-28 18:06:34 +00:00
|
|
|
|
using System;
|
2021-12-07 15:56:08 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
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; }
|
2021-10-16 22:35:45 +00:00
|
|
|
|
public int CurrentState => AttachedObject._stateIndex;
|
2020-12-24 10:06:17 +00:00
|
|
|
|
|
2021-12-11 22:38:54 +00:00
|
|
|
|
public override void Init()
|
2020-12-23 22:43:05 +00:00
|
|
|
|
{
|
2021-12-11 22:38:54 +00:00
|
|
|
|
base.Init();
|
2021-10-16 22:35:45 +00:00
|
|
|
|
|
2021-12-02 08:42:24 +00:00
|
|
|
|
StartDelayedReady();
|
2022-01-18 08:27:32 +00:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(() => QSBWorldSync.AllObjectsAdded, () =>
|
2021-10-16 22:35:45 +00:00
|
|
|
|
{
|
2021-12-02 08:42:24 +00:00
|
|
|
|
FinishDelayedReady();
|
|
|
|
|
|
2021-12-26 06:37:20 +00:00
|
|
|
|
QuantumStates = AttachedObject._states.Select(QSBWorldSync.GetWorldObject<QSBQuantumState>).ToList();
|
2021-12-02 08:42:24 +00:00
|
|
|
|
|
|
|
|
|
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 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 18:06:34 +00:00
|
|
|
|
public override string ReturnLabel()
|
|
|
|
|
=> $"{LogName}{Environment.NewLine}StateIndex:{AttachedObject._stateIndex}";
|
|
|
|
|
|
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 21:38:32 +00:00
|
|
|
|
|
2021-03-17 17:04:57 +00:00
|
|
|
|
QuantumStates[newStateIndex].SetVisible(true);
|
2021-10-16 22:35:45 +00:00
|
|
|
|
AttachedObject._stateIndex = newStateIndex;
|
2020-12-23 22:43:05 +00:00
|
|
|
|
}
|
2020-12-23 11:26:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|