2020-11-16 00:50:06 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.Core.Unity;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
using UnityExplorer.UI;
|
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 InteractiveBool : InteractiveValue
|
|
|
|
|
{
|
2020-11-16 01:32:58 +11:00
|
|
|
|
public InteractiveBool(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;
|
|
|
|
|
|
|
|
|
|
internal Toggle m_toggle;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
internal Button m_applyBtn;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
|
|
|
|
public override void OnValueUpdated()
|
|
|
|
|
{
|
|
|
|
|
base.OnValueUpdated();
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void RefreshUIForValue()
|
|
|
|
|
{
|
|
|
|
|
GetDefaultLabel();
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (Owner.HasEvaluated)
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
var val = (bool)Value;
|
|
|
|
|
|
|
|
|
|
if (Owner.CanWrite)
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
|
|
|
|
if (!m_toggle.gameObject.activeSelf)
|
|
|
|
|
m_toggle.gameObject.SetActive(true);
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (!m_applyBtn.gameObject.activeSelf)
|
|
|
|
|
m_applyBtn.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
|
|
if (val != m_toggle.isOn)
|
2020-11-16 00:50:06 +11:00
|
|
|
|
m_toggle.isOn = val;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
var color = val
|
|
|
|
|
? "6bc981" // on
|
|
|
|
|
: "c96b6b"; // off
|
|
|
|
|
|
|
|
|
|
m_baseLabel.text = $"<color=#{color}>{val}</color>";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_baseLabel.text = DefaultLabel;
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void OnException(CacheMember member)
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
base.OnException(member);
|
|
|
|
|
|
|
|
|
|
if (Owner.CanWrite)
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (m_toggle.gameObject.activeSelf)
|
|
|
|
|
m_toggle.gameObject.SetActive(false);
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
if (m_applyBtn.gameObject.activeSelf)
|
|
|
|
|
m_applyBtn.gameObject.SetActive(false);
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void OnToggleValueChanged(bool val)
|
|
|
|
|
{
|
|
|
|
|
Value = val;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
RefreshUIForValue();
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
|
|
|
|
{
|
|
|
|
|
base.ConstructUI(parent, subGroup);
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
var baseLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
|
|
|
|
|
baseLayout.flexibleWidth = 0;
|
|
|
|
|
baseLayout.minWidth = 50;
|
|
|
|
|
|
|
|
|
|
if (Owner.CanWrite)
|
2020-11-16 00:50:06 +11:00
|
|
|
|
{
|
2021-03-30 19:50:04 +11:00
|
|
|
|
var toggleObj = UIFactory.CreateToggle(m_valueContent, "InteractiveBoolToggle", out m_toggle, out _, new Color(0.1f, 0.1f, 0.1f));
|
|
|
|
|
UIFactory.SetLayoutElement(toggleObj, minWidth: 24);
|
2020-11-16 00:50:06 +11:00
|
|
|
|
m_toggle.onValueChanged.AddListener(OnToggleValueChanged);
|
|
|
|
|
|
|
|
|
|
m_baseLabel.transform.SetAsLastSibling();
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
m_applyBtn = UIFactory.CreateButton(m_valueContent,
|
|
|
|
|
"ApplyButton",
|
|
|
|
|
"Apply",
|
|
|
|
|
() => { Owner.SetValue(); },
|
|
|
|
|
new Color(0.2f, 0.2f, 0.2f));
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
toggleObj.SetActive(false);
|
2021-03-30 19:50:04 +11:00
|
|
|
|
m_applyBtn.gameObject.SetActive(false);
|
2020-11-16 00:50:06 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|