UnityExplorer/src/CacheObject/IValues/InteractiveValue.cs

59 lines
1.7 KiB
C#
Raw Normal View History

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
namespace UnityExplorer.CacheObject.IValues
2021-04-30 21:34:50 +10:00
{
public abstract class InteractiveValue : IPooledObject
2021-04-30 21:34:50 +10:00
{
public static Type GetIValueTypeForState(ValueState state)
{
return state switch
{
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,
};
}
public GameObject UIRoot { get; set; }
public float DefaultHeight => -1f;
public virtual bool CanWrite => this.CurrentOwner.CanWrite;
public CacheObjectBase CurrentOwner => owner;
private CacheObjectBase owner;
public bool PendingValueWanted;
public virtual void OnBorrowed(CacheObjectBase owner)
2021-04-30 21:34:50 +10: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?");
ReleaseFromOwner();
2021-04-30 21:34:50 +10:00
}
this.owner = owner;
2021-04-30 21:34:50 +10:00
}
public virtual void ReleaseFromOwner()
2021-04-30 21:34:50 +10:00
{
if (this.owner == null)
2021-04-30 21:34:50 +10:00
return;
this.owner = null;
2021-04-30 21:34:50 +10:00
}
public abstract void SetValue(object value);
public virtual void SetLayout() { }
2021-04-30 21:34:50 +10:00
public abstract GameObject CreateContent(GameObject parent);
2021-04-30 21:34:50 +10:00
}
}