1
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using UnityEngine;
|
||||
|
@@ -12,7 +12,8 @@
|
||||
"GUID:30cdc242b1ac6a944a460f4ab0b77b88",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:ef0bb553b58b90b488bdbe8672e3be0b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITFALL.Player.Inventory;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
@@ -20,7 +21,7 @@ namespace BITFALL
|
||||
/// 支持,护甲,头盔和背包等
|
||||
/// </summary>
|
||||
[CustomType(typeof(IPlayerEquipContainer))]
|
||||
public class PlayerEquipContainer : EntityComponent, TaskSubscriber<IBasicItem>, IPlayerEquipContainer
|
||||
public class PlayerEquipContainer : EntityComponent, IPlayerEquipContainer
|
||||
{
|
||||
private readonly Dictionary<IEquipmentSlot, IBasicItem> dictionary = new();
|
||||
private IBasicItemContainer inventory;
|
||||
@@ -44,8 +45,9 @@ namespace BITFALL
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
entity.RegisterCallback<TaskSubscriber<IBasicItem>>(this);
|
||||
inventory = entity.Get<IBasicItemContainer>();
|
||||
var playerInventory = entity.Get<IPlayerInventory>();
|
||||
playerInventory.OnUseItem += TryExecute;
|
||||
}
|
||||
|
||||
public Action<IEquipmentSlot, IBasicItem> OnEquip { get; set; }
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -7,17 +8,13 @@ using UnityEngine.UIElements;
|
||||
using System.Text;
|
||||
using BITKit.Entities;
|
||||
using System.Linq;
|
||||
using BITFALL.Player.Inventory;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
public class PlayerInventory : EntityInventory,ISelectableCallback,TaskPublisher<IBasicItem>
|
||||
[CustomType(typeof(IPlayerInventory))]
|
||||
public class PlayerInventory : EntityInventory,ISelectableCallback,IPlayerInventory
|
||||
{
|
||||
public override void Initialize(IEntity entity)
|
||||
{
|
||||
base.Initialize(entity);
|
||||
entity.Set<IBasicItemContainer>(this);
|
||||
entity.Set<TaskPublisher<IBasicItem>>(this);
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
@@ -35,7 +32,7 @@ namespace BITFALL
|
||||
item.Picked();
|
||||
}
|
||||
}
|
||||
else if(trans.TryGetComponentAny<IBasicItemContainer>(out var container))
|
||||
else if(trans.TryGetComponentAny<IBasicItemContainer>(out _))
|
||||
{
|
||||
|
||||
}
|
||||
@@ -48,18 +45,15 @@ namespace BITFALL
|
||||
void ISelectableCallback.OnInactive(ISelectable selectable)
|
||||
{
|
||||
}
|
||||
public bool Execute(IBasicItem value)
|
||||
public bool TryUseItem(IBasicItem item)
|
||||
{
|
||||
foreach (var excutor in entity.GetCallbacks<TaskSubscriber<IBasicItem>>())
|
||||
{
|
||||
if(excutor.TryExecute(value))
|
||||
{
|
||||
Remove(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (OnUseItem is null) return false;
|
||||
if (!OnUseItem.CastAsFunc().Any(func => func.Invoke(item))) return false;
|
||||
Remove(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
public event Func<IBasicItem, bool> OnUseItem;
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(PlayerInventory))]
|
||||
|
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "BITFALL.Entities.EquipSelector.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:b355af20142c0c541ba9588ab1d0f64e",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:30cdc242b1ac6a944a460f4ab0b77b88",
|
||||
"GUID:677cd05ca06c46b4395470200b1acdad",
|
||||
"GUID:7efac18f239530141802fb139776f333",
|
||||
"GUID:84d565da37ad40546a118cfb3c3509f3",
|
||||
"GUID:42a9827d94e00374aa52e51f0a1b035c",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:9354affc93e0f3e4a904785e7d4c0f59",
|
||||
"GUID:ef0bb553b58b90b488bdbe8672e3be0b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine.InputSystem;
|
||||
using static UnityEditor.Progress;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using BITFALL.Player.Inventory;
|
||||
using BITKit.Entities.Player;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
[CustomType(typeof(IPlayerEquipSelector))]
|
||||
public class PlayerEquipSelector : EntityComponent,IEntityInventoryCallback,IPlayerEquipSelector
|
||||
{
|
||||
[Header(Constant.Header.Components)]
|
||||
public EntityEquipment equipment;
|
||||
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
private readonly Dictionary<int, IBasicItem> equips=new();
|
||||
private IBasicItemContainer inventory;
|
||||
|
||||
public event Action<IBasicItem> OnEquip;
|
||||
public event Action<IBasicItem> OnDeEquip;
|
||||
public event Action<IDictionary<int, IBasicItem>> OnUpdateEquip;
|
||||
|
||||
private IBasicItem currentEquip;
|
||||
public override void OnAwake()
|
||||
{
|
||||
var health = entity.Get<IHealth>();
|
||||
health.OnSetAlive += OnSetAlive;
|
||||
OnDeEquip += DeEquip;
|
||||
OnEquip += Equip;
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
|
||||
entity.Get<IPlayerInventory>().OnUseItem += TryExecute;
|
||||
|
||||
inventory = entity.Get<IBasicItemContainer>();
|
||||
}
|
||||
public void OnPrimary(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context is not {interaction:PressInteraction ,performed:true}) return;
|
||||
Equip(1);
|
||||
}
|
||||
public void OnSecondary(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context is not {interaction:PressInteraction ,performed:true}) return;
|
||||
Equip(2);
|
||||
}
|
||||
public void OnTertiary(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context is not {interaction:PressInteraction ,performed:true}) return;
|
||||
if (Equip(3) is false)
|
||||
{
|
||||
Equip(-1);
|
||||
}
|
||||
}
|
||||
public void OnQuaternary(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context is not {interaction:PressInteraction ,performed:true}) return;
|
||||
Equip(4);
|
||||
}
|
||||
public void OnHolster(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context is not {interaction:PressInteraction ,performed:true}) return;
|
||||
Equip(-1);
|
||||
}
|
||||
private void OnSetAlive(bool alive)
|
||||
{
|
||||
if (alive) return;
|
||||
foreach (var x in equips.ToArray())
|
||||
{
|
||||
inventory.Add(x.Value);
|
||||
}
|
||||
equips.Clear();
|
||||
UpdateEquip();
|
||||
Equip(-1);
|
||||
}
|
||||
private bool TryExecute(IBasicItem value)
|
||||
{
|
||||
var asset = value.GetAssetable();
|
||||
if (IsSupportItem(value) is false) return false;
|
||||
switch (asset)
|
||||
{
|
||||
case var _ when asset.TryGetProperty<EquipmentAsWeapon>(out _):
|
||||
if (equips.TryAdd(1, value) || equips.TryAdd(2,value))
|
||||
{
|
||||
OnEquip?.Invoke(value);
|
||||
UpdateEquip();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void OnAdd(IBasicItem item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnRemove(IBasicItem item)
|
||||
{
|
||||
if (IsSupportItem(item) is false)
|
||||
{
|
||||
UpdateEquip();
|
||||
}
|
||||
}
|
||||
private bool IsSupportItem(IBasicItem item)
|
||||
{
|
||||
return equipment.equips.list.Any(x => x.AddressablePath == item.AddressablePath);
|
||||
}
|
||||
private void UpdateEquip()
|
||||
{
|
||||
OnUpdateEquip?.Invoke(new Dictionary<int, IBasicItem>(equips));
|
||||
}
|
||||
|
||||
public bool TryDeEquip(IBasicItem item)
|
||||
{
|
||||
if (item is null) return false;
|
||||
if (equips.Any(x => x.Value.AddressablePath == item.AddressablePath) is false) return false;
|
||||
var index = equips.Single(x=>x.Value.AddressablePath==item.AddressablePath).Key;
|
||||
if (equips.TryRemove(index) is false) return false;
|
||||
if (!inventory.Add(item)) return false;
|
||||
OnDeEquip?.Invoke(item);
|
||||
UpdateEquip();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Equip(IBasicItem item)
|
||||
{
|
||||
if (item is null)
|
||||
{
|
||||
equipment.equips.Entry(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
equipment.equips.Entry(x=>x.AddressablePath == item.AddressablePath);
|
||||
}
|
||||
}
|
||||
|
||||
private bool Equip(int index)
|
||||
{
|
||||
if (!equips.TryGetValue(index, out var x) && index is not -1) return false;
|
||||
if (index is -1)
|
||||
{
|
||||
OnEquip?.Invoke(x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void DeEquip(IBasicItem item)
|
||||
{
|
||||
equipment.equips.Entry(-1);
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,7 +17,9 @@
|
||||
"GUID:900280954c76a0d41bc47cef37f91107",
|
||||
"GUID:1235ca61e7f433b408ed5a68767e7123",
|
||||
"GUID:0a8b74b3309f0cc44bdd9a796253baef",
|
||||
"GUID:8d74bfb2f67c5c14a810215b78383d40"
|
||||
"GUID:8d74bfb2f67c5c14a810215b78383d40",
|
||||
"GUID:96f476e982d6fb945bfc9140ba094b7f",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -68,7 +68,6 @@ namespace BITFALL.Guns
|
||||
//简单设置
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private Vector3 bulletInitialOffset;
|
||||
[SerializeField] private int initialAimFov = 60;
|
||||
[SerializeField] private SpringEulerAngle recoilSpring=new();
|
||||
|
||||
// 输入系统
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Data.Odbc;
|
||||
using BITFALL.Player.Equip;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
@@ -147,10 +148,12 @@ namespace BITFALL.Guns.States
|
||||
public class Aim : GunState
|
||||
{
|
||||
private IEntityMovement _entityMovement;
|
||||
private IEquipService _equipService;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_entityMovement = root.Entity.Get<IEntityMovement>();
|
||||
_equipService = root.Entity.Get<IEquipService>();
|
||||
}
|
||||
|
||||
public override void OnStateEntry(IState old)
|
||||
@@ -165,7 +168,7 @@ namespace BITFALL.Guns.States
|
||||
root.animator.CrossFade(BITGun._Aim, 0.16f);
|
||||
break;
|
||||
}
|
||||
|
||||
_equipService.Zoom.Allow = true;
|
||||
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
}
|
||||
|
||||
@@ -188,6 +191,13 @@ namespace BITFALL.Guns.States
|
||||
{
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
_equipService.Zoom.Value = root.aimAction.action.ReadValue<float>();
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
base.OnStateExit(old, newState);
|
||||
_equipService.Zoom.Allow = false;
|
||||
}
|
||||
|
||||
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Player.Equip;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
@@ -18,15 +19,23 @@ namespace BITFALL.Player.Movement
|
||||
private Quaternion currentRotation;
|
||||
private Vector3 currentPosition;
|
||||
private IEntityMovement _movement;
|
||||
private IEquipService _equipService;
|
||||
public override void OnAwake()
|
||||
{
|
||||
_movement = entity.Get<IEntityMovement>();
|
||||
_equipService = entity.Get<IEquipService>();
|
||||
}
|
||||
|
||||
public override void OnLateUpdate(float deltaTime)
|
||||
{
|
||||
var velocity = _movement.LocomotionBasedVelocity;
|
||||
var angularVelocity = _movement.AngularVelocity;
|
||||
|
||||
if (_equipService.Zoom.Allow)
|
||||
{
|
||||
velocity = default;
|
||||
angularVelocity = default;
|
||||
}
|
||||
|
||||
currentPosition = Vector3.Lerp(currentPosition,velocity * posValue,posDelta * deltaTime);
|
||||
currentRotation = Quaternion.Lerp(currentRotation,Quaternion.Euler(angularVelocity * rotValue),rotDelta * deltaTime);
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,10 @@
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:26fc13cbbc427414f9af2143d581330a",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
|
||||
"GUID:677cd05ca06c46b4395470200b1acdad",
|
||||
"GUID:30cdc242b1ac6a944a460f4ab0b77b88"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
36
Assets/Artists/Scripts/Player/Survival/PlayerEatService.cs
Normal file
36
Assets/Artists/Scripts/Player/Survival/PlayerEatService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -36,19 +36,13 @@ namespace BITFALL.Scenes
|
||||
if(EditorApplication.isPlaying is false)
|
||||
return;
|
||||
#endif
|
||||
rigidbodyComponent.Velocity = animator.velocity;
|
||||
rigidbodyComponent.AngularVelocity = animator.angularVelocity;
|
||||
rigidbodyComponent.MoveAndRotate(currentPosition,currentRotation);
|
||||
}
|
||||
private void OnAnimatorMove()
|
||||
{
|
||||
animator.ApplyBuiltinRootMotion();
|
||||
#if UNITY_EDITOR
|
||||
// if (EditorApplication.isPlaying is false)
|
||||
// {
|
||||
// transform.position = animator.rootPosition;
|
||||
// transform.rotation = animator.rootRotation;
|
||||
// }
|
||||
#endif
|
||||
|
||||
currentPosition = animator.rootPosition;
|
||||
currentRotation = animator.rootRotation;
|
||||
}
|
||||
|
@@ -23,7 +23,9 @@
|
||||
"GUID:2289059ddf1745b4d80a0f184af99d6b",
|
||||
"GUID:9354affc93e0f3e4a904785e7d4c0f59",
|
||||
"GUID:1bb4187526a9431478feccaef064696a",
|
||||
"GUID:26fc13cbbc427414f9af2143d581330a"
|
||||
"GUID:26fc13cbbc427414f9af2143d581330a",
|
||||
"GUID:96f476e982d6fb945bfc9140ba094b7f",
|
||||
"GUID:ef0bb553b58b90b488bdbe8672e3be0b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Player.Equip;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -9,6 +10,7 @@ using BITKit.UX;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Entities.Player;
|
||||
using BITKit.Steamwork;
|
||||
using UnityEditor;
|
||||
|
||||
namespace BITFALL.UX
|
||||
{
|
||||
@@ -22,6 +24,7 @@ namespace BITFALL.UX
|
||||
|
||||
[Header(Constant.Header.Components)]
|
||||
[SerializeField] private UXImage crosshairImage;
|
||||
[SerializeField] private UXImage crosshairParentImage;
|
||||
[SerializeField] private UXLabel playerNameLabel;
|
||||
[SerializeField] private UXImage playerAvatarImage;
|
||||
[SerializeField] private UXBar healthBar;
|
||||
@@ -33,6 +36,8 @@ namespace BITFALL.UX
|
||||
public UXLabel nameLabel;
|
||||
private IHealth _health;
|
||||
protected IEntityMovement _entityMovement;
|
||||
|
||||
private IEquipService _equipService;
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -85,6 +90,8 @@ namespace BITFALL.UX
|
||||
playerNameLabel.Set(steamService.Name);
|
||||
var avatar = await steamService.GetAvatarAsync(cancellationToken);
|
||||
playerAvatarImage.SetTexture(avatar);
|
||||
|
||||
_equipService = entity.Get<IEquipService>();
|
||||
}
|
||||
private void OnInventory(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -98,6 +105,11 @@ namespace BITFALL.UX
|
||||
{
|
||||
if (playerService.LocalPlayer is null) return;
|
||||
crosshairImage.SetPosition(_entityMovement.ViewCenter + _entityMovement.ViewRotation * Vector3.forward);
|
||||
|
||||
if(_equipService is null) return;
|
||||
|
||||
var currentCrosshairOpacity = crosshairParentImage.visualElement.style.opacity.value;
|
||||
crosshairParentImage.visualElement.style.opacity = Mathf.Lerp(currentCrosshairOpacity, _equipService.Zoom.Allow ? 0 : 1, Time.deltaTime * 5);
|
||||
}
|
||||
|
||||
private static void OnReturn(InputAction.CallbackContext context)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Player.Inventory;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -146,7 +147,7 @@ namespace BITFALL.UX
|
||||
}
|
||||
private void UseItem(IBasicItem item)
|
||||
{
|
||||
_entity.Get<TaskPublisher<IBasicItem>>().Execute(item);
|
||||
_entity.Get<IPlayerInventory>().TryUseItem(item);
|
||||
}
|
||||
private void DropItem(IBasicItem item)
|
||||
{
|
||||
|
@@ -6,6 +6,7 @@ using BITFALL.Player.Survival;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Entities.Player;
|
||||
using BITKit.UX;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using RotaryHeart.Lib.SerializableDictionary;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore.Text;
|
||||
@@ -16,46 +17,33 @@ namespace BITFALL.UX
|
||||
public class UXSurvival : MonoBehaviour
|
||||
{
|
||||
[SerializeReference,SubclassSelector] private IPlayerService playerService;
|
||||
[SerializeField] private SerializableDictionaryBase<string,Sprite> survivalEventIcons;
|
||||
[SerializeField] private UXBuilder survivalEventBuilder;
|
||||
private readonly ConcurrentDictionary<string,UXContainer> spawnedSurvivalEvents = new();
|
||||
private IPlayerSurvival _playerSurvival;
|
||||
private void Awake()
|
||||
private readonly ConcurrentDictionary<IPlayerSurvivalElement,UXContainer> spawnedSurvivalEvents = new();
|
||||
private IPlayerSurvivalService _playerSurvival;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
playerService.OnPlayerInitialized += OnPlayerInitialized;
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
playerService.OnPlayerInitialized -= OnPlayerInitialized;
|
||||
}
|
||||
private void OnPlayerInitialized(Entity obj)
|
||||
{
|
||||
_playerSurvival = obj.Get<IPlayerSurvival>();
|
||||
|
||||
_playerSurvival.OnSurvivalEventOpened += OnSurvivalEventOpened;
|
||||
_playerSurvival.OnSurvivalEventClosed += OnSurvivalEventClosed;
|
||||
}
|
||||
|
||||
private void OnSurvivalEventClosed(IPlayerSurvivalEvent obj)
|
||||
private async void OnPlayerInitialized(Entity obj)
|
||||
{
|
||||
if (spawnedSurvivalEvents.TryRemove(obj.GetType().Name, out var container))
|
||||
await UniTask.Yield();
|
||||
_playerSurvival = obj.Get<IPlayerSurvivalService>();
|
||||
foreach (var x in _playerSurvival.Elements)
|
||||
{
|
||||
container.visualElement.RemoveFromHierarchy();
|
||||
spawnedSurvivalEvents.GetOrAdd(x, Create);
|
||||
}
|
||||
}
|
||||
private void OnSurvivalEventOpened(IPlayerSurvivalEvent obj)
|
||||
{
|
||||
spawnedSurvivalEvents.GetOrAdd(obj.GetType().Name, (x)=>Create(obj));
|
||||
}
|
||||
private UXContainer Create(IPlayerSurvivalEvent playerSurvivalEvent)
|
||||
private UXContainer Create(IPlayerSurvivalElement arg)
|
||||
{
|
||||
var container = survivalEventBuilder.BuildAsContainer();
|
||||
var key = playerSurvivalEvent.GetType().Name;
|
||||
if (survivalEventIcons.TryGetValue(key, out var sprite))
|
||||
{
|
||||
container.icon.style.backgroundImage = new StyleBackground(sprite);
|
||||
}
|
||||
container.contextLabel.text = playerSurvivalEvent.Title;
|
||||
container.Get<Label>(0).text = arg.Name;
|
||||
container.SetProcess(arg.Value);
|
||||
|
||||
arg.OnValueChanged += value => container.SetProcess(value*0.01f);
|
||||
|
||||
spawnedSurvivalEvents.TryAdd(arg,container);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user