This commit is contained in:
CortexCore
2023-10-02 23:24:56 +08:00
parent 8ef5c7ec0a
commit 947e52e748
183 changed files with 107857 additions and 9378 deletions

View File

@@ -27,8 +27,9 @@ namespace BITFALL.Entities.Player.Movement
[SerializeReference, SubclassSelector]
private IProvider adsProvider;
[SerializeField] private LocationAdditive locationAdditive;
[SerializeField] private Transform cameraTransform;
public Vector3 ViewCenter { get; set; }
public Quaternion ViewRotation { get; set; }
public Vector3 LocomotionBasedVelocity { get;private set; }
@@ -43,8 +44,8 @@ namespace BITFALL.Entities.Player.Movement
public ExpectState<bool> ExpectJump;
public ExpectState<bool> ExpectCrouch;
public ExpectState<bool> ExpectSprint;
public ExpectState<Vector3> expectClimb;
public Vector3 CurrentCameraPosition;
public ExpectState<Vector3> ExpectClimb;
public ExpectState<Vector3> CurrentCameraPosition;
private readonly ValidHandle allowMovement = new();
private readonly ValidHandle allowRun = new();
private IEntityPhysics physics;
@@ -53,7 +54,6 @@ namespace BITFALL.Entities.Player.Movement
private Vector3 keepVelocity;
public override void OnAwake()
{
CurrentCameraPosition = initialCameraPosition;
_health = entity.Get<IHealth>();
_health.OnSetAlive += OnSetAlive;
physics = entity.Get<IEntityPhysics>();
@@ -126,7 +126,7 @@ namespace BITFALL.Entities.Player.Movement
var playerConfig = Data.Get<PlayerConfig>() ?? new PlayerConfig();
var ads = adsProvider.Get<float>();
if (ads is 0) ads = 1;
var raw = context.ReadValue<Vector2>() * playerConfig.sensitivity * playerConfig.m_yaw * ads;
var raw = context.ReadValue<Vector2>() * playerConfig.Sensitivity * playerConfig.M_Yaw * ads;
var lookInput = LookInput;
lookInput.x -= raw.y;
lookInput.y += raw.x;
@@ -148,7 +148,7 @@ namespace BITFALL.Entities.Player.Movement
ExpectCrouch.Reset();
if (climbClosePoint.TryGetClosePoint(out var closePoint))
{
expectClimb.shouldBe = closePoint;
ExpectClimb.shouldBe = closePoint;
TransitionState<Climb>();
}
}
@@ -188,8 +188,10 @@ namespace BITFALL.Entities.Player.Movement
public override void OnUpdate(float deltaTime)
{
CurrentState?.BeforeUpdateMovement(deltaTime);
CurrentState?.AfterUpdateMovement(deltaTime);
}
public override void OnFixedUpdate(float deltaTime)
{
var currentVelocity = actor.Velocity;
@@ -215,13 +217,19 @@ namespace BITFALL.Entities.Player.Movement
public override void OnLateUpdate(float deltaTime)
{
if (allowMovement.Allow is false) return;
var rotation = Quaternion.Euler(LookInput);
cameraTransform.rotation = rotation;
CurrentState?.AfterUpdateMovement(deltaTime);
cameraTransform.localPosition = Vector3.Lerp(cameraTransform.localPosition,CurrentCameraPosition,5 * deltaTime);
var additiveTransform = locationAdditive.transform;
var rotation = Quaternion.Euler(LookInput);
locationAdditive.SetGlobalRotation(rotation);
CurrentCameraPosition.being = Vector3.Lerp(CurrentCameraPosition.being,CurrentCameraPosition.shouldBe,5 * deltaTime);
locationAdditive.AddPosition(CurrentCameraPosition);
ViewCenter = cameraTransform.position;
ViewRotation = rotation;
ViewCenter = additiveTransform.position + additiveTransform.forward;
}
public void AddViewEuler(float2 euler)

View File

@@ -18,7 +18,7 @@ namespace BITFALL.Entities.Player.Movement.States
[SerializeField] protected float initialJumpForce = 5f;
public override void BeforeUpdateMovement(float deltaTime)
{
characterController.CurrentCameraPosition = initialCameraPosition;
characterController.CurrentCameraPosition.shouldBe = initialCameraPosition;
}
public override void UpdateVelocity(ref Vector3 currentVelocity,float deltaTime)

View File

@@ -20,7 +20,7 @@ namespace BITFALL.Entities.Player.Movement.States
}
public override void OnStateUpdate(float deltaTime)
{
if (Vector3.Distance(characterController.expectClimb.shouldBe, characterController.transform.position) < 0.1f || actor.IsStable)
if (Vector3.Distance(characterController.ExpectClimb.shouldBe, characterController.transform.position) < 0.1f || actor.IsStable)
{
characterController.TransitionState<Walk>();
}
@@ -35,7 +35,7 @@ namespace BITFALL.Entities.Player.Movement.States
public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
{
currentVelocity =(characterController.expectClimb.shouldBe - characterController.transform.position)*lerpDelta;
currentVelocity =(characterController.ExpectClimb.shouldBe - characterController.transform.position)*lerpDelta;
}
}
}

