2020-10-23 19:06:11 +01:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Utility;
|
2020-09-29 21:34:46 +01:00
|
|
|
|
using QSB.WorldSync;
|
2020-12-04 22:15:41 +00:00
|
|
|
|
using QuantumUNET;
|
2020-09-29 21:34:46 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.OrbSync
|
|
|
|
|
{
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public class OrbManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public static OrbManager Instance { get; private set; }
|
2020-09-29 21:34:46 +01:00
|
|
|
|
|
2020-12-18 20:28:22 +00:00
|
|
|
|
private void Awake() => Instance = this;
|
2020-09-29 21:34:46 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
private void BuildOrbSlots()
|
|
|
|
|
{
|
2020-12-11 13:14:58 +00:00
|
|
|
|
QSBWorldSync.RemoveWorldObjects<QSBOrbSlot>();
|
2020-12-02 21:29:53 +00:00
|
|
|
|
var orbSlots = Resources.FindObjectsOfTypeAll<NomaiInterfaceSlot>();
|
|
|
|
|
for (var id = 0; id < orbSlots.Length; id++)
|
|
|
|
|
{
|
2020-12-11 13:14:58 +00:00
|
|
|
|
var qsbOrbSlot = QSBWorldSync.GetWorldObject<QSBOrbSlot>(id) ?? new QSBOrbSlot();
|
2020-12-02 21:29:53 +00:00
|
|
|
|
qsbOrbSlot.Init(orbSlots[id], id);
|
|
|
|
|
}
|
2020-09-29 21:34:46 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
DebugLog.DebugWrite($"Finished orb slot build with {orbSlots.Length} slots.", MessageType.Success);
|
|
|
|
|
}
|
2020-09-29 21:34:46 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public void BuildOrbs()
|
|
|
|
|
{
|
2020-12-11 13:14:58 +00:00
|
|
|
|
QSBWorldSync.OldOrbList.Clear();
|
|
|
|
|
QSBWorldSync.OldOrbList = Resources.FindObjectsOfTypeAll<NomaiInterfaceOrb>().ToList();
|
2020-12-02 21:29:53 +00:00
|
|
|
|
if (QSBNetworkServer.active)
|
|
|
|
|
{
|
2020-12-11 13:14:58 +00:00
|
|
|
|
QSBWorldSync.OrbSyncList.ForEach(x => QSBNetworkServer.Destroy(x.gameObject));
|
|
|
|
|
QSBWorldSync.OrbSyncList.Clear();
|
|
|
|
|
QSBWorldSync.OldOrbList.ForEach(x => QSBNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.OrbPrefab)));
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2020-12-11 13:14:58 +00:00
|
|
|
|
DebugLog.DebugWrite($"Finished orb build with {QSBWorldSync.OldOrbList.Count} orbs.", MessageType.Success);
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2020-09-29 21:34:46 +01:00
|
|
|
|
|
2020-12-14 16:24:52 +00:00
|
|
|
|
public void QueueBuildSlots() => QSBCore.Helper.Events.Unity.RunWhen(() => QSBCore.HasWokenUp, BuildOrbSlots);
|
|
|
|
|
public void QueueBuildOrbs() => QSBCore.Helper.Events.Unity.RunWhen(() => QSBNetworkServer.active, BuildOrbs);
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2020-09-29 21:34:46 +01:00
|
|
|
|
}
|