/// <summary> /// Create a copy of SlowMotionInfo /// </summary> /// <param name="other">Oter SlowMotionInfo to copy</param> public void CopyFrom(SlowMotionInfo other) { this.Freez = other.Freez; this.Duration = other.Duration; this.TimeScale = other.TimeScale; this.Pitch = other.Pitch; }
/// <summary> /// Notify globla that a SlowMotion happened /// </summary> /// <param name="sender"> The source of the event. </param> /// <param name="info"> Slow motion information</param> public static void RaiseSlowMotion(object sender, SlowMotionInfo info) { if (SlowMotion != null) { SlowMotion(sender, new SlowMotionEventArgs(new SlowMotionInfo(info))); } }
private void Global_SlowMotion(object sender, SlowMotionEventArgs args) { if (_MotionTW.IsEnabled) { return; } if (args == null || args.Motion == null) { return; } if (_Info == null) { _Info = new SlowMotionInfo(); } _Info.CopyFrom(args.Motion); _MotionTW.Begin(_Info.Duration, true); if (_Info.Freez > _Info.Duration) { _Info.Freez = _Info.Duration; } if (_Info.Freez > 0) { _FreezeTW.Begin(_Info.Freez, true); } else { _FreezeTW.End(); } enabled = true; _PreFixedDeltaTime = Time.fixedDeltaTime; _PreTimeScale = Time.timeScale; if (Skill.Framework.Audio.PitchController.Instance != null) { _PrePitch = Skill.Framework.Audio.PitchController.Instance.Pitch; } TimeScale = _Info.TimeScale; OnStartSlowMotion(); }
/// <summary> /// Create SlowMotionEventArgs /// </summary> /// <param name="motion"> SlowMotion information </param> public SlowMotionEventArgs(SlowMotionInfo motion) { this.Motion = motion; }
/// <summary> /// Create a copy of SlowMotionInfo /// </summary> /// <param name="other">Oter SlowMotionInfo to copy</param> public SlowMotionInfo(SlowMotionInfo other) { CopyFrom(other); }
/// <summary> /// Update /// </summary> protected override void Update() { // it is possible to player pasue game when slowmotion // as we control slowmotion by realtime of game, we need to save how many times left from start of slowmotion to continue after resume game if (Global.IsGamePaused) { if (!_Paused) { _TimeLeftWhenPaused = _MotionTW.OverTime - Time.realtimeSinceStartup; _FreezTimeLeftWhenPaused = _FreezeTW.OverTime - Time.realtimeSinceStartup; } _Paused = true; } else { if (_Paused) { if (_TimeLeftWhenPaused > 0) { _MotionTW.Begin(_TimeLeftWhenPaused, true); } if (_FreezTimeLeftWhenPaused > 0 && _Info.Freez > 0) { _FreezeTW.Begin(_FreezTimeLeftWhenPaused, true); } _Paused = false; _TimeLeftWhenPaused = 0; _FreezTimeLeftWhenPaused = 0; } if (_MotionTW.IsEnabled) { if (_MotionTW.IsOver) { if (Skill.Framework.Audio.PitchController.Instance != null) { Skill.Framework.Audio.PitchController.Instance.Pitch = _PrePitch; } TimeScale = Time.timeScale = _PreTimeScale; Time.fixedDeltaTime = _PreFixedDeltaTime; enabled = false; _MotionTW.End(); _Info = null; _TimeLeftWhenPaused = 0; _FreezTimeLeftWhenPaused = 0; OnEndSlowMotion(); } else { if (_FreezeTW.IsEnabledAndOver) { _FreezeTW.End(); } if (Skill.Framework.Audio.PitchController.Instance != null) { Skill.Framework.Audio.PitchController.Instance.Pitch = _Info.Pitch; } if (!_FreezeTW.IsEnabled) { TimeScale = Time.timeScale = _Info.TimeScale; } else { TimeScale = Time.timeScale = 0; } } Time.fixedDeltaTime = _PreFixedDeltaTime * Time.timeScale; } } base.Update(); }