{"TotalCount":15,"Files":[{"Ident":"blackdev.ezcamerashakeforsbox","Path":"Code/CameraShaker.cs","FileName":"CameraShaker.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\nusing System.Collections.Generic;\n\nnamespace EZCameraShake\n{\n    public class CameraShaker : Component\n    {\n        /// \u003Csummary\u003E\n        /// The single instance of the CameraShaker in the current scene. Do not use if you have multiple instances.\n        /// \u003C/summary\u003E\n        public static CameraShaker Instance;\n        static Dictionary\u003Cstring, CameraShaker\u003E instanceList = new Dictionary\u003Cstring, CameraShaker\u003E();\n\n        /// \u003Csummary\u003E\n        /// The default position influcence of all shakes created by this shaker.\n        /// \u003C/summary\u003E\n        [Property] public Vector3 DefaultPosInfluence = new Vector3(0.15f, 0.15f, 0.15f);\r\n\t\t/// \u003Csummary\u003E\n\t\t/// The default rotation influcence of all shakes created by this shaker.\n\t\t/// \u003C/summary\u003E\n\t\t[Property]  public Vector3 DefaultRotInfluence = new Vector3(1, 1, 1);\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Offset that will be applied to the camera\u0027s default (0,0,0) rest position\n\t\t/// \u003C/summary\u003E\n\t\t[Property] public Vector3 RestPositionOffset = new Vector3(0, 0, 0);\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Offset that will be applied to the camera\u0027s default (0,0,0) rest rotation\n\t\t/// \u003C/summary\u003E\n\t\t[Property] public Vector3 RestRotationOffset = new Vector3(0, 0, 0);\n\n        Vector3 posAddShake, rotAddShake;\n\n        List\u003CCameraShakeInstance\u003E cameraShakeInstances = new List\u003CCameraShakeInstance\u003E();\n\n        protected override void OnAwake()\n        {\n            Instance = this;\n            instanceList.Add(GameObject.Name, this);\n        }\r\n\r\n\t\tprotected override void OnUpdate()\n        {\n            posAddShake = Vector3.Zero;\n            rotAddShake = Vector3.Zero;\n\n            for (int i = 0; i \u003C cameraShakeInstances.Count; i\u002B\u002B)\n            {\n                if (i \u003E= cameraShakeInstances.Count)\n                    break;\n\n                CameraShakeInstance c = cameraShakeInstances[i];\n\n                if (c.CurrentState == CameraShakeState.Inactive \u0026\u0026 c.DeleteOnInactive)\n                {\n                    cameraShakeInstances.RemoveAt(i);\n                    i--;\n                }\n                else if (c.CurrentState != CameraShakeState.Inactive)\n                {\n                    posAddShake \u002B= CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence);\n                    rotAddShake \u002B= CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence);\n                }\n            }\n\n            Transform.LocalPosition = (posAddShake) \u002B RestPositionOffset;\r\n\t\t\tVector3 thing = (rotAddShake / 100) \u002B RestRotationOffset;\n\r\n\t\t\tTransform.LocalRotation = new Angles(thing.x, thing.y, thing.z);\n        }\n\n        /// \u003Csummary\u003E\n        /// Gets the CameraShaker with the given name, if it exists.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022name\u0022\u003EThe name of the camera shaker instance.\u003C/param\u003E\n        /// \u003Creturns\u003E\u003C/returns\u003E\n        public static CameraShaker GetInstance(string name)\n        {\n            CameraShaker c;\n\n            if (instanceList.TryGetValue(name, out c))\n                return c;\n\n            Log.Error(\u0022CameraShake \u0022 \u002B name \u002B \u0022 not found!\u0022);\n\n            return null;\n        }\n\n        /// \u003Csummary\u003E\n        /// Starts a shake using the given preset.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022shake\u0022\u003EThe preset to use.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance Shake(CameraShakeInstance shake)\n        {\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Shake the camera once, fading in and out  over a specified durations.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EHow long to fade out the shake, in seconds.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Shake the camera once, fading in and out over a specified durations.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EHow long to fade out the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022posInfluence\u0022\u003EHow much this shake influences position.\u003C/param\u003E\n        /// \u003Cparam name=\u0022rotInfluence\u0022\u003EHow much this shake influences rotation.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Start shaking the camera.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Start shaking the camera.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022posInfluence\u0022\u003EHow much this shake influences position.\u003C/param\u003E\n        /// \u003Cparam name=\u0022rotInfluence\u0022\u003EHow much this shake influences rotation.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Gets a copy of the list of current camera shake instances.\n        /// \u003C/summary\u003E\n        public List\u003CCameraShakeInstance\u003E ShakeInstances\n        { get { return new List\u003CCameraShakeInstance\u003E(cameraShakeInstances); } }\r\n\r\n\t\tprotected override void OnDestroy()\n        {\n            instanceList.Remove(GameObject.Name);\n        }\n    }\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"PlayerController.cs","FileName":"PlayerController.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox.Citizen;\r\nusing System.Text.Json;\r\n\r\n[Group( \u0022Walker\u0022 )]\r\n[Title( \u0022Walker - Player Controller\u0022 )]\r\npublic sealed class PlayerController : Component\r\n{\r\n\t[Property] public CharacterController CharacterController { get; set; }\r\n\t[Property] public float CrouchMoveSpeed { get; set; } = 64.0f;\r\n\t[Property] public float WalkMoveSpeed { get; set; } = 190.0f;\r\n\t[Property] public float RunMoveSpeed { get; set; } = 190.0f;\r\n\t[Property] public float SprintMoveSpeed { get; set; } = 320.0f;\r\n\r\n\t[Property] public CitizenAnimationHelper AnimationHelper { get; set; }\r\n\r\n\t[Sync] public bool Crouching { get; set; }\r\n\t[Sync] public Angles EyeAngles { get; set; }\r\n\t[Sync] public Vector3 WishVelocity { get; set; }\r\n\r\n\r\n\tpublic bool WishCrouch;\r\n\tpublic float EyeHeight = 64;\r\n\r\n\r\n\tprotected override void OnAwake()\r\n\t{\r\n\t\tif ( !IsProxy ) Tags.Add( \u0022player_local\u0022 );\r\n\t\tif ( IsProxy ) Tags.Remove( \u0022player_local\u0022 );\r\n\r\n\t\tLog.Info( Tags );\r\n\t\tLog.Info( JsonSerializer.Serialize( Tags ) );\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif (!IsProxy)\r\n\t\t{\r\n\t\t\tMouseInput();\r\n\t\t\tTransform.Rotation = new Angles( 0, EyeAngles.yaw, 0 );\r\n\t\t}\r\n\t\t\r\n\t\tUpdateAnimation();\r\n\t}\r\n\r\n\tprotected override void OnFixedUpdate()\r\n\t{\r\n\t\tif ( IsProxy ) return;\r\n\t\tCrouchingInput();\r\n\t\tMovementInput();\r\n\t}\r\n\r\n\tprivate void MouseInput()\r\n\t{\r\n\t\tvar e = EyeAngles;\r\n\t\te \u002B= Input.AnalogLook;\r\n\t\te.pitch = e.pitch.Clamp( -90, 90 );\r\n\t\te.roll = 0.0f;\r\n\t\tEyeAngles = e;\r\n\t}\r\n\r\n\tfloat CurrentMoveSpeed\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif ( Crouching ) return CrouchMoveSpeed;\r\n\t\t\tif ( Input.Down( \u0022run\u0022 ) ) return SprintMoveSpeed;\r\n\t\t\tif ( Input.Down( \u0022walk\u0022 ) ) return WalkMoveSpeed;\r\n\r\n\t\t\treturn RunMoveSpeed;\r\n\t\t}\r\n\t}\r\n\r\n\tRealTimeSince lastGrounded;\r\n\tRealTimeSince lastUngrounded;\r\n\tRealTimeSince lastJump;\r\n\r\n\tfloat GetFriction()\r\n\t{\r\n\t\tif ( CharacterController.IsOnGround ) return 6.0f;\r\n\r\n\t\t// air friction\r\n\t\treturn 0.2f;\r\n\t}\r\n\r\n\tprivate void MovementInput()\r\n\t{\r\n\t\tif ( CharacterController is null )\r\n\t\t\treturn;\r\n\r\n\t\tvar cc = CharacterController;\r\n\r\n\t\tVector3 halfGravity = Scene.PhysicsWorld.Gravity * Time.Delta * 0.5f;\r\n\r\n\t\tWishVelocity = Input.AnalogMove;\r\n\r\n\t\tif ( lastGrounded \u003C 0.2f \u0026\u0026 lastJump \u003E 0.3f \u0026\u0026 Input.Pressed( \u0022jump\u0022 ) )\r\n\t\t{\r\n\t\t\tlastJump = 0;\r\n\t\t\tcc.Punch( Vector3.Up * 300 );\r\n\t\t}\r\n\r\n\t\tif ( !WishVelocity.IsNearlyZero() )\r\n\t\t{\r\n\t\t\tWishVelocity = new Angles( 0, EyeAngles.yaw, 0 ).ToRotation() * WishVelocity;\r\n\t\t\tWishVelocity = WishVelocity.WithZ( 0 );\r\n\t\t\tWishVelocity = WishVelocity.ClampLength( 1 );\r\n\t\t\tWishVelocity *= CurrentMoveSpeed;\r\n\r\n\t\t\tif ( !cc.IsOnGround )\r\n\t\t\t{\r\n\t\t\t\tWishVelocity = WishVelocity.ClampLength( 50 );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tcc.ApplyFriction( GetFriction() );\r\n\r\n\t\tif ( cc.IsOnGround )\r\n\t\t{\r\n\t\t\tcc.Accelerate( WishVelocity );\r\n\t\t\tcc.Velocity = CharacterController.Velocity.WithZ( 0 );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tcc.Velocity \u002B= halfGravity;\r\n\t\t\tcc.Accelerate( WishVelocity );\r\n\r\n\t\t}\r\n\r\n\t\t//\r\n\t\t// Don\u0027t walk through other players, let them push you out of the way\r\n\t\t//\r\n\t\tvar pushVelocity = PlayerPusher.GetPushVector( Transform.Position \u002B Vector3.Up * 40.0f, Scene, GameObject );\r\n\t\tif ( !pushVelocity.IsNearlyZero() )\r\n\t\t{\r\n\t\t\tvar travelDot = cc.Velocity.Dot( pushVelocity.Normal );\r\n\t\t\tif ( travelDot \u003C 0 )\r\n\t\t\t{\r\n\t\t\t\tcc.Velocity -= pushVelocity.Normal * travelDot * 0.6f;\r\n\t\t\t}\r\n\r\n\t\t\tcc.Velocity \u002B= pushVelocity * 128.0f;\r\n\t\t}\r\n\r\n\t\tcc.Move();\r\n\r\n\t\tif ( !cc.IsOnGround )\r\n\t\t{\r\n\t\t\tcc.Velocity \u002B= halfGravity;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tcc.Velocity = cc.Velocity.WithZ( 0 );\r\n\t\t}\r\n\r\n\t\tif ( cc.IsOnGround )\r\n\t\t{\r\n\t\t\tlastGrounded = 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlastUngrounded = 0;\r\n\t\t}\r\n\t}\r\n\tfloat DuckHeight = (64 - 36);\r\n\r\n\tbool CanUncrouch()\r\n\t{\r\n\t\tif ( !Crouching ) return true;\r\n\t\tif ( lastUngrounded \u003C 0.2f ) return false;\r\n\r\n\t\tvar tr = CharacterController.TraceDirection( Vector3.Up * DuckHeight );\r\n\t\treturn !tr.Hit; // hit nothing - we can!\r\n\t}\r\n\r\n\tpublic void CrouchingInput()\r\n\t{\r\n\t\tWishCrouch = Input.Down( \u0022duck\u0022 );\r\n\r\n\t\tif ( WishCrouch == Crouching )\r\n\t\t\treturn;\r\n\r\n\t\t// crouch\r\n\t\tif ( WishCrouch )\r\n\t\t{\r\n\t\t\tCharacterController.Height = 36;\r\n\t\t\tCrouching = WishCrouch;\r\n\r\n\t\t\t// if we\u0027re not on the ground, slide up our bbox so when we crouch\r\n\t\t\t// the bottom shrinks, instead of the top, which will mean we can reach\r\n\t\t\t// places by crouch jumping that we couldn\u0027t.\r\n\t\t\tif ( !CharacterController.IsOnGround )\r\n\t\t\t{\r\n\t\t\t\tCharacterController.MoveTo( Transform.Position \u002B= Vector3.Up * DuckHeight, false );\r\n\t\t\t\tTransform.ClearInterpolation();\r\n\t\t\t\tEyeHeight -= DuckHeight;\r\n\t\t\t}\r\n\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// uncrouch\r\n\t\tif ( !WishCrouch )\r\n\t\t{\r\n\t\t\tif ( !CanUncrouch() ) return;\r\n\r\n\t\t\tCharacterController.Height = 64;\r\n\t\t\tCrouching = WishCrouch;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\r\n\t}\r\n\r\n\tprivate void UpdateCamera()\r\n\t{\r\n\t\tvar camera = Scene.GetAllComponents\u003CCameraComponent\u003E().Where( x =\u003E x.IsMainCamera ).FirstOrDefault();\r\n\t\tif ( camera is null ) return;\r\n\r\n\t\t// Determine target eye height based on crouching state\r\n\t\tvar targetEyeHeight = Crouching ? -10f : 6.4f;\r\n\t\tEyeHeight = EyeHeight.LerpTo( targetEyeHeight, RealTime.Delta * 10.0f );\r\n\r\n\t\t// Get the camera\u0027s local position relative to the player\u0027s position\r\n\t\tvar targetLocalCameraPos = new Vector3( 0, 0, EyeHeight );  // Local offset for the camera (only affects z for height)\r\n\r\n\t\t// Smooth transition when ungrounded (e.g. going up/down stairs or ducking)\r\n\t\tif ( lastUngrounded \u003E 0.2f )\r\n\t\t{\r\n\t\t\t// Interpolating z-axis (local space) smoothly\r\n\t\t\ttargetLocalCameraPos.z = camera.Transform.LocalPosition.z.LerpTo( targetLocalCameraPos.z, RealTime.Delta * 25.0f );\r\n\t\t}\r\n\r\n\t\t// Apply local position and rotation to the camera\r\n\t\tcamera.Transform.LocalPosition = targetLocalCameraPos;\r\n\r\n\t\t// Set the camera\u0027s local rotation based on player\u0027s current view angles\r\n\t\tcamera.Transform.LocalRotation = new Angles( EyeAngles.pitch, 0, EyeAngles.roll );\r\n\r\n\t\t// Set the camera\u0027s field of view from player preferences\r\n\t\tcamera.FieldOfView = Preferences.FieldOfView;\r\n\t}\r\n\r\n\r\n\tprotected override void OnPreRender()\r\n\t{\r\n\t\tUpdateBodyVisibility();\r\n\r\n\t\tif ( IsProxy )\r\n\t\t\treturn;\r\n\r\n\t\tUpdateCamera();\r\n\t}\r\n\r\n\tprivate void UpdateAnimation()\r\n\t{\r\n\t\tif ( AnimationHelper is null ) return;\r\n\r\n\t\tvar wv = WishVelocity.Length;\r\n\r\n\t\tAnimationHelper.WithWishVelocity( WishVelocity );\r\n\t\tAnimationHelper.WithVelocity( CharacterController.Velocity );\r\n\t\tAnimationHelper.IsGrounded = CharacterController.IsOnGround;\r\n\t\tAnimationHelper.DuckLevel = Crouching ? 1.0f : 0.0f;\r\n\r\n\t\tAnimationHelper.MoveStyle = wv \u003C 160f ? CitizenAnimationHelper.MoveStyles.Walk : CitizenAnimationHelper.MoveStyles.Run;\r\n\r\n\t\tvar lookDir = EyeAngles.ToRotation().Forward * 1024;\r\n\t\tAnimationHelper.WithLook( lookDir, 1, 0.5f, 0.25f );\r\n\t}\r\n\r\n\tprivate void UpdateBodyVisibility()\r\n\t{\r\n\t\tif ( AnimationHelper is null )\r\n\t\t\treturn;\r\n\r\n\t\tvar renderMode = ModelRenderer.ShadowRenderType.On;\r\n\t\tif ( !IsProxy ) renderMode = ModelRenderer.ShadowRenderType.ShadowsOnly;\r\n\r\n\t\tAnimationHelper.Target.RenderType = renderMode;\r\n\r\n\t\tforeach ( var clothing in AnimationHelper.Target.Components.GetAll\u003CModelRenderer\u003E( FindMode.InChildren ) )\r\n\t\t{\r\n\t\t\tif ( !clothing.Tags.Has( \u0022clothing\u0022 ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tclothing.RenderType = renderMode;\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"MotionPath.cs","FileName":"MotionPath.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\r\nusing System;\r\nusing System.Linq;\r\n\r\n/// \u003Csummary\u003E\r\n/// Move an object around a path.\r\n/// \u003C/summary\u003E\r\n[Title( \u0022Motion Path\u0022 )]\r\npublic class MotionPath : Component, Component.ExecuteInEditor\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// The object that moves around this path.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic GameObject Target { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Normalized time between 0 and 1 for how far the target is on this path.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Range( 0.0f, 1.0f )]\r\n\t[HostSync] public float Time { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Rotate the target using the rotation of points, otherwise use the curvature of the path.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic bool UsePointRotation { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Time is controlled manually.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic bool Manual { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How long the path takes to complete.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, ShowIf( nameof( Manual ), false )]\r\n\tpublic float Duration { get; set; } = 10;\r\n\r\n\tpublic enum SplineType\r\n\t{\r\n\t\tTcb,\r\n\t\tCatmullRom\r\n\t};\r\n\r\n\t[Title( \u0022Mode\u0022 ), Group( \u0022Spline\u0022 )]\r\n\t[Property] public SplineType SplineMode { get; set; }\r\n\r\n\t[Title( \u0022Tension\u0022 ), Group( \u0022Spline\u0022 ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]\r\n\t[Property, Range( -1, 1 )] public float SplineTension { get; set; }\r\n\r\n\t[Title( \u0022Continuity\u0022 ), Group( \u0022Spline\u0022 ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]\r\n\t[Property, Range( -1, 1 )] public float SplineContinuity { get; set; }\r\n\r\n\t[Title( \u0022Bias\u0022 ), Group( \u0022Spline\u0022 ), ShowIf( nameof( SplineMode ), SplineType.Tcb )]\r\n\t[Property, Range( -1, 1 )] public float SplineBias { get; set; }\r\n\r\n\tprivate Vector3[] _previewPoints;\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tbase.OnStart();\r\n\r\n\t\tif ( Scene.IsEditor )\r\n\t\t{\r\n\t\t\tif ( !GameObject.GetAllObjects( true )\r\n\t\t\t\t.Select( x =\u003E x.Components.Get\u003CMotionPathPoint\u003E() )\r\n\t\t\t\t.Where( x =\u003E x.IsValid() )\r\n\t\t\t\t.Any() )\r\n\t\t\t{\r\n\t\t\t\tvar go = new GameObject( true, \u0022Point\u0022 );\r\n\t\t\t\tgo.SetParent( GameObject, false );\r\n\t\t\t\tgo.Components.Create\u003CMotionPathPoint\u003E( true );\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tbase.DrawGizmos();\r\n\r\n\t\tif ( _previewPoints is null )\r\n\t\t\treturn;\r\n\r\n\t\tusing ( Gizmo.Hitbox.LineScope() )\r\n\t\t{\r\n\t\t\tfor ( var i = 0; i \u003C _previewPoints.Length - 1; i\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tvar pointA = Transform.World.PointToLocal( _previewPoints[i] );\r\n\t\t\t\tvar pointB = Transform.World.PointToLocal( _previewPoints[i \u002B 1] );\r\n\t\t\t\tGizmo.Draw.Color = Gizmo.IsSelected ? Gizmo.Colors.Active : Gizmo.IsHovered ? Gizmo.Colors.Hovered : Color.White.WithAlpha( 0.5f );\r\n\t\t\t\tGizmo.Draw.LineThickness = Gizmo.IsHovered || Gizmo.IsSelected ? 2 : 1;\r\n\t\t\t\tGizmo.Draw.Line( pointA, pointB );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif ( Target.IsValid() )\r\n\t\t{\r\n\t\t\tGizmo.Draw.Color = Gizmo.Colors.Forward;\r\n\t\t\tvar pointA = Transform.World.PointToLocal( Target.Transform.Position );\r\n\t\t\tvar pointB = Transform.World.NormalToLocal( Target.Transform.Rotation.Forward ) * 5;\r\n\t\t\tGizmo.Draw.SolidCone( pointA, pointB, 2 );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate Vector3 GetPointOnSpline( Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float delta )\r\n\t{\r\n\t\tif ( SplineMode == SplineType.Tcb )\r\n\t\t\treturn Vector3.TcbSpline( p0, p1, p2, p3, SplineTension, SplineContinuity, SplineBias, delta );\r\n\t\telse if ( SplineMode == SplineType.CatmullRom )\r\n\t\t\treturn Vector3.CatmullRomSpline( p0, p1, p2, p3, delta );\r\n\r\n\t\treturn default;\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tbase.OnUpdate();\r\n\r\n\t\tvar motionPoints = GameObject.GetAllObjects( true )\r\n\t\t\t.Select( x =\u003E x.Components.Get\u003CMotionPathPoint\u003E() )\r\n\t\t\t.Where( x =\u003E x.IsValid() )\r\n\t\t\t.ToArray();\r\n\r\n\t\tvar points = motionPoints.Select( x =\u003E x.Transform.Position )\r\n\t\t\t.ToArray();\r\n\r\n\t\tif ( SplineMode == SplineType.Tcb )\r\n\t\t\t_previewPoints = points.TcbSpline( 32, SplineTension, SplineContinuity, SplineBias ).ToArray();\r\n\t\telse if ( SplineMode == SplineType.CatmullRom )\r\n\t\t\t_previewPoints = points.CatmullRomSpline( 32 ).ToArray();\r\n\r\n\t\tif ( points.Length \u003C 2 )\r\n\t\t\treturn;\r\n\r\n\t\tif ( points.Length == 2 )\r\n\t\t\t_previewPoints = new Vector3[2] { points[0], points[1] };\r\n\r\n\t\tif ( Target.IsValid() )\r\n\t\t{\r\n\t\t\tvar pointCount = points.Length;\r\n\r\n\t\t\tif ( !Manual \u0026\u0026 !Duration.AlmostEqual( 0.0f ) )\r\n\t\t\t\tTime = Sandbox.Time.Now % Duration / Duration;\r\n\r\n\t\t\tvar time = Time.Clamp( 0.0f, 1.0f );\r\n\r\n\t\t\tvar segmentIndex = (int)((pointCount - 1) * time);\r\n\t\t\tsegmentIndex = Math.Min( segmentIndex, pointCount - 2 );\r\n\t\t\tvar delta = ((pointCount - 1) * time) - segmentIndex;\r\n\r\n\t\t\tvar p0 = segmentIndex \u003E 0 ? points[segmentIndex - 1] : points[0];\r\n\t\t\tvar p1 = points[segmentIndex];\r\n\t\t\tvar p2 = segmentIndex \u003C pointCount - 1 ? points[segmentIndex \u002B 1] : points[pointCount - 1];\r\n\t\t\tvar p3 = segmentIndex \u003C pointCount - 2 ? points[segmentIndex \u002B 2] : points[pointCount - 1];\r\n\r\n\t\t\tvar offset = time.AlmostEqual( 1.0f ) ? -0.01f : 0.01f;\r\n\t\t\tvar positionA = GetPointOnSpline( p0, p1, p2, p3, delta );\r\n\r\n\t\t\tif ( UsePointRotation )\r\n\t\t\t{\r\n\t\t\t\tvar r1 = motionPoints[segmentIndex];\r\n\t\t\t\tvar r2 = segmentIndex \u003C pointCount - 1 ? motionPoints[segmentIndex \u002B 1] : motionPoints[pointCount - 1];\r\n\t\t\t\tvar rotationStart = r1.Transform.Rotation;\r\n\t\t\t\tvar rotationEnd = r2.Transform.Rotation;\r\n\r\n\t\t\t\tif ( r1.LookAt.IsValid() )\r\n\t\t\t\t\trotationStart = Rotation.LookAt( (r1.LookAt.Transform.Position - r1.Transform.Position).Normal );\r\n\r\n\t\t\t\tif ( r2.LookAt.IsValid() )\r\n\t\t\t\t\trotationEnd = Rotation.LookAt( (r2.LookAt.Transform.Position - r2.Transform.Position).Normal );\r\n\r\n\t\t\t\tTarget.Transform.Rotation = Rotation.Slerp( rotationStart, rotationEnd, delta );\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tvar positionB = GetPointOnSpline( p0, p1, p2, p3, delta \u002B offset );\r\n\t\t\t\tvar forward = (positionB - positionA).Normal * MathF.Sign( offset );\r\n\t\t\t\tvar right = forward.Cross( Vector3.Up ).Normal;\r\n\t\t\t\tvar up = right.Cross( forward ).Normal;\r\n\r\n\t\t\t\tTarget.Transform.Rotation = Rotation.LookAt( forward, up );\r\n\t\t\t}\r\n\r\n\t\t\tTarget.Transform.Position = positionA;\r\n\t\t}\r\n\t}\r\n}\r\n\r\npublic class MotionPathPoint : Component, Component.ExecuteInEditor\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// Look at this object.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic GameObject LookAt { get; set; }\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tbase.DrawGizmos();\r\n\r\n\t\tconst float radius = 2.0f;\r\n\t\tGizmo.Hitbox.DepthBias = 0.1f;\r\n\t\tGizmo.Hitbox.Sphere( new Sphere( 0, radius ) );\r\n\t\tGizmo.Draw.Color = Gizmo.IsSelected ? Gizmo.Colors.Active : Gizmo.IsHovered ? Gizmo.Colors.Hovered : Color.White;\r\n\t\tGizmo.Draw.SolidSphere( 0, radius );\r\n\r\n\t\tif ( Gizmo.IsSelected || Gizmo.IsHovered )\r\n\t\t{\r\n\t\t\tvar end = LookAt.IsValid() ? Transform.World.PointToLocal( LookAt.Transform.Position ) : Vector3.Forward * 6;\r\n\t\t\tGizmo.Draw.Color = Gizmo.Colors.Forward;\r\n\t\t\tGizmo.Draw.Arrow( 0, end, 2, 1 );\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"Code/CameraShakePresets.cs","FileName":"CameraShakePresets.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\n\nnamespace EZCameraShake\n{\n\n    public static class CameraShakePresets\n    {\n        /// \u003Csummary\u003E\n        /// [One-Shot] A high magnitude, short, yet smooth shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Bump\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(2.5f, 4, 0.1f, 0.75f);\n                c.PositionInfluence = Vector3.One * 0.15f;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [One-Shot] An intense and rough shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Explosion\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(5f, 10, 0, 1.5f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(4, 1, 1);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A continuous, rough shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Earthquake\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.6f, 3.5f, 2f, 10f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(1, 1, 4);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A bizarre shake with a very high magnitude and low roughness.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance BadTrip\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(10f, 0.15f, 5f, 10f);\n                c.PositionInfluence = new Vector3(0, 0, 0.15f);\n                c.RotationInfluence = new Vector3(2, 1, 4);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A subtle, slow shake. \n        /// \u003C/summary\u003E\n        public static CameraShakeInstance HandheldCamera\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1f, 0.25f, 5f, 10f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = new Vector3(1, 0.5f, 0.5f);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A very rough, yet low magnitude shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Vibration\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.4f, 20f, 2f, 2f);\n                c.PositionInfluence = new Vector3(0, 0.15f, 0);\n                c.RotationInfluence = new Vector3(1.25f, 0, 4);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A slightly rough, medium magnitude shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance RoughDriving\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1, 2f, 1f, 1f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n    }\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"Assembly.cs","FileName":"Assembly.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"global using System;\r\nglobal using Sandbox;\r\nglobal using System.Linq;\r\nglobal using System.Threading.Tasks;\r\nglobal using System.Collections.Generic;\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"CameraShakePresets.cs","FileName":"CameraShakePresets.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\n\nnamespace EZCameraShake\n{\n\n    public static class CameraShakePresets\n    {\n        /// \u003Csummary\u003E\n        /// [One-Shot] A high magnitude, short, yet smooth shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Bump\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(2.5f, 4, 0.1f, 0.75f);\n                c.PositionInfluence = Vector3.One * 0.15f;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [One-Shot] An intense and rough shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Explosion\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(5f, 10, 0, 1.5f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(4, 1, 1);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A continuous, rough shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Earthquake\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.6f, 3.5f, 2f, 10f);\n                c.PositionInfluence = Vector3.One * 0.25f;\n                c.RotationInfluence = new Vector3(1, 1, 4);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A bizarre shake with a very high magnitude and low roughness.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance BadTrip\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(10f, 0.15f, 5f, 10f);\n                c.PositionInfluence = new Vector3(0, 0, 0.15f);\n                c.RotationInfluence = new Vector3(2, 1, 4);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A subtle, slow shake. \n        /// \u003C/summary\u003E\n        public static CameraShakeInstance HandheldCamera\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1f, 0.25f, 5f, 10f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = new Vector3(1, 0.5f, 0.5f);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A very rough, yet low magnitude shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance Vibration\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(0.4f, 20f, 2f, 2f);\n                c.PositionInfluence = new Vector3(0, 0.15f, 0);\n                c.RotationInfluence = new Vector3(1.25f, 0, 4);\n                return c;\n            }\n        }\n\n        /// \u003Csummary\u003E\n        /// [Sustained] A slightly rough, medium magnitude shake.\n        /// \u003C/summary\u003E\n        public static CameraShakeInstance RoughDriving\n        {\n            get\n            {\n                CameraShakeInstance c = new CameraShakeInstance(1, 2f, 1f, 1f);\n                c.PositionInfluence = Vector3.Zero;\n                c.RotationInfluence = Vector3.One;\n                return c;\n            }\n        }\n    }\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":".obj/__compiler_extra.cs","FileName":"__compiler_extra.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"global using static Sandbox.Internal.GlobalGameNamespace;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonTitle\u0022, \u0022EZ Camera Shake for s\u0026box\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonIdent\u0022, \u0022ezcamerashakeforsbox\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022OrgIdent\u0022, \u0022blackdev\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022Ident\u0022, \u0022blackdev.ezcamerashakeforsbox\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022CompileTime\u0022, \u00228/14/2024 11:37:11 PM\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineVersion\u0022, \u002217\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineMinorVersion\u0022, \u00221\u0022 )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \u0022.NETCoreApp,Version=v7.0\u0022, FrameworkDisplayName = \u0022.NET 7.0\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\u00220.0.115.0\u0022)]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\u00220.0.115.0\u0022)]"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"CameraUtilities.cs","FileName":"CameraUtilities.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\r\nusing System;\n\nnamespace EZCameraShake\n{\n    public class CameraUtilities\n    {\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Smoothes a Vector3 that represents euler angles.\n\t\t/// \u003C/summary\u003E\n\t\t/// \u003Cparam name=\u0022current\u0022\u003EThe current Vector3 value.\u003C/param\u003E\n\t\t/// \u003Cparam name=\u0022target\u0022\u003EThe target Vector3 value.\u003C/param\u003E\n\t\t/// \u003Cparam name=\u0022velocity\u0022\u003EA refernce Vector3 used internally.\u003C/param\u003E\n\t\t/// \u003Cparam name=\u0022smoothTime\u0022\u003EThe time to smooth, in seconds.\u003C/param\u003E\n\t\t/// \u003Creturns\u003EThe smoothed Vector3 value.\u003C/returns\u003E\n\t\tpublic static Vector3 SmoothDampEuler( Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime, float deltaTime )\r\n\t\t{\r\n\t\t\tfloat velocityX = velocity.x;\r\n\t\t\tfloat velocityY = velocity.y;\r\n\t\t\tfloat velocityZ = velocity.z;\r\n\r\n\t\t\tfloat x = MathExtensions.SmoothDampAngle( current.x, target.x, ref velocityX, smoothTime, deltaTime );\r\n\t\t\tfloat y = MathExtensions.SmoothDampAngle( current.y, target.y, ref velocityY, smoothTime, deltaTime );\r\n\t\t\tfloat z = MathExtensions.SmoothDampAngle( current.z, target.z, ref velocityZ, smoothTime, deltaTime );\r\n\r\n\t\t\tvelocity = new Vector3( velocityX, velocityY, velocityZ );\r\n\r\n\t\t\treturn new Vector3( x, y, z );\r\n\t\t}\r\n\r\n\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Multiplies each element in Vector3 v by the corresponding element of w.\n\t\t/// \u003C/summary\u003E\n\t\tpublic static Vector3 MultiplyVectors(Vector3 v, Vector3 w)\n        {\n            v.x *= w.x;\n            v.y *= w.y;\n            v.z *= w.z;\n\n            return v;\n        }\n    }\n}\r\n\r\npublic static class MathExtensions\r\n{\r\n\tpublic static float SmoothDampAngle( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Ensure smoothTime is never too small\r\n\t\tsmoothTime = Math.Max( 0.0001f, smoothTime );\r\n\r\n\t\t// Calculate the difference between the current and target angles\r\n\t\tfloat deltaAngle = MathfDeltaAngle( current, target );\r\n\r\n\t\t// Calculate the desired target position by adding deltaAngle to the current angle\r\n\t\ttarget = current \u002B deltaAngle;\r\n\r\n\t\t// SmoothDamp logic for interpolating between angles\r\n\t\tfloat result = SmoothDamp( current, target, ref currentVelocity, smoothTime, deltaTime, maxSpeed );\r\n\r\n\t\treturn result;\r\n\t}\r\n\r\n\t// SmoothDamp function: interpolates between two values using velocity and smooth time\r\n\tpublic static float SmoothDamp( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Similar to Mathf.SmoothDamp logic in Unity\r\n\t\tfloat num = 2f / smoothTime;\r\n\t\tfloat num2 = num * deltaTime;\r\n\t\tfloat num3 = 1f / (1f \u002B num2 \u002B 0.48f * num2 * num2 \u002B 0.235f * num2 * num2 * num2);\r\n\t\tfloat num4 = current - target;\r\n\t\tfloat num5 = target;\r\n\t\tfloat maxDelta = maxSpeed * smoothTime;\r\n\t\tnum4 = Clamp( num4, -maxDelta, maxDelta );\r\n\t\ttarget = current - num4;\r\n\t\tfloat num7 = (currentVelocity \u002B num * num4) * deltaTime;\r\n\t\tcurrentVelocity = (currentVelocity - num * num7) * num3;\r\n\t\tfloat num8 = target \u002B (num4 \u002B num7) * num3;\r\n\r\n\t\t// Prevent overshooting\r\n\t\tif ( num5 - current \u003E 0f == num8 \u003E num5 )\r\n\t\t{\r\n\t\t\tnum8 = num5;\r\n\t\t\tcurrentVelocity = (num8 - num5) / deltaTime;\r\n\t\t}\r\n\t\treturn num8;\r\n\t}\r\n\r\n\t// Function to calculate the shortest difference between two angles, handling wrap-around\r\n\tpublic static float MathfDeltaAngle( float current, float target )\r\n\t{\r\n\t\tfloat delta = target - current;\r\n\t\twhile ( delta \u003C -180f ) delta \u002B= 360f;\r\n\t\twhile ( delta \u003E 180f ) delta -= 360f;\r\n\t\treturn delta;\r\n\t}\r\n\r\n\t// Clamp function to restrict values between min and max\r\n\tpublic static float Clamp( float value, float min, float max )\r\n\t{\r\n\t\tif ( value \u003C min ) return min;\r\n\t\tif ( value \u003E max ) return max;\r\n\t\treturn value;\r\n\t}\r\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"Code/CameraUtilities.cs","FileName":"CameraUtilities.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\r\nusing System;\n\nnamespace EZCameraShake\n{\n    public class CameraUtilities\n    {\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Smoothes a Vector3 that represents euler angles.\n\t\t/// \u003C/summary\u003E\n\t\t/// \u003Cparam name=\u0022current\u0022\u003EThe current Vector3 value.\u003C/param\u003E\n\t\t/// \u003Cparam name=\u0022target\u0022\u003EThe target Vector3 value.\u003C/param\u003E\n\t\t/// \u003Cparam name=\u0022velocity\u0022\u003EA refernce Vector3 used internally.\u003C/param\u003E\n\t\t/// \u003Cparam name=\u0022smoothTime\u0022\u003EThe time to smooth, in seconds.\u003C/param\u003E\n\t\t/// \u003Creturns\u003EThe smoothed Vector3 value.\u003C/returns\u003E\n\t\tpublic static Vector3 SmoothDampEuler( Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime, float deltaTime )\r\n\t\t{\r\n\t\t\tfloat velocityX = velocity.x;\r\n\t\t\tfloat velocityY = velocity.y;\r\n\t\t\tfloat velocityZ = velocity.z;\r\n\r\n\t\t\tfloat x = MathExtensions.SmoothDampAngle( current.x, target.x, ref velocityX, smoothTime, deltaTime );\r\n\t\t\tfloat y = MathExtensions.SmoothDampAngle( current.y, target.y, ref velocityY, smoothTime, deltaTime );\r\n\t\t\tfloat z = MathExtensions.SmoothDampAngle( current.z, target.z, ref velocityZ, smoothTime, deltaTime );\r\n\r\n\t\t\tvelocity = new Vector3( velocityX, velocityY, velocityZ );\r\n\r\n\t\t\treturn new Vector3( x, y, z );\r\n\t\t}\r\n\r\n\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Multiplies each element in Vector3 v by the corresponding element of w.\n\t\t/// \u003C/summary\u003E\n\t\tpublic static Vector3 MultiplyVectors(Vector3 v, Vector3 w)\n        {\n            v.x *= w.x;\n            v.y *= w.y;\n            v.z *= w.z;\n\n            return v;\n        }\n    }\n}\r\n\r\npublic static class MathExtensions\r\n{\r\n\tpublic static float SmoothDampAngle( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Ensure smoothTime is never too small\r\n\t\tsmoothTime = Math.Max( 0.0001f, smoothTime );\r\n\r\n\t\t// Calculate the difference between the current and target angles\r\n\t\tfloat deltaAngle = MathfDeltaAngle( current, target );\r\n\r\n\t\t// Calculate the desired target position by adding deltaAngle to the current angle\r\n\t\ttarget = current \u002B deltaAngle;\r\n\r\n\t\t// SmoothDamp logic for interpolating between angles\r\n\t\tfloat result = SmoothDamp( current, target, ref currentVelocity, smoothTime, deltaTime, maxSpeed );\r\n\r\n\t\treturn result;\r\n\t}\r\n\r\n\t// SmoothDamp function: interpolates between two values using velocity and smooth time\r\n\tpublic static float SmoothDamp( float current, float target, ref float currentVelocity, float smoothTime, float deltaTime, float maxSpeed = float.PositiveInfinity )\r\n\t{\r\n\t\t// Similar to Mathf.SmoothDamp logic in Unity\r\n\t\tfloat num = 2f / smoothTime;\r\n\t\tfloat num2 = num * deltaTime;\r\n\t\tfloat num3 = 1f / (1f \u002B num2 \u002B 0.48f * num2 * num2 \u002B 0.235f * num2 * num2 * num2);\r\n\t\tfloat num4 = current - target;\r\n\t\tfloat num5 = target;\r\n\t\tfloat maxDelta = maxSpeed * smoothTime;\r\n\t\tnum4 = Clamp( num4, -maxDelta, maxDelta );\r\n\t\ttarget = current - num4;\r\n\t\tfloat num7 = (currentVelocity \u002B num * num4) * deltaTime;\r\n\t\tcurrentVelocity = (currentVelocity - num * num7) * num3;\r\n\t\tfloat num8 = target \u002B (num4 \u002B num7) * num3;\r\n\r\n\t\t// Prevent overshooting\r\n\t\tif ( num5 - current \u003E 0f == num8 \u003E num5 )\r\n\t\t{\r\n\t\t\tnum8 = num5;\r\n\t\t\tcurrentVelocity = (num8 - num5) / deltaTime;\r\n\t\t}\r\n\t\treturn num8;\r\n\t}\r\n\r\n\t// Function to calculate the shortest difference between two angles, handling wrap-around\r\n\tpublic static float MathfDeltaAngle( float current, float target )\r\n\t{\r\n\t\tfloat delta = target - current;\r\n\t\twhile ( delta \u003C -180f ) delta \u002B= 360f;\r\n\t\twhile ( delta \u003E 180f ) delta -= 360f;\r\n\t\treturn delta;\r\n\t}\r\n\r\n\t// Clamp function to restrict values between min and max\r\n\tpublic static float Clamp( float value, float min, float max )\r\n\t{\r\n\t\tif ( value \u003C min ) return min;\r\n\t\tif ( value \u003E max ) return max;\r\n\t\treturn value;\r\n\t}\r\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"CameraShaker.cs","FileName":"CameraShaker.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\nusing System.Collections.Generic;\n\nnamespace EZCameraShake\n{\n    public class CameraShaker : Component\n    {\n        /// \u003Csummary\u003E\n        /// The single instance of the CameraShaker in the current scene. Do not use if you have multiple instances.\n        /// \u003C/summary\u003E\n        public static CameraShaker Instance;\n        static Dictionary\u003Cstring, CameraShaker\u003E instanceList = new Dictionary\u003Cstring, CameraShaker\u003E();\n\n        /// \u003Csummary\u003E\n        /// The default position influcence of all shakes created by this shaker.\n        /// \u003C/summary\u003E\n        [Property] public Vector3 DefaultPosInfluence = new Vector3(0.15f, 0.15f, 0.15f);\r\n\t\t/// \u003Csummary\u003E\n\t\t/// The default rotation influcence of all shakes created by this shaker.\n\t\t/// \u003C/summary\u003E\n\t\t[Property]  public Vector3 DefaultRotInfluence = new Vector3(1, 1, 1);\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Offset that will be applied to the camera\u0027s default (0,0,0) rest position\n\t\t/// \u003C/summary\u003E\n\t\t[Property] public Vector3 RestPositionOffset = new Vector3(0, 0, 0);\r\n\t\t/// \u003Csummary\u003E\n\t\t/// Offset that will be applied to the camera\u0027s default (0,0,0) rest rotation\n\t\t/// \u003C/summary\u003E\n\t\t[Property] public Vector3 RestRotationOffset = new Vector3(0, 0, 0);\n\n        Vector3 posAddShake, rotAddShake;\n\n        List\u003CCameraShakeInstance\u003E cameraShakeInstances = new List\u003CCameraShakeInstance\u003E();\n\n        protected override void OnAwake()\n        {\n            Instance = this;\n            instanceList.Add(GameObject.Name, this);\n        }\r\n\r\n\t\tprotected override void OnUpdate()\n        {\n            posAddShake = Vector3.Zero;\n            rotAddShake = Vector3.Zero;\n\n            for (int i = 0; i \u003C cameraShakeInstances.Count; i\u002B\u002B)\n            {\n                if (i \u003E= cameraShakeInstances.Count)\n                    break;\n\n                CameraShakeInstance c = cameraShakeInstances[i];\n\n                if (c.CurrentState == CameraShakeState.Inactive \u0026\u0026 c.DeleteOnInactive)\n                {\n                    cameraShakeInstances.RemoveAt(i);\n                    i--;\n                }\n                else if (c.CurrentState != CameraShakeState.Inactive)\n                {\n                    posAddShake \u002B= CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence);\n                    rotAddShake \u002B= CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence);\n                }\n            }\n\n            Transform.LocalPosition = (posAddShake) \u002B RestPositionOffset;\r\n\t\t\tVector3 thing = (rotAddShake / 100) \u002B RestRotationOffset;\n\r\n\t\t\tTransform.LocalRotation = new Angles(thing.x, thing.y, thing.z);\n        }\n\n        /// \u003Csummary\u003E\n        /// Gets the CameraShaker with the given name, if it exists.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022name\u0022\u003EThe name of the camera shaker instance.\u003C/param\u003E\n        /// \u003Creturns\u003E\u003C/returns\u003E\n        public static CameraShaker GetInstance(string name)\n        {\n            CameraShaker c;\n\n            if (instanceList.TryGetValue(name, out c))\n                return c;\n\n            Log.Error(\u0022CameraShake \u0022 \u002B name \u002B \u0022 not found!\u0022);\n\n            return null;\n        }\n\n        /// \u003Csummary\u003E\n        /// Starts a shake using the given preset.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022shake\u0022\u003EThe preset to use.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance Shake(CameraShakeInstance shake)\n        {\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Shake the camera once, fading in and out  over a specified durations.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EHow long to fade out the shake, in seconds.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Shake the camera once, fading in and out over a specified durations.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EHow long to fade out the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022posInfluence\u0022\u003EHow much this shake influences position.\u003C/param\u003E\n        /// \u003Cparam name=\u0022rotInfluence\u0022\u003EHow much this shake influences rotation.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance ShakeOnce(float magnitude, float roughness, float fadeInTime, float fadeOutTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness, fadeInTime, fadeOutTime);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            cameraShakeInstances.Add(shake);\n\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Start shaking the camera.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = DefaultPosInfluence;\n            shake.RotationInfluence = DefaultRotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Start shaking the camera.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EHow long to fade in the shake, in seconds.\u003C/param\u003E\n        /// \u003Cparam name=\u0022posInfluence\u0022\u003EHow much this shake influences position.\u003C/param\u003E\n        /// \u003Cparam name=\u0022rotInfluence\u0022\u003EHow much this shake influences rotation.\u003C/param\u003E\n        /// \u003Creturns\u003EA CameraShakeInstance that can be used to alter the shake\u0027s properties.\u003C/returns\u003E\n        public CameraShakeInstance StartShake(float magnitude, float roughness, float fadeInTime, Vector3 posInfluence, Vector3 rotInfluence)\n        {\n            CameraShakeInstance shake = new CameraShakeInstance(magnitude, roughness);\n            shake.PositionInfluence = posInfluence;\n            shake.RotationInfluence = rotInfluence;\n            shake.StartFadeIn(fadeInTime);\n            cameraShakeInstances.Add(shake);\n            return shake;\n        }\n\n        /// \u003Csummary\u003E\n        /// Gets a copy of the list of current camera shake instances.\n        /// \u003C/summary\u003E\n        public List\u003CCameraShakeInstance\u003E ShakeInstances\n        { get { return new List\u003CCameraShakeInstance\u003E(cameraShakeInstances); } }\r\n\r\n\t\tprotected override void OnDestroy()\n        {\n            instanceList.Remove(GameObject.Name);\n        }\n    }\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"__gen_RazorNamespace.cs","FileName":"__gen_RazorNamespace.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"global using Microsoft.AspNetCore.Components; \nglobal using Microsoft.AspNetCore.Components.Rendering;\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"Code/CameraShakeInstance.cs","FileName":"CameraShakeInstance.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\nusing Sandbox.Utility;\nusing System;\n\nnamespace EZCameraShake\n{\n    public enum CameraShakeState { FadingIn, FadingOut, Sustained, Inactive }\n\n    public class CameraShakeInstance\n    {\n        /// \u003Csummary\u003EF*\n        /// The intensity of the shake. It is recommended that you use ScaleMagnitude to alter the magnitude of a shake.\n        /// \u003C/summary\u003E\n        public float Magnitude;\n\n        /// \u003Csummary\u003E\n        /// Roughness of the shake. It is recommended that you use ScaleRoughness to alter the roughness of a shake.\n        /// \u003C/summary\u003E\n        public float Roughness;\n\n        /// \u003Csummary\u003E\n        /// How much influence this shake has over the local position axes of the camera.\n        /// \u003C/summary\u003E\n        public Vector3 PositionInfluence;\n\n        /// \u003Csummary\u003E\n        /// How much influence this shake has over the local rotation axes of the camera.\n        /// \u003C/summary\u003E\n        public Vector3 RotationInfluence;\n\n        /// \u003Csummary\u003E\n        /// Should this shake be removed from the CameraShakeInstance list when not active?\n        /// \u003C/summary\u003E\n        public bool DeleteOnInactive = true;\n\n\n        float roughMod = 1, magnMod = 1;\n        float fadeOutDuration, fadeInDuration;\n        bool sustain;\n        float currentFadeTime;\n        float tick = 0;\n        Vector3 amt;\n\n        /// \u003Csummary\u003E\n        /// Will create a new instance that will shake once and fade over the given number of seconds.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EHow long, in seconds, to fade out the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        public CameraShakeInstance(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            this.Magnitude = magnitude;\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = fadeInTime;\n            this.Roughness = roughness;\n            if (fadeInTime \u003E 0)\n            {\n                sustain = true;\n                currentFadeTime = 0;\n            }\n            else\n            {\n                sustain = false;\n                currentFadeTime = 1;\n            }\n\r\n\t\t\tRandom rand = new Random();\n            tick = rand.Float(-100, 100);\n        }\n\n        /// \u003Csummary\u003E\n        /// Will create a new instance that will start a sustained shake.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        public CameraShakeInstance(float magnitude, float roughness)\n        {\n            this.Magnitude = magnitude;\n            this.Roughness = roughness;\n            sustain = true;\r\n\r\n\t\t\tRandom rand = new Random();\r\n\t\t\ttick = rand.Float( -100, 100 );\r\n\t\t}\n\n        public Vector3 UpdateShake()\n        {\n            amt.x = Noise.Perlin(tick, 0) - 0.5f;\n            amt.y = Noise.Perlin(0, tick) - 0.5f;\n            amt.z = Noise.Perlin(tick, tick) - 0.5f;\n\n            if (fadeInDuration \u003E 0 \u0026\u0026 sustain)\n            {\n                if (currentFadeTime \u003C 1)\n                    currentFadeTime \u002B= Time.Delta / fadeInDuration;\n                else if (fadeOutDuration \u003E 0)\n                    sustain = false;\n            }\n\n            if (!sustain)\n                currentFadeTime -= Time.Delta / fadeOutDuration;\n\n            if (sustain)\n                tick \u002B= Time.Delta * Roughness * roughMod;\n            else\n                tick \u002B= Time.Delta * Roughness * roughMod * currentFadeTime;\n\n            return amt * Magnitude * magnMod * currentFadeTime;\n        }\n\n        /// \u003Csummary\u003E\n        /// Starts a fade out over the given number of seconds.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EThe duration, in seconds, of the fade out.\u003C/param\u003E\n        public void StartFadeOut(float fadeOutTime)\n        {\n            if (fadeOutTime == 0)\n                currentFadeTime = 0;\n\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = 0;\n            sustain = false;\n        }\n\n        /// \u003Csummary\u003E\n        /// Starts a fade in over the given number of seconds.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EThe duration, in seconds, of the fade in.\u003C/param\u003E\n        public void StartFadeIn(float fadeInTime)\n        {\n            if (fadeInTime == 0)\n                currentFadeTime = 1;\n\n            fadeInDuration = fadeInTime;\n            fadeOutDuration = 0;\n            sustain = true;\n        }\n\n        /// \u003Csummary\u003E\n        /// Scales this shake\u0027s roughness while preserving the initial Roughness.\n        /// \u003C/summary\u003E\n        public float ScaleRoughness\n        {\n            get { return roughMod; }\n            set { roughMod = value; }\n        }\n\n        /// \u003Csummary\u003E\n        /// Scales this shake\u0027s magnitude while preserving the initial Magnitude.\n        /// \u003C/summary\u003E\n        public float ScaleMagnitude\n        {\n            get { return magnMod; }\n            set { magnMod = value; }\n        }\n\n        /// \u003Csummary\u003E\n        /// A normalized value (about 0 to about 1) that represents the current level of intensity.\n        /// \u003C/summary\u003E\n        public float NormalizedFadeTime\n        { get { return currentFadeTime; } }\n\n        bool IsShaking\n        { get { return currentFadeTime \u003E 0 || sustain; } }\n\n        bool IsFadingOut\n        { get { return !sustain \u0026\u0026 currentFadeTime \u003E 0; } }\n\n        bool IsFadingIn\n        { get { return currentFadeTime \u003C 1 \u0026\u0026 sustain \u0026\u0026 fadeInDuration \u003E 0; } }\n\n        /// \u003Csummary\u003E\n        /// Gets the current state of the shake.\n        /// \u003C/summary\u003E\n        public CameraShakeState CurrentState\n        {\n            get\n            {\n                if (IsFadingIn)\n                    return CameraShakeState.FadingIn;\n                else if (IsFadingOut)\n                    return CameraShakeState.FadingOut;\n                else if (IsShaking)\n                    return CameraShakeState.Sustained;\n                else\n                    return CameraShakeState.Inactive;\n            }\n        }\n    }\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"CameraShakeInstance.cs","FileName":"CameraShakeInstance.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"using Sandbox;\nusing Sandbox.Utility;\nusing System;\n\nnamespace EZCameraShake\n{\n    public enum CameraShakeState { FadingIn, FadingOut, Sustained, Inactive }\n\n    public class CameraShakeInstance\n    {\n        /// \u003Csummary\u003EF*\n        /// The intensity of the shake. It is recommended that you use ScaleMagnitude to alter the magnitude of a shake.\n        /// \u003C/summary\u003E\n        public float Magnitude;\n\n        /// \u003Csummary\u003E\n        /// Roughness of the shake. It is recommended that you use ScaleRoughness to alter the roughness of a shake.\n        /// \u003C/summary\u003E\n        public float Roughness;\n\n        /// \u003Csummary\u003E\n        /// How much influence this shake has over the local position axes of the camera.\n        /// \u003C/summary\u003E\n        public Vector3 PositionInfluence;\n\n        /// \u003Csummary\u003E\n        /// How much influence this shake has over the local rotation axes of the camera.\n        /// \u003C/summary\u003E\n        public Vector3 RotationInfluence;\n\n        /// \u003Csummary\u003E\n        /// Should this shake be removed from the CameraShakeInstance list when not active?\n        /// \u003C/summary\u003E\n        public bool DeleteOnInactive = true;\n\n\n        float roughMod = 1, magnMod = 1;\n        float fadeOutDuration, fadeInDuration;\n        bool sustain;\n        float currentFadeTime;\n        float tick = 0;\n        Vector3 amt;\n\n        /// \u003Csummary\u003E\n        /// Will create a new instance that will shake once and fade over the given number of seconds.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EHow long, in seconds, to fade out the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        public CameraShakeInstance(float magnitude, float roughness, float fadeInTime, float fadeOutTime)\n        {\n            this.Magnitude = magnitude;\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = fadeInTime;\n            this.Roughness = roughness;\n            if (fadeInTime \u003E 0)\n            {\n                sustain = true;\n                currentFadeTime = 0;\n            }\n            else\n            {\n                sustain = false;\n                currentFadeTime = 1;\n            }\n\r\n\t\t\tRandom rand = new Random();\n            tick = rand.Float(-100, 100);\n        }\n\n        /// \u003Csummary\u003E\n        /// Will create a new instance that will start a sustained shake.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022magnitude\u0022\u003EThe intensity of the shake.\u003C/param\u003E\n        /// \u003Cparam name=\u0022roughness\u0022\u003ERoughness of the shake. Lower values are smoother, higher values are more jarring.\u003C/param\u003E\n        public CameraShakeInstance(float magnitude, float roughness)\n        {\n            this.Magnitude = magnitude;\n            this.Roughness = roughness;\n            sustain = true;\r\n\r\n\t\t\tRandom rand = new Random();\r\n\t\t\ttick = rand.Float( -100, 100 );\r\n\t\t}\n\n        public Vector3 UpdateShake()\n        {\n            amt.x = Noise.Perlin(tick, 0) - 0.5f;\n            amt.y = Noise.Perlin(0, tick) - 0.5f;\n            amt.z = Noise.Perlin(tick, tick) - 0.5f;\n\n            if (fadeInDuration \u003E 0 \u0026\u0026 sustain)\n            {\n                if (currentFadeTime \u003C 1)\n                    currentFadeTime \u002B= Time.Delta / fadeInDuration;\n                else if (fadeOutDuration \u003E 0)\n                    sustain = false;\n            }\n\n            if (!sustain)\n                currentFadeTime -= Time.Delta / fadeOutDuration;\n\n            if (sustain)\n                tick \u002B= Time.Delta * Roughness * roughMod;\n            else\n                tick \u002B= Time.Delta * Roughness * roughMod * currentFadeTime;\n\n            return amt * Magnitude * magnMod * currentFadeTime;\n        }\n\n        /// \u003Csummary\u003E\n        /// Starts a fade out over the given number of seconds.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022fadeOutTime\u0022\u003EThe duration, in seconds, of the fade out.\u003C/param\u003E\n        public void StartFadeOut(float fadeOutTime)\n        {\n            if (fadeOutTime == 0)\n                currentFadeTime = 0;\n\n            fadeOutDuration = fadeOutTime;\n            fadeInDuration = 0;\n            sustain = false;\n        }\n\n        /// \u003Csummary\u003E\n        /// Starts a fade in over the given number of seconds.\n        /// \u003C/summary\u003E\n        /// \u003Cparam name=\u0022fadeInTime\u0022\u003EThe duration, in seconds, of the fade in.\u003C/param\u003E\n        public void StartFadeIn(float fadeInTime)\n        {\n            if (fadeInTime == 0)\n                currentFadeTime = 1;\n\n            fadeInDuration = fadeInTime;\n            fadeOutDuration = 0;\n            sustain = true;\n        }\n\n        /// \u003Csummary\u003E\n        /// Scales this shake\u0027s roughness while preserving the initial Roughness.\n        /// \u003C/summary\u003E\n        public float ScaleRoughness\n        {\n            get { return roughMod; }\n            set { roughMod = value; }\n        }\n\n        /// \u003Csummary\u003E\n        /// Scales this shake\u0027s magnitude while preserving the initial Magnitude.\n        /// \u003C/summary\u003E\n        public float ScaleMagnitude\n        {\n            get { return magnMod; }\n            set { magnMod = value; }\n        }\n\n        /// \u003Csummary\u003E\n        /// A normalized value (about 0 to about 1) that represents the current level of intensity.\n        /// \u003C/summary\u003E\n        public float NormalizedFadeTime\n        { get { return currentFadeTime; } }\n\n        bool IsShaking\n        { get { return currentFadeTime \u003E 0 || sustain; } }\n\n        bool IsFadingOut\n        { get { return !sustain \u0026\u0026 currentFadeTime \u003E 0; } }\n\n        bool IsFadingIn\n        { get { return currentFadeTime \u003C 1 \u0026\u0026 sustain \u0026\u0026 fadeInDuration \u003E 0; } }\n\n        /// \u003Csummary\u003E\n        /// Gets the current state of the shake.\n        /// \u003C/summary\u003E\n        public CameraShakeState CurrentState\n        {\n            get\n            {\n                if (IsFadingIn)\n                    return CameraShakeState.FadingIn;\n                else if (IsFadingOut)\n                    return CameraShakeState.FadingOut;\n                else if (IsShaking)\n                    return CameraShakeState.Sustained;\n                else\n                    return CameraShakeState.Inactive;\n            }\n        }\n    }\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"PlayerFootsteps.cs","FileName":"PlayerFootsteps.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"\r\npublic sealed class PlayerFootsteps : Component\r\n{\r\n\t[Property] SkinnedModelRenderer Source { get; set; }\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tif ( Source is null )\r\n\t\t\treturn;\r\n\r\n\t\tSource.OnFootstepEvent \u002B= OnEvent;\r\n\t}\r\n\r\n\tprotected override void OnDisabled()\r\n\t{\r\n\t\tif ( Source is null )\r\n\t\t\treturn;\r\n\r\n\t\tSource.OnFootstepEvent -= OnEvent;\r\n\t}\r\n\r\n\tTimeSince timeSinceStep;\r\n\r\n\tprivate void OnEvent( SceneModel.FootstepEvent e )\r\n\t{\r\n\t\tif ( timeSinceStep \u003C 0.2f )\r\n\t\t\treturn;\r\n\r\n\t\tvar tr = Scene.Trace\r\n\t\t\t.Ray( e.Transform.Position \u002B Vector3.Up * 20, e.Transform.Position \u002B Vector3.Up * -20 )\r\n\t\t\t.Run();\r\n\r\n\t\tif ( !tr.Hit )\r\n\t\t\treturn;\r\n\r\n\t\tif ( tr.Surface is null )\r\n\t\t\treturn;\r\n\r\n\t\ttimeSinceStep = 0;\r\n\r\n\t\tvar sound = e.FootId == 0 ? tr.Surface.Sounds.FootLeft : tr.Surface.Sounds.FootRight;\r\n\t\tif ( sound is null ) return;\r\n\r\n\t\tvar handle = Sound.Play( sound, tr.HitPosition \u002B tr.Normal * 5 );\r\n\t\thandle.Volume *= e.Volume;\r\n\t}\r\n}\r\n"},{"Ident":"blackdev.ezcamerashakeforsbox","Path":"PlayerPusher.cs","FileName":"PlayerPusher.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":66193,"IsPrivate":false,"Code":"\r\npublic sealed class PlayerPusher : Component\r\n{\r\n\t[Property] public float Radius { get; set; } = 100;\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tbase.DrawGizmos();\r\n\r\n\t\tGizmo.Draw.LineSphere( Vector3.Zero, Radius );\r\n\t}\r\n\r\n\tpublic static Vector3 GetPushVector( in Vector3 position, Scene scene, GameObject ignore )\r\n\t{\r\n\t\tVector3 vec = default;\r\n\r\n\t\tforeach ( var pusher in scene.GetAllComponents\u003CPlayerPusher\u003E() )\r\n\t\t{\r\n\t\t\tif ( pusher.GameObject.IsAncestor( ignore ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tpusher.Collect( position, ref vec );\r\n\t\t}\r\n\r\n\t\treturn vec;\r\n\t}\r\n\r\n\tprivate void Collect( Vector3 position, ref Vector3 output )\r\n\t{\r\n\t\tvar delta = (position - Transform.Position);\r\n\t\tif ( delta.Length \u003E Radius ) return;\r\n\r\n\t\tdelta.z = 0; // ignore z\r\n\r\n\t\tvar distanceDelta = (delta.Length / Radius);\r\n\r\n\t\toutput \u002B= delta.Normal * (1.0f - distanceDelta);\r\n\t}\r\n}\r\n"}]}