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

47 lines
1.2 KiB
C#
Raw Normal View History

2021-12-07 15:56:08 +00:00
using QSB.Utility;
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
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; }
public int CurrentState => AttachedObject._stateIndex;
2020-12-24 10:06:17 +00:00
public override void Init()
2020-12-23 22:43:05 +00:00
{
base.Init();
StartDelayedReady();
QSBCore.UnityEvents.RunWhen(() => QSBWorldSync.AllObjectsAdded, () =>
{
FinishDelayedReady();
QuantumStates = AttachedObject._states.Select(QSBWorldSync.GetWorldObject<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-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);
AttachedObject._stateIndex = newStateIndex;
2020-12-23 22:43:05 +00:00
}
2020-12-23 11:26:47 +00:00
}
}