using OWML.Common; using QSB.ItemSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; using UnityEngine; namespace QSB.ItemSync { internal class ItemManager : MonoBehaviour { public static ItemManager Instance { get; private set; } 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); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); foreach (var streaming in Resources.FindObjectsOfTypeAll()) { streaming.gameObject.AddComponent(); streaming.enabled = false; DebugLog.DebugWrite($"Adding custom streaming to {streaming.name}"); } foreach (var camera in Resources.FindObjectsOfTypeAll()) { camera.gameObject.AddComponent(); camera.enabled = false; DebugLog.DebugWrite($"Adding custom camera to {camera.name}"); } foreach (var platform in Resources.FindObjectsOfTypeAll()) { platform.gameObject.AddComponent(); platform.enabled = false; DebugLog.DebugWrite($"Adding custom platform to {platform.name}"); } } public static IQSBOWItem GetObject(OWItem unityObject) { if (unityObject == null) { return default; } IQSBOWItem worldObj = null; if (unityObject.GetType() == typeof(ScrollItem)) { worldObj = QSBWorldSync.GetWorldFromUnity((ScrollItem)unityObject); } else if (unityObject.GetType() == typeof(SharedStone)) { worldObj = QSBWorldSync.GetWorldFromUnity((SharedStone)unityObject); } else if (unityObject.GetType() == typeof(WarpCoreItem)) { worldObj = QSBWorldSync.GetWorldFromUnity((WarpCoreItem)unityObject); } else if (unityObject.GetType() == typeof(NomaiConversationStone)) { worldObj = QSBWorldSync.GetWorldFromUnity((NomaiConversationStone)unityObject); } else { DebugLog.ToConsole($"Warning - couldn't work out type of OWItem {unityObject.name}.", MessageType.Warning); } return worldObj; } public static IQSBOWItemSocket GetObject(OWItemSocket unityObject) { if (unityObject == null) { return default; } IQSBOWItemSocket worldObj = null; if (unityObject.GetType() == typeof(ScrollSocket)) { worldObj = QSBWorldSync.GetWorldFromUnity((ScrollSocket)unityObject); } else if (unityObject.GetType() == typeof(SharedStoneSocket)) { worldObj = QSBWorldSync.GetWorldFromUnity((SharedStoneSocket)unityObject); } else if (unityObject.GetType() == typeof(WarpCoreSocket)) { worldObj = QSBWorldSync.GetWorldFromUnity((WarpCoreSocket)unityObject); } else if (unityObject.GetType() == typeof(NomaiConversationStone)) { worldObj = QSBWorldSync.GetWorldFromUnity((NomaiConversationStoneSocket)unityObject); } else { DebugLog.ToConsole($"Warning - couldn't work out type of OWItemSocket {unityObject.name}.", MessageType.Warning); } return worldObj; } } }