UnityExplorer/src/UI/CacheObject/IValues/InteractiveValue.cs

70 lines
2.0 KiB
C#
Raw Normal View History

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;
2021-05-05 21:27:09 +10:00
using UnityExplorer.UI.CacheObject;
2021-05-26 17:40:09 +10:00
using UnityExplorer.UI.Models;
2021-04-30 21:34:50 +10:00
2021-05-26 17:40:09 +10:00
namespace UnityExplorer.UI.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)
{
switch (state)
{
case ValueState.String:
return typeof(InteractiveString);
2021-05-08 06:16:43 +10:00
case ValueState.Enum:
return typeof(InteractiveEnum);
case ValueState.Collection:
return typeof(InteractiveList);
case ValueState.Dictionary:
return typeof(InteractiveDictionary);
case ValueState.ValueStruct:
return typeof(InteractiveValueStruct);
2021-05-08 06:16:43 +10:00
case ValueState.Color:
return typeof(InteractiveColor);
default: return null;
}
}
public GameObject UIRoot { get; set; }
public float DefaultHeight => -1f;
public virtual bool CanWrite => this.CurrentOwner.CanWrite;
public CacheObjectBase CurrentOwner => m_owner;
private CacheObjectBase m_owner;
public bool PendingValueWanted;
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?");
ReleaseFromOwner();
2021-04-30 21:34:50 +10:00
}
this.m_owner = owner;
}
public virtual void ReleaseFromOwner()
2021-04-30 21:34:50 +10:00
{
if (this.m_owner == null)
return;
this.m_owner = null;
}
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
}
}