86 lines
3.5 KiB
C#
86 lines
3.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Michsky.MUIP;
|
|
|
|
public class UnlockSelectorController : MonoBehaviour {
|
|
enum SelectorType {
|
|
Outfit,
|
|
Hair
|
|
}
|
|
[SerializeField] HorizontalSelector selector;
|
|
[SerializeField] SelectorType selectorType;
|
|
[SerializeField] Image vnSprite; // Changes when updating the selector.
|
|
[SerializeField] Image vnHairBackSprite; // Changes when updating the selector.
|
|
[SerializeField] Image vnIcon;
|
|
[SerializeField] VNObjectController managerAssets;
|
|
|
|
// Start is called before the first frame update
|
|
void Start() {
|
|
switch (selectorType) {
|
|
case SelectorType.Outfit:
|
|
UpdateUnlockedOutfits();
|
|
vnIcon.sprite = managerAssets.outfitIcons[(int)GameData.GLOBAL.bodyChoice - 1];
|
|
break;
|
|
case SelectorType.Hair:
|
|
UpdateUnlockedHairs();
|
|
vnIcon.sprite = managerAssets.hairIcons[(int)GameData.GLOBAL.hairChoice - 1];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void UpdateUnlockedOutfits() {
|
|
// Build a list of unlocked outfits, with the "meta" item field set to the index of the outfit (enum value).
|
|
// Meta is used later to set the outfit in the DialogueBox.
|
|
selector.items = new List<HorizontalSelector.Item>();
|
|
for (int i = 0; i < System.Enum.GetNames(typeof(Body)).Length; i++) {
|
|
if (GameData.GLOBAL.unlockedOutfits.Contains((Body)i)) {
|
|
HorizontalSelector.Item item = new HorizontalSelector.Item();
|
|
item.meta = i;
|
|
item.itemTitle = VNData.OUTFIT_INFO[(Body)i].name;
|
|
selector.items.Add(item);
|
|
if (GameData.GLOBAL.bodyChoice == (Body)i) {
|
|
selector.index = selector.items.Count - 1;
|
|
}
|
|
}
|
|
}
|
|
selector.UpdateUI();
|
|
}
|
|
|
|
public void UpdateUnlockedHairs() {
|
|
// Build a list of unlocked hairs, with the "meta" item field set to the index of the hair (enum value).
|
|
// Meta is used later to set the outfit in the DialogueBox.
|
|
selector.items = new List<HorizontalSelector.Item>();
|
|
for (int i = 0; i < System.Enum.GetNames(typeof(Hair)).Length; i++) {
|
|
if (GameData.GLOBAL.unlockedHairs.Contains((Hair)i)) {
|
|
HorizontalSelector.Item item = new HorizontalSelector.Item();
|
|
item.meta = i;
|
|
item.itemTitle = VNData.HAIR_INFO[(Hair)i].name;
|
|
selector.items.Add(item);
|
|
if (GameData.GLOBAL.hairChoice == (Hair)i) {
|
|
selector.index = selector.items.Count - 1;
|
|
}
|
|
}
|
|
}
|
|
selector.UpdateUI();
|
|
}
|
|
|
|
public void SelectedValueChanged() {
|
|
if (selectorType == SelectorType.Outfit) {
|
|
int i = selector.items[selector.index].meta;
|
|
GameData.GLOBAL.bodyChoice = (Body)i;
|
|
vnSprite.sprite = managerAssets.sprites[i - 1];
|
|
vnIcon.sprite = managerAssets.outfitIcons[i - 1];
|
|
} else if (selectorType == SelectorType.Hair) {
|
|
int i = selector.items[selector.index].meta;
|
|
GameData.GLOBAL.hairChoice = (Hair)i;
|
|
vnSprite.sprite = managerAssets.spriteHairs[i - 1];
|
|
vnHairBackSprite.sprite = managerAssets.spriteHairBacks[i - 1];
|
|
vnIcon.sprite = managerAssets.hairIcons[i - 1];
|
|
}
|
|
}
|
|
}
|