mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
Fix TryFocusActiveInspector for classes
This commit is contained in:
parent
5e07847356
commit
cef8c12d20
@ -1,6 +1,8 @@
|
|||||||
using UnityEngine;
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityExplorer.UI.Panels;
|
using UnityExplorer.UI.Panels;
|
||||||
|
using UniverseLib;
|
||||||
using UniverseLib.UI.ObjectPool;
|
using UniverseLib.UI.ObjectPool;
|
||||||
|
|
||||||
namespace UnityExplorer.Inspectors
|
namespace UnityExplorer.Inspectors
|
||||||
@ -9,6 +11,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
{
|
{
|
||||||
public bool IsActive { get; internal set; }
|
public bool IsActive { get; internal set; }
|
||||||
public object Target { get; set; }
|
public object Target { get; set; }
|
||||||
|
public Type TargetType { get; protected set; }
|
||||||
|
|
||||||
public InspectorTab Tab { get; internal set; }
|
public InspectorTab Tab { get; internal set; }
|
||||||
|
|
||||||
@ -24,6 +27,8 @@ namespace UnityExplorer.Inspectors
|
|||||||
public virtual void OnBorrowedFromPool(object target)
|
public virtual void OnBorrowedFromPool(object target)
|
||||||
{
|
{
|
||||||
this.Target = target;
|
this.Target = target;
|
||||||
|
this.TargetType = target is Type type ? type : target.GetActualType();
|
||||||
|
|
||||||
Tab = Pool<InspectorTab>.Borrow();
|
Tab = Pool<InspectorTab>.Borrow();
|
||||||
Tab.UIRoot.transform.SetParent(InspectorPanel.Instance.NavbarHolder.transform, false);
|
Tab.UIRoot.transform.SetParent(InspectorPanel.Instance.NavbarHolder.transform, false);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace UnityExplorer
|
|||||||
|
|
||||||
public static event Action OnInspectedTabsChanged;
|
public static event Action OnInspectedTabsChanged;
|
||||||
|
|
||||||
public static void Inspect(object obj, CacheObjectBase sourceCache = null)
|
public static void Inspect(object obj, CacheObjectBase parent = null)
|
||||||
{
|
{
|
||||||
if (obj.IsNullOrDestroyed())
|
if (obj.IsNullOrDestroyed())
|
||||||
return;
|
return;
|
||||||
@ -36,19 +36,34 @@ namespace UnityExplorer
|
|||||||
if (obj is GameObject)
|
if (obj is GameObject)
|
||||||
CreateInspector<GameObjectInspector>(obj);
|
CreateInspector<GameObjectInspector>(obj);
|
||||||
else
|
else
|
||||||
CreateInspector<ReflectionInspector>(obj, false, sourceCache);
|
CreateInspector<ReflectionInspector>(obj, false, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Inspect(Type type)
|
public static void Inspect(Type type)
|
||||||
{
|
{
|
||||||
|
if (TryFocusActiveInspector(type))
|
||||||
|
return;
|
||||||
|
|
||||||
CreateInspector<ReflectionInspector>(type, true);
|
CreateInspector<ReflectionInspector>(type, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryFocusActiveInspector(object target)
|
static bool TryFocusActiveInspector(object target)
|
||||||
{
|
{
|
||||||
foreach (InspectorBase inspector in Inspectors)
|
foreach (InspectorBase inspector in Inspectors)
|
||||||
{
|
{
|
||||||
if (inspector.Target.ReferenceEqual(target))
|
bool shouldFocus = false;
|
||||||
|
|
||||||
|
if (target is Type targetAsType)
|
||||||
|
{
|
||||||
|
if (inspector.TargetType.FullName == targetAsType.FullName)
|
||||||
|
shouldFocus = true;
|
||||||
|
}
|
||||||
|
else if(inspector.Target.ReferenceEqual(target))
|
||||||
|
{
|
||||||
|
shouldFocus = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldFocus)
|
||||||
{
|
{
|
||||||
UIManager.SetPanelActive(UIManager.Panels.Inspector, true);
|
UIManager.SetPanelActive(UIManager.Panels.Inspector, true);
|
||||||
SetInspectorActive(inspector);
|
SetInspectorActive(inspector);
|
||||||
@ -76,7 +91,7 @@ namespace UnityExplorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void CloseAllTabs()
|
public static void CloseAllTabs()
|
||||||
{
|
{
|
||||||
if (Inspectors.Any())
|
if (Inspectors.Any())
|
||||||
{
|
{
|
||||||
@ -89,18 +104,17 @@ namespace UnityExplorer
|
|||||||
UIManager.SetPanelActive(UIManager.Panels.Inspector, false);
|
UIManager.SetPanelActive(UIManager.Panels.Inspector, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateInspector<T>(object target, bool staticReflection = false,
|
static void CreateInspector<T>(object target, bool staticReflection = false, CacheObjectBase parent = null) where T : InspectorBase
|
||||||
CacheObjectBase parentObject = null) where T : InspectorBase
|
|
||||||
{
|
{
|
||||||
T inspector = Pool<T>.Borrow();
|
T inspector = Pool<T>.Borrow();
|
||||||
Inspectors.Add(inspector);
|
Inspectors.Add(inspector);
|
||||||
inspector.Target = target;
|
inspector.Target = target;
|
||||||
|
|
||||||
if (parentObject != null && parentObject.CanWrite)
|
if (parent != null && parent.CanWrite)
|
||||||
{
|
{
|
||||||
// only set parent cache object if we are inspecting a struct, otherwise there is no point.
|
// only set parent cache object if we are inspecting a struct, otherwise there is no point.
|
||||||
if (target.GetType().IsValueType && inspector is ReflectionInspector ri)
|
if (target.GetType().IsValueType && inspector is ReflectionInspector ri)
|
||||||
ri.ParentCacheObject = parentObject;
|
ri.ParentCacheObject = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIManager.SetPanelActive(UIManager.Panels.Inspector, true);
|
UIManager.SetPanelActive(UIManager.Panels.Inspector, true);
|
||||||
@ -115,7 +129,7 @@ namespace UnityExplorer
|
|||||||
OnInspectedTabsChanged?.Invoke();
|
OnInspectedTabsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void ReleaseInspector<T>(T inspector) where T : InspectorBase
|
public static void ReleaseInspector<T>(T inspector) where T : InspectorBase
|
||||||
{
|
{
|
||||||
if (lastActiveInspector == inspector)
|
if (lastActiveInspector == inspector)
|
||||||
lastActiveInspector = null;
|
lastActiveInspector = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user