using System.Collections; using System.Collections.Generic; using UnityEngine; public class DialoguePanelController : MonoBehaviour { [SerializeField] List characterCGSpots; // Fill this with CharacterCG Prefab Variants according to // the poses in the order of the NPCCG Enum. [SerializeField] List characterCGIndex; List characterCGs = new List() { null, null, null, null }; private List currentCGIndices = new List() { -1, -1, -1, -1 }; private static Dictionary gloveIndex = new Dictionary() { { ItemSubType.NONE, -1 }, { ItemSubType.ARCHER_GLOVES, 0 }, { ItemSubType.BANDIT_GLOVES, 1 }, }; private static Dictionary bowIndex = new Dictionary() { { ItemSubType.NONE, 0 }, { ItemSubType.ARCHER_BOW, 1 }, { ItemSubType.BANDIT_BOW, 2 }, { ItemSubType.FAIRY_BOW, 3 }, { ItemSubType.ELITE_BOW, 4 }, }; private static Dictionary outfitIndex = new Dictionary() { { ItemSubType.NONE, 0 }, { ItemSubType.ARCHER_TUNIC, 1 }, { ItemSubType.BANDIT_OUTFIT, 2 }, { ItemSubType.FAIRY_DRESS, 3 }, { ItemSubType.ELITE_DRESS, 4 }, }; private static Dictionary shoeIndex = new Dictionary() { { ItemSubType.NONE, -1 }, { ItemSubType.ARCHER_BOOTS, 0 }, { ItemSubType.BANDIT_BOOTS, 1 }, { ItemSubType.FAIRY_SANDALS, 2 }, { ItemSubType.ELITE_BOOTS, 3 }, }; private static Dictionary outfitBackIndex = new Dictionary() { { ItemSubType.NONE, -1 }, { ItemSubType.ARCHER_TUNIC, -1 }, { ItemSubType.BANDIT_OUTFIT, -1 }, { ItemSubType.FAIRY_DRESS, -1 }, { ItemSubType.ELITE_DRESS, 0 }, }; public void Reset() { for (int i = 0; i < characterCGs.Count; i++) { if (characterCGs[i] != null) { Destroy(characterCGs[i]); characterCGs[i] = null; } } currentCGIndices = new List() { -1, -1, -1, -1 }; } public ItemSubType GetSubType(ItemType itemType) { if (!State.state.inventory.equipped.ContainsKey(itemType)) { return ItemSubType.NONE; } Item item = ((Item)State.state.inventory.equipped[itemType]); return (item != null) ? item.subType : ItemSubType.NONE; } public void SetTalkingPosition(int talkingSpot) { for (int i = 0; i < characterCGs.Count; i++) { if (characterCGs[i] != null) { characterCGs[i].GetComponent().SetIsTalking(i == talkingSpot); } } } public void ShowCG(int location, NpcCG cgIndex, int expressionIndex) { if (cgIndex == NpcCG.NONE) { characterCGs[location].GetComponent().SetCGLayers(null); return; } int index = (int)cgIndex - 1; ItemSubType shoesSubType = GetSubType(ItemType.EQUIP_SHOES); ItemSubType gloveSubType = GetSubType(ItemType.EQUIP_GLOVES); ItemSubType bowSubType = GetSubType(ItemType.EQUIP_BOW); ItemSubType outfitSubType = GetSubType(ItemType.EQUIP_OVERALL); List indexList; if (cgIndex == NpcCG.AIRA_POSE1) { indexList = new List() { /*BodyUnder=*/0, /*GloveUnder=*/gloveIndex[gloveSubType], /*Bow=*/bowIndex[bowSubType], /*BodyUpper=*/0, /*Shoes=*/shoeIndex[shoesSubType], /*Outfit=*/outfitIndex[outfitSubType], /*GloveOver=*/gloveIndex[gloveSubType], /*Face=*/ expressionIndex, /*FrontHair=*/0, /*outfitBack=*/outfitBackIndex[outfitSubType]}; } else if (cgIndex == NpcCG.AIRA_POSE2) { indexList = new List() { /*Body=*/0, /*Shoes=*/shoeIndex[shoesSubType], /*Outfit=*/outfitIndex[outfitSubType], /*Bow=*/bowIndex[bowSubType], /*Gloves=*/gloveIndex[gloveSubType], /*Face=*/ expressionIndex, /*Hair=*/0, /*OutfitBack=*/outfitBackIndex[outfitSubType]}; } else { indexList = new List() { 0, expressionIndex }; } // Re-spawn the object in that slot if it's not already associated with the right CG. if (currentCGIndices[location] != index) { currentCGIndices[location] = index; if (characterCGs[location] != null) { Destroy(characterCGs[location]); } characterCGs[location] = Instantiate(characterCGIndex[index]); } characterCGs[location].transform.SetParent(transform); characterCGs[location].transform.position = characterCGSpots[location].transform.position; characterCGs[location].transform.localScale = characterCGSpots[location].transform.localScale; characterCGs[location].GetComponent() .SetCGLayers(indexList); } }