1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "BITFALL.Entities.Core.EquipSelector",
|
||||
"name": "BITFALL.Entities.EquipSelector",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
/// <summary>
|
||||
/// 玩家装备选择器接口
|
||||
/// </summary>
|
||||
public interface IPlayerEquipSelector
|
||||
{
|
||||
event Action<IBasicItem> OnEquip;
|
||||
event Action<IBasicItem> OnDeEquip;
|
||||
event Action<IDictionary<int, IBasicItem>> OnUpdateEquip;
|
||||
bool TryDeEquip(IBasicItem item);
|
||||
}
|
||||
}
|
@@ -1,196 +0,0 @@
|
||||
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;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
public interface IEquipSelectorCallback
|
||||
{
|
||||
void OnEquip(IBasicItem item);
|
||||
void OnDeEquip(IBasicItem item);
|
||||
void OnUpdateEquip(IDictionary<int,IBasicItem> maps);
|
||||
}
|
||||
public class PlayerEquipSelector : EntityComponent,IExcutor<IBasicItem>,IEntityInventoryCallback
|
||||
{
|
||||
[Header(Constant.Header.Input)]
|
||||
public InputActionReference primaryAction;
|
||||
public InputActionReference secondaryAction;
|
||||
public InputActionReference tertiaryAction;
|
||||
public InputActionReference quaternaryAction;
|
||||
public InputActionReference holsterAction;
|
||||
public InputActionGroup inputActionGroup;
|
||||
[Header(Constant.Header.Components)]
|
||||
public EntityEquipment equipment;
|
||||
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
private readonly Dictionary<int, IBasicItem> equips=new();
|
||||
private IBasicItemContainer inventory;
|
||||
public override void OnAwake()
|
||||
{
|
||||
var health = entity.Get<IHealth>();
|
||||
health.OnSetAlive += OnSetAlive;
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
inputActionGroup.RegisterCallback(primaryAction, OnPrimary);
|
||||
inputActionGroup.RegisterCallback(secondaryAction, OnSecondary);
|
||||
inputActionGroup.RegisterCallback(tertiaryAction, OnMelee);
|
||||
inputActionGroup.RegisterCallback(holsterAction, OnHolster);
|
||||
|
||||
entity.RegisterCallback<IExcutor<IBasicItem>>(this);
|
||||
|
||||
inventory = entity.Get<IBasicItemContainer>();
|
||||
}
|
||||
public void OnPrimary(InputAction.CallbackContext context)
|
||||
{
|
||||
if (!context.started) return;
|
||||
TryEquip(1);
|
||||
}
|
||||
public void OnSecondary(InputAction.CallbackContext context)
|
||||
{
|
||||
if (!context.started) return;
|
||||
TryEquip(2);
|
||||
}
|
||||
public void OnMelee(InputAction.CallbackContext context)
|
||||
{
|
||||
if (TryEquip(3))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TryEquip(-1);
|
||||
}
|
||||
}
|
||||
public void OnTertiary(InputAction.CallbackContext context)
|
||||
{
|
||||
TryEquip(4);
|
||||
}
|
||||
void OnHolster(InputAction.CallbackContext context)
|
||||
{
|
||||
TryEquip(-1);
|
||||
}
|
||||
public void OnPlayerInitialized()
|
||||
{
|
||||
inputActionGroup.allowInput.SetElements(this, true);
|
||||
}
|
||||
public void OnPlayerDispose()
|
||||
{
|
||||
inputActionGroup.allowInput.SetElements(this, false);
|
||||
}
|
||||
|
||||
private void OnSetAlive(bool alive)
|
||||
{
|
||||
inputActionGroup.allowInput.SetElements(nameof(IHealthCallback), alive);
|
||||
if (alive) return;
|
||||
foreach (var x in equips.ToArray())
|
||||
{
|
||||
inventory.Add(x.Value);
|
||||
}
|
||||
equips.Clear();
|
||||
TryEquip(-1);
|
||||
}
|
||||
|
||||
public bool TryExecute(IBasicItem value)
|
||||
{
|
||||
var asset = value.GetAssetable();
|
||||
if (IsSupportItem(value) is false) return false;
|
||||
var i = 1;
|
||||
var length = 4;
|
||||
if (value.TryGetProperty<EquipmentAsEquip>(out _))
|
||||
{
|
||||
i = 1;
|
||||
length = 2;
|
||||
}
|
||||
else if (value.TryGetProperty<EquipmentAsMelee>(out _))
|
||||
{
|
||||
i = 3;
|
||||
length = 3;
|
||||
}else if (value.TryGetProperty<EquipmentAsHeal>(out _))
|
||||
{
|
||||
i = 4;
|
||||
length = 4;
|
||||
}
|
||||
for (; i <=length; i++)
|
||||
{
|
||||
if (equips.ContainsKey(i) is true) continue;
|
||||
equips.Add(i, value);
|
||||
if (equips.ContainsKey(0) is true) return true;
|
||||
Equip(value);
|
||||
UpdateEquiped();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private bool TryEquip(int index)
|
||||
{
|
||||
if (equips.TryGetValue(index, out var equip))
|
||||
{
|
||||
Equip(equip);
|
||||
return true;
|
||||
}
|
||||
else if (index is -1)
|
||||
{
|
||||
equips.TryRemove(0);
|
||||
Equip(null);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private void Equip(IBasicItem item)
|
||||
{
|
||||
var index = equipment.equips.list.FindIndex(x => x?.AddressablePath == item?.AdressablePath);
|
||||
if (equips.TryGetValue(0, out var equipd))
|
||||
{
|
||||
entity.GetCallbacks<IEquipSelectorCallback>().ForEach(x => x.OnDeEquip(equipd));
|
||||
}
|
||||
|
||||
if (index is -1)
|
||||
{
|
||||
equips.TryRemove(0);
|
||||
equipment.equips.Entry(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.GetCallbacks<IEquipSelectorCallback>().ForEach(x => x.OnEquip(item));
|
||||
equips.Insert(0,item);
|
||||
equipment.equips.Entry(index);
|
||||
}
|
||||
UpdateEquiped();
|
||||
}
|
||||
public void OnAdd(IBasicItem item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnRemove(IBasicItem item)
|
||||
{
|
||||
if (IsSupportItem(item) is false)
|
||||
{
|
||||
UpdateEquiped();
|
||||
}
|
||||
}
|
||||
private bool IsSupportItem(IBasicItem item)
|
||||
{
|
||||
return equipment.equips.list.FindIndex(x => x.AddressablePath == item.AdressablePath) is not -1;
|
||||
}
|
||||
void UpdateEquiped()
|
||||
{
|
||||
foreach (var x in entity.GetCallbacks<IEquipSelectorCallback>())
|
||||
{
|
||||
x.OnUpdateEquip(new Dictionary<int, IBasicItem>(equips));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -41,86 +41,67 @@ namespace BITFALL
|
||||
public event Action<IBasicItem> OnSet;
|
||||
public event Action<IBasicItem> OnDrop;
|
||||
public event Action<IBasicItemContainer> OnRebuild;
|
||||
private CancellationToken _cancellationToken;
|
||||
private IHealth _health;
|
||||
public override void OnAwake()
|
||||
{
|
||||
_cancellationToken = entity.Get<CancellationToken>();
|
||||
var health = entity.Get<IHealth>();
|
||||
health.OnSetAlive += OnSetAlive;
|
||||
_health = entity.Get<IHealth>();
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
}
|
||||
|
||||
private async void OnSetAlive(bool alive)
|
||||
private void OnSetAlive(bool alive)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.NextFrame(_cancellationToken);
|
||||
await UniTask.NextFrame(_cancellationToken);
|
||||
await UniTask.NextFrame(_cancellationToken);
|
||||
foreach (var x in dictionary.Keys.ToArray())
|
||||
{
|
||||
Drop(x);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
if (alive) return;
|
||||
foreach (var x in dictionary.Values.ToArray())
|
||||
{
|
||||
OnRemove?.Invoke(x);
|
||||
Drop(x);
|
||||
}
|
||||
dictionary.Clear();
|
||||
}
|
||||
public virtual bool Add(IBasicItem item)
|
||||
{
|
||||
var pars = new object[] { item };
|
||||
if (AddFactory != null)
|
||||
foreach (var x in AddFactory.GetInvocationList())
|
||||
{
|
||||
if (x.Method.Invoke(x.Target, pars) is false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (dictionary.TryAdd(item.Id, item))
|
||||
if (_health.IsAlive is false)
|
||||
{
|
||||
Drop(item);
|
||||
return true;
|
||||
}
|
||||
if (AddFactory?.GetInvocationList().Cast<Func<IBasicItem, bool>>().Any(x => x.Invoke(item)) is false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!dictionary.TryAdd(item.Id, item)) return false;
|
||||
{
|
||||
OnAdd?.Invoke(item);
|
||||
foreach (var x in entity.GetCallbacks<IEntityInventoryCallback>())
|
||||
{
|
||||
x.OnAdd(item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IBasicItem[] GetItems() => dictionary.Values.ToArray();
|
||||
public virtual bool Remove(IBasicItem item)
|
||||
{
|
||||
return Remove(item.Id);
|
||||
}
|
||||
|
||||
public virtual bool Remove(int id)
|
||||
{
|
||||
if (!dictionary.TryGetValue(id, out var item)) return false;
|
||||
if (RemoveFactory is not null)
|
||||
if (RemoveFactory.GetInvocationList().Cast<Func<IBasicItem,bool>>().Any(x => x.Invoke(item) is false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dictionary.TryGetValue(id, out var item))
|
||||
dictionary.Remove(id);
|
||||
foreach (var x in entity.GetCallbacks<IEntityInventoryCallback>())
|
||||
{
|
||||
var pars = new object[] { item };
|
||||
if(RemoveFactory is not null)
|
||||
foreach (var x in RemoveFactory.GetInvocationList())
|
||||
{
|
||||
if (x.Method.Invoke(x.Target, pars) is false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
dictionary.Remove(id);
|
||||
foreach (var x in entity.GetCallbacks<IEntityInventoryCallback>())
|
||||
{
|
||||
x.OnRemove(item);
|
||||
}
|
||||
OnRemove?.Invoke(item);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
x.OnRemove(item);
|
||||
}
|
||||
OnRemove?.Invoke(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool Remove(Func<IBasicItem, bool> removeFactory)
|
||||
@@ -141,17 +122,23 @@ namespace BITFALL
|
||||
return dictionary.Values.TryGetAny(func, out item);
|
||||
}
|
||||
|
||||
public bool Drop(int Id)
|
||||
public bool Drop(int _Id)
|
||||
{
|
||||
if (!dictionary.TryGetValue(Id, out var item)) return false;
|
||||
if (!dictionary.TryGetValue(_Id, out var item)) return false;
|
||||
if (!Remove(item)) return false;
|
||||
var pars = new object[] { item };
|
||||
if (DropFactory is not null)
|
||||
if (DropFactory.GetInvocationList().Any(x => x.Method.Invoke(x.Target, pars) is false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var prefab = Addressables.LoadAssetAsync<AssetableItem>(item.AdressablePath).WaitForCompletion();
|
||||
if (DropFactory != null && DropFactory.GetInvocationList().Cast<Func<IBasicItem, bool>>()
|
||||
.Any(x => x.Invoke(item) is false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Drop(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Drop(IBasicItem item)
|
||||
{
|
||||
OnDrop?.Invoke(item);
|
||||
var prefab = Addressables.LoadAssetAsync<AssetableItem>(item.AddressablePath).WaitForCompletion();
|
||||
var _transform = transform;
|
||||
var position = _transform.position;
|
||||
var rotation = _transform.rotation;
|
||||
@@ -162,7 +149,6 @@ namespace BITFALL
|
||||
}
|
||||
var instance = Instantiate(prefab.GetPrefab(), position, rotation);
|
||||
instance.CopyItemsFrom(item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,24 +1,23 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
public interface IWeightedCallback
|
||||
public interface IPlayerInventoryWeightable
|
||||
{
|
||||
public void OnWeighted(float current, float max);
|
||||
event Action<double,double> OnWeighted;
|
||||
}
|
||||
|
||||
public class InventoryWeightable : EntityComponent,IPlayerEquipCallback
|
||||
[CustomType(typeof(IPlayerInventoryWeightable))]
|
||||
public class InventoryWeightable : EntityComponent,IPlayerInventoryWeightable
|
||||
{
|
||||
[Header(Constant.Header.Data)]
|
||||
public float currentWeight;
|
||||
public double currentWeight;
|
||||
[Header(Constant.Header.Settings)]
|
||||
public float maxWeight =8;
|
||||
public double maxWeight =8;
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
IBasicItemContainer container;
|
||||
|
||||
|
||||
private IBasicItemContainer container;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
@@ -26,37 +25,25 @@ namespace BITFALL
|
||||
container.AddFactory += AddFactory;
|
||||
container.OnAdd += OnAdd;
|
||||
container.OnRemove += OnRemove;
|
||||
|
||||
entity.RegisterCallback<IPlayerEquipCallback>(this);
|
||||
|
||||
var playerEquipContainer = entity.Get<IPlayerEquipContainer>();
|
||||
playerEquipContainer.OnEquip += OnEquip;
|
||||
playerEquipContainer.OnDeEquip += DeEquip;
|
||||
}
|
||||
|
||||
private bool AddFactory(IBasicItem item)
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if (asset.TryGetProperty<ItemWeight>(out var itemWeight))
|
||||
{
|
||||
if (currentWeight + itemWeight <= maxWeight)
|
||||
{
|
||||
|
||||
}
|
||||
else if (currentWeight + itemWeight > maxWeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
if (!asset.TryGetProperty<ItemWeight>(out var itemWeight)) return true;
|
||||
return currentWeight + itemWeight <= maxWeight;
|
||||
}
|
||||
|
||||
private void OnAdd(IBasicItem item)
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if (asset.TryGetProperty<ItemWeight>(out var itemWeight))
|
||||
{
|
||||
currentWeight += itemWeight;
|
||||
InvokeCallback();
|
||||
}
|
||||
|
||||
if (!asset.TryGetProperty<ItemWeight>(out var itemWeight)) return;
|
||||
currentWeight += itemWeight;
|
||||
InvokeCallback();
|
||||
}
|
||||
private void OnRemove(IBasicItem item)
|
||||
{
|
||||
@@ -67,29 +54,23 @@ namespace BITFALL
|
||||
|
||||
}
|
||||
|
||||
public void DeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
private void DeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
if (item.GetAssetable().TryGetProperty<AddInventoryMaxWeight>(out var addWeight))
|
||||
{
|
||||
maxWeight -= addWeight.AddWeight;
|
||||
InvokeCallback();
|
||||
}
|
||||
if (!item.GetAssetable().TryGetProperty<AddInventoryMaxWeight>(out var addWeight)) return;
|
||||
maxWeight -= addWeight.AddWeight;
|
||||
InvokeCallback();
|
||||
}
|
||||
|
||||
public void OnEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
private void OnEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
if (item.GetAssetable().TryGetProperty<AddInventoryMaxWeight>(out var addWeight))
|
||||
{
|
||||
maxWeight += addWeight.AddWeight;
|
||||
InvokeCallback();
|
||||
}
|
||||
if (!item.GetAssetable().TryGetProperty<AddInventoryMaxWeight>(out var addWeight)) return;
|
||||
maxWeight += addWeight.AddWeight;
|
||||
InvokeCallback();
|
||||
}
|
||||
void InvokeCallback()
|
||||
private void InvokeCallback()
|
||||
{
|
||||
foreach (var x in entity.GetCallbacks<IWeightedCallback>())
|
||||
{
|
||||
x.OnWeighted(currentWeight, maxWeight);
|
||||
}
|
||||
OnWeighted?.Invoke(currentWeight, maxWeight);
|
||||
}
|
||||
public event Action<double,double> OnWeighted;
|
||||
}
|
||||
}
|
@@ -10,21 +10,18 @@ using Google.Apis.Sheets.v4.Data;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
public interface IPlayerEquipCallback
|
||||
{
|
||||
void OnEquip(IEquipmentSlot slot,IBasicItem item);
|
||||
void DeEquip(IEquipmentSlot slot, IBasicItem item);
|
||||
}
|
||||
public interface IPlayerEquipContainer {
|
||||
Action<IEquipmentSlot, IBasicItem> OnEquip { get; set; }
|
||||
Action<IEquipmentSlot, IBasicItem> OnDeEquip { get; set; }
|
||||
bool TryDeEquip<T>(T slot=default) where T : IEquipmentSlot;
|
||||
}
|
||||
/// <summary>
|
||||
/// 玩家装备容器
|
||||
/// 支持,护甲,头盔和背包等
|
||||
/// </summary>
|
||||
public class PlayerEquipContainer : EntityComponent, IExcutor<IBasicItem>, IPlayerEquipContainer,IServiceRegister
|
||||
[CustomType(typeof(IPlayerEquipContainer))]
|
||||
public class PlayerEquipContainer : EntityComponent, TaskSubscriber<IBasicItem>, IPlayerEquipContainer
|
||||
{
|
||||
public override Type BaseType => typeof(IPlayerEquipContainer);
|
||||
private readonly Dictionary<IEquipmentSlot, IBasicItem> dictionary = new();
|
||||
private IBasicItemContainer inventory;
|
||||
public override void OnAwake()
|
||||
@@ -35,19 +32,25 @@ namespace BITFALL
|
||||
|
||||
private void OnSetAlive(bool obj)
|
||||
{
|
||||
if (obj is false) return;
|
||||
foreach (var x in dictionary.Keys.ToArray())
|
||||
if (obj) return;
|
||||
foreach (var x in dictionary.ToArray())
|
||||
{
|
||||
TryDeEquip(x);
|
||||
OnDeEquip?.Invoke(x.Key, x.Value);
|
||||
inventory.Add(x.Value);
|
||||
}
|
||||
dictionary.Clear();
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
entity.RegisterCallback<IExcutor<IBasicItem>>(this);
|
||||
entity.RegisterCallback<TaskSubscriber<IBasicItem>>(this);
|
||||
inventory = entity.Get<IBasicItemContainer>();
|
||||
}
|
||||
|
||||
public Action<IEquipmentSlot, IBasicItem> OnEquip { get; set; }
|
||||
public Action<IEquipmentSlot, IBasicItem> OnDeEquip { get; set; }
|
||||
|
||||
public bool TryDeEquip<T>(T slot) where T : IEquipmentSlot
|
||||
{
|
||||
if (!dictionary.TryGetValue(slot, out var equipable)) return false;
|
||||
@@ -60,21 +63,16 @@ namespace BITFALL
|
||||
private bool Equip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
dictionary.Add(slot, item);
|
||||
foreach (var x in entity.GetCallbacks<IPlayerEquipCallback>())
|
||||
{
|
||||
x.OnEquip(slot, item);
|
||||
}
|
||||
OnEquip?.Invoke(slot, item);
|
||||
return true;
|
||||
}
|
||||
private bool DeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
dictionary.Remove(slot);
|
||||
foreach (var x in entity.GetCallbacks<IPlayerEquipCallback>())
|
||||
{
|
||||
x.DeEquip(slot, item);
|
||||
}
|
||||
OnDeEquip?.Invoke(slot, item);
|
||||
return true;
|
||||
}
|
||||
public int Priority => 0;
|
||||
|
||||
public bool TryExecute(IBasicItem value)
|
||||
{
|
||||
|
@@ -10,13 +10,13 @@ using System.Linq;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
public class PlayerInventory : EntityInventory,ISelectableCallback,IRequestor<IBasicItem>
|
||||
public class PlayerInventory : EntityInventory,ISelectableCallback,TaskPublisher<IBasicItem>
|
||||
{
|
||||
public override void Initialize(IEntity entity)
|
||||
{
|
||||
base.Initialize(entity);
|
||||
entity.Set<IBasicItemContainer>(this);
|
||||
entity.Set<IRequestor<IBasicItem>>(this);
|
||||
entity.Set<TaskPublisher<IBasicItem>>(this);
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace BITFALL
|
||||
entity.RegisterCallback<ISelectableCallback>(this);
|
||||
}
|
||||
/// <summary>咋整啊这个</summary>
|
||||
public void OnActive(ISelectable selectable)
|
||||
void ISelectableCallback.OnActive(ISelectable selectable)
|
||||
{
|
||||
var trans = selectable.GetTransform();
|
||||
|
||||
@@ -41,16 +41,16 @@ namespace BITFALL
|
||||
}
|
||||
}
|
||||
|
||||
public void OnHover(ISelectable selectable)
|
||||
void ISelectableCallback.OnHover(ISelectable selectable)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnInactive(ISelectable selectable)
|
||||
void ISelectableCallback.OnInactive(ISelectable selectable)
|
||||
{
|
||||
}
|
||||
public bool Excute(IBasicItem value)
|
||||
public bool Execute(IBasicItem value)
|
||||
{
|
||||
foreach (var excutor in entity.GetCallbacks<IExcutor<IBasicItem>>())
|
||||
foreach (var excutor in entity.GetCallbacks<TaskSubscriber<IBasicItem>>())
|
||||
{
|
||||
if(excutor.TryExecute(value))
|
||||
{
|
||||
@@ -61,24 +61,24 @@ namespace BITFALL
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// #if UNITY_EDITOR
|
||||
// [UnityEditor.CustomEditor(typeof(PlayerInventory))]
|
||||
// public class EntityPlayerInventoryInsepctor : BITInspector<PlayerInventory>
|
||||
// {
|
||||
// public override VisualElement CreateInspectorGUI()
|
||||
// {
|
||||
// FillDefaultInspector();
|
||||
// CreateSubTitle(Constant.Header.Debug);
|
||||
// var serializeLabel = root.Create<Label>();
|
||||
//
|
||||
// StringBuilder stringBuilder = new StringBuilder();
|
||||
// foreach (var x in agent.GetItems())
|
||||
// {
|
||||
// stringBuilder.AppendLine($"{x.Id}@{x.Name}");
|
||||
// }
|
||||
// serializeLabel.text=stringBuilder.ToString();
|
||||
// return root;
|
||||
// }
|
||||
// }
|
||||
// #endif
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(PlayerInventory))]
|
||||
public class EntityPlayerInventoryInsepctor : BITInspector<PlayerInventory>
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
FillDefaultInspector();
|
||||
CreateSubTitle(Constant.Header.Debug);
|
||||
var serializeLabel = root.Create<Label>();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (var x in agent.GetItems())
|
||||
{
|
||||
stringBuilder.AppendLine($"{x.Id}@{x.Name}");
|
||||
}
|
||||
serializeLabel.text=stringBuilder.ToString();
|
||||
return root;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -6,15 +6,23 @@ using AYellowpaper.SerializedCollections;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
public class EntityPropsDisplay : EntityComponent,IEquipSelectorCallback,IPlayerEquipCallback
|
||||
public class EntityPropsDisplay : EntityComponent
|
||||
{
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> equipments = new();
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> unEquipDictionary = new();
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> equipDictionary = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
entity.RegisterCallback<IPlayerEquipCallback>(this);
|
||||
entity.RegisterCallback<IEquipSelectorCallback>(this);
|
||||
var playerEquipContainer = entity.Get<IPlayerEquipContainer>();
|
||||
var equipSelector = entity.Get<IPlayerEquipSelector>();
|
||||
|
||||
playerEquipContainer.OnEquip += OnEquip;
|
||||
playerEquipContainer.OnDeEquip += OnDeEquip;
|
||||
|
||||
equipSelector.OnEquip += OnEquip;
|
||||
equipSelector.OnDeEquip += OnDeEquip;
|
||||
equipSelector.OnUpdateEquip += OnUpdateEquip;
|
||||
|
||||
foreach (var x in equipments)
|
||||
{
|
||||
x.Value.SetActive(false);
|
||||
@@ -28,39 +36,40 @@ namespace BITFALL
|
||||
x.Value.SetActive(false);
|
||||
}
|
||||
}
|
||||
public void DeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
private void OnDeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if (equipments.TryGetValue(asset.AdressablePath, out GameObject prop))
|
||||
if (equipments.TryGetValue(asset.AddressablePath, out GameObject prop))
|
||||
{
|
||||
prop.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
private void OnEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if(equipments.TryGetValue(asset.AdressablePath, out GameObject prop)) {
|
||||
if(equipments.TryGetValue(asset.AddressablePath, out GameObject prop)) {
|
||||
prop.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEquip(IBasicItem item)
|
||||
private void OnEquip(IBasicItem item)
|
||||
{
|
||||
if (equipDictionary.TryGetValue(item.AdressablePath, out var model))
|
||||
if(item is null) return;
|
||||
if (equipDictionary.TryGetValue(item.AddressablePath, out var model))
|
||||
{
|
||||
model.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDeEquip(IBasicItem item)
|
||||
private void OnDeEquip(IBasicItem item)
|
||||
{
|
||||
foreach (var x in equipDictionary)
|
||||
{
|
||||
x.Value.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
public void OnUpdateEquip(IDictionary<int, IBasicItem> maps)
|
||||
private void OnUpdateEquip(IDictionary<int, IBasicItem> maps)
|
||||
{
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user