111 lines
2.3 KiB
C#
111 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AYellowpaper.SerializedCollections;
|
|
using BITFALL.Entities.Equipment;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using IEntity = BITKit.Entities.IEntity;
|
|
|
|
namespace BITFALL.Player.Equip
|
|
{
|
|
public class PlayerImprovisedController : MonoBehaviour, IEquipBase
|
|
{
|
|
[SerializeField] private AssetableItem[] supportItems;
|
|
[SerializeField] private SerializedDictionary<string, Transform> modelDictionary = new();
|
|
[SerializeField] private SpriteRenderer spriteRenderer;
|
|
|
|
[Inject]
|
|
private IEntityEquipment _entityEquipment;
|
|
|
|
|
|
public void OnAwake()
|
|
{
|
|
_entityEquipment.OnEquip += OnEquip;
|
|
_entityEquipment.OnUnEquip += OnUnEquip;
|
|
}
|
|
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;
|
|
}
|
|
|
|
public void Entered()
|
|
{
|
|
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
spriteRenderer.enabled = false;
|
|
}
|
|
public UniTask ExitAsync()
|
|
{
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
public void Exited()
|
|
{
|
|
}
|
|
|
|
private void OnUnEquip(IBasicItem obj)
|
|
{
|
|
foreach (var x in modelDictionary.Values)
|
|
{
|
|
x.gameObject.SetActive(false);
|
|
}
|
|
spriteRenderer.sprite = null;
|
|
}
|
|
|
|
private void OnEquip(IBasicItem obj)
|
|
{
|
|
if (IsEntered is false) return;
|
|
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)
|
|
{
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|