mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
62 lines
No EOL
1.8 KiB
C#
62 lines
No EOL
1.8 KiB
C#
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<Dropdown>();
|
|
label = transform.Find("Label").GetComponent<Text>();
|
|
}
|
|
|
|
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<AlienRaceDef> 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;
|
|
}
|
|
}
|
|
} |