2022-09-02 00:57:47 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
2024-01-06 03:51:27 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2022-09-02 00:57:47 +00:00
|
|
|
using System.Linq;
|
|
|
|
using TMPro;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Editor
|
|
|
|
{
|
|
|
|
public class EnumChartPropertyPrefab : RemixPropertyPrefab
|
|
|
|
{
|
|
|
|
[Header("Dropdown")]
|
|
|
|
[Space(10)]
|
|
|
|
public TMP_Dropdown dropdown;
|
|
|
|
|
|
|
|
new public void SetProperties(RemixPropertiesDialog diag, string propertyName, object type, string caption)
|
|
|
|
{
|
|
|
|
InitProperties(diag, propertyName, caption);
|
|
|
|
|
2024-01-06 03:51:27 +00:00
|
|
|
Type enumType = type.GetType();
|
|
|
|
Array enumVals = Enum.GetValues(enumType);
|
|
|
|
List<string> enumNames = Enum.GetNames(enumType).ToList();
|
2022-09-02 00:57:47 +00:00
|
|
|
|
|
|
|
// Can we assume non-holey enum?
|
|
|
|
// If we can we can simplify to dropdown.value = (int) parameterManager.chart[propertyName]
|
|
|
|
var currentlySelected = (int) parameterManager.chart[propertyName];
|
|
|
|
var selected = enumVals
|
|
|
|
.Cast<object>()
|
|
|
|
.ToList()
|
|
|
|
.FindIndex(val => (int) val == currentlySelected);
|
|
|
|
|
|
|
|
dropdown.AddOptions(enumNames);
|
|
|
|
dropdown.value = selected;
|
|
|
|
|
|
|
|
dropdown.onValueChanged.AddListener(_ =>
|
2024-01-06 03:51:27 +00:00
|
|
|
parameterManager.chart[propertyName] = Enum.ToObject(enumType, (int) enumVals.GetValue(dropdown.value))
|
2022-09-02 00:57:47 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|