2022-04-22 21:02:45 +10:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
using UnityEngine.UI;
|
2021-04-25 00:21:12 +10:00
|
|
|
|
using UnityExplorer.UI.Panels;
|
2022-04-22 21:02:45 +10:00
|
|
|
|
using UniverseLib;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.UI.ObjectPool;
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-06-30 07:49:58 +10:00
|
|
|
|
namespace UnityExplorer.Inspectors
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public abstract class InspectorBase : IPooledObject
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public bool IsActive { get; internal set; }
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public object Target { get; set; }
|
2022-04-22 21:02:45 +10:00
|
|
|
|
public Type TargetType { get; protected set; }
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
public InspectorTab Tab { get; internal set; }
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public GameObject UIRoot { get; set; }
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public float DefaultHeight => -1f;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
public abstract GameObject CreateContent(GameObject parent);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public abstract void Update();
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-05-16 21:46:19 +10:00
|
|
|
|
public abstract void CloseInspector();
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public virtual void OnBorrowedFromPool(object target)
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
this.Target = target;
|
2022-04-22 21:02:45 +10:00
|
|
|
|
this.TargetType = target is Type type ? type : target.GetActualType();
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
Tab = Pool<InspectorTab>.Borrow();
|
|
|
|
|
Tab.UIRoot.transform.SetParent(InspectorPanel.Instance.NavbarHolder.transform, false);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
Tab.TabButton.OnClick += OnTabButtonClicked;
|
2021-05-16 21:46:19 +10:00
|
|
|
|
Tab.CloseButton.OnClick += CloseInspector;
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public virtual void OnReturnToPool()
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
Pool<InspectorTab>.Return(Tab);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
this.Target = null;
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
Tab.TabButton.OnClick -= OnTabButtonClicked;
|
2021-05-16 21:46:19 +10:00
|
|
|
|
Tab.CloseButton.OnClick -= CloseInspector;
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public virtual void OnSetActive()
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-28 23:58:13 +10:00
|
|
|
|
Tab.SetTabColor(true);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
UIRoot.SetActive(true);
|
|
|
|
|
IsActive = true;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(UIRoot.GetComponent<RectTransform>());
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public virtual void OnSetInactive()
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-28 23:58:13 +10:00
|
|
|
|
Tab.SetTabColor(false);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
UIRoot.SetActive(false);
|
|
|
|
|
IsActive = false;
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
private void OnTabButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
InspectorManager.SetInspectorActive(this);
|
|
|
|
|
}
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
}
|