2021-04-25 00:21:12 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
using System.Text;
|
2021-04-25 00:21:12 +10:00
|
|
|
|
using UnityEngine;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
using UnityExplorer.UI.ObjectPool;
|
2021-04-25 00:21:12 +10:00
|
|
|
|
using UnityExplorer.UI.Panels;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Inspectors
|
|
|
|
|
{
|
|
|
|
|
public static class InspectorManager
|
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public static readonly List<InspectorBase> Inspectors = new List<InspectorBase>();
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public static InspectorBase ActiveInspector { get; private set; }
|
|
|
|
|
|
|
|
|
|
public static void Inspect(object obj)
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
obj = obj.TryCast();
|
|
|
|
|
if (obj is GameObject)
|
|
|
|
|
CreateInspector<GameObjectInspector>(obj);
|
2021-04-25 21:20:50 +10:00
|
|
|
|
else
|
2021-04-26 19:56:21 +10:00
|
|
|
|
CreateInspector<InstanceInspector>(obj);
|
2021-04-25 21:20:50 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public static void Inspect(Type type)
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
CreateInspector<StaticInspector>(type);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public static void SetInspectorActive(InspectorBase inspector)
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
UnsetActiveInspector();
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
ActiveInspector = inspector;
|
|
|
|
|
inspector.OnSetActive();
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public static void UnsetActiveInspector()
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
if (ActiveInspector != null)
|
|
|
|
|
ActiveInspector.OnSetInactive();
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
private static void CreateInspector<T>(object target) where T : InspectorBase
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
var inspector = Pool<T>.Borrow();
|
|
|
|
|
Inspectors.Add(inspector);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
inspector.UIRoot.transform.SetParent(InspectorPanel.Instance.ContentHolder.transform, false);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
inspector.OnBorrowedFromPool(target);
|
|
|
|
|
SetInspectorActive(inspector);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
UIManager.SetPanelActive(UIManager.Panels.Inspector, true);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
internal static void ReleaseInspector<T>(T inspector) where T : InspectorBase
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
inspector.OnReturnToPool();
|
|
|
|
|
Pool<T>.Return(inspector);
|
|
|
|
|
|
|
|
|
|
Inspectors.Remove(inspector);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
internal static void Update()
|
2021-04-25 00:21:12 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
foreach (var inspector in Inspectors)
|
|
|
|
|
{
|
|
|
|
|
inspector.Update();
|
|
|
|
|
}
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void OnPanelResized()
|
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-25 00:21:12 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|