2021-04-30 21:34:50 +10:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.UI.ObjectPool;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-06-30 07:49:58 +10:00
|
|
|
|
namespace UnityExplorer.CacheObject.IValues
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
2021-05-07 17:06:56 +10:00
|
|
|
|
public abstract class InteractiveValue : IPooledObject
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public static Type GetIValueTypeForState(ValueState state)
|
|
|
|
|
{
|
2022-04-01 18:14:50 +11:00
|
|
|
|
return state switch
|
2021-05-01 20:55:27 +10:00
|
|
|
|
{
|
2022-04-01 18:14:50 +11:00
|
|
|
|
ValueState.Exception or ValueState.String => typeof(InteractiveString),
|
|
|
|
|
ValueState.Enum => typeof(InteractiveEnum),
|
|
|
|
|
ValueState.Collection => typeof(InteractiveList),
|
|
|
|
|
ValueState.Dictionary => typeof(InteractiveDictionary),
|
|
|
|
|
ValueState.ValueStruct => typeof(InteractiveValueStruct),
|
|
|
|
|
ValueState.Color => typeof(InteractiveColor),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
2021-05-01 20:55:27 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 17:06:56 +10:00
|
|
|
|
public GameObject UIRoot { get; set; }
|
|
|
|
|
public float DefaultHeight => -1f;
|
|
|
|
|
|
|
|
|
|
public virtual bool CanWrite => this.CurrentOwner.CanWrite;
|
|
|
|
|
|
2022-04-01 18:14:50 +11:00
|
|
|
|
public CacheObjectBase CurrentOwner => owner;
|
|
|
|
|
private CacheObjectBase owner;
|
2021-05-07 17:06:56 +10:00
|
|
|
|
|
2021-05-09 02:22:03 +10:00
|
|
|
|
public bool PendingValueWanted;
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public virtual void OnBorrowed(CacheObjectBase owner)
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
2022-04-01 18:14:50 +11:00
|
|
|
|
if (this.owner != null)
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 18:14:50 +11:00
|
|
|
|
this.owner = owner;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public virtual void ReleaseFromOwner()
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
2022-04-01 18:14:50 +11:00
|
|
|
|
if (this.owner == null)
|
2021-04-30 21:34:50 +10:00
|
|
|
|
return;
|
|
|
|
|
|
2022-04-01 18:14:50 +11:00
|
|
|
|
this.owner = null;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 17:06:56 +10:00
|
|
|
|
public abstract void SetValue(object value);
|
2021-05-06 20:28:04 +10:00
|
|
|
|
|
2021-05-07 17:06:56 +10:00
|
|
|
|
public virtual void SetLayout() { }
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-07 17:06:56 +10:00
|
|
|
|
public abstract GameObject CreateContent(GameObject parent);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
}
|