using System; using System.Collections; using System.Collections.Generic; using System.Linq; using BITFALL.Entities.Equipment; using BITFALL.Entities.Inventory; using BITFALL.Player.Movement; using BITKit; using BITKit.Entities; using BITKit.UX; using Cysharp.Threading.Tasks; using UnityEngine; namespace BITFALL.Player.Equip { [Serializable] public struct TimeBarUseData:IProperty { public float Duration; } public class TimeBarUseController : MonoBehaviour,IEquipBase { [Inject] private IPlayerEquipSelector _equipSelector; [Inject] private IEntityInventory _inventory; [Inject] private IUXBarService _barService; [Inject] private IEntityMovement _movement; public bool IsEntered { get; set; } private float progress; private float delta = 1; public void Entry() { progress = 0; _barService.SetOrCreate(Item.Id, $"使用:{Item.Name}", 0); if (Item.GetAssetable().TryGetProperty(out var data)) { delta = data.Duration; } _movement.ExecuteCommand(new PlayerPauseRunCommand(this,true)); _movement.ExecuteCommand(new PlayerLimitMoveSpeedCommand() { Limit = true, Id = Item.Id ,Speed = 1 }); } public UniTask EntryAsync() { return UniTask.CompletedTask; } public void Entered() { } public void Exit() { _barService.Remove(Item.Id); } public UniTask ExitAsync() { return UniTask.CompletedTask; } public void Exited() { progress = 0; _movement.ExecuteCommand(new PlayerPauseRunCommand(this,false)); _movement.ExecuteCommand(new PlayerLimitMoveSpeedCommand() { Limit = false, Id = Item.Id }); } public void OnAwake() { } public void OnStart() { } public void OnUpdate(float deltaTime) { progress += deltaTime / delta; _barService.SetOrCreate(Item.Id, $"使用:{Item.Name}", progress); if (!(progress >= 1)) return; _inventory.UseItem(Item); progress = 0; _equipSelector.Cancel(); } public string AddressablePath { get; set; } public IEntity Entity { get; set; } public IBasicItem Item { get; set; } public bool IsSupportItem(IBasicItem item) => item is not null && item.GetAssetable().TryGetProperty(out _) //&& supportItems.Contains(item.GetAssetable() ; public void PlayAudio(string name) { } } }