Input/Output Properties Panel
Added methods for properties that allow reading and writing
This commit is contained in:
parent
50a8059ed4
commit
87ebb18c0b
15 changed files with 2650 additions and 475 deletions
11
Assets/Scripts/UI/BoolField.cs
Normal file
11
Assets/Scripts/UI/BoolField.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BoolField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Toggle Toggle;
|
||||
}
|
||||
11
Assets/Scripts/UI/BoolField.cs.meta
Normal file
11
Assets/Scripts/UI/BoolField.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d340b5dca7aebb40925dc6fe985e731
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Scripts/UI/EnumField.cs
Normal file
10
Assets/Scripts/UI/EnumField.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnumField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public TMP_Dropdown Dropdown;
|
||||
}
|
||||
11
Assets/Scripts/UI/EnumField.cs.meta
Normal file
11
Assets/Scripts/UI/EnumField.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6693f0cab8ab72b49bdbc76515d0fc1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Scripts/UI/InputField.cs
Normal file
10
Assets/Scripts/UI/InputField.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class InputField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public TMP_InputField Field;
|
||||
}
|
||||
11
Assets/Scripts/UI/InputField.cs.meta
Normal file
11
Assets/Scripts/UI/InputField.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eaba78dd36b0e9e4ba8123c4b149fc43
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Scripts/UI/RangedFloatField.cs
Normal file
11
Assets/Scripts/UI/RangedFloatField.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RangedFloatField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Slider Slider;
|
||||
}
|
||||
11
Assets/Scripts/UI/RangedFloatField.cs.meta
Normal file
11
Assets/Scripts/UI/RangedFloatField.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f6e88386192c944b8c95e1a6251be66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -10,11 +12,17 @@ public class ReadOnlyPropertiesPanel : MonoBehaviour
|
|||
public RectTransform SectionPrefab;
|
||||
public PropertiesList ListPrefab;
|
||||
public PropertyLabel PropertyPrefab;
|
||||
public AttributeProperty AttributePrefab;
|
||||
public InputField InputField;
|
||||
public RangedFloatField RangedFloatField;
|
||||
public EnumField EnumField;
|
||||
public BoolField BoolField;
|
||||
public bool ChildRadioSelection;
|
||||
|
||||
protected List<GameObject> Properties = new List<GameObject>();
|
||||
protected List<FlatFlatButton> Buttons = new List<FlatFlatButton>();
|
||||
protected FlatFlatButton SelectedChild;
|
||||
protected event Action RefreshPropertyValues;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
|
@ -71,4 +79,92 @@ public class ReadOnlyPropertiesPanel : MonoBehaviour
|
|||
Properties.Add(list.gameObject);
|
||||
return list;
|
||||
}
|
||||
|
||||
public AttributeProperty AddAttribute(PersonalityAttribute attribute, float value)
|
||||
{
|
||||
var attributeInstance = Instantiate(AttributePrefab, transform);
|
||||
attributeInstance.Slider.value = value;
|
||||
attributeInstance.Title.text = attribute.Name;
|
||||
attributeInstance.HighLabel.text = attribute.HighName;
|
||||
attributeInstance.LowLabel.text = attribute.LowName;
|
||||
return attributeInstance;
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<string> read, Action<string> write)
|
||||
{
|
||||
var field = Instantiate(InputField, transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.Standard;
|
||||
field.Field.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Field.text = read();
|
||||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<float> read, Action<float> write)
|
||||
{
|
||||
var field = Instantiate(InputField, transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.DecimalNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(float.Parse(val)));
|
||||
RefreshPropertyValues += () => field.Field.text = read().ToString(CultureInfo.InvariantCulture);
|
||||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<int> read, Action<int> write)
|
||||
{
|
||||
var field = Instantiate(InputField, transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
|
||||
RefreshPropertyValues += () => field.Field.text = read().ToString(CultureInfo.InvariantCulture);
|
||||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<float> read, Action<float> write, float min, float max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = false;
|
||||
field.Slider.minValue = min;
|
||||
field.Slider.maxValue = max;
|
||||
field.Slider.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<int> read, Action<int> write, int min, int max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = true;
|
||||
field.Slider.minValue = min;
|
||||
field.Slider.maxValue = max;
|
||||
field.Slider.onValueChanged.AddListener(val => write(Mathf.RoundToInt(val)));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<bool> read, Action<bool> write)
|
||||
{
|
||||
var field = Instantiate(BoolField, transform);
|
||||
field.Label.text = name;
|
||||
field.Toggle.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Toggle.isOn = read();
|
||||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<int> read, Action<int> write, string[] enumOptions)
|
||||
{
|
||||
var field = Instantiate(EnumField, transform);
|
||||
field.Label.text = name;
|
||||
field.Dropdown.options = enumOptions.Select(s => new TMP_Dropdown.OptionData(s)).ToList();
|
||||
field.Dropdown.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Dropdown.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void RefreshValues()
|
||||
{
|
||||
RefreshPropertyValues?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue