Compare commits
4 Commits
e5e350d2e4
...
f25c48ee4c
| Author | SHA1 | Date | |
|---|---|---|---|
| f25c48ee4c | |||
| 00efc742b4 | |||
| 809e03522c | |||
| 78c575d472 |
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "KCC.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:59e0d194a3386664994b93ac9f3170db"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd50bb19a3b51754ea8e27fe94e3f679
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "KCC"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59e0d194a3386664994b93ac9f3170db
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
8
Assets/Scripts.meta
Normal file
8
Assets/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0a3d3b0395872c409bf55cd8db1154f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Editor.meta
Normal file
8
Assets/Scripts/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e55b2b3e75ec6fe449c14e686fa948be
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Runtime.meta
Normal file
8
Assets/Scripts/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a8b2008d08303f4892c6124e12ce451
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/Runtime/Boxfriend.asmdef
Normal file
18
Assets/Scripts/Runtime/Boxfriend.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Boxfriend",
|
||||
"rootNamespace": "Boxfriend",
|
||||
"references": [
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:59e0d194a3386664994b93ac9f3170db",
|
||||
"GUID:753ee3d76e3343644abe0f9a98da4ded"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/Runtime/Boxfriend.asmdef.meta
Normal file
7
Assets/Scripts/Runtime/Boxfriend.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f526343eafc68ba469a85bca718544f4
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Runtime/ConstantStrings.cs
Normal file
15
Assets/Scripts/Runtime/ConstantStrings.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Boxfriend
|
||||
{
|
||||
public class ConstantStrings
|
||||
{
|
||||
public const string PlayerActionMap = "Player";
|
||||
public const string InteractInput = "Interact";
|
||||
public const string JumpInput = "Jump";
|
||||
public const string MoveInput = "Move";
|
||||
public const string CrouchInput = "Crouch";
|
||||
public const string SprintInput = "Sprint";
|
||||
public const string LookInput = "Look";
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Runtime/ConstantStrings.cs.meta
Normal file
2
Assets/Scripts/Runtime/ConstantStrings.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb691a8ce5d40ee46897a94cf9324b80
|
||||
8
Assets/Scripts/Runtime/Input.meta
Normal file
8
Assets/Scripts/Runtime/Input.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffc1fd0c06f8ee049864fababfc75429
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Scripts/Runtime/Input/InputDispatcher.cs
Normal file
47
Assets/Scripts/Runtime/Input/InputDispatcher.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Boxfriend.Input
|
||||
{
|
||||
public class InputDispatcher : MonoBehaviour
|
||||
{
|
||||
public event Action<Vector2> OnMove;
|
||||
public event Action<Vector2> OnLook;
|
||||
public event Action<bool> OnSprint;
|
||||
public event Action<bool> OnCrouch;
|
||||
public event Action OnJump;
|
||||
public event Action OnInteract;
|
||||
|
||||
private InputActionMap _inputActions;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_inputActions = InputSystem.actions.FindActionMap(ConstantStrings.PlayerActionMap);
|
||||
|
||||
Subscribe();
|
||||
}
|
||||
|
||||
private void Subscribe()
|
||||
{
|
||||
_inputActions.FindAction(ConstantStrings.InteractInput).performed += _ => OnInteract?.Invoke();
|
||||
|
||||
_inputActions.FindAction(ConstantStrings.JumpInput).performed += _ => OnJump?.Invoke();
|
||||
|
||||
_inputActions.FindAction(ConstantStrings.MoveInput).performed += ctx => OnMove?.Invoke(ctx.ReadValue<Vector2>());
|
||||
_inputActions.FindAction(ConstantStrings.MoveInput).canceled += ctx => OnMove?.Invoke(ctx.ReadValue<Vector2>());
|
||||
|
||||
_inputActions.FindAction(ConstantStrings.LookInput).performed += ctx => OnLook?.Invoke(ctx.ReadValue<Vector2>());
|
||||
|
||||
_inputActions.FindAction(ConstantStrings.SprintInput).performed += ctx => OnSprint?.Invoke(ctx.ReadValueAsButton());
|
||||
_inputActions.FindAction(ConstantStrings.SprintInput).canceled += ctx => OnSprint?.Invoke(ctx.ReadValueAsButton());
|
||||
|
||||
_inputActions.FindAction(ConstantStrings.CrouchInput).performed += ctx => OnCrouch?.Invoke(ctx.ReadValueAsButton());
|
||||
_inputActions.FindAction(ConstantStrings.CrouchInput).canceled += ctx => OnCrouch?.Invoke(ctx.ReadValueAsButton());
|
||||
}
|
||||
|
||||
private void OnEnable () => _inputActions.Enable();
|
||||
private void OnDisable () => _inputActions.Disable();
|
||||
private void OnDestroy () => _inputActions.Dispose();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Runtime/Input/InputDispatcher.cs.meta
Normal file
2
Assets/Scripts/Runtime/Input/InputDispatcher.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa5ffe305bd55df4da17e57cf5f34574
|
||||
8
Assets/Scripts/Runtime/Player.meta
Normal file
8
Assets/Scripts/Runtime/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f9c675b73c66254baa0d7f1beedcb87
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
99
Assets/Scripts/Runtime/Player/PlayerMotor.cs
Normal file
99
Assets/Scripts/Runtime/Player/PlayerMotor.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using Boxfriend.Extensions;
|
||||
using Boxfriend.Input;
|
||||
using KinematicCharacterController;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Boxfriend.Player
|
||||
{
|
||||
[RequireComponent(typeof(InputDispatcher))]
|
||||
[RequireComponent(typeof(KinematicCharacterMotor))]
|
||||
public class PlayerMotor : MonoBehaviour, ICharacterController
|
||||
{
|
||||
[SerializeField, InspectorOnly] private KinematicCharacterMotor _characterMotor;
|
||||
[SerializeField, InspectorOnly] private InputDispatcher _input;
|
||||
|
||||
private bool _isSprinting;
|
||||
private float _yRotation;
|
||||
private float _gravityVelocity;
|
||||
private Vector3 _moveDirection;
|
||||
private Vector3 _groundNormal = Vector3.up;
|
||||
|
||||
[SerializeField, InspectorOnly] private float _moveSpeed;
|
||||
[SerializeField, InspectorOnly] private float _defaultGravity;
|
||||
[SerializeField, InspectorOnly] private float _jumpForce;
|
||||
|
||||
|
||||
private void Awake ()
|
||||
{
|
||||
_input.OnLook += OnLook;
|
||||
_input.OnMove += OnMove;
|
||||
_input.OnJump += OnJump;
|
||||
_input.OnSprint += OnSprint;
|
||||
|
||||
_characterMotor.CharacterController = this;
|
||||
}
|
||||
|
||||
private void OnLook (Vector2 delta) => _yRotation = Mathf.Repeat(_yRotation + delta.x, 360);
|
||||
private void OnMove (Vector2 inputDir) => _moveDirection = inputDir.To3D();
|
||||
|
||||
private void OnSprint (bool sprinting) => _isSprinting = sprinting;
|
||||
private void OnJump ()
|
||||
{
|
||||
if (!_characterMotor.GroundingStatus.IsStableOnGround)
|
||||
return;
|
||||
|
||||
|
||||
_characterMotor.ForceUnground();
|
||||
_groundNormal = Vector3.up;
|
||||
_gravityVelocity = _jumpForce;
|
||||
}
|
||||
|
||||
public void UpdateRotation (ref Quaternion currentRotation, float deltaTime) => currentRotation = Quaternion.Euler(0, _yRotation, 0);
|
||||
|
||||
public void UpdateVelocity (ref Vector3 currentVelocity, float deltaTime)
|
||||
{
|
||||
if (!_characterMotor.GroundingStatus.IsStableOnGround)
|
||||
{
|
||||
_gravityVelocity += _defaultGravity * deltaTime;
|
||||
currentVelocity.y = _gravityVelocity;
|
||||
return;
|
||||
}
|
||||
|
||||
_gravityVelocity = 0;
|
||||
|
||||
var moveDir = transform.TransformDirection(_moveDirection);
|
||||
var direction = _characterMotor.GetDirectionTangentToSurface(moveDir, _groundNormal);
|
||||
direction *= _isSprinting ? _moveSpeed * 1.5f : _moveSpeed;
|
||||
direction.y += _gravityVelocity;
|
||||
|
||||
currentVelocity = direction;
|
||||
}
|
||||
|
||||
public void BeforeCharacterUpdate (float deltaTime) { }
|
||||
|
||||
public void PostGroundingUpdate (float deltaTime) { }
|
||||
|
||||
public void AfterCharacterUpdate (float deltaTime) { }
|
||||
|
||||
public bool IsColliderValidForCollisions (Collider coll) => coll != _characterMotor.Capsule;
|
||||
|
||||
public void OnGroundHit (Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint,
|
||||
ref HitStabilityReport hitStabilityReport) => _groundNormal = hitNormal;
|
||||
|
||||
public void OnMovementHit (Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint,
|
||||
ref HitStabilityReport hitStabilityReport)
|
||||
{ }
|
||||
|
||||
public void ProcessHitStabilityReport (Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, Vector3 atCharacterPosition,
|
||||
Quaternion atCharacterRotation, ref HitStabilityReport hitStabilityReport)
|
||||
{ }
|
||||
|
||||
public void OnDiscreteCollisionDetected (Collider hitCollider) { }
|
||||
|
||||
private void Reset ()
|
||||
{
|
||||
_characterMotor = GetComponent<KinematicCharacterMotor>();
|
||||
_input = GetComponent<InputDispatcher>();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Runtime/Player/PlayerMotor.cs.meta
Normal file
2
Assets/Scripts/Runtime/Player/PlayerMotor.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aae104d826c777940970b41deaa82b38
|
||||
@@ -24,20 +24,11 @@
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Attack",
|
||||
"type": "Button",
|
||||
"id": "6c2ab1b8-8984-453a-af3d-a3c78ae1679a",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Interact",
|
||||
"type": "Button",
|
||||
"id": "852140f2-7766-474d-8707-702459ba45f3",
|
||||
"expectedControlType": "Button",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "Hold",
|
||||
"initialStateCheck": false
|
||||
@@ -60,29 +51,11 @@
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Previous",
|
||||
"type": "Button",
|
||||
"id": "2776c80d-3c14-4091-8c56-d04ced07a2b0",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Next",
|
||||
"type": "Button",
|
||||
"id": "b7230bb6-fc9b-4f52-8b25-f5e19cb2c2ba",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Sprint",
|
||||
"type": "Button",
|
||||
"id": "641cd816-40e6-41b4-8c3d-04687c349290",
|
||||
"expectedControlType": "Button",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
@@ -254,94 +227,6 @@
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "143bb1cd-cc10-4eca-a2f0-a3664166fe91",
|
||||
"path": "<Gamepad>/buttonWest",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Gamepad",
|
||||
"action": "Attack",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "05f6913d-c316-48b2-a6bb-e225f14c7960",
|
||||
"path": "<Mouse>/leftButton",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Attack",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "886e731e-7071-4ae4-95c0-e61739dad6fd",
|
||||
"path": "<Touchscreen>/primaryTouch/tap",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Touch",
|
||||
"action": "Attack",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "ee3d0cd2-254e-47a7-a8cb-bc94d9658c54",
|
||||
"path": "<Joystick>/trigger",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Joystick",
|
||||
"action": "Attack",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "8255d333-5683-4943-a58a-ccb207ff1dce",
|
||||
"path": "<XRController>/{PrimaryAction}",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "XR",
|
||||
"action": "Attack",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "b3c1c7f0-bd20-4ee7-a0f1-899b24bca6d7",
|
||||
"path": "<Keyboard>/enter",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard&Mouse",
|
||||
"action": "Attack",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "cbac6039-9c09-46a1-b5f2-4e5124ccb5ed",
|
||||
"path": "<Keyboard>/2",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard&Mouse",
|
||||
"action": "Next",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "e15ca19d-e649-4852-97d5-7fe8ccc44e94",
|
||||
"path": "<Gamepad>/dpad/right",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Gamepad",
|
||||
"action": "Next",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "f2e9ba44-c423-42a7-ad56-f20975884794",
|
||||
@@ -408,28 +293,6 @@
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "1534dc16-a6aa-499d-9c3a-22b47347b52a",
|
||||
"path": "<Keyboard>/1",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard&Mouse",
|
||||
"action": "Previous",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "25060bbd-a3a6-476e-8fba-45ae484aad05",
|
||||
"path": "<Gamepad>/dpad/left",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Gamepad",
|
||||
"action": "Previous",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "1c04ea5f-b012-41d1-a6f7-02e963b52893",
|
||||
@@ -466,7 +329,7 @@
|
||||
{
|
||||
"name": "",
|
||||
"id": "36e52cba-0905-478e-a818-f4bfcb9f3b9a",
|
||||
"path": "<Keyboard>/c",
|
||||
"path": "<Keyboard>/ctrl",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard&Mouse",
|
||||
8
Assets/Settings/URP.meta
Normal file
8
Assets/Settings/URP.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9975e5819c0cc954994cc862a9f51464
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 6000.4.0a4
|
||||
m_EditorVersionWithRevision: 6000.4.0a4 (e3c84445ccf5)
|
||||
m_EditorVersion: 6000.4.0a5
|
||||
m_EditorVersionWithRevision: 6000.4.0a5 (12f7d227ffca)
|
||||
|
||||
Reference in New Issue
Block a user