1
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
"GUID:28c2d6a6727d47442a24a353f0d37846",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153"
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:96f476e982d6fb945bfc9140ba094b7f",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -5,6 +5,9 @@ using BITKit;
|
||||
using BITKit.Animations;
|
||||
using BITKit.StateMachine;
|
||||
using System.Linq;
|
||||
using BITFALL.Player.Equip;
|
||||
using Cinemachine;
|
||||
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public interface IEquipBase : IEntryElement, IAwake, IStart, IUpdate
|
||||
@@ -31,10 +34,17 @@ namespace BITKit.Entities
|
||||
public virtual void EquipEvent(string eventName){}
|
||||
public virtual void AnimationEvent(string eventName){}
|
||||
}
|
||||
public class EntityEquipment : EntityComponent
|
||||
[CustomType(typeof(IEquipService))]
|
||||
public class EntityEquipment : EntityComponent,IEquipService
|
||||
{
|
||||
public EntryGroup<IEquipBase> equips = new();
|
||||
public IOptional<float> Zoom { get; } = new Optional<float>(){Value = 1};
|
||||
|
||||
public float InitialFov;
|
||||
|
||||
[SerializeField] private CinemachineVirtualCamera virtualCamera;
|
||||
protected IEquipBase entryComplete;
|
||||
private PlayerConfig playerConfig;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
@@ -56,6 +66,13 @@ namespace BITKit.Entities
|
||||
{
|
||||
entryComplete.OnUpdate(deltaTime);
|
||||
}
|
||||
|
||||
var current = virtualCamera.m_Lens.FieldOfView;
|
||||
current= Mathf.Lerp(current,Zoom.Allow ? InitialFov / Zoom.Value : PlayerConfig.Singleton.Fov , deltaTime * 5);
|
||||
current = Mathf.Clamp(current, 10, PlayerConfig.Singleton.Fov);
|
||||
virtualCamera.m_Lens.FieldOfView = current;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -6,7 +6,10 @@
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:f822dbf6fdfd4a5469cccaa2e4eed3b6",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c"
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:508392158bd966c4d9c21e19661a441d"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using BITKit.Sensors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
@@ -6,24 +7,16 @@ namespace BITKit.Entities.Player
|
||||
public class EntityInteractive : EntityPlayerComponent
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public float distance;
|
||||
public LayerMask layerMask;
|
||||
|
||||
[Header(Constant.Header.Input)]
|
||||
public InputActionReference interactiveAction;
|
||||
private readonly InputActionGroup inputActionGroup = new();
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform cameraTransform;
|
||||
[SerializeReference, SubclassSelector] private ISensor sensor;
|
||||
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
private ISelectable selected;
|
||||
private IntervalUpdate cd = new(0.08f);
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (Physics.Raycast(cameraTransform.position,cameraTransform.forward, out var raycastHit, distance, layerMask,QueryTriggerInteraction.Collide))
|
||||
if (sensor.Get().TryGetAny(x=>x.TryGetComponentAny<ISelectable>(out _),out var detected))
|
||||
{
|
||||
if (raycastHit.transform.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
if (detected.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
{
|
||||
if (_detected == selected)
|
||||
{
|
||||
@@ -68,7 +61,7 @@ namespace BITKit.Entities.Player
|
||||
}
|
||||
public void Interactive(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.interaction is not PressInteraction || !context.performed) return;
|
||||
if (context.interaction is not PressInteraction || !context.performed || cd.AllowUpdate is false) return;
|
||||
var _selected = selected;
|
||||
if (_selected is not MonoBehaviour monoBehaviour) return;
|
||||
if (monoBehaviour.TryGetComponentAny<IAction>(out var action))
|
||||
|
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "BITKit.Entities.Value",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Entities.Value
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体属性接口,通常用于角色的可被数值化的属性
|
||||
/// </summary>
|
||||
public interface IEntityValue
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -17,8 +17,21 @@ namespace BITKit.Entities
|
||||
private readonly Processor processor = new();
|
||||
public IEntityComponent[] entityComponents { get; set; }
|
||||
public ulong Id { get; private set; }
|
||||
public CancellationToken CancellationToken => _cancellationToken;
|
||||
|
||||
Core.Entites.IEntityComponent[] Core.Entites.IEntity.Components => _components;
|
||||
|
||||
bool Core.Entites.IEntity.RegisterComponent<T>(T component)
|
||||
{
|
||||
throw new InvalidOperationException("Unity Entity can't register component");
|
||||
}
|
||||
|
||||
IServiceProvider Core.Entites.IEntity.ServiceProvider=> throw new InvalidOperationException("Unity Entity can't register component");
|
||||
|
||||
private CancellationToken _cancellationToken;
|
||||
private bool isInitialized;
|
||||
private Core.Entites.IEntityComponent[] _components => entityComponents;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Id = (ulong)Guid.NewGuid().GetHashCode();
|
||||
|
@@ -41,22 +41,22 @@ public class UnityEntitiesServiceSingleton:IEntitiesService
|
||||
|
||||
public IEntity Get(ulong id) => UnityEntitiesService.Get(id);
|
||||
|
||||
public IEntity[] Query<T>() where T : IEntityComponent
|
||||
public IEntity[] Query<T>()
|
||||
{
|
||||
return UnityEntitiesService.Query<T>();
|
||||
}
|
||||
|
||||
public T[] QueryComponents<T>() where T : IEntityComponent
|
||||
public T[] QueryComponents<T>()
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T>();
|
||||
}
|
||||
|
||||
public (T, T1)[] QueryComponents<T, T1>() where T : IEntityComponent where T1 : IEntityComponent
|
||||
public (T, T1)[] QueryComponents<T, T1>()
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T, T1>();
|
||||
}
|
||||
|
||||
public (T, T1, T2)[] QueryComponents<T, T1, T2>() where T : IEntityComponent where T1 : IEntityComponent where T2 : IEntityComponent
|
||||
public (T, T1, T2)[] QueryComponents<T, T1, T2>()
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T, T1, T2>();
|
||||
}
|
||||
@@ -64,13 +64,12 @@ public class UnityEntitiesServiceSingleton:IEntitiesService
|
||||
|
||||
public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
{
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void Initialize()
|
||||
{
|
||||
Dictionary.Clear();
|
||||
RegisterQueue.Clear();
|
||||
UnRegisterQueue.Clear();
|
||||
|
||||
}
|
||||
public static bool Register(IEntity entity)
|
||||
{
|
||||
@@ -127,12 +126,12 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
public static IEntity Get(ulong id)=>Dictionary[id];
|
||||
IEntity IEntitiesService.Get(ulong id)=>Get(id);
|
||||
IEntity[] IEntitiesService.Query<T>()=>Query<T>();
|
||||
public static IEntity[] Query<T>() where T : IEntityComponent
|
||||
public static IEntity[] Query<T>()
|
||||
{
|
||||
return Entities.Where(x => ((Entity)x).TryGetComponentAny<T>(out _)).ToArray();
|
||||
}
|
||||
T[] IEntitiesService.QueryComponents<T>()=>QueryComponents<T>();
|
||||
public static T[] QueryComponents<T>() where T : IEntityComponent
|
||||
public static T[] QueryComponents<T>()
|
||||
{
|
||||
var list = ListPool<T>.Get();
|
||||
foreach (var iEntity in Entities)
|
||||
@@ -150,7 +149,7 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
return value;
|
||||
}
|
||||
(T, T1)[] IEntitiesService.QueryComponents<T,T1>()=>QueryComponents<T,T1>();
|
||||
public static (T, T1)[] QueryComponents<T, T1>() where T : IEntityComponent where T1 : IEntityComponent
|
||||
public static (T, T1)[] QueryComponents<T, T1>()
|
||||
{
|
||||
var list = ListPool<(T t, T1 t1)>.Get();
|
||||
foreach (var iEntity in Entities)
|
||||
@@ -168,7 +167,7 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
return value;
|
||||
}
|
||||
(T, T1, T2)[] IEntitiesService.QueryComponents<T,T1,T2>()=>QueryComponents<T,T1,T2>();
|
||||
public static (T, T1, T2)[] QueryComponents<T, T1, T2>() where T : IEntityComponent where T1 : IEntityComponent where T2 : IEntityComponent
|
||||
public static (T, T1, T2)[] QueryComponents<T, T1, T2>()
|
||||
{
|
||||
var list = ListPool<(T t, T1 t1, T2 t2)>.Get();
|
||||
foreach (var iEntity in Entities)
|
||||
|
@@ -25,7 +25,6 @@ namespace BITKit.Entities.Editor
|
||||
rootVisualElement.styleSheets.Add(BITEditorUtils.InspectorStyleSheet);
|
||||
rootVisualElement.styleSheets.Add(BITEditorUtils.Style);
|
||||
rootVisualElement.AddToClassList("pa-8");
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -1,164 +0,0 @@
|
||||
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 BITKit.Entities.Player;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
[CustomType(typeof(IPlayerEquipSelector))]
|
||||
public class PlayerEquipSelector : EntityComponent,TaskSubscriber<IBasicItem>,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.RegisterCallback<TaskSubscriber<IBasicItem>>(this);
|
||||
|
||||
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);
|
||||
}
|
||||
int TaskSubscriber<IBasicItem>.Priority => 0;
|
||||
|
||||
bool TaskSubscriber<IBasicItem>.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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user