2021-04-30 21:34:50 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.UI.Inspectors.CacheObject;
|
|
|
|
|
using UnityExplorer.UI.ObjectPool;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Inspectors.IValues
|
|
|
|
|
{
|
|
|
|
|
public class InteractiveValue : IPooledObject
|
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public GameObject UIRoot { get; set; }
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
|
|
|
|
public float DefaultHeight => -1f;
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public virtual bool CanWrite => this.CurrentOwner.CanWrite;
|
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public CacheObjectBase CurrentOwner { get; }
|
|
|
|
|
private CacheObjectBase m_owner;
|
|
|
|
|
|
|
|
|
|
public object EditedValue { get; private set; }
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public virtual void SetLayout() { }
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public static Type GetIValueTypeForState(ValueState state)
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
//case ValueState.String:
|
|
|
|
|
// return null;
|
|
|
|
|
//case ValueState.Enum:
|
|
|
|
|
// return null;
|
|
|
|
|
case ValueState.Collection:
|
|
|
|
|
return typeof(InteractiveList);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
case ValueState.Dictionary:
|
|
|
|
|
return typeof(InteractiveDictionary);
|
2021-05-01 20:55:27 +10:00
|
|
|
|
//case ValueState.ValueStruct:
|
|
|
|
|
// return null;
|
|
|
|
|
//case ValueState.Color:
|
|
|
|
|
// return null;
|
|
|
|
|
default: return typeof(InteractiveValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public virtual void OnBorrowed(CacheObjectBase owner)
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
|
|
|
|
if (this.m_owner != null)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning("Setting an IValue's owner but there is already one set. Maybe it wasn't cleaned up?");
|
2021-05-01 20:55:27 +10:00
|
|
|
|
ReleaseFromOwner();
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.m_owner = owner;
|
|
|
|
|
// ...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void SetValue(object value)
|
|
|
|
|
{
|
|
|
|
|
this.EditedValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public virtual void ReleaseFromOwner()
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
|
|
|
|
if (this.m_owner == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.m_owner = null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public virtual GameObject CreateContent(GameObject parent)
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
UIRoot = UIFactory.CreateUIObject(this.GetType().Name, parent);
|
2021-05-03 21:02:01 +10:00
|
|
|
|
UIRoot.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
|
|
|
|
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(UIRoot, true, true, true, true, 3, childAlignment: TextAnchor.MiddleLeft);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
UIFactory.CreateLabel(UIRoot, "Label", "this is an ivalue", TextAnchor.MiddleLeft);
|
2021-05-03 21:02:01 +10:00
|
|
|
|
UIFactory.CreateInputField(UIRoot, "InputFIeld", "...", out var input);
|
|
|
|
|
UIFactory.SetLayoutElement(input.gameObject, minHeight: 25, flexibleHeight: 500);
|
|
|
|
|
input.lineType = InputField.LineType.MultiLineNewline;
|
|
|
|
|
input.gameObject.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
return UIRoot;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|