2020-10-23 19:06:11 +01:00
|
|
|
|
using OWML.Common;
|
2021-01-26 14:07:17 +00:00
|
|
|
|
using OWML.Utils;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.OrbSync.WorldObjects;
|
2020-10-23 19:06:11 +01:00
|
|
|
|
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-24 09:41:38 +01:00
|
|
|
|
QSBWorldSync.RemoveWorldObjects<QSBOrbSlot>();
|
2020-12-23 22:43:05 +00:00
|
|
|
|
QSBWorldSync.Init<QSBOrbSlot, NomaiInterfaceSlot>();
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
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-23 12:58:45 +00:00
|
|
|
|
if (QNetworkServer.active)
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2020-12-23 12:58:45 +00:00
|
|
|
|
QSBWorldSync.OrbSyncList.ForEach(x => QNetworkServer.Destroy(x.gameObject));
|
2020-12-11 13:14:58 +00:00
|
|
|
|
QSBWorldSync.OrbSyncList.Clear();
|
2020-12-23 12:58:45 +00:00
|
|
|
|
QSBWorldSync.OldOrbList.ForEach(x => QNetworkServer.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
|
|
|
|
|
2021-01-26 14:07:17 +00:00
|
|
|
|
public void OnRenderObject()
|
|
|
|
|
{
|
|
|
|
|
if (!QSBCore.HasWokenUp || !QSBCore.DebugMode)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var orb in QSBWorldSync.OldOrbList)
|
|
|
|
|
{
|
|
|
|
|
Popcron.Gizmos.Cube(orb.transform.position, orb.transform.rotation, Vector3.one / 3);
|
|
|
|
|
|
|
|
|
|
var rails = orb.GetValue<OWRail[]>("_safetyRails");
|
|
|
|
|
if (rails.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var rail in rails)
|
|
|
|
|
{
|
|
|
|
|
var points = rail.GetValue<Vector3[]>("_railPoints");
|
|
|
|
|
for (var i = 0; i < points.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i > 0)
|
|
|
|
|
{
|
|
|
|
|
Popcron.Gizmos.Line(rail.transform.TransformPoint(points[i - 1]), rail.transform.TransformPoint(points[i]), Color.white);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 16:24:52 +00:00
|
|
|
|
public void QueueBuildSlots() => QSBCore.Helper.Events.Unity.RunWhen(() => QSBCore.HasWokenUp, BuildOrbSlots);
|
2020-12-23 12:58:45 +00:00
|
|
|
|
public void QueueBuildOrbs() => QSBCore.Helper.Events.Unity.RunWhen(() => QNetworkServer.active, BuildOrbs);
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2020-09-29 21:34:46 +01:00
|
|
|
|
}
|