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)); } }
void ClickedQuit(object ctx) { base.MenuImpl.Hide(); bool saveDone = false; bool fadeDone = base.Owner._fadeEffect == null; OverlayFader.OnDoneFunc onDone = delegate() { if (saveDone && fadeDone) { this.DoQuit(); } }; if (base.Owner._fadeEffect != null) { OverlayFader.StartFade(base.Owner._fadeEffect, true, delegate() { fadeDone = true; onDone(); }, null); } base.Owner._saver.SaveAll(true, delegate(bool success, string error) { saveDone = true; onDone(); }); }
public void DoRespawn() { this.inForceRespawn = false; if (this._doDeathOffset && this.levelRoot != null) { this.levelRoot.gameObject.SetActive(true); } ProjectileFactory.Instance.DeactivateAll(); Vector3 vector = (!this.useRoomSpawn) ? this.spawnPos : this.roomSpawnPos; Vector3 dir = (!this.useRoomSpawn) ? this.spawnDir : this.roomSpawnDir; this.ent.RealTransform.position = vector; this.ent.Activate(); this.ent.TurnTo(dir, 0f); if (this.varOverrider != null) { this.varOverrider.Apply(this.ent); } this.RegEvents(this.ent); base.enabled = false; this.roomSpawnPos = vector; this.roomSpawnDir = dir; this.controller.ControlEntity(this.ent); if (this.attachTag != null) { this.attachTag.Free(); } this.attachTag = null; if (this.attacher != null) { this.attachTag = this.attacher.Attach(this.ent); } if (this.followCam != null) { this.followCam.ClearFollowScale(); } LevelRoom roomForPosition = LevelRoom.GetRoomForPosition(vector + Vector3.up * 0.25f, null); if (roomForPosition != null) { roomForPosition.SetImportantPoint(vector); LevelRoom.SetCurrentActiveRoom(roomForPosition, true); if (this.levelCam != null) { this.levelCam.SetRoom(roomForPosition); } } if (this.hud != null) { this.hud.Observe(this.ent, this.controller); } if (this._fadeIn != null || this._fadeOut != null) { FadeEffectData data = this._fadeIn ?? this._fadeOut; Vector3 value = new Vector3(0f, 0f, 0f); OverlayFader.StartFade(data, false, null, new Vector3?(value)); } EventListener.PlayerSpawn(true); // Invoke custom event }
void IUpdatable.UpdateObject() { if (this.waitForDespawn) { if (!this.ent.gameObject.activeInHierarchy) { base.enabled = false; this.waitForDespawn = false; this.DoRespawn(); } return; } this.timer -= Time.deltaTime; if (this.backCam != null && this.fadeTimer > 0f) { this.fadeTimer -= Time.deltaTime; float num = Mathf.Max(0f, this.fadeTimer * this.fadeTimeScale); this.backCam.backgroundColor = Color.Lerp(this.startFadeColor, this._bgFadeColor, num); } if (this.timer <= 0f) { if (this.backCam != null) { this.backCam.backgroundColor = this.startFadeColor; } base.enabled = false; if (this.ShouldChangeLevels()) { this.ChangeLevelRespawn(); } else if (this._fadeOut != null && !this.noFadeOut) { Vector3 value = CoordinateTransformer.ToViewport("Main Camera", this.ent.WorldPosition); OverlayFader.StartFade(this._fadeOut, true, new OverlayFader.OnDoneFunc(this.StartSpawnWait), new Vector3?(value)); } else { this.DoRespawn(); } } }
public void ForceRespawn() { if (this.inForceRespawn) { return; } this.inForceRespawn = true; if (this.WillChangeLevels()) { this.localPauseTag = ObjectUpdater.Instance.RequestPause(null); Killable entityComponent = this.ent.GetEntityComponent <Killable>(); if (entityComponent != null) { entityComponent.CurrentHp = entityComponent.MaxHp; } this.ChangeLevelRespawn(); return; } ObjectUpdater.PauseTag pauseTag = ObjectUpdater.Instance.RequestPause(null); OverlayFader.OnDoneFunc onDoneFunc = delegate() { this.inForceRespawn = false; pauseTag.Release(); Killable entityComponent2 = this.ent.GetEntityComponent <Killable>(); if (entityComponent2 != null) { Killable.DeathData deathData = new Killable.DeathData(true); entityComponent2.ForceDeath(0f, deathData, true); } }; if (this._fadeOut != null) { Vector3 value = CoordinateTransformer.ToViewport("Main Camera", this.ent.WorldPosition); OverlayFader.StartFade(this._fadeOut, true, onDoneFunc, new Vector3?(value)); } else { onDoneFunc(); } }
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(); }