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 onDestroyCallback)
        {
            if (_instance == null)
            {
                _instance = new GuidManager();
            }

            return(_instance.ResolveGuidInternal(guid, null, onDestroyCallback));
        }
        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));
        }
Exemple #6
0
        public static void Remove(System.Guid guid)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            Instance.InternalRemove(guid);
        }
Exemple #7
0
        // When de-serializing 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)
            {
#if UNITY_EDITOR
                // if in editor, make sure we aren't a prefab of some kind
                if (IsAssetOnDisk())
                {
                    return;
                }

                Undo.RecordObject(this, "Added GUID");
#endif
                _guid          = System.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
                if (PrefabUtility.IsPartOfNonAssetPrefabInstance(this))
                {
                    PrefabUtility.RecordPrefabInstancePropertyModifications(this);
                }
#endif
            }
            else if (_guid == System.Guid.Empty)
            {
                // otherwise, we should set our system guid to our serialized guid
                _guid = new System.Guid(serializedGuid);
            }

            // register with the GUID Manager so that other components can access this
            if (_guid != System.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          = System.Guid.Empty;
                    CreateGuid();
                }
            }
        }
Exemple #8
0
        // 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();
                }
            }
        }
Exemple #9
0
 // let the manager know we are gone, so other objects no longer find this
 public void OnDestroy()
 {
     GuidManager.Remove(_guid);
 }