mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-10 03:35:10 +00:00
split event properties into own scripts
This commit is contained in:
parent
d74dd315d2
commit
c6d60d6d20
14 changed files with 409 additions and 256 deletions
|
@ -4799,20 +4799,13 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 184838087}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3b7c76a246115c1459c963e93f7db056, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 8ada001011e54c74b87c04d7186d5f3c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 44496736}
|
||||
parameterManager: {fileID: 830452354}
|
||||
slider: {fileID: 0}
|
||||
inputField: {fileID: 0}
|
||||
toggle: {fileID: 0}
|
||||
parameterManager: {fileID: 0}
|
||||
propertyName:
|
||||
dropdown: {fileID: 9172948791891367920}
|
||||
ColorBTN: {fileID: 0}
|
||||
ColorTable: {fileID: 0}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 0}
|
||||
inputFieldString: {fileID: 0}
|
||||
--- !u!1 &189878587
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -7942,20 +7935,14 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 345301789}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3b7c76a246115c1459c963e93f7db056, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 6e9ad350a96f5644dbb1e4686a6bcaed, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 1882704219}
|
||||
parameterManager: {fileID: 830452354}
|
||||
parameterManager: {fileID: 0}
|
||||
propertyName:
|
||||
slider: {fileID: 749529046}
|
||||
inputField: {fileID: 735918245}
|
||||
toggle: {fileID: 0}
|
||||
dropdown: {fileID: 0}
|
||||
ColorBTN: {fileID: 0}
|
||||
ColorTable: {fileID: 0}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 0}
|
||||
inputFieldString: {fileID: 0}
|
||||
--- !u!224 &345301791
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -8251,15 +8238,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 419538178}
|
||||
parameterManager: {fileID: 830452354}
|
||||
slider: {fileID: 0}
|
||||
inputField: {fileID: 606981307}
|
||||
toggle: {fileID: 0}
|
||||
dropdown: {fileID: 0}
|
||||
ColorBTN: {fileID: 0}
|
||||
ColorTable: {fileID: 0}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 0}
|
||||
inputFieldString: {fileID: 0}
|
||||
propertyName:
|
||||
--- !u!1 &365690205
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -8604,20 +8583,14 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 396879232}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3b7c76a246115c1459c963e93f7db056, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 6e9ad350a96f5644dbb1e4686a6bcaed, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 5490985}
|
||||
parameterManager: {fileID: 830452354}
|
||||
parameterManager: {fileID: 0}
|
||||
propertyName:
|
||||
slider: {fileID: 2067224779}
|
||||
inputField: {fileID: 1182082595}
|
||||
toggle: {fileID: 0}
|
||||
dropdown: {fileID: 0}
|
||||
ColorBTN: {fileID: 0}
|
||||
ColorTable: {fileID: 0}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 0}
|
||||
inputFieldString: {fileID: 0}
|
||||
--- !u!1 &407289014
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -9586,15 +9559,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 0}
|
||||
parameterManager: {fileID: 830452354}
|
||||
slider: {fileID: 390818399}
|
||||
inputField: {fileID: 2031558985}
|
||||
toggle: {fileID: 0}
|
||||
dropdown: {fileID: 0}
|
||||
ColorBTN: {fileID: 0}
|
||||
ColorTable: {fileID: 0}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 0}
|
||||
inputFieldString: {fileID: 0}
|
||||
propertyName:
|
||||
--- !u!1 &435201908
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -17147,20 +17112,13 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 755586977}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3b7c76a246115c1459c963e93f7db056, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 9aa690f14ccbf9e4bb6bd339d500c3e7, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 774969486}
|
||||
parameterManager: {fileID: 830452354}
|
||||
slider: {fileID: 0}
|
||||
inputField: {fileID: 0}
|
||||
parameterManager: {fileID: 0}
|
||||
propertyName:
|
||||
toggle: {fileID: 279538359}
|
||||
dropdown: {fileID: 0}
|
||||
ColorBTN: {fileID: 0}
|
||||
ColorTable: {fileID: 0}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 0}
|
||||
inputFieldString: {fileID: 0}
|
||||
--- !u!1 &767779042
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -31745,20 +31703,16 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 1443721746}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3b7c76a246115c1459c963e93f7db056, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: c1c576a0586b70d4395de537078023d5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 537615369}
|
||||
parameterManager: {fileID: 830452354}
|
||||
slider: {fileID: 0}
|
||||
inputField: {fileID: 0}
|
||||
toggle: {fileID: 0}
|
||||
dropdown: {fileID: 0}
|
||||
parameterManager: {fileID: 0}
|
||||
propertyName:
|
||||
ColorBTN: {fileID: 1535224918}
|
||||
ColorTable: {fileID: 723094753}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 1535224921}
|
||||
inputFieldString: {fileID: 0}
|
||||
--- !u!1 &1453521077
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -36133,19 +36087,12 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 1671827686}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3b7c76a246115c1459c963e93f7db056, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: c01fcc0bb14adee46a4869c1c009850e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
caption: {fileID: 1478022678}
|
||||
parameterManager: {fileID: 830452354}
|
||||
slider: {fileID: 0}
|
||||
inputField: {fileID: 0}
|
||||
toggle: {fileID: 0}
|
||||
dropdown: {fileID: 0}
|
||||
ColorBTN: {fileID: 0}
|
||||
ColorTable: {fileID: 0}
|
||||
colorTableActive: 0
|
||||
colorPreview: {fileID: 0}
|
||||
parameterManager: {fileID: 0}
|
||||
propertyName:
|
||||
inputFieldString: {fileID: 1776034728}
|
||||
--- !u!1 &1682022763
|
||||
GameObject:
|
||||
|
|
|
@ -99,46 +99,70 @@ namespace HeavenStudio.Editor
|
|||
private void AddParam(string propertyName, object type, string caption, string tooltip = "")
|
||||
{
|
||||
GameObject prefab = IntegerP;
|
||||
GameObject input;
|
||||
|
||||
var objType = type.GetType();
|
||||
|
||||
if (objType == typeof(EntityTypes.Integer))
|
||||
{
|
||||
prefab = IntegerP;
|
||||
input = InitPrefab(prefab, tooltip);
|
||||
var property = input.GetComponent<NumberPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
}
|
||||
else if (objType == typeof(EntityTypes.Float))
|
||||
{
|
||||
prefab = FloatP;
|
||||
input = InitPrefab(prefab, tooltip);
|
||||
var property = input.GetComponent<NumberPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
}
|
||||
else if(type is bool)
|
||||
{
|
||||
prefab = BooleanP;
|
||||
input = InitPrefab(prefab, tooltip);
|
||||
var property = input.GetComponent<BoolPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
}
|
||||
else if (objType.IsEnum)
|
||||
{
|
||||
prefab = DropdownP;
|
||||
input = InitPrefab(prefab, tooltip);
|
||||
var property = input.GetComponent<EnumPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
}
|
||||
else if (objType == typeof(Color))
|
||||
{
|
||||
prefab = ColorP;
|
||||
input = InitPrefab(prefab, tooltip);
|
||||
var property = input.GetComponent<ColorPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
}
|
||||
else if(objType == typeof(string))
|
||||
{
|
||||
prefab = StringP;
|
||||
input = InitPrefab(prefab, tooltip);
|
||||
var property = input.GetComponent<StringPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Can't make property interface of type: " + type.GetType());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject InitPrefab(GameObject prefab, string tooltip = "")
|
||||
{
|
||||
GameObject input = Instantiate(prefab);
|
||||
input.transform.SetParent(this.gameObject.transform);
|
||||
input.SetActive(true);
|
||||
input.transform.localScale = Vector2.one;
|
||||
|
||||
if(tooltip != "")
|
||||
{
|
||||
if(tooltip != string.Empty)
|
||||
Tooltip.AddTooltip(input, "", tooltip);
|
||||
}
|
||||
|
||||
var property = input.GetComponent<EventPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
return input;
|
||||
}
|
||||
|
||||
private void DestroyParams()
|
||||
|
|
|
@ -14,189 +14,16 @@ namespace HeavenStudio.Editor
|
|||
public class EventPropertyPrefab : MonoBehaviour
|
||||
{
|
||||
public TMP_Text caption;
|
||||
[SerializeField] private EventParameterManager parameterManager;
|
||||
public EventParameterManager parameterManager;
|
||||
public string propertyName;
|
||||
|
||||
[Header("Integer and Float")]
|
||||
[Space(10)]
|
||||
public Slider slider;
|
||||
public TMP_InputField inputField;
|
||||
public void SetProperties(string propertyName, object type, string caption) {}
|
||||
|
||||
[Header("Boolean")]
|
||||
[Space(10)]
|
||||
public Toggle toggle;
|
||||
|
||||
[Header("Dropdown")]
|
||||
[Space(10)]
|
||||
public TMP_Dropdown dropdown;
|
||||
|
||||
[Header("Color")]
|
||||
[Space(10)]
|
||||
public Button ColorBTN;
|
||||
public RectTransform ColorTable;
|
||||
public bool colorTableActive;
|
||||
public ColorPreview colorPreview;
|
||||
|
||||
[Header("String")] //why wasn't this a thing before
|
||||
[Space(10)]
|
||||
public TMP_InputField inputFieldString;
|
||||
|
||||
private string propertyName;
|
||||
|
||||
public void SetProperties(string propertyName, object type, string caption)
|
||||
public void InitProperties(string propertyName, string caption)
|
||||
{
|
||||
this.parameterManager = EventParameterManager.instance;
|
||||
this.propertyName = propertyName;
|
||||
this.caption.text = caption;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EntityTypes.Integer integer:
|
||||
slider.minValue = integer.min;
|
||||
slider.maxValue = integer.max;
|
||||
|
||||
slider.wholeNumbers = true;
|
||||
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
||||
inputField.text = slider.value.ToString();
|
||||
|
||||
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;
|
||||
|
||||
// case EntityTypes.SerializableColor _:
|
||||
case Color _:
|
||||
colorPreview.colorPicker.onColorChanged += _ =>
|
||||
parameterManager.entity[propertyName] = colorPreview.colorPicker.color;
|
||||
|
||||
Color paramCol = parameterManager.entity[propertyName];
|
||||
|
||||
ColorBTN.onClick.AddListener(
|
||||
() =>
|
||||
{
|
||||
ColorTable.gameObject.SetActive(true);
|
||||
colorTableActive = true;
|
||||
colorPreview.ChangeColor(paramCol);
|
||||
}
|
||||
);
|
||||
|
||||
colorPreview.ChangeColor(paramCol);
|
||||
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(_ =>
|
||||
parameterManager.entity[propertyName] = (int) enumVals.GetValue(dropdown.value)
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(type), type, "I don't know how to make a property of this type!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (colorTableActive)
|
||||
{
|
||||
if (!Editor.MouseInRectTransform(ColorTable))
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
ColorTable.gameObject.SetActive(false);
|
||||
colorTableActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b86ddd3d47bb04e48a61db47242e02ed
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,37 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
using HeavenStudio.Util;
|
||||
using HeavenStudio.Editor;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
public class BoolPropertyPrefab : EventPropertyPrefab
|
||||
{
|
||||
[Header("Boolean")]
|
||||
[Space(10)]
|
||||
public Toggle toggle;
|
||||
|
||||
new public void SetProperties(string propertyName, object type, string caption)
|
||||
{
|
||||
InitProperties(propertyName, caption);
|
||||
|
||||
// ' (bool)type ' always results in false
|
||||
toggle.isOn = Convert.ToBoolean(parameterManager.entity[propertyName]);
|
||||
|
||||
toggle.onValueChanged.AddListener(
|
||||
_ => parameterManager.entity[propertyName] = toggle.isOn
|
||||
);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9aa690f14ccbf9e4bb6bd339d500c3e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,61 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
using HeavenStudio.Util;
|
||||
using HeavenStudio.Editor;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
public class ColorPropertyPrefab : EventPropertyPrefab
|
||||
{
|
||||
[Header("Color")]
|
||||
[Space(10)]
|
||||
public Button ColorBTN;
|
||||
public RectTransform ColorTable;
|
||||
public bool colorTableActive;
|
||||
public ColorPreview colorPreview;
|
||||
|
||||
new public void SetProperties(string propertyName, object type, string caption)
|
||||
{
|
||||
InitProperties(propertyName, caption);
|
||||
|
||||
colorPreview.colorPicker.onColorChanged += _ =>
|
||||
parameterManager.entity[propertyName] = colorPreview.colorPicker.color;
|
||||
|
||||
Color paramCol = parameterManager.entity[propertyName];
|
||||
|
||||
ColorBTN.onClick.AddListener(
|
||||
() =>
|
||||
{
|
||||
ColorTable.gameObject.SetActive(true);
|
||||
colorTableActive = true;
|
||||
colorPreview.ChangeColor(paramCol);
|
||||
}
|
||||
);
|
||||
|
||||
colorPreview.ChangeColor(paramCol);
|
||||
ColorTable.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (colorTableActive)
|
||||
{
|
||||
if (!Editor.MouseInRectTransform(ColorTable))
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
ColorTable.gameObject.SetActive(false);
|
||||
colorTableActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1c576a0586b70d4395de537078023d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,49 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
using HeavenStudio.Util;
|
||||
using HeavenStudio.Editor;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
public class EnumPropertyPrefab : EventPropertyPrefab
|
||||
{
|
||||
[Header("Dropdown")]
|
||||
[Space(10)]
|
||||
public TMP_Dropdown dropdown;
|
||||
|
||||
new public void SetProperties(string propertyName, object type, string caption)
|
||||
{
|
||||
InitProperties(propertyName, caption);
|
||||
|
||||
var enumType = type.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(_ =>
|
||||
parameterManager.entity[propertyName] = (int) enumVals.GetValue(dropdown.value)
|
||||
);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ada001011e54c74b87c04d7186d5f3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,101 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
using HeavenStudio.Util;
|
||||
using HeavenStudio.Editor;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
public class NumberPropertyPrefab : EventPropertyPrefab
|
||||
{
|
||||
[Header("Integer and Float")]
|
||||
[Space(10)]
|
||||
public Slider slider;
|
||||
public TMP_InputField inputField;
|
||||
|
||||
new public void SetProperties(string propertyName, object type, string caption)
|
||||
{
|
||||
InitProperties(propertyName, caption);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EntityTypes.Integer integer:
|
||||
slider.minValue = integer.min;
|
||||
slider.maxValue = integer.max;
|
||||
|
||||
slider.wholeNumbers = true;
|
||||
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
||||
inputField.text = slider.value.ToString();
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(type), type, "I don't know how to make a property of this type!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e9ad350a96f5644dbb1e4686a6bcaed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,44 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
using HeavenStudio.Util;
|
||||
using HeavenStudio.Editor;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
public class StringPropertyPrefab : EventPropertyPrefab
|
||||
{
|
||||
[Header("String")] //why wasn't this a thing before
|
||||
[Space(10)]
|
||||
public TMP_InputField inputFieldString;
|
||||
|
||||
new public void SetProperties(string propertyName, object type, string caption)
|
||||
{
|
||||
InitProperties(propertyName, caption);
|
||||
|
||||
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;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c01fcc0bb14adee46a4869c1c009850e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue