using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; 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(); label = transform.Find("Label").GetComponent(); } public void Update() { if (Workspace.animationDef == null) return; if (actorID != Workspace.actorID || hashcode != AlienRaceDefs.allDefs.GetHashCode()) { UpdateDropdown(); } } public void UpdateDropdown() { if (dropdown == null) { OnEnable(); } string alienRaceDefName = Workspace.animationDef.actors[Workspace.actorID].GetAlienRaceDef().defName; dropdown.ClearOptions(); dropdown.options.Add(new Dropdown.OptionData(alienRaceDefName)); dropdown.value = 0; label.text = alienRaceDefName; List optionsList = AlienRaceDefs.allDefs; foreach (AlienRaceDef alienRaceDef in optionsList) { if (alienRaceDef.defName != alienRaceDefName) { dropdown.options.Add(new Dropdown.OptionData(alienRaceDef.defName)); } } actorID = Workspace.actorID; hashcode = AlienRaceDefs.allDefs.GetHashCode(); } public void UpdateActorRace() { if (Workspace.animationDef == null) return; Workspace.animationDef.actors[Workspace.actorID].SetAlienRaceDef(label.text); Workspace.selectedBodyPart = null; } } }