示例#1
0
        public static GameObject ResolveGuid(System.Guid guid, Action onDestroyCallback)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            return(Instance.ResolveGuidInternal(guid, null, onDestroyCallback));
        }
示例#2
0
        public static GameObject ResolveGuid(System.Guid guid)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            return(Instance.ResolveGuidInternal(guid, null, null));
        }
示例#3
0
        public static GameObject ResolveGuid(System.Guid guid, Action <GameObject> onAddCallback, Action onRemoveCallback)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            return(Instance.ResolveGuidInternal(guid, onAddCallback, onRemoveCallback));
        }
示例#4
0
        public static void Remove(System.Guid guid)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            Instance.InternalRemove(guid);
        }
示例#5
0
        // 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));
        }
示例#6
0
        // When de-serializing or creating this component, we want to either restore our serialized GUID
        // or create a new one.
        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();
                }
            }
        }
示例#7
0
 // let the manager know we are gone, so other objects no longer find this
 public void OnDestroy()
 {
     GuidManager.Remove(guid);
 }