mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-04 02:47:22 +00:00
47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using QSB.Utility;
|
|
using QSB.WorldSync;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace QSB.QuantumSync.WorldObjects
|
|
{
|
|
internal class QSBMultiStateQuantumObject : QSBQuantumObject<MultiStateQuantumObject>
|
|
{
|
|
public List<QSBQuantumState> QuantumStates { get; private set; }
|
|
public int CurrentState => AttachedObject._stateIndex;
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
|
|
StartDelayedReady();
|
|
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.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);
|
|
}
|
|
});
|
|
}
|
|
|
|
public override string ReturnLabel()
|
|
=> $"{LogName}{Environment.NewLine}StateIndex:{AttachedObject._stateIndex}";
|
|
|
|
public void ChangeState(int newStateIndex)
|
|
{
|
|
if (CurrentState != -1)
|
|
{
|
|
QuantumStates[CurrentState].SetVisible(false);
|
|
}
|
|
|
|
QuantumStates[newStateIndex].SetVisible(true);
|
|
AttachedObject._stateIndex = newStateIndex;
|
|
}
|
|
}
|
|
}
|