86 lines
2.2 KiB
Plaintext
86 lines
2.2 KiB
Plaintext
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<GameObject>(MapperResourcePath).GetComponent<ODUnityObjectMapper>();
|
|
if (s_objectMapper == null)
|
|
{
|
|
Debug.LogError($"ObjectMapper not found at {MapperResourcePath}. GameplayMachines need this to save UnityObjects properly.");
|
|
}
|
|
|
|
return s_objectMapper;
|
|
}
|
|
}
|
|
|
|
public List<string> WhiteListPath = new List<string>()
|
|
{
|
|
|
|
};
|
|
|
|
public List<UnityEngine.Object> AllUnityObjects;
|
|
public List<string> AllUnityObjectGUIDs;
|
|
|
|
private Dictionary<UnityEngine.Object, string> m_dict;
|
|
private Dictionary<string, UnityEngine.Object> m_reverseDict;
|
|
private void EnsureDict()
|
|
{
|
|
if (m_dict == null || m_reverseDict == null)
|
|
{
|
|
m_dict = new Dictionary<Object, string>();
|
|
m_reverseDict = new Dictionary<string, Object>();
|
|
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;
|
|
}
|
|
}
|