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-06 08:28:14 +00:00
|
|
|
var objType = type.GetType();
|
|
|
|
|
|
|
|
if (objType == typeof(EntityTypes.Integer))
|
2022-02-04 22:16:22 +00:00
|
|
|
{
|
|
|
|
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 03:25:18 +00:00
|
|
|
|
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 03:25:18 +00:00
|
|
|
|
2022-02-04 22:16:22 +00:00
|
|
|
slider.onValueChanged.AddListener(delegate
|
|
|
|
{
|
|
|
|
inputField.text = slider.value.ToString();
|
|
|
|
parameterManager.entity[propertyName] = (int)slider.value;
|
2022-02-06 09:28:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
inputField.onEndEdit.AddListener(delegate
|
|
|
|
{
|
|
|
|
slider.value = Mathf.RoundToInt(System.Convert.ToSingle(System.Convert.ToSingle(inputField.text)));
|
|
|
|
parameterManager.entity[propertyName] = (int)slider.value;
|
2022-02-04 22:16:22 +00:00
|
|
|
});
|
|
|
|
}
|
2022-02-06 08:28:14 +00:00
|
|
|
else if (objType == typeof(EntityTypes.Float))
|
|
|
|
{
|
|
|
|
var fl = ((EntityTypes.Float)type);
|
|
|
|
|
|
|
|
slider.minValue = fl.min;
|
|
|
|
slider.maxValue = fl.max;
|
|
|
|
|
|
|
|
slider.value = System.Convert.ToSingle(parameterManager.entity[propertyName]);
|
|
|
|
inputField.text = slider.value.ToString("G4"); // G4 = Display no more than 4 decimal places.
|
|
|
|
|
|
|
|
slider.onValueChanged.AddListener(delegate
|
|
|
|
{
|
|
|
|
inputField.text = slider.value.ToString("G4");
|
|
|
|
parameterManager.entity[propertyName] = (float)System.Math.Round(slider.value, 4);
|
|
|
|
});
|
|
|
|
|
|
|
|
inputField.onEndEdit.AddListener(delegate
|
|
|
|
{
|
|
|
|
slider.value = (float)System.Math.Round(System.Convert.ToSingle(inputField.text), 4);
|
|
|
|
parameterManager.entity[propertyName] = slider.value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (objType == typeof(EasingFunction.Ease))
|
2022-02-04 22:16:22 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|