s&box Package Code Search

Search C# source code, UI razor templates, shaders, and configs across s&box packages.

Showing code results for query: * (7 total matches found)
facepunch.playercontroller / Code/PlayerController.cs
Game library
using Sandbox.Citizen;

[Group( "Walker" )]
[Title( "Walker - Player Controller" )]
public sealed class PlayerController : Component
{
	[Property] public CharacterController CharacterController { get; set; }
	[Property] public float CrouchMoveSpeed { get; set; } = 64.0f;
	[Property] public float WalkMoveSpeed { get; set; } = 190.0f;
	[Property] public float RunMoveSpeed { get; set; } = 190.0f;
	[Property] public float SprintMoveSpeed { get; set; } = 320.0f;

	[Property] public CitizenAnimationHelper AnimationHelper { get; set; }

	[Sync] public bool Crouching { get; set; }
	[Sync] public Angles EyeAngles { get; set; }
	[Sync] public Vector3 WishVelocity { get; set; }

	public bool WishCrouch;
	public float EyeHeight = 64;

	protected override void OnUpdate()
	{
		if ( !IsProxy )
		{
			MouseInput();
			Transform.Rotation = new Angles( 0, EyeAngles.yaw, 0 );
		}

		UpdateAnimation();
	}

	protected override void OnFixedUpdate()
	{
		if ( IsProxy )
			return;

		CrouchingInput();
		MovementInput();
	}

	private void MouseInput()
	{
		var e = EyeAngles;
		e += Input.AnalogLook;
		e.pitch = e.pitch.Clamp( -90, 90 );
		e.roll = 0.0f;
		EyeAngles = e;
	}

	float CurrentMoveSpeed
	{
		get
		{
			if ( Crouching ) return CrouchMoveSpeed;
			if ( Input.Down( "run" ) ) return SprintMoveSpeed;
			if ( Input.Down( "walk" ) ) return WalkMoveSpeed;

			return RunMoveSpeed;
		}
	}

	RealTimeSince lastGrounded;
	RealTimeSince lastUngrounded;
	RealTimeSince lastJump;

	float GetFriction()
	{
		if ( CharacterController.IsOnGround ) return 6.0f;

		// air friction
		return 0.2f;
	}

	private void MovementInput()
	{
		if ( CharacterController is null )
			return;

		var cc = CharacterController;

		Vector3 halfGravity = Scene.PhysicsWorld.Gravity * Time.Delta * 0.5f;

		WishVelocity = Input.AnalogMove;

		if ( lastGrounded < 0.2f && lastJump > 0.3f && Input.Pressed( "jump" ) )
		{
			lastJump = 0;
			cc.Punch( Vector3.Up * 300 );
		}

		if ( !WishVelocity.IsNearlyZero() )
		{
			WishVelocity = new Angles( 0, EyeAngles.yaw, 0 ).ToRotation() * WishVelocity;
			WishVelocity = WishVelocity.WithZ( 0 );
			WishVelocity = WishVelocity.ClampLength( 1 );
			WishVelocity *= CurrentMoveSpeed;

			if ( !cc.IsOnGround )
			{
				WishVelocity = WishVelocity.ClampLength( 50 );
			}
		}


		cc.ApplyFriction( GetFriction() );

		if ( cc.IsOnGround )
		{
			cc.Accelerate( WishVelocity );
			cc.Velocity = CharacterController.Velocity.WithZ( 0 );
		}
		else
		{
			cc.Velocity += halfGravity;
			cc.Accelerate( WishVelocity );

		}

		//
		// Don't walk through other players, let them push you out of the way
		//
		var pushVelocity = PlayerPusher.GetPushVector( Transform.Position + Vector3.Up * 40.0f, Scene, GameObject );
		if ( !pushVelocity.IsNearlyZero() )
		{
			var travelDot = cc.Velocity.Dot( pushVelocity.Normal );
			if ( travelDot < 0 )
			{
				cc.Velocity -= pushVelocity.Normal * travelDot * 0.6f;
			}

			cc.Velocity += pushVelocity * 128.0f;
		}

		cc.Move();

		if ( !cc.IsOnGround )
		{
			cc.Velocity += halfGravity;
		}
		else
		{
			cc.Velocity = cc.Velocity.WithZ( 0 );
		}

		if ( cc.IsOnGround )
		{
			lastGrounded = 0;
		}
		else
		{
			lastUngrounded = 0;
		}
	}
	float DuckHeight = (64 - 36);

	bool CanUncrouch()
	{
		if ( !Crouching ) return true;
		if ( lastUngrounded < 0.2f ) return false;

		var tr = CharacterController.TraceDirection( Vector3.Up * DuckHeight );
		return !tr.Hit; // hit nothing - we can!
	}

	public void CrouchingInput()
	{
		WishCrouch = Input.Down( "duck" );

		if ( WishCrouch == Crouching )
			return;

		// crouch
		if ( WishCrouch )
		{
			CharacterController.Height = 36;
			Crouching = WishCrouch;

			// if we're not on the ground, slide up our bbox so when we crouch
			// the bottom shrinks, instead of the top, which will mean we can reach
			// places by crouch jumping that we couldn't.
			if ( !CharacterController.IsOnGround )
			{
				CharacterController.MoveTo( Transform.Position += Vector3.Up * DuckHeight, false );
				Transform.ClearLerp();
				EyeHeight -= DuckHeight;
			}

			return;
		}

		// uncrouch
		if ( !WishCrouch )
		{
			if ( !CanUncrouch() ) return;

			CharacterController.Height = 64;
			Crouching = WishCrouch;
			return;
		}


	}

	private void UpdateCamera()
	{
		var camera = Scene.GetAllComponents<CameraComponent>().Where( x => x.IsMainCamera ).FirstOrDefault();
		if ( camera is null ) return;

		var targetEyeHeight = Crouching ? 28 : 64;
		EyeHeight = EyeHeight.LerpTo( targetEyeHeight, RealTime.Delta * 10.0f );

		var targetCameraPos = Transform.Position + new Vector3( 0, 0, EyeHeight );

		// smooth view z, so when going up and down stairs or ducking, it's smooth af
		if ( lastUngrounded > 0.2f )
		{
			targetCameraPos.z = camera.Transform.Position.z.LerpTo( targetCameraPos.z, RealTime.Delta * 25.0f );
		}

		camera.Transform.Position = targetCameraPos;
		camera.Transform.Rotation = EyeAngles;
		camera.FieldOfView = Preferences.FieldOfView;
	}

	protected override void OnPreRender()
	{
		UpdateBodyVisibility();

		if ( IsProxy )
			return;

		UpdateCamera();
	}

	private void UpdateAnimation()
	{
		if ( AnimationHelper is null ) return;

		var wv = WishVelocity.Length;

		AnimationHelper.WithWishVelocity( WishVelocity );
		AnimationHelper.WithVelocity( CharacterController.Velocity );
		AnimationHelper.IsGrounded = CharacterController.IsOnGround;
		AnimationHelper.DuckLevel = Crouching ? 1.0f : 0.0f;

		AnimationHelper.MoveStyle = wv < 160f ? CitizenAnimationHelper.MoveStyles.Walk : CitizenAnimationHelper.MoveStyles.Run;

		var lookDir = EyeAngles.ToRotation().Forward * 1024;
		AnimationHelper.WithLook( lookDir, 1, 0.5f, 0.25f );
	}

	private void UpdateBodyVisibility()
	{
		if ( AnimationHelper is null )
			return;

		var renderMode = ModelRenderer.ShadowRenderType.On;
		if ( !IsProxy ) renderMode = ModelRenderer.ShadowRenderType.ShadowsOnly;

		AnimationHelper.Target.RenderType = renderMode;

		foreach ( var clothing in AnimationHelper.Target.Components.GetAll<ModelRenderer>( FindMode.InChildren ) )
		{
			if ( !clothing.Tags.Has( "clothing" ) )
				continue;

			clothing.RenderType = renderMode;
		}
	}

}
facepunch.playercontroller / Code/Assembly.cs
Game library
global using System;
global using Sandbox;
global using System.Linq;
global using System.Threading.Tasks;
global using System.Collections.Generic;
facepunch.playercontroller / UnitTests/UnitTest.cs
UnitTest library
global using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class TestInit
{
	[AssemblyInitialize]
	public static void ClassInitialize( TestContext context )
	{
		Sandbox.Application.InitUnitTest();
	}
}
facepunch.playercontroller / UnitTests/LibraryTest.cs
UnitTest library
using Sandbox;

[TestClass]
public partial class LibraryTests
{
	[TestMethod]
	public void SceneTest()
	{
		var scene = new Scene();
		using ( scene.Push() )
		{
			var go = new GameObject();

			Assert.AreEqual( 1, scene.Directory.GameObjectCount );
		}
	}

}
facepunch.playercontroller / Code/PlayerPusher.cs
Game library
public sealed class PlayerPusher : Component
{
	[Property] public float Radius { get; set; } = 100;

	protected override void DrawGizmos()
	{
		base.DrawGizmos();

		Gizmo.Draw.LineSphere( Vector3.Zero, Radius );
	}

	public static Vector3 GetPushVector( in Vector3 position, Scene scene, GameObject ignore )
	{
		Vector3 vec = default;

		foreach ( var pusher in scene.GetAllComponents<PlayerPusher>() )
		{
			if ( pusher.GameObject.IsAncestor( ignore ) )
				continue;

			pusher.Collect( position, ref vec );
		}

		return vec;
	}

	private void Collect( Vector3 position, ref Vector3 output )
	{
		var delta = (position - Transform.Position);
		if ( delta.Length > Radius ) return;

		delta.z = 0; // ignore z

		var distanceDelta = (delta.Length / Radius);

		output += delta.Normal * (1.0f - distanceDelta);
	}
}
facepunch.playercontroller / Code/PlayerFootsteps.cs
Game library
public sealed class PlayerFootsteps : Component
{
	[Property] SkinnedModelRenderer Source { get; set; }

	protected override void OnEnabled()
	{
		if ( Source is null )
			return;

		Source.OnFootstepEvent += OnEvent;
	}

	protected override void OnDisabled()
	{
		if ( Source is null )
			return;

		Source.OnFootstepEvent -= OnEvent;
	}

	TimeSince timeSinceStep;

	private void OnEvent( SceneModel.FootstepEvent e )
	{
		if ( timeSinceStep < 0.2f )
			return;

		var tr = Scene.Trace
			.Ray( e.Transform.Position + Vector3.Up * 20, e.Transform.Position + Vector3.Up * -20 )
			.Run();

		if ( !tr.Hit )
			return;

		if ( tr.Surface is null )
			return;

		timeSinceStep = 0;

		var sound = e.FootId == 0 ? tr.Surface.Sounds.FootLeft : tr.Surface.Sounds.FootRight;
		if ( sound is null ) return;

		var handle = Sound.Play( sound, tr.HitPosition + tr.Normal * 5 );
		handle.Volume *= e.Volume;
		handle.Update();
	}
}
facepunch.playercontroller / Editor/MyEditorMenu.cs
Editor library
using Editor;

