using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using UnityEngine; public class ODUnityObjectMapper : MonoBehaviour { #region Define public const string MapperResourcePath = "ODUnityExtension/ObjectMapping/ObjectMapper"; #endregion private static ODUnityObjectMapper s_objectMapper; public static ODUnityObjectMapper ObjectMapper { get { if (s_objectMapper != null) { return s_objectMapper; } s_objectMapper = Resources.Load(MapperResourcePath).GetComponent(); if (s_objectMapper == null) { Debug.LogError($"ObjectMapper not found at {MapperResourcePath}. GameplayMachines need this to save UnityObjects properly."); } return s_objectMapper; } } public List WhiteListPath = new List() { }; public List AllUnityObjects; public List AllUnityObjectGUIDs; private Dictionary m_dict; private Dictionary m_reverseDict; private void EnsureDict() { if (m_dict == null || m_reverseDict == null) { m_dict = new Dictionary(); m_reverseDict = new Dictionary(); int count = AllUnityObjects.Count; for (int i = 0; i < count; i++) { m_dict.Add(AllUnityObjects[i], AllUnityObjectGUIDs[i]); m_reverseDict.Add(AllUnityObjectGUIDs[i], AllUnityObjects[i]); } } } public string GetObjectGUID(UnityEngine.Object obj) { EnsureDict(); string result; if (!m_dict.TryGetValue(obj, out result)) { return null; } return result; } public UnityEngine.Object GetObject(string guid) { EnsureDict(); UnityEngine.Object result; if (!m_reverseDict.TryGetValue(guid, out result)) { return null; } return result; } }