Files
pgs/Assets/PlayerAnimationController.cs

123 lines
4.7 KiB
C#
Raw Permalink Normal View History

2026-02-21 16:58:22 -08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class LayerSprite {
public List<Sprite> sprites;
}
public class PlayerAnimationController : MonoBehaviour
{
[SerializeField] int offset = 0;
[SerializeField] Animator animator;
[SerializeField] List<LayerSprite> bowSprites;
[SerializeField] List<LayerSprite> bootsSprites;
[SerializeField] List<LayerSprite> glovesSprites;
[SerializeField] List<LayerSprite> outfitSprites;
[SerializeField] List<LayerSprite> bowBackSprites;
[SerializeField] List<Sprite> bodySprites;
[SerializeField] SpriteRenderer bowSprite;
[SerializeField] SpriteRenderer bodySprite;
[SerializeField] SpriteRenderer bootsSprite;
[SerializeField] SpriteRenderer glovesSprite;
[SerializeField] SpriteRenderer outfitSprite;
[SerializeField] SpriteRenderer bowBackSprite;
public Dictionary<ItemSubType, int> itemSpriteIndices =
new Dictionary<ItemSubType, int> {
{ ItemSubType.NONE, 0 },
{ ItemSubType.ARCHER_TUNIC, 1 },
{ ItemSubType.BANDIT_OUTFIT, 2 },
{ ItemSubType.FAIRY_DRESS, 3 },
{ ItemSubType.GUARDIAN_OUTFIT, 4 },
{ ItemSubType.ARCHER_GLOVES, 1 },
{ ItemSubType.BANDIT_GLOVES, 2 },
{ ItemSubType.GUARDIAN_CUFFS, 3 },
{ ItemSubType.ARCHER_BOOTS, 1 },
{ ItemSubType.BANDIT_BOOTS, 2 },
{ ItemSubType.FAIRY_SANDALS, 3 },
{ ItemSubType.GUARDIAN_BOOTS, 4 },
{ ItemSubType.ARCHER_BOW, 1 },
{ ItemSubType.BANDIT_BOW, 2 },
{ ItemSubType.FAIRY_BOW, 3 },
{ ItemSubType.GUARDIAN_BOW, 4 },
};
private void FixedUpdate() {
if (State.state.inventory.equipped.ContainsKey(ItemType.EQUIP_BOW) &&
State.state.inventory.equipped[ItemType.EQUIP_BOW] != null) {
bowSprite.sprite = bowSprites[itemSpriteIndices[State.state.inventory.equipped[ItemType.EQUIP_BOW].subType]].sprites[offset];
bowBackSprite.sprite = bowSprites[itemSpriteIndices[State.state.inventory.equipped[ItemType.EQUIP_BOW].subType]].sprites[offset];
} else {
bowSprite.sprite = bowSprites[itemSpriteIndices[ItemSubType.NONE]].sprites[offset];
bowBackSprite.sprite = bowSprites[itemSpriteIndices[ItemSubType.NONE]].sprites[offset];
}
if (State.state.inventory.equipped.ContainsKey(ItemType.EQUIP_GLOVES) &&
State.state.inventory.equipped[ItemType.EQUIP_GLOVES] != null) {
glovesSprite.sprite = glovesSprites[itemSpriteIndices[State.state.inventory.equipped[ItemType.EQUIP_GLOVES].subType]].sprites[offset];
} else {
glovesSprite.sprite = glovesSprites[itemSpriteIndices[ItemSubType.NONE]].sprites[offset];
}
if (State.state.inventory.equipped.ContainsKey(ItemType.EQUIP_OVERALL) &&
State.state.inventory.equipped[ItemType.EQUIP_OVERALL] != null) {
outfitSprite.sprite = outfitSprites[itemSpriteIndices[State.state.inventory.equipped[ItemType.EQUIP_OVERALL].subType]].sprites[offset];
} else {
outfitSprite.sprite = outfitSprites[itemSpriteIndices[ItemSubType.NONE]].sprites[offset];
}
if (State.state.inventory.equipped.ContainsKey(ItemType.EQUIP_SHOES) &&
State.state.inventory.equipped[ItemType.EQUIP_SHOES] != null) {
bootsSprite.sprite = bootsSprites[itemSpriteIndices[State.state.inventory.equipped[ItemType.EQUIP_SHOES].subType]].sprites[offset];
} else {
bootsSprite.sprite = bootsSprites[itemSpriteIndices[ItemSubType.NONE]].sprites[offset];
}
bodySprite.sprite = bodySprites[offset];
}
public void Broadcast(string name, float value) {
animator.SetFloat(name, value);
}
public void Broadcast(string name, int value) {
animator.SetInteger(name, value);
}
public void Broadcast(string name, bool value) {
animator.SetBool(name, value);
}
public bool GetBool(string name) {
return animator.GetBool(name);
}
public bool isIdling() {
if (animator.GetBool("isFalling")
|| animator.GetBool("isJumping")
|| animator.GetBool("isDashing")
|| animator.GetBool("isAttacking")
|| animator.GetBool("isFlipAttacking")
|| animator.GetBool("isArrowBarraging")
|| animator.GetBool("isJudging")
|| animator.GetBool("isFiring")
|| animator.GetBool("isExecuting")) {
return false;
}
return true;
}
public void ChangeEquip(ItemType a, ItemSubType b) { }
}