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
|
|
@ -1754,6 +1754,7 @@
|
|||
<e p="UI" t="Include">
|
||||
<e p="AttributeProperty.cs" t="Include" />
|
||||
<e p="BackgroundRenderer.cs" t="Include" />
|
||||
<e p="BoolField.cs" t="Include" />
|
||||
<e p="ClickableCollider.cs" t="Include" />
|
||||
<e p="ClickCatcher.cs" t="Include" />
|
||||
<e p="ClickRaycaster.cs" t="Include" />
|
||||
|
|
@ -1761,15 +1762,18 @@
|
|||
<e p="ContextMenuOption.cs" t="Include" />
|
||||
<e p="CorporationMenuItem.cs" t="Include" />
|
||||
<e p="DragHandler.cs" t="Include" />
|
||||
<e p="EnumField.cs" t="Include" />
|
||||
<e p="FlatButton.cs" t="Include" />
|
||||
<e p="FlatFlatButton.cs" t="Include" />
|
||||
<e p="GalaxyZone.cs" t="Include" />
|
||||
<e p="Icons.cs" t="Include" />
|
||||
<e p="InputField.cs" t="Include" />
|
||||
<e p="LoginScreen.cs" t="Include" />
|
||||
<e p="MouseHover.cs" t="Include" />
|
||||
<e p="PropertiesList.cs" t="Include" />
|
||||
<e p="PropertiesPanel.cs" t="Include" />
|
||||
<e p="PropertyLabel.cs" t="Include" />
|
||||
<e p="RangedFloatField.cs" t="Include" />
|
||||
<e p="ReadOnlyPropertiesPanel.cs" t="Include" />
|
||||
<e p="TabActivator.cs" t="Include" />
|
||||
<e p="TabButton.cs" t="Include" />
|
||||
|
|
|
|||
|
|
@ -870,6 +870,7 @@
|
|||
<Compile Include="Assets\Scripts\TechTreeMsagl.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\AttributeProperty.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\BackgroundRenderer.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\BoolField.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ClickableCollider.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ClickCatcher.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ClickRaycaster.cs" />
|
||||
|
|
@ -877,15 +878,18 @@
|
|||
<Compile Include="Assets\Scripts\UI\ContextMenuOption.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\CorporationMenuItem.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\DragHandler.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\EnumField.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\FlatButton.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\FlatFlatButton.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\GalaxyZone.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\Icons.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\InputField.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\LoginScreen.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\MouseHover.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\PropertiesList.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\PropertiesPanel.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\PropertyLabel.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\RangedFloatField.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ReadOnlyPropertiesPanel.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\TabActivator.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\TabButton.cs" />
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -12,7 +12,7 @@ namespace UniRx.Examples
|
|||
// Open Sample12Scene. Set from canvas
|
||||
public Button MyButton;
|
||||
public Toggle MyToggle;
|
||||
public InputField MyInput;
|
||||
public UnityEngine.UI.InputField MyInput;
|
||||
public Text MyText;
|
||||
public Slider MySlider;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace UniRx.Examples
|
|||
{
|
||||
// Open Sample13Scene. Set from canvas
|
||||
public Text Title;
|
||||
public InputField ToDoInput;
|
||||
public UnityEngine.UI.InputField ToDoInput;
|
||||
public Button AddButton;
|
||||
public Button ClearButton;
|
||||
public GameObject TodoList;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace UniRx
|
|||
}
|
||||
|
||||
/// <summary>Observe onEndEdit(Submit) event.</summary>
|
||||
public static IObservable<string> OnEndEditAsObservable(this InputField inputField)
|
||||
public static IObservable<string> OnEndEditAsObservable(this UnityEngine.UI.InputField inputField)
|
||||
{
|
||||
return inputField.onEndEdit.AsObservable();
|
||||
}
|
||||
|
|
@ -86,9 +86,9 @@ namespace UniRx
|
|||
#if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
|
||||
[Obsolete("onValueChange has been renamed to onValueChanged")]
|
||||
#endif
|
||||
public static IObservable<string> OnValueChangeAsObservable(this InputField inputField)
|
||||
public static IObservable<string> OnValueChangeAsObservable(this UnityEngine.UI.InputField inputField)
|
||||
{
|
||||
return Observable.CreateWithState<string, InputField>(inputField, (i, observer) =>
|
||||
return Observable.CreateWithState<string, UnityEngine.UI.InputField>(inputField, (i, observer) =>
|
||||
{
|
||||
observer.OnNext(i.text);
|
||||
#if (UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
|
||||
|
|
@ -101,9 +101,9 @@ namespace UniRx
|
|||
|
||||
#if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
|
||||
/// <summary>Observe onValueChanged with current `text` value on subscribe.</summary>
|
||||
public static IObservable<string> OnValueChangedAsObservable(this InputField inputField)
|
||||
public static IObservable<string> OnValueChangedAsObservable(this UnityEngine.UI.InputField inputField)
|
||||
{
|
||||
return Observable.CreateWithState<string, InputField>(inputField, (i, observer) =>
|
||||
return Observable.CreateWithState<string, UnityEngine.UI.InputField>(inputField, (i, observer) =>
|
||||
{
|
||||
observer.OnNext(i.text);
|
||||
return i.onValueChanged.AsObservable().Subscribe(observer);
|
||||
|
|
|
|||
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