예제 #1
0
    void StartFadeout(RoomSwitchable switcher)
    {
        Vector3 vector  = base.transform.forward;
        Vector3 vector2 = base.transform.position + vector * this._moveDist;

        if (switcher != null)
        {
            Vector3 value    = SceneDoor.WorldToScreen(base.transform.position);
            Vector3 position = base.transform.position;
            if (this._moveFromCenter)
            {
                position = switcher.transform.position;
                vector   = (vector2 - position).normalized;
            }
            if (switcher.StartLevelTransition(position, vector2, vector, this._enterAnim))
            {
                EffectFactory.Instance.PlayQuickEffect(this._enterEffect, switcher.transform.position, switcher.transform.forward, null);
                OverlayFader.StartFade(this._fadeData, true, delegate()
                {
                    this.DoLoad();
                }, new Vector3?(value));
            }
        }
        else
        {
            OverlayFader.StartFade(this._fadeData, true, delegate()
            {
                this.DoLoad();
            }, new Vector3?(Vector3.zero));
        }
    }
예제 #2
0
    public void DoLoad()
    {
        Entity           player     = null;
        Camera           playerCam  = null;
        PlayerController playerCont = null;
        TileMeshRefOwner refOwner   = null;
        SceneDoor        targetDoor = null;

        PlayerSpawner.DoSpawnFunc onDoSpawn = null;
        Vector3        spawnDir             = base.transform.forward;
        Vector3        defSpawnPos          = this._fallbackPosition;
        bool           hasFallbackPos       = this._hasFallbackPos;
        string         wantedDoor           = this._correspondingDoor;
        FadeEffectData fadeData             = this._fadeInData ?? this._fadeData;

        OverlayFader.OnStartFunc onStartFade = null;
        OverlayFader.OnDoneFunc  startFadeIn = null;
        startFadeIn = delegate()
        {
            startFadeIn = null;
            if (onStartFade != null)
            {
                if (targetDoor != null)
                {
                    onStartFade(new Vector3?(SceneDoor.WorldToScreen(targetDoor.transform.position)));
                }
                else
                {
                    onStartFade(null);
                }
            }
            if (player != null)
            {
                BC_Collider component = player.GetComponent <BC_Collider>();
                if (component != null)
                {
                    component.enabled = true;
                }
                try
                {
                    RoomSwitchable component2 = player.GetComponent <RoomSwitchable>();
                    if (component2 != null)
                    {
                        component2.SendStartEvent();
                    }
                }
                catch (Exception exception)
                {
                    UnityEngine.Debug.LogException(exception, player);
                }
            }
            if (playerCont != null)
            {
                playerCont.SetEnabled(true);
            }
            SceneDoor.CheckStartIn(player, targetDoor);
        };
        PlayerSpawner.RegisterSpawnListener(delegate(Entity p, GameObject c, PlayerController cont)
        {
            player = p;
            BC_Collider component = p.GetComponent <BC_Collider>();
            if (component != null)
            {
                component.enabled = false;
            }
            playerCont = cont;
            playerCont.SetEnabled(false);
            Camera[] componentsInChildren = c.GetComponentsInChildren <Camera>();
            for (int j = 0; j < componentsInChildren.Length; j++)
            {
                if (componentsInChildren[j].name == "Main Camera")
                {
                    playerCam = componentsInChildren[j];
                }
            }
            onStartFade = OverlayFader.PrepareFadeOut(fadeData, null);
            SceneDoor.CheckAndBuild(player, playerCam, refOwner, startFadeIn);
        });
        PlayerSpawner.RegisterSpawnDelegation(delegate(PlayerSpawner.DoSpawnFunc func, Vector3 pos, Vector3 dir)
        {
            onDoSpawn = func;
            if (!hasFallbackPos)
            {
                defSpawnPos = pos;
            }
        });
        TileMeshRefOwner.RegisterAwakeListener(delegate(TileMeshRefOwner owner)
        {
            refOwner = owner;
            SceneDoor.CheckAndBuild(player, playerCam, refOwner, startFadeIn);
        });
        SceneDoor.RegisterListener(wantedDoor, delegate(SceneDoor door)
        {
            targetDoor          = door;
            targetDoor.coolDown = 1f;

            if (onDoSpawn == null)
            {
                return;
            }
            Vector3 pos = targetDoor.transform.TransformPoint(targetDoor._spawnOffset);
            spawnDir    = -targetDoor.transform.forward;
            PlayerSpawner.DoSpawnFunc doSpawnFunc = onDoSpawn;
            onDoSpawn = (PlayerSpawner.DoSpawnFunc)null;
            doSpawnFunc(pos, spawnDir);
        });
        Stopwatch clock = null;

        LevelLoadListener.RegisterListener(delegate
        {
            if (onDoSpawn != null)
            {
                if (targetDoor == null)
                {
                    UnityEngine.Debug.Log(string.Concat(new object[]
                    {
                        "didn't find ",
                        wantedDoor,
                        ", spawning at default: ",
                        defSpawnPos
                    }));
                }
                else
                {
                    defSpawnPos = targetDoor.transform.TransformPoint(targetDoor._spawnOffset);
                    spawnDir    = -targetDoor.transform.forward;
                }
                PlayerSpawner.DoSpawnFunc doSpawnFunc = onDoSpawn;
                onDoSpawn = (PlayerSpawner.DoSpawnFunc)null;
                doSpawnFunc(defSpawnPos, spawnDir);
            }
            else if (UnityEngine.Object.FindObjectOfType <PlayerSpawner>() == null)
            {
                UnityEngine.Debug.Log("didn't find a spawner in " + Utility.GetCurrentSceneName());
                SceneDoor.ClearListeners();
                PlayerSpawner.ClearListeners();
                if (onStartFade == null)
                {
                    onStartFade = OverlayFader.PrepareFadeOut(fadeData, null);
                }
            }
            else
            {
                UnityEngine.Debug.Log("awaiting spawning in " + Utility.GetCurrentSceneName());
            }
            clock.Stop();
            UnityEngine.Debug.Log(string.Concat(new object[]
            {
                "Loading ",
                this._scene,
                " took ",
                clock.ElapsedMilliseconds,
                " ms"
            }));
            if (UnityEngine.Object.FindObjectOfType <TileMeshRefOwner>() == null && startFadeIn != null)
            {
                startFadeIn();
            }
        });
        int prepareCounter = 0;

        SceneDoor.OnPrepareFunc onPrepareDone = delegate()
        {
            --prepareCounter;
            if (prepareCounter > 0)
            {
                return;
            }
            clock = Stopwatch.StartNew();
            Utility.LoadLevel(this._scene);
        };
        List <SceneDoor.OnPrepareFunc> list = new List <SceneDoor.OnPrepareFunc>();

        if (this._saver != null)
        {
            list.Add(delegate
            {
                this.SaveStartPos(this._saver, wantedDoor, null);
                this._saver.SaveAll(true, delegate(bool success, string msg)
                {
                    if (!success)
                    {
                        UnityEngine.Debug.LogError("Error saving: " + msg);
                    }
                    else
                    {
                        UnityEngine.Debug.Log("Game saved");
                    }
                    onPrepareDone();
                });
            });
        }
        prepareCounter = list.Count;
        if (prepareCounter == 0)
        {
            onPrepareDone();
            return;
        }
        for (int i = 0; i < list.Count; i++)
        {
            list[i]();
        }

        // Invoke custom event
        EventListener.SceneUnload();
    }