View File

@@ -7,7 +7,10 @@
"GUID:d525ad6bd40672747bde77962f1c401e",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:26fc13cbbc427414f9af2143d581330a",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
"GUID:677cd05ca06c46b4395470200b1acdad",
"GUID:30cdc242b1ac6a944a460f4ab0b77b88"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Player.Inventory;
using BITKit;
using BITKit.Entities;
using UnityEngine;
namespace BITFALL.Player.Survival
{
public class PlayerEatService : EntityComponent
{
private IPlayerSurvivalService _survival;
private IPlayerInventory _inventory;
public override void OnStart()
{
base.OnStart();
_inventory = entity.Get<IPlayerInventory>();
_inventory.OnUseItem += OnUseItem;
_survival = entity.Get<IPlayerSurvivalService>();
}
private bool OnUseItem(IBasicItem arg)
{
switch (arg)
{
case var _ when arg.GetAssetable().TryGetProperty<PlayerEatAddHunger>(out var addHunger) &&
_survival.Elements.TryGetAny(x => x is PlayerSurvivalHunger, out var hunger):
hunger.Value += addHunger.Value;
return true;
}
return false;
}
}
}

View File

@@ -8,47 +8,25 @@ using UnityEngine;
namespace BITFALL.Player.Survival
{
[CustomType(typeof(IPlayerSurvival))]
public class PlayerSurvival : EntityComponent, IPlayerSurvival
[CustomType(typeof(IPlayerSurvivalService))]
public class PlayerSurvivalService : EntityComponent, IPlayerSurvivalService
{
[SerializeReference, SubclassSelector] private IPlayerSurvivalState[] survivalStates;
private readonly IntervalUpdate interval = new(1);
private bool initialized;
private CancellationToken _cancellationToken;
public IPlayerSurvivalElement[] Elements { get; set; } = Array.Empty<IPlayerSurvivalElement>();
[SerializeReference, SubclassSelector] private IPlayerSurvivalElement[] initialElements = Array.Empty<IPlayerSurvivalElement>();
private IntervalUpdate _interval = new(1);
public override void OnAwake()
{
_cancellationToken = entity.Get<CancellationToken>();
foreach (var x in survivalStates)
{
x.OnStateInitialize();
}
Elements = initialElements;
}
public override async void OnStart()
public override void OnUpdate(float deltaTime)
{
foreach (var x in survivalStates)
if (_interval.AllowUpdate is false) return;
foreach (var x in Elements)
{
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);
x.Value -= 1;
}
}
public event Action<IPlayerSurvivalState> OnSurvivalStateChanged;
public event Action<IPlayerSurvivalEvent> OnSurvivalEventOpened;
public event Action<IPlayerSurvivalEvent> OnSurvivalEventClosed;
}
}