HeavenStudioPlus/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs

72 lines
2.4 KiB
C#
Raw Normal View History

2022-02-03 22:20:26 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
2022-02-04 22:16:22 +00:00
using RhythmHeavenMania.Util;
2022-02-03 22:20:26 +00:00
namespace RhythmHeavenMania.Editor
{
public class EventPropertyPrefab : MonoBehaviour
{
public TMP_Text caption;
2022-02-04 22:16:22 +00:00
[SerializeField] private EventParameterManager parameterManager;
[Header("Integer and Float")]
[Space(10)]
2022-02-03 22:20:26 +00:00
public Slider slider;
public TMP_InputField inputField;
2022-02-04 22:16:22 +00:00
[Header("Dropdown")]
[Space(10)]
public TMP_Dropdown dropdown;
2022-02-03 22:20:26 +00:00
private string propertyName;
public void SetProperties(string propertyName, object type, string caption)
{
this.propertyName = propertyName;
this.caption.text = caption;
2022-02-04 22:16:22 +00:00
if (type.GetType() == typeof(EntityTypes.Integer))
{
var integer = ((EntityTypes.Integer)type);
2022-02-03 22:20:26 +00:00
2022-02-04 22:16:22 +00:00
slider.minValue = integer.min;
slider.maxValue = integer.max;
2022-02-04 22:16:22 +00:00
slider.value = Mathf.RoundToInt(System.Convert.ToSingle(parameterManager.entity[propertyName]));
inputField.text = slider.value.ToString();
2022-02-04 22:16:22 +00:00
slider.onValueChanged.AddListener(delegate
{
inputField.text = slider.value.ToString();
parameterManager.entity[propertyName] = (int)slider.value;
});
}
else if (type.GetType() == typeof(EasingFunction.Ease))
{
List<TMP_Dropdown.OptionData> dropDownData = new List<TMP_Dropdown.OptionData>();
for (int i = 0; i < System.Enum.GetValues(typeof(EasingFunction.Ease)).Length; i++)
{
string name = System.Enum.GetNames(typeof(EasingFunction.Ease))[i];
TMP_Dropdown.OptionData optionData = new TMP_Dropdown.OptionData();
2022-02-03 22:20:26 +00:00
2022-02-04 22:16:22 +00:00
optionData.text = name;
dropDownData.Add(optionData);
}
dropdown.AddOptions(dropDownData);
dropdown.value = ((int)(EasingFunction.Ease)parameterManager.entity[propertyName]);
dropdown.onValueChanged.AddListener(delegate
{
parameterManager.entity[propertyName] = (EasingFunction.Ease)dropdown.value;
});
}
2022-02-03 22:20:26 +00:00
}
}
}