quantum-space-buddies/QSB/ItemSync/ItemManager.cs

85 lines
2.5 KiB
C#
Raw Normal View History

2021-02-23 14:42:18 +00:00
using OWML.Common;
using QSB.ItemSync.WorldObjects;
using QSB.Utility;
using QSB.WorldSync;
2021-02-25 13:52:49 +00:00
using System.Collections.Generic;
2021-02-23 14:42:18 +00:00
using UnityEngine;
namespace QSB.ItemSync
{
2021-02-24 10:45:25 +00:00
internal class ItemManager : MonoBehaviour
2021-02-23 14:42:18 +00:00
{
public static ItemManager Instance { get; private set; }
2021-02-25 13:52:49 +00:00
private List<ScrollItem> _oldScrollList = new List<ScrollItem>();
2021-02-23 14:42:18 +00:00
public void Awake()
{
Instance = this;
QSBSceneManager.OnUniverseSceneLoaded += RebuildItems;
}
public void OnDestroy() => QSBSceneManager.OnUniverseSceneLoaded -= RebuildItems;
public void RebuildItems(OWScene scene)
{
DebugLog.DebugWrite("Rebuilding OWItems...", MessageType.Warning);
2021-02-25 13:52:49 +00:00
_oldScrollList = QSBWorldSync.Init<QSBScrollItem, ScrollItem>();
2021-02-23 14:42:18 +00:00
QSBWorldSync.Init<QSBScrollSocket, ScrollSocket>();
}
2021-02-25 13:52:49 +00:00
public static IQSBOWItem GetObject(OWItem unityObject)
{
IQSBOWItem worldObj = null;
if (unityObject.GetType() == typeof(ScrollItem))
{
worldObj = QSBWorldSync.GetWorldFromUnity<QSBScrollItem, ScrollItem>((ScrollItem)unityObject);
}
else if (unityObject.GetType() == typeof(NomaiConversationStone))
{
//worldObj = QSBWorldSync.GetWorldFromUnity<QSBMultiStateQuantumObject, MultiStateQuantumObject>((MultiStateQuantumObject)unityObject);
}
else if (unityObject.GetType() == typeof(SharedStone))
{
//worldObj = QSBWorldSync.GetWorldFromUnity<QSBQuantumShuffleObject, QuantumShuffleObject>((QuantumShuffleObject)unityObject);
}
else if (unityObject.GetType() == typeof(WarpCoreItem))
{
//worldObj = QSBWorldSync.GetWorldFromUnity<QSBQuantumShuffleObject, QuantumShuffleObject>((QuantumShuffleObject)unityObject);
}
else
{
DebugLog.ToConsole($"Warning - couldn't work out type of OWITem {unityObject.name}.", MessageType.Warning);
}
return worldObj;
}
public static IQSBOWItemSocket GetObject(OWItemSocket unityObject)
{
IQSBOWItemSocket worldObj = null;
if (unityObject.GetType() == typeof(ScrollItem))
{
worldObj = QSBWorldSync.GetWorldFromUnity<QSBScrollSocket, ScrollSocket>((ScrollSocket)unityObject);
}
else
{
DebugLog.ToConsole($"Warning - couldn't work out type of OWITemSocket {unityObject.name}.", MessageType.Warning);
}
return worldObj;
}
public void OnRenderObject()
{
if (!QSBCore.HasWokenUp || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug)
{
return;
}
foreach (var item in _oldScrollList)
{
Popcron.Gizmos.Cube(item.transform.position, item.transform.rotation, Vector3.one, Color.blue);
}
}
2021-02-23 14:42:18 +00:00
}
}