public static class MyEditorMenu
{
	[Menu( "Editor", "playercontroller/My Menu Option" )]
	public static void OpenMyMenu()
	{
		EditorUtility.DisplayDialog( "It worked!", "This is being called from your library's editor code!" );
	}
}
Debug: View Raw JSON Response
{
    "TotalCount": 7,
    "Files": [
        {
            "Ident": "facepunch.playercontroller",
            "Path": "Code/PlayerController.cs",
            "FileName": "PlayerController.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 56200,
            "IsPrivate": false,
            "Code": "using Sandbox.Citizen;\r\n\r\n[Group( \"Walker\" )]\r\n[Title( \"Walker - Player Controller\" )]\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\tpublic bool WishCrouch;\r\n\tpublic float EyeHeight = 64;\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\r\n\t\tUpdateAnimation();\r\n\t}\r\n\r\n\tprotected override void OnFixedUpdate()\r\n\t{\r\n\t\tif ( IsProxy )\r\n\t\t\treturn;\r\n\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 += 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( \"run\" ) ) return SprintMoveSpeed;\r\n\t\t\tif ( Input.Down( \"walk\" ) ) 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 < 0.2f && lastJump > 0.3f && Input.Pressed( \"jump\" ) )\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 += 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't 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 + 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 < 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 += 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 += 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 < 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( \"duck\" );\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're 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't.\r\n\t\t\tif ( !CharacterController.IsOnGround )\r\n\t\t\t{\r\n\t\t\t\tCharacterController.MoveTo( Transform.Position += Vector3.Up * DuckHeight, false );\r\n\t\t\t\tTransform.ClearLerp();\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<CameraComponent>().Where( x => x.IsMainCamera ).FirstOrDefault();\r\n\t\tif ( camera is null ) return;\r\n\r\n\t\tvar targetEyeHeight = Crouching ? 28 : 64;\r\n\t\tEyeHeight = EyeHeight.LerpTo( targetEyeHeight, RealTime.Delta * 10.0f );\r\n\r\n\t\tvar targetCameraPos = Transform.Position + new Vector3( 0, 0, EyeHeight );\r\n\r\n\t\t// smooth view z, so when going up and down stairs or ducking, it's smooth af\r\n\t\tif ( lastUngrounded > 0.2f )\r\n\t\t{\r\n\t\t\ttargetCameraPos.z = camera.Transform.Position.z.LerpTo( targetCameraPos.z, RealTime.Delta * 25.0f );\r\n\t\t}\r\n\r\n\t\tcamera.Transform.Position = targetCameraPos;\r\n\t\tcamera.Transform.Rotation = EyeAngles;\r\n\t\tcamera.FieldOfView = Preferences.FieldOfView;\r\n\t}\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 < 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<ModelRenderer>( FindMode.InChildren ) )\r\n\t\t{\r\n\t\t\tif ( !clothing.Tags.Has( \"clothing\" ) )\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": "facepunch.playercontroller",
            "Path": "Code/Assembly.cs",
            "FileName": "Assembly.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 56200,
            "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": "facepunch.playercontroller",
            "Path": "UnitTests/UnitTest.cs",
            "FileName": "UnitTest.cs",
            "PackageType": "library",
            "CodeKind": "UnitTest",
            "AssetVersionId": 56200,
            "IsPrivate": false,
            "Code": "global using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n\r\n[TestClass]\r\npublic class TestInit\r\n{\r\n\t[AssemblyInitialize]\r\n\tpublic static void ClassInitialize( TestContext context )\r\n\t{\r\n\t\tSandbox.Application.InitUnitTest();\r\n\t}\r\n}\r\n"
        },
        {
            "Ident": "facepunch.playercontroller",
            "Path": "UnitTests/LibraryTest.cs",
            "FileName": "LibraryTest.cs",
            "PackageType": "library",
            "CodeKind": "UnitTest",
            "AssetVersionId": 56200,
            "IsPrivate": false,
            "Code": "using Sandbox;\r\n\r\n[TestClass]\r\npublic partial class LibraryTests\r\n{\r\n\t[TestMethod]\r\n\tpublic void SceneTest()\r\n\t{\r\n\t\tvar scene = new Scene();\r\n\t\tusing ( scene.Push() )\r\n\t\t{\r\n\t\t\tvar go = new GameObject();\r\n\r\n\t\t\tAssert.AreEqual( 1, scene.Directory.GameObjectCount );\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"
        },
        {
            "Ident": "facepunch.playercontroller",
            "Path": "Code/PlayerPusher.cs",
            "FileName": "PlayerPusher.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 56200,
            "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<PlayerPusher>() )\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 > 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 += delta.Normal * (1.0f - distanceDelta);\r\n\t}\r\n}\r\n"
        },
        {
            "Ident": "facepunch.playercontroller",
            "Path": "Code/PlayerFootsteps.cs",
            "FileName": "PlayerFootsteps.cs",
            "PackageType": "library",
            "CodeKind": "Game",
            "AssetVersionId": 56200,
            "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 += 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 < 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 + Vector3.Up * 20, e.Transform.Position + 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 + tr.Normal * 5 );\r\n\t\thandle.Volume *= e.Volume;\r\n\t\thandle.Update();\r\n\t}\r\n}\r\n"
        },
        {
            "Ident": "facepunch.playercontroller",
            "Path": "Editor/MyEditorMenu.cs",
            "FileName": "MyEditorMenu.cs",
            "PackageType": "library",
            "CodeKind": "Editor",
            "AssetVersionId": 56200,
            "IsPrivate": false,
            "Code": "using Editor;\r\n\r\npublic static class MyEditorMenu\r\n{\r\n\t[Menu( \"Editor\", \"playercontroller/My Menu Option\" )]\r\n\tpublic static void OpenMyMenu()\r\n\t{\r\n\t\tEditorUtility.DisplayDialog( \"It worked!\", \"This is being called from your library's editor code!\" );\r\n\t}\r\n}\r\n"
        }
    ]
}