rimworld-animation-studio/Assets/Scripts/GUI/SelectRaceDropdown.cs

70 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectRaceDropdown : MonoBehaviour
{
private Dropdown dropdown;
private Text label;
private int actorID = -1;
private int hashcode = -1;
public void OnEnable()
{
dropdown = GetComponent<Dropdown>();
label = transform.Find("Label").GetComponent<Text>();
}
public void Update()
{
//if (Workspace.animationDef == null) return;
//if (actorID != Workspace.actorID || hashcode != CustomTags.defNames.GetHashCode())
//{ UpdateDropdown(); }
if (hashcode != CustomTags.defNames.GetHashCode())
{ UpdateDropdown(); }
}
public void UpdateDropdown()
{
if (dropdown == null)
{ OnEnable(); }
dropdown.ClearOptions();
/*string alienRaceDefName = Workspace.animationDef.actors[Workspace.actorID].GetAlienRaceDef().defName;
dropdown.ClearOptions();
dropdown.options.Add(new Dropdown.OptionData(alienRaceDefName));*/
IEnumerable<string> optionsList = Tags.defNames.Concat(CustomTags.defNames);
foreach (string defName in optionsList)
{
//if (defName != alienRaceDefName)
//{ dropdown.options.Add(new Dropdown.OptionData(defName)); }
dropdown.options.Add(new Dropdown.OptionData(defName));
}
dropdown.value = 0;
label.text = dropdown.options[0].text;
//actorID = Workspace.actorID;
hashcode = CustomTags.defNames.GetHashCode();
}
public void UpdateActorRace()
{
if (Workspace.animationDef == null) return;
Workspace.animationDef.actors[Workspace.actorID].SetAlienRaceDef(label.text);
Workspace.selectedBodyPart = null;
}
}
}