2020-11-16 00:50:06 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
using System.Reflection;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
using UnityEngine;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.Helpers;
|
|
|
|
|
using UnityExplorer.UI;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Inspectors.Reflection
|
|
|
|
|
{
|
|
|
|
|
public class InteractiveNumber : InteractiveValue
|
|
|
|
|
{
|
2020-11-16 01:32:58 +11:00
|
|
|
|
public InteractiveNumber(object value, Type valueType) : base(value, valueType) { }
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
|
|
|
|
public override bool HasSubContent => false;
|
|
|
|
|
public override bool SubContentWanted => false;
|
|
|
|
|
public override bool WantInspectBtn => false;
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void OnValueUpdated()
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
base.OnValueUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnException(CacheMember member)
|
|
|
|
|
{
|
|
|
|
|
base.OnException(member);
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (m_valueInput.gameObject.activeSelf)
|
|
|
|
|
m_valueInput.gameObject.SetActive(false);
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (Owner.CanWrite)
|
|
|
|
|
{
|
|
|
|
|
if (m_applyBtn.gameObject.activeSelf)
|
|
|
|
|
m_applyBtn.gameObject.SetActive(false);
|
|
|
|
|
}
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void RefreshUIForValue()
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (!Owner.HasEvaluated)
|
|
|
|
|
{
|
|
|
|
|
GetDefaultLabel();
|
|
|
|
|
m_baseLabel.text = DefaultLabel;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_baseLabel.text = UISyntaxHighlight.ParseFullSyntax(FallbackType, false);
|
|
|
|
|
m_valueInput.text = Value.ToString();
|
|
|
|
|
|
|
|
|
|
if (Owner.CanWrite)
|
|
|
|
|
{
|
|
|
|
|
if (!m_applyBtn.gameObject.activeSelf)
|
|
|
|
|
m_applyBtn.gameObject.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_valueInput.gameObject.activeSelf)
|
|
|
|
|
m_valueInput.gameObject.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MethodInfo ParseMethod => m_parseMethod ?? (m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }));
|
|
|
|
|
private MethodInfo m_parseMethod;
|
|
|
|
|
|
|
|
|
|
internal void OnApplyClicked()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Value = ParseMethod.Invoke(null, new object[] { m_valueInput.text });
|
|
|
|
|
Owner.SetValue();
|
|
|
|
|
RefreshUIForValue();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning("Could not parse input! " + ReflectionHelpers.ExceptionToString(e, true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal InputField m_valueInput;
|
|
|
|
|
internal Button m_applyBtn;
|
|
|
|
|
|
|
|
|
|
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
|
|
|
|
{
|
|
|
|
|
base.ConstructUI(parent, subGroup);
|
|
|
|
|
|
|
|
|
|
var labelLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
|
|
|
|
|
labelLayout.minWidth = 50;
|
|
|
|
|
labelLayout.flexibleWidth = 0;
|
|
|
|
|
|
|
|
|
|
var inputObj = UIFactory.CreateInputField(m_valueContent);
|
|
|
|
|
var inputLayout = inputObj.AddComponent<LayoutElement>();
|
|
|
|
|
inputLayout.minWidth = 120;
|
|
|
|
|
inputLayout.minHeight = 25;
|
|
|
|
|
inputLayout.flexibleWidth = 0;
|
|
|
|
|
|
|
|
|
|
m_valueInput = inputObj.GetComponent<InputField>();
|
|
|
|
|
m_valueInput.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
if (this.FallbackType == typeof(float)
|
|
|
|
|
|| this.FallbackType == typeof(double)
|
|
|
|
|
|| this.FallbackType == typeof(decimal))
|
|
|
|
|
{
|
|
|
|
|
m_valueInput.characterValidation = InputField.CharacterValidation.Decimal;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_valueInput.characterValidation = InputField.CharacterValidation.Integer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Owner.CanWrite)
|
|
|
|
|
{
|
|
|
|
|
var applyBtnObj = UIFactory.CreateButton(m_valueContent, new Color(0.2f, 0.2f, 0.2f));
|
|
|
|
|
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
|
|
|
|
applyLayout.minWidth = 50;
|
|
|
|
|
applyLayout.minHeight = 25;
|
|
|
|
|
applyLayout.flexibleWidth = 0;
|
|
|
|
|
m_applyBtn = applyBtnObj.GetComponent<Button>();
|
|
|
|
|
m_applyBtn.onClick.AddListener(OnApplyClicked);
|
|
|
|
|
|
|
|
|
|
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
|
|
|
|
applyText.text = "Apply";
|
|
|
|
|
}
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|