Beispiel #1
0
        private static void TryResolveTargetGate(Scene a, Scene b)
        {
            if (!_hasTarget)
            {
                GatewaysEvents.OnTargetMissing();
                return;
            }

            GameObject gameObject = GuidManager.ResolveGuid(_target);

            if (gameObject == null)
            {
                GatewaysEvents.OnGateUnresolved();
                return;
            }

            GateBase gate = gameObject.GetComponent <GateBase>();

            if (gate == null)
            {
                GatewaysEvents.OnGateComponentNotFound();
                return;
            }

            _hasTarget = false;
            _target    = Guid.Empty;

            gate.OnGateResolved();
        }
Beispiel #2
0
 public static GameObject ResolveGuid(System.Guid guid)
 {
     if (Instance == null)
     {
         Instance = new GuidManager();
     }
     return(Instance.ResolveGuidInternal(guid, null, null));
 }
Beispiel #3
0
        public static GameObject ResolveGuid(System.Guid guid, Action onDestroyCallback)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

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

            Instance.InternalRemove(guid);
        }
Beispiel #6
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));
        }
Beispiel #7
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();
                }
            }
        }
Beispiel #8
0
 // let the manager know we are gone, so other objects no longer find this
 public void OnDestroy()
 {
     GuidManager.Remove(guid);
 }