2022-02-03 22:20:26 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
2022-02-20 13:31:55 +00:00
|
|
|
using System;
|
2022-08-19 01:28:05 +00:00
|
|
|
using System.Linq;
|
2022-02-03 22:20:26 +00:00
|
|
|
using TMPro;
|
2022-02-08 01:07:03 +00:00
|
|
|
using Starpelly;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-02-04 22:16:22 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Editor
|
2022-02-03 22:20:26 +00:00
|
|
|
{
|
|
|
|
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-03-01 07:27:49 +00:00
|
|
|
[Header("Boolean")]
|
|
|
|
[Space(10)]
|
|
|
|
public Toggle toggle;
|
|
|
|
|
2022-02-04 22:16:22 +00:00
|
|
|
[Header("Dropdown")]
|
|
|
|
[Space(10)]
|
|
|
|
public TMP_Dropdown dropdown;
|
|
|
|
|
2022-02-08 01:07:03 +00:00
|
|
|
[Header("Color")]
|
|
|
|
[Space(10)]
|
|
|
|
public Button ColorBTN;
|
|
|
|
public RectTransform ColorTable;
|
|
|
|
public bool colorTableActive;
|
|
|
|
public ColorPreview colorPreview;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2022-06-04 03:15:05 +00:00
|
|
|
[Header("String")] //why wasn't this a thing before
|
|
|
|
[Space(10)]
|
|
|
|
public TMP_InputField inputFieldString;
|
|
|
|
|
2022-02-08 01:07:03 +00:00
|
|
|
private string propertyName;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
|
|
|
public void SetProperties(string propertyName, object type, string caption)
|
|
|
|
{
|
|
|
|
this.propertyName = propertyName;
|
|
|
|
this.caption.text = caption;
|
|
|
|
|
2022-08-19 01:28:05 +00:00
|
|
|
switch (type)
|
2022-02-04 22:16:22 +00:00
|
|
|
{
|
2022-08-19 01:28:05 +00:00
|
|
|
case EntityTypes.Integer integer:
|
|
|
|
slider.minValue = integer.min;
|
|
|
|
slider.maxValue = integer.max;
|
2022-02-04 03:25:18 +00:00
|
|
|
|
2022-08-19 01:28:05 +00:00
|
|
|
slider.wholeNumbers = true;
|
|
|
|
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
2022-02-04 22:16:22 +00:00
|
|
|
inputField.text = slider.value.ToString();
|
2022-03-01 07:27:49 +00:00
|
|
|
|
2022-08-19 01:28:05 +00:00
|
|
|
slider.onValueChanged.AddListener(
|
|
|
|
_ =>
|
|
|
|
{
|
|
|
|
inputField.text = slider.value.ToString();
|
|
|
|
parameterManager.entity[propertyName] = (int) slider.value;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
inputField.onSelect.AddListener(
|
|
|
|
_ =>
|
|
|
|
Editor.instance.editingInputField = true
|
|
|
|
);
|
|
|
|
|
|
|
|
inputField.onEndEdit.AddListener(
|
|
|
|
_ =>
|
|
|
|
{
|
|
|
|
slider.value = Convert.ToSingle(inputField.text);
|
|
|
|
parameterManager.entity[propertyName] = (int) slider.value;
|
|
|
|
Editor.instance.editingInputField = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EntityTypes.Float fl:
|
|
|
|
slider.minValue = fl.min;
|
|
|
|
slider.maxValue = fl.max;
|
|
|
|
|
|
|
|
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
|
|
|
inputField.text = slider.value.ToString("G");
|
|
|
|
|
|
|
|
slider.onValueChanged.AddListener(
|
|
|
|
_ =>
|
|
|
|
{
|
|
|
|
var newValue = (float) Math.Round(slider.value, 4);
|
|
|
|
inputField.text = newValue.ToString("G");
|
|
|
|
parameterManager.entity[propertyName] = newValue;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
inputField.onSelect.AddListener(
|
|
|
|
_ =>
|
|
|
|
Editor.instance.editingInputField = true
|
|
|
|
);
|
|
|
|
|
|
|
|
inputField.onEndEdit.AddListener(
|
|
|
|
_ =>
|
|
|
|
{
|
|
|
|
slider.value = (float) Math.Round(Convert.ToSingle(inputField.text), 4);
|
|
|
|
parameterManager.entity[propertyName] = slider.value;
|
|
|
|
Editor.instance.editingInputField = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case bool _:
|
|
|
|
// ' (bool)type ' always results in false
|
|
|
|
toggle.isOn = Convert.ToBoolean(parameterManager.entity[propertyName]);
|
|
|
|
|
|
|
|
toggle.onValueChanged.AddListener(
|
|
|
|
_ => parameterManager.entity[propertyName] = toggle.isOn
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2022-08-22 01:57:32 +00:00
|
|
|
// case EntityTypes.SerializableColor _:
|
2022-08-22 00:50:19 +00:00
|
|
|
case Color _:
|
2022-08-19 01:28:05 +00:00
|
|
|
colorPreview.colorPicker.onColorChanged += _ =>
|
2022-08-22 01:57:32 +00:00
|
|
|
parameterManager.entity[propertyName] = colorPreview.colorPicker.color;
|
2022-08-19 01:28:05 +00:00
|
|
|
|
2022-08-21 23:46:45 +00:00
|
|
|
Color paramCol = parameterManager.entity[propertyName];
|
2022-08-19 01:28:05 +00:00
|
|
|
|
|
|
|
ColorBTN.onClick.AddListener(
|
|
|
|
() =>
|
|
|
|
{
|
|
|
|
ColorTable.gameObject.SetActive(true);
|
|
|
|
colorTableActive = true;
|
|
|
|
colorPreview.ChangeColor(paramCol);
|
|
|
|
}
|
|
|
|
);
|
2022-03-01 17:40:59 +00:00
|
|
|
|
2022-02-08 01:07:03 +00:00
|
|
|
colorPreview.ChangeColor(paramCol);
|
2022-08-19 01:28:05 +00:00
|
|
|
ColorTable.gameObject.SetActive(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case string _:
|
|
|
|
inputFieldString.text = (string) parameterManager.entity[propertyName];
|
|
|
|
|
|
|
|
inputFieldString.onSelect.AddListener(
|
|
|
|
_ =>
|
|
|
|
Editor.instance.editingInputField = true
|
|
|
|
);
|
|
|
|
inputFieldString.onEndEdit.AddListener(
|
|
|
|
_ =>
|
|
|
|
{;
|
|
|
|
parameterManager.entity[propertyName] = inputFieldString.text;
|
|
|
|
Editor.instance.editingInputField = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum enumKind:
|
|
|
|
var enumType = enumKind.GetType();
|
|
|
|
var enumVals = Enum.GetValues(enumType);
|
|
|
|
var enumNames = Enum.GetNames(enumType).ToList();
|
|
|
|
|
|
|
|
// Can we assume non-holey enum?
|
|
|
|
// If we can we can simplify to dropdown.value = (int) parameterManager.entity[propertyName]
|
|
|
|
var currentlySelected = (int) parameterManager.entity[propertyName];
|
|
|
|
var selected = enumVals
|
|
|
|
.Cast<object>()
|
|
|
|
.ToList()
|
|
|
|
.FindIndex(val => (int) val == currentlySelected);
|
|
|
|
|
|
|
|
dropdown.AddOptions(enumNames);
|
|
|
|
dropdown.value = selected;
|
|
|
|
|
|
|
|
dropdown.onValueChanged.AddListener(_ =>
|
2022-08-21 21:40:40 +00:00
|
|
|
parameterManager.entity[propertyName] = (int) enumVals.GetValue(dropdown.value)
|
2022-08-19 01:28:05 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(
|
|
|
|
nameof(type), type, "I don't know how to make a property of this type!"
|
|
|
|
);
|
2022-06-04 03:15:05 +00:00
|
|
|
}
|
2022-02-08 01:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (colorTableActive)
|
|
|
|
{
|
|
|
|
if (!Editor.MouseInRectTransform(ColorTable))
|
|
|
|
{
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
{
|
|
|
|
ColorTable.gameObject.SetActive(false);
|
|
|
|
colorTableActive = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-03 22:20:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|