2020-11-09 21:38:25 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityExplorer.UI;
|
|
|
|
|
using UnityExplorer.UI.Shared;
|
|
|
|
|
using UnityExplorer.Helpers;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
using UnityEngine.UI;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Inspectors.Reflection
|
|
|
|
|
{
|
2020-11-15 21:11:43 +11:00
|
|
|
|
public abstract class CacheObjectBase
|
2020-11-09 21:38:25 +11:00
|
|
|
|
{
|
|
|
|
|
public InteractiveValue IValue;
|
|
|
|
|
|
|
|
|
|
public virtual bool CanWrite => false;
|
|
|
|
|
public virtual bool HasParameters => false;
|
|
|
|
|
public virtual bool IsMember => false;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
public virtual bool HasEvaluated => true;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-15 21:11:43 +11:00
|
|
|
|
public abstract Type FallbackType { get; }
|
2020-11-14 19:51:16 +11:00
|
|
|
|
|
2020-11-15 21:11:43 +11:00
|
|
|
|
public abstract void CreateIValue(object value, Type fallbackType);
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
|
|
|
|
public virtual void Enable()
|
|
|
|
|
{
|
|
|
|
|
if (!m_constructedUI)
|
|
|
|
|
{
|
|
|
|
|
ConstructUI();
|
|
|
|
|
UpdateValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_mainContent.SetActive(true);
|
2020-11-14 19:51:16 +11:00
|
|
|
|
m_mainContent.transform.SetAsLastSibling();
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 20:16:43 +11:00
|
|
|
|
public virtual void Disable()
|
2020-11-09 21:38:25 +11:00
|
|
|
|
{
|
2020-11-15 21:11:43 +11:00
|
|
|
|
m_mainContent?.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Destroy()
|
|
|
|
|
{
|
|
|
|
|
GameObject.Destroy(this.m_mainContent);
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void UpdateValue()
|
|
|
|
|
{
|
2020-11-15 21:11:43 +11:00
|
|
|
|
var value = IValue.Value;
|
|
|
|
|
|
2020-11-16 01:32:58 +11:00
|
|
|
|
// if the type has changed fundamentally, make a new interactivevalue for it
|
2020-11-15 21:11:43 +11:00
|
|
|
|
var type = value == null
|
|
|
|
|
? FallbackType
|
|
|
|
|
: ReflectionHelpers.GetActualType(value);
|
2020-11-16 01:32:58 +11:00
|
|
|
|
|
2020-11-15 21:11:43 +11:00
|
|
|
|
var ivalueType = InteractiveValue.GetIValueForType(type);
|
|
|
|
|
|
2020-11-16 01:32:58 +11:00
|
|
|
|
if (ivalueType != IValue.GetType())
|
2020-11-15 21:11:43 +11:00
|
|
|
|
{
|
|
|
|
|
IValue.OnDestroy();
|
|
|
|
|
CreateIValue(value, FallbackType);
|
|
|
|
|
m_subContent.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 19:51:16 +11:00
|
|
|
|
IValue.OnValueUpdated();
|
2020-11-16 00:50:06 +11:00
|
|
|
|
|
|
|
|
|
IValue.RefreshElementsAfterUpdate();
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void SetValue() => throw new NotImplementedException();
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
|
|
|
|
#region UI CONSTRUCTION
|
|
|
|
|
|
|
|
|
|
internal bool m_constructedUI;
|
|
|
|
|
internal GameObject m_parentContent;
|
2020-11-15 21:11:43 +11:00
|
|
|
|
internal RectTransform m_mainRect;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
internal GameObject m_mainContent;
|
2020-11-15 21:11:43 +11:00
|
|
|
|
internal GameObject m_subContent;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
|
|
|
|
// Make base UI holder for CacheObject, this doesnt actually display anything.
|
|
|
|
|
internal virtual void ConstructUI()
|
|
|
|
|
{
|
|
|
|
|
m_constructedUI = true;
|
|
|
|
|
|
|
|
|
|
m_mainContent = UIFactory.CreateVerticalGroup(m_parentContent, new Color(0.1f, 0.1f, 0.1f));
|
2020-11-15 21:11:43 +11:00
|
|
|
|
m_mainContent.name = "CacheObjectBase.MainContent";
|
|
|
|
|
m_mainRect = m_mainContent.GetComponent<RectTransform>();
|
|
|
|
|
m_mainRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25);
|
|
|
|
|
var mainGroup = m_mainContent.GetComponent<VerticalLayoutGroup>();
|
|
|
|
|
mainGroup.childForceExpandWidth = true;
|
|
|
|
|
mainGroup.childControlWidth = true;
|
|
|
|
|
mainGroup.childForceExpandHeight = true;
|
|
|
|
|
mainGroup.childControlHeight = true;
|
|
|
|
|
var mainLayout = m_mainContent.AddComponent<LayoutElement>();
|
|
|
|
|
mainLayout.minHeight = 25;
|
|
|
|
|
mainLayout.flexibleHeight = 9999;
|
|
|
|
|
mainLayout.minWidth = 200;
|
|
|
|
|
mainLayout.flexibleWidth = 5000;
|
|
|
|
|
|
|
|
|
|
// subcontent
|
|
|
|
|
|
|
|
|
|
m_subContent = UIFactory.CreateVerticalGroup(m_mainContent, new Color(0.085f, 0.085f, 0.085f));
|
|
|
|
|
m_subContent.name = "CacheObjectBase.SubContent";
|
|
|
|
|
var subGroup = m_subContent.GetComponent<VerticalLayoutGroup>();
|
|
|
|
|
subGroup.childForceExpandWidth = true;
|
|
|
|
|
subGroup.childForceExpandHeight = false;
|
|
|
|
|
var subLayout = m_subContent.AddComponent<LayoutElement>();
|
|
|
|
|
subLayout.minHeight = 30;
|
|
|
|
|
subLayout.flexibleHeight = 9999;
|
|
|
|
|
subLayout.minWidth = 125;
|
|
|
|
|
subLayout.flexibleWidth = 9000;
|
|
|
|
|
|
|
|
|
|
m_subContent.SetActive(false);
|
|
|
|
|
|
|
|
|
|
IValue.m_subContentParent = m_subContent;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
}
|