Пример #1
0
        public static GUIDManager GetInstance()
        {
            if (_instance == null)
            {
                _instance = new GUIDManager();
            }

            return(_instance);
        }
Пример #2
0
        //=============================================================================//
        //============ Private Methods
        //=============================================================================//.
        #region Private Methods

        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) == false)
                {
                    // if registration fails, we probably have a duplicate or invalid GUID, get us a new one.
                    _serializedGuid = null;
                    guid            = System.Guid.Empty;
                    CreateGuid();
                }
            }
        }
Пример #3
0
        //=============================================================================//
        //============ Lifecycle Methods
        //=============================================================================//.
        #region Lifecycle Methods

        public void OnDestroy()
        {
            GUIDManager.Remove(guid);
        }