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;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.Core.Unity;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
using UnityExplorer.UI;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.Core;
|
|
|
|
|
using UnityExplorer.UI.Utility;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
using UnityExplorer.UI.CacheObject;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
namespace UnityExplorer.UI.InteractiveValues
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 17:17:29 +11:00
|
|
|
|
m_baseLabel.text = SignatureHighlighter.ParseFullSyntax(FallbackType, false);
|
2020-11-16 21:21:04 +11:00
|
|
|
|
m_valueInput.text = Value.ToString();
|
|
|
|
|
|
2020-11-17 02:51:20 +11:00
|
|
|
|
var type = Value.GetType();
|
|
|
|
|
if (type == typeof(float)
|
|
|
|
|
|| type == typeof(double)
|
|
|
|
|
|| type == typeof(decimal))
|
|
|
|
|
{
|
|
|
|
|
m_valueInput.characterValidation = InputField.CharacterValidation.Decimal;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_valueInput.characterValidation = InputField.CharacterValidation.Integer;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-03-18 17:17:29 +11:00
|
|
|
|
ExplorerCore.LogWarning("Could not parse input! " + ReflectionUtility.ReflectionExToString(e, true));
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-03-31 22:58:17 +11:00
|
|
|
|
var inputObj = UIFactory.CreateInputField(m_mainContent, "InteractiveNumberInput", "...");
|
2021-03-30 19:50:04 +11:00
|
|
|
|
UIFactory.SetLayoutElement(inputObj, minWidth: 120, minHeight: 25, flexibleWidth: 0);
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
|
|
|
|
m_valueInput = inputObj.GetComponent<InputField>();
|
|
|
|
|
m_valueInput.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
if (Owner.CanWrite)
|
|
|
|
|
{
|
2021-03-31 22:58:17 +11:00
|
|
|
|
m_applyBtn = UIFactory.CreateButton(m_mainContent, "ApplyButton", "Apply", OnApplyClicked, new Color(0.2f, 0.2f, 0.2f));
|
2021-03-30 19:50:04 +11:00
|
|
|
|
UIFactory.SetLayoutElement(m_applyBtn.gameObject, minWidth: 50, minHeight: 25, flexibleWidth: 0);
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|