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

70 lines
2.0 KiB
C#
Raw Normal View History

2022-09-24 07:17:40 +00:00
using System.Collections;
using System.Collections.Generic;
2022-10-12 05:22:29 +00:00
using System.Linq;
2022-09-24 07:17:40 +00:00
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;
2022-09-25 06:15:27 +00:00
public void OnEnable()
2022-09-24 07:17:40 +00:00
{
dropdown = GetComponent<Dropdown>();
label = transform.Find("Label").GetComponent<Text>();
}
public void Update()
{
2022-10-12 06:16:08 +00:00
//if (Workspace.animationDef == null) return;
//if (actorID != Workspace.actorID || hashcode != CustomTags.defNames.GetHashCode())
//{ UpdateDropdown(); }
2022-09-24 07:17:40 +00:00
2022-10-12 06:16:08 +00:00
if (hashcode != CustomTags.defNames.GetHashCode())
2022-09-24 07:17:40 +00:00
{ UpdateDropdown(); }
}
public void UpdateDropdown()
{
2022-09-27 05:56:35 +00:00
if (dropdown == null)
{ OnEnable(); }
2022-10-12 06:16:08 +00:00
dropdown.ClearOptions();
/*string alienRaceDefName = Workspace.animationDef.actors[Workspace.actorID].GetAlienRaceDef().defName;
2022-09-24 07:17:40 +00:00
dropdown.ClearOptions();
2022-10-12 06:16:08 +00:00
dropdown.options.Add(new Dropdown.OptionData(alienRaceDefName));*/
2022-09-24 07:17:40 +00:00
2022-10-12 05:22:29 +00:00
IEnumerable<string> optionsList = Tags.defNames.Concat(CustomTags.defNames);
foreach (string defName in optionsList)
2022-09-24 07:17:40 +00:00
{
2022-10-12 06:16:08 +00:00
//if (defName != alienRaceDefName)
//{ dropdown.options.Add(new Dropdown.OptionData(defName)); }
dropdown.options.Add(new Dropdown.OptionData(defName));
2022-09-24 07:17:40 +00:00
}
2022-10-12 06:16:08 +00:00
dropdown.value = 0;
label.text = dropdown.options[0].text;
//actorID = Workspace.actorID;
2022-10-12 05:22:29 +00:00
hashcode = CustomTags.defNames.GetHashCode();
2022-09-24 07:17:40 +00:00
}
public void UpdateActorRace()
{
if (Workspace.animationDef == null) return;
Workspace.animationDef.actors[Workspace.actorID].SetAlienRaceDef(label.text);
2022-10-09 02:15:28 +00:00
Workspace.selectedBodyPart = null;
2022-09-24 07:17:40 +00:00
}
}
}