BITFALL/Assets/Artists/Scripts/Equip/PlayerImprovisedController.cs

111 lines
2.3 KiB
C#
Raw Normal View History

2023-10-20 19:31:12 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
2023-12-15 00:08:02 +08:00
using AYellowpaper.SerializedCollections;
2023-10-20 19:31:12 +08:00
using BITFALL.Entities.Equipment;
using BITKit;
using BITKit.Entities;
using Cysharp.Threading.Tasks;
using UnityEngine;
2023-10-30 01:25:53 +08:00
using IEntity = BITKit.Entities.IEntity;
2023-10-20 19:31:12 +08:00
namespace BITFALL.Player.Equip
{
public class PlayerImprovisedController : MonoBehaviour, IEquipBase
{
[SerializeField] private AssetableItem[] supportItems;
2023-12-15 00:08:02 +08:00
[SerializeField] private SerializedDictionary<string, Transform> modelDictionary = new();
2023-10-20 19:31:12 +08:00
[SerializeField] private SpriteRenderer spriteRenderer;
[Inject]
private IEntityEquipment _entityEquipment;
public void OnAwake()
{
_entityEquipment.OnEquip += OnEquip;
2023-10-29 15:27:13 +08:00
_entityEquipment.OnUnEquip += OnUnEquip;
2023-10-20 19:31:12 +08:00
}
public void OnStart()
{
foreach (var x in modelDictionary.Values)
{
x.gameObject.SetActive(false);
}
spriteRenderer.enabled = false;
}
public void OnUpdate(float deltaTime)
{
}
public bool IsEntered { get; set; }
public void Entry()
{
spriteRenderer.enabled = true;
}
public UniTask EntryAsync()
{
return UniTask.CompletedTask;
}
2023-11-15 23:54:54 +08:00
public void Entered()
{
}
2023-10-20 19:31:12 +08:00
public void Exit()
{
spriteRenderer.enabled = false;
}
public UniTask ExitAsync()
{
return UniTask.CompletedTask;
}
2023-11-15 23:54:54 +08:00
public void Exited()
{
}
2023-10-29 15:27:13 +08:00
private void OnUnEquip(IBasicItem obj)
2023-10-20 19:31:12 +08:00
{
foreach (var x in modelDictionary.Values)
{
x.gameObject.SetActive(false);
}
spriteRenderer.sprite = null;
}
private void OnEquip(IBasicItem obj)
{
2023-10-24 23:37:59 +08:00
if (IsEntered is false) return;
2023-10-20 19:31:12 +08:00
spriteRenderer.sprite = null;
if (modelDictionary.TryGetValue(obj.AddressablePath, out var model))
model.gameObject.SetActive(true);
else
{
var texture = obj.GetAssetable().SquareIcon;
if (texture is not null)
{
spriteRenderer.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
}
}
}
public string AddressablePath { get; set; } = "Assets/Artists/Addressables/Items/Improvised/ImprovisedItem.prefab";
public IEntity Entity { get; set; }
public IBasicItem Item { get; set; }
public bool IsSupportItem(IBasicItem item) =>item is not null && supportItems.Any(x => x.AddressablePath == item.AddressablePath);
public void PlayAudio(string name)
{
}
}
}