137 lines
5.3 KiB
C#
137 lines
5.3 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class DialoguePanelController : MonoBehaviour {
|
|||
|
|
[SerializeField] List<Transform> characterCGSpots;
|
|||
|
|
|
|||
|
|
// Fill this with CharacterCG Prefab Variants according to
|
|||
|
|
// the poses in the order of the NPCCG Enum.
|
|||
|
|
[SerializeField] List<GameObject> characterCGIndex;
|
|||
|
|
|
|||
|
|
List<GameObject> characterCGs = new List<GameObject>() { null, null, null, null };
|
|||
|
|
|
|||
|
|
private List<int> currentCGIndices = new List<int>() { -1, -1, -1, -1 };
|
|||
|
|
|
|||
|
|
private static Dictionary<ItemSubType, int> gloveIndex =
|
|||
|
|
new Dictionary<ItemSubType, int>() {
|
|||
|
|
{ ItemSubType.NONE, -1 },
|
|||
|
|
{ ItemSubType.ARCHER_GLOVES, 0 },
|
|||
|
|
{ ItemSubType.BANDIT_GLOVES, 1 },
|
|||
|
|
};
|
|||
|
|
private static Dictionary<ItemSubType, int> bowIndex =
|
|||
|
|
new Dictionary<ItemSubType, int>() {
|
|||
|
|
{ ItemSubType.NONE, 0 },
|
|||
|
|
{ ItemSubType.ARCHER_BOW, 1 },
|
|||
|
|
{ ItemSubType.BANDIT_BOW, 2 },
|
|||
|
|
{ ItemSubType.FAIRY_BOW, 3 },
|
|||
|
|
{ ItemSubType.ELITE_BOW, 4 },
|
|||
|
|
};
|
|||
|
|
private static Dictionary<ItemSubType, int> outfitIndex =
|
|||
|
|
new Dictionary<ItemSubType, int>() {
|
|||
|
|
{ ItemSubType.NONE, 0 },
|
|||
|
|
{ ItemSubType.ARCHER_TUNIC, 1 },
|
|||
|
|
{ ItemSubType.BANDIT_OUTFIT, 2 },
|
|||
|
|
{ ItemSubType.FAIRY_DRESS, 3 },
|
|||
|
|
{ ItemSubType.ELITE_DRESS, 4 },
|
|||
|
|
};
|
|||
|
|
private static Dictionary<ItemSubType, int> shoeIndex =
|
|||
|
|
new Dictionary<ItemSubType, int>() {
|
|||
|
|
{ ItemSubType.NONE, -1 },
|
|||
|
|
{ ItemSubType.ARCHER_BOOTS, 0 },
|
|||
|
|
{ ItemSubType.BANDIT_BOOTS, 1 },
|
|||
|
|
{ ItemSubType.FAIRY_SANDALS, 2 },
|
|||
|
|
{ ItemSubType.ELITE_BOOTS, 3 },
|
|||
|
|
};
|
|||
|
|
private static Dictionary<ItemSubType, int> outfitBackIndex =
|
|||
|
|
new Dictionary<ItemSubType, int>() {
|
|||
|
|
{ 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<int>() { -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<CharacterCGController>().SetIsTalking(i == talkingSpot);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ShowCG(int location, NpcCG cgIndex, int expressionIndex) {
|
|||
|
|
if (cgIndex == NpcCG.NONE) {
|
|||
|
|
characterCGs[location].GetComponent<CharacterCGController>().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<int> indexList;
|
|||
|
|
if (cgIndex == NpcCG.AIRA_POSE1) {
|
|||
|
|
indexList = new List<int>() {
|
|||
|
|
/*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<int>() {
|
|||
|
|
/*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<int>() { 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<CharacterCGController>()
|
|||
|
|
.SetCGLayers(indexList);
|
|||
|
|
}
|
|||
|
|
}
|