From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/XCameraShakeComponent.cs | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XCameraShakeComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XCameraShakeComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XCameraShakeComponent.cs b/Client/Assets/Scripts/XMainClient/XCameraShakeComponent.cs new file mode 100644 index 00000000..82dfed04 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XCameraShakeComponent.cs @@ -0,0 +1,155 @@ +using System; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XCameraShakeComponent : XComponent + { + public override uint ID + { + get + { + return XCameraShakeComponent.uuID; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("Camera_Basic_Shake"); + + private XCameraEffectData _args; + + private XCameraEx _camera = null; + + private float _timeEscaped = 0f; + + private float _timeInterval = 0f; + + private float _fov = 0f; + + private float _time_scale = 1f; + + private bool _shake = false; + + private Vector3 x = Vector3.right; + + private Vector3 y = Vector3.up; + + private Vector3 z = Vector3.forward; + + private bool _random = false; + + private int _rfactor = 1; + + protected override void EventSubscribe() + { + base.RegisterEvent(XEventDefine.XEvent_CameraShake, new XComponent.XEventHandler(this.OnBasicShake)); + } + + public override void OnAttachToHost(XObject host) + { + base.OnAttachToHost(host); + this._camera = (host as XCameraEx); + this._fov = this._camera.InitFOV; + } + + private bool OnBasicShake(XEventArgs e) + { + bool flag = this._camera != null; + if (flag) + { + XCameraShakeEventArgs xcameraShakeEventArgs = e as XCameraShakeEventArgs; + bool flag2 = xcameraShakeEventArgs.Effect == null; + if (flag2) + { + this.StopShake(); + return true; + } + this._time_scale = xcameraShakeEventArgs.TimeScale; + this._args = xcameraShakeEventArgs.Effect; + this._timeEscaped = 0f; + this._timeInterval = 0f; + this._fov = this._camera.InitFOV; + this._shake = true; + switch (this._args.Coordinate) + { + case CameraMotionSpace.World: + this.x = Vector3.right; + this.y = Vector3.up; + this.z = Vector3.forward; + break; + case CameraMotionSpace.Self: + this.x = XSingleton.singleton.Player.EngineObject.Right; + this.y = XSingleton.singleton.Player.EngineObject.Up; + this.z = XSingleton.singleton.Player.EngineObject.Forward; + break; + case CameraMotionSpace.Camera: + this.x = XSingleton.singleton.GameCamera.UnityCamera.transform.right; + this.y = XSingleton.singleton.GameCamera.UnityCamera.transform.up; + this.z = XSingleton.singleton.GameCamera.UnityCamera.transform.forward; + break; + } + this._random = this._args.Random; + } + this._rfactor = 1; + return true; + } + + public override void PostUpdate(float fDeltaT) + { + bool flag = this._camera != null && this._shake; + if (flag) + { + this._timeEscaped += fDeltaT; + this._timeInterval += fDeltaT; + bool flag2 = XSingleton.singleton.IsGreater(this._timeEscaped, this._args.Time * this._time_scale); + if (flag2) + { + this.StopShake(); + } + else + { + bool flag3 = XSingleton.singleton.IsGreater(this._timeInterval, 1f / this._args.Frequency * this._time_scale); + if (flag3) + { + this._rfactor = -this._rfactor; + this._camera.CameraTrans.position += this.Shake(); + this._camera.UnityCamera.fieldOfView = this._fov + (this._random ? UnityEngine.Random.Range(-this._args.FovAmp, this._args.FovAmp) : (this._args.FovAmp * (float)this._rfactor)); + this._timeInterval = 0f; + } + } + } + } + + private void StopShake() + { + this._args = null; + this._timeEscaped = 0f; + this._shake = false; + this._camera.FovBack(); + } + + private Vector3 Shake() + { + float num = this._random ? UnityEngine.Random.Range(-this._args.AmplitudeX, this._args.AmplitudeX) : (this._args.AmplitudeX * (float)this._rfactor); + float num2 = this._random ? UnityEngine.Random.Range(-this._args.AmplitudeY, this._args.AmplitudeY) : (this._args.AmplitudeY * (float)this._rfactor); + float num3 = this._random ? UnityEngine.Random.Range(-this._args.AmplitudeZ, this._args.AmplitudeZ) : (this._args.AmplitudeZ * (float)this._rfactor); + Vector3 vector = Vector3.zero; + bool shakeX = this._args.ShakeX; + if (shakeX) + { + vector += this.x * num; + } + bool shakeY = this._args.ShakeY; + if (shakeY) + { + vector += this.y * num2; + } + bool shakeZ = this._args.ShakeZ; + if (shakeZ) + { + vector += this.z * num3; + } + return vector; + } + } +} -- cgit v1.1-26-g67d0