1
This commit is contained in:
@@ -14,7 +14,8 @@
|
||||
"GUID:1235ca61e7f433b408ed5a68767e7123",
|
||||
"GUID:bea3628e8b592ae47ade218cb9ec98db",
|
||||
"GUID:f822dbf6fdfd4a5469cccaa2e4eed3b6",
|
||||
"GUID:a3de65b07192e7d49bad7b4032d681de"
|
||||
"GUID:a3de65b07192e7d49bad7b4032d681de",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using BITFALL.Entities.Player.Movement.States;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Entities.Physics;
|
||||
using BITKit.Entities.Player;
|
||||
using Lightbug.CharacterControllerPro.Core;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
@@ -12,11 +14,13 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace BITFALL.Entities.Player.Movement
|
||||
{
|
||||
public class PlayerCharacterController : StateBasedPlayerComponent<IEntityMovementState>,IEntityMovement,IServiceRegister
|
||||
[CustomType(typeof(IEntityMovement))]
|
||||
[CustomType(typeof(IPlayerMovement))]
|
||||
public class PlayerCharacterController : StateBasedPlayerComponent<IEntityMovementState>,IEntityMovement,IServiceRegister,IPlayerMovement
|
||||
{
|
||||
public override Type BaseType => typeof(IEntityMovement);
|
||||
[SerializeField] private CharacterActor actor;
|
||||
[SerializeField] private Vector3 initialCameraPosition = new Vector3(0,0.11f,0.27f);
|
||||
[SerializeField] private Vector3 initialCameraPosition = new(0,0.11f,0.27f);
|
||||
[SerializeField] private float initialSpeed;
|
||||
|
||||
[SerializeReference,SubclassSelector] private IClosePoint climbClosePoint;
|
||||
@@ -25,9 +29,12 @@ namespace BITFALL.Entities.Player.Movement
|
||||
private IProvider adsProvider;
|
||||
|
||||
[SerializeField] private Transform cameraTransform;
|
||||
public Vector3 ViewCenter { get; set; }
|
||||
public Quaternion ViewRotation { get; set; }
|
||||
public Vector3 LocomotionBasedVelocity { get;private set; }
|
||||
public Vector3 Velocity => actor.Velocity;
|
||||
public Vector3 GroundVelocity=>actor.GroundVelocity;
|
||||
public Vector3 AngularVelocity { get;private set; }
|
||||
public bool IsGrounded => actor.IsGrounded;
|
||||
|
||||
public Vector3 MovementInput { get; private set; }
|
||||
@@ -38,8 +45,8 @@ namespace BITFALL.Entities.Player.Movement
|
||||
public ExpectState<bool> ExpectSprint;
|
||||
public ExpectState<Vector3> expectClimb;
|
||||
public Vector3 CurrentCameraPosition;
|
||||
|
||||
private readonly ValidHandle allowMovement = new();
|
||||
private readonly ValidHandle allowRun = new();
|
||||
private IEntityPhysics physics;
|
||||
private IHealth _health;
|
||||
private bool isDead;
|
||||
@@ -63,6 +70,7 @@ namespace BITFALL.Entities.Player.Movement
|
||||
private void OnSetAlive(bool obj)
|
||||
{
|
||||
allowMovement.SetElements(this,obj);
|
||||
allowRun.SetElements(this,obj);
|
||||
if (obj)
|
||||
{
|
||||
if (!isDead) return;
|
||||
@@ -91,13 +99,26 @@ namespace BITFALL.Entities.Player.Movement
|
||||
ExpectSprint.Reset();
|
||||
}
|
||||
|
||||
public void ExecuteCommand<T>(T command)
|
||||
public void ExecuteCommand<T>(T command=default)
|
||||
{
|
||||
foreach (var x in StateDictionary.Values)
|
||||
{
|
||||
x.ExecuteCommand<T>(command);
|
||||
}
|
||||
switch (command)
|
||||
{
|
||||
case PlayerEnableRunCommand enableRunCommand:
|
||||
allowRun.RemoveDisableElements(enableRunCommand.Lock);
|
||||
ExpectRun.Reset();
|
||||
ExpectSprint.Reset();
|
||||
break;
|
||||
case PlayerDisableRunCommand disableRunCommand:
|
||||
allowRun.AddDisableElements(disableRunCommand.Lock);
|
||||
break;
|
||||
}
|
||||
OnCommand?.Invoke(command);
|
||||
}
|
||||
public event Action<object> OnCommand;
|
||||
|
||||
public void View(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -111,6 +132,12 @@ namespace BITFALL.Entities.Player.Movement
|
||||
lookInput.y += raw.x;
|
||||
lookInput.x = Mathf.Clamp(lookInput.x, -80, 80);
|
||||
LookInput = lookInput;
|
||||
|
||||
AngularVelocity = new Vector3
|
||||
(
|
||||
raw.y,
|
||||
-raw.x
|
||||
);
|
||||
}
|
||||
public void Jump(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -127,6 +154,7 @@ namespace BITFALL.Entities.Player.Movement
|
||||
}
|
||||
public void Run(InputAction.CallbackContext context)
|
||||
{
|
||||
if (allowRun.Allow is false) return;
|
||||
switch (context)
|
||||
{
|
||||
case { interaction: PressInteraction, started: true }:
|
||||
@@ -191,6 +219,18 @@ namespace BITFALL.Entities.Player.Movement
|
||||
cameraTransform.rotation = rotation;
|
||||
CurrentState?.AfterUpdateMovement(deltaTime);
|
||||
cameraTransform.localPosition = Vector3.Lerp(cameraTransform.localPosition,CurrentCameraPosition,5 * deltaTime);
|
||||
|
||||
ViewCenter = cameraTransform.position;
|
||||
ViewRotation = rotation;
|
||||
}
|
||||
|
||||
public void AddViewEuler(float2 euler)
|
||||
{
|
||||
LookInput = new Vector3
|
||||
{
|
||||
x = LookInput.x + euler.x,
|
||||
y = LookInput.y + euler.y
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -37,11 +37,14 @@ namespace BITFALL.Entities.Player.Movement.States
|
||||
|
||||
// Smooth movement Velocity
|
||||
currentVelocity = Vector3.Lerp(currentVelocity, targetMovementVelocity, 1f - Mathf.Exp(-16 * deltaTime));
|
||||
|
||||
if (!characterController.ExpectJump.shouldBe) return;
|
||||
actor.ForceNotGrounded();
|
||||
currentVelocity += Vector3.up * initialJumpForce;
|
||||
characterController.ExpectJump.Reset();
|
||||
|
||||
if (characterController.ExpectJump.shouldBe)
|
||||
{
|
||||
actor.ForceNotGrounded();
|
||||
currentVelocity += Vector3.up * initialJumpForce;
|
||||
characterController.ExpectJump.Reset();
|
||||
characterController.ExecuteCommand<OnPlayerJumpCommand>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "BITFALL.Player.Survival.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:26fc13cbbc427414f9af2143d581330a",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
54
Assets/Artists/Scripts/Player/Survival/PlayerSurvival.cs
Normal file
54
Assets/Artists/Scripts/Player/Survival/PlayerSurvival.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Player.Survival
|
||||
{
|
||||
[CustomType(typeof(IPlayerSurvival))]
|
||||
public class PlayerSurvival : EntityComponent, IPlayerSurvival
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private IPlayerSurvivalState[] survivalStates;
|
||||
private readonly IntervalUpdate interval = new(1);
|
||||
private bool initialized;
|
||||
private CancellationToken _cancellationToken;
|
||||
public override void OnAwake()
|
||||
{
|
||||
_cancellationToken = entity.Get<CancellationToken>();
|
||||
foreach (var x in survivalStates)
|
||||
{
|
||||
x.OnStateInitialize();
|
||||
}
|
||||
}
|
||||
public override async void OnStart()
|
||||
{
|
||||
foreach (var x in survivalStates)
|
||||
{
|
||||
await x.OnStateInitializeAsync(_cancellationToken);
|
||||
}
|
||||
foreach (var x in survivalStates)
|
||||
{
|
||||
x.OnStateInitialized();
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
public override void OnFixedUpdate(float deltaTime)
|
||||
{
|
||||
if (interval.AllowUpdate is false || initialized is false) return;
|
||||
foreach (var x in survivalStates)
|
||||
{
|
||||
x.ProcessState();
|
||||
if(x.TryGetNewEvent(out var newEvent))
|
||||
OnSurvivalEventOpened?.Invoke(newEvent);
|
||||
if(x.TryGetClosedEvent(out var closedEvent))
|
||||
OnSurvivalEventClosed?.Invoke(closedEvent);
|
||||
}
|
||||
}
|
||||
public event Action<IPlayerSurvivalState> OnSurvivalStateChanged;
|
||||
public event Action<IPlayerSurvivalEvent> OnSurvivalEventOpened;
|
||||
public event Action<IPlayerSurvivalEvent> OnSurvivalEventClosed;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user