public static GameObject ResolveGuid(Guid guid, Action onDestroyCallback) { if (_instance == null) { _instance = new GuidManager(); } return(_instance.ResolveGuidInternal(guid, null, onDestroyCallback)); }
public static GameObject ResolveGuid(Guid guid) { if (_instance == null) { _instance = new GuidManager(); } return(_instance.ResolveGuidInternal(guid, null, null)); }
public static GameObject ResolveGuid(Guid guid, Action <GameObject> onAddCallback, Action onRemoveCallback) { if (_instance == null) { _instance = new GuidManager(); } return(_instance.ResolveGuidInternal(guid, onAddCallback, onRemoveCallback)); }
public static void Remove(Guid guid) { if (_instance == null) { _instance = new GuidManager(); } _instance.InternalRemove(guid); }
// All the public API is static so you need not worry about creating an instance public static bool Add(GuidComponent guidComponent) { if (_instance == null) { _instance = new GuidManager(); } return(_instance.InternalAdd(guidComponent)); }
// When deserializaing or creating this component, we want to either restore our serialized GUID // or create a new one. private void CreateGuid() { // if our serialized data is invalid, then we are a new object and need a new GUID if (serializedGuid == null || serializedGuid.Length != 16) { guid = Guid.NewGuid(); serializedGuid = guid.ToByteArray(); #if UNITY_EDITOR // If we are creating a new GUID for a prefab instance of a prefab, but we have somehow lost our prefab connection // force a save of the modified prefab instance properties PrefabType prefabType = PrefabUtility.GetPrefabType(this); if (prefabType == PrefabType.PrefabInstance) { PrefabUtility.RecordPrefabInstancePropertyModifications(this); } #endif } else if (guid == Guid.Empty) { // otherwise, we should set our system guid to our serialized guid guid = new Guid(serializedGuid); } // register with the GUID Manager so that other components can access this if (guid != Guid.Empty) { if (!GuidManager.Add(this)) { // if registration fails, we probably have a duplicate or invalid GUID, get us a new one. serializedGuid = null; guid = Guid.Empty; CreateGuid(); } } }
public void OnDestroy() { GuidManager.Remove(guid); }