コード例 #1
0
ファイル: GatewayMapper.cs プロジェクト: nmacadam/Gateways
        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();
        }
コード例 #2
0
ファイル: GuidManager.cs プロジェクト: nmacadam/Gateways
 public static GameObject ResolveGuid(System.Guid guid)
 {
     if (Instance == null)
     {
         Instance = new GuidManager();
     }
     return(Instance.ResolveGuidInternal(guid, null, null));
 }
コード例 #3
0
ファイル: GuidManager.cs プロジェクト: nmacadam/Gateways
        public static GameObject ResolveGuid(System.Guid guid, Action onDestroyCallback)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            return(Instance.ResolveGuidInternal(guid, null, onDestroyCallback));
        }
コード例 #4
0
ファイル: GuidManager.cs プロジェクト: nmacadam/Gateways
        public static GameObject ResolveGuid(System.Guid guid, Action <GameObject> onAddCallback, Action onRemoveCallback)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            return(Instance.ResolveGuidInternal(guid, onAddCallback, onRemoveCallback));
        }
コード例 #5
0
ファイル: GuidManager.cs プロジェクト: nmacadam/Gateways
        public static void Remove(System.Guid guid)
        {
            if (Instance == null)
            {
                Instance = new GuidManager();
            }

            Instance.InternalRemove(guid);
        }
コード例 #6
0
ファイル: GuidManager.cs プロジェクト: nmacadam/Gateways
        // 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));
        }
コード例 #7
0
ファイル: GuidComponent.cs プロジェクト: nmacadam/Gateways
        // 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();
                }
            }
        }
コード例 #8
0
ファイル: GuidComponent.cs プロジェクト: nmacadam/Gateways
 // let the manager know we are gone, so other objects no longer find this
 public void OnDestroy()
 {
     GuidManager.Remove(guid);
 }