mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-20 23:12:38 +08:00
12ed06d43c
- Added collapse/expand button to groups in search results page - Added lazy scene search option: when enabled, unloaded scenes that have potential references are not loaded immediately; instead, they are searched on demand (via Refresh button)(faster search) - Search algorithm now prefers SerializedObjects when possible, uses reflection as fallback - Added "Search for References" to Hierarchy objects' right-click context menu - Searching for references of objects in prefab mode is now supported - A simple search progress bar is now always shown, but is not refreshed frequently unless "Show detailed progress bar" is enabled and thus, it won't affect the search performance noticably - Removed settings like "Search properties" and "Search depth", it doesn't make much sense to limit the search algorithm in an asset whose sole purpose is to find "all" references - Removed "Select All (GameObject-wise)" and "Select All (Component-wise)" buttons (use CTRL or Shift keys to enable multi-select while clicking search entries in results page) - Double clicking a prefab entry in search results page will now open that prefab in prefab mode
78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using UnityEngine;
|
|
|
|
namespace AssetUsageDetectorNamespace.Extras
|
|
{
|
|
// Delegate to get the value of a variable (either field or property)
|
|
public delegate object VariableGetVal( object obj );
|
|
|
|
// Custom struct to hold a variable, its important properties and its getter function
|
|
public struct VariableGetterHolder
|
|
{
|
|
public readonly string name;
|
|
public readonly bool isProperty;
|
|
public readonly bool isSerializable;
|
|
private readonly VariableGetVal getter;
|
|
|
|
public VariableGetterHolder( FieldInfo fieldInfo, VariableGetVal getter, bool isSerializable )
|
|
{
|
|
name = fieldInfo.Name;
|
|
isProperty = false;
|
|
this.isSerializable = isSerializable;
|
|
this.getter = getter;
|
|
}
|
|
|
|
public VariableGetterHolder( PropertyInfo propertyInfo, VariableGetVal getter, bool isSerializable )
|
|
{
|
|
name = propertyInfo.Name;
|
|
isProperty = true;
|
|
this.isSerializable = isSerializable;
|
|
this.getter = getter;
|
|
}
|
|
|
|
public object Get( object obj )
|
|
{
|
|
try
|
|
{
|
|
return getter( obj );
|
|
}
|
|
catch( Exception e )
|
|
{
|
|
Debug.LogException( e );
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Credit: http://stackoverflow.com/questions/724143/how-do-i-create-a-delegate-for-a-net-property
|
|
public interface IPropertyAccessor
|
|
{
|
|
object GetValue( object source );
|
|
}
|
|
|
|
// A wrapper class for properties to get their values more efficiently
|
|
public class PropertyWrapper<TObject, TValue> : IPropertyAccessor where TObject : class
|
|
{
|
|
private readonly Func<TObject, TValue> getter;
|
|
|
|
public PropertyWrapper( MethodInfo getterMethod )
|
|
{
|
|
getter = (Func<TObject, TValue>) Delegate.CreateDelegate( typeof( Func<TObject, TValue> ), getterMethod );
|
|
}
|
|
|
|
public object GetValue( object obj )
|
|
{
|
|
try
|
|
{
|
|
return getter( (TObject) obj );
|
|
}
|
|
catch
|
|
{
|
|
// Property getters may return various kinds of exceptions
|
|
// if their backing fields are not initialized (yet)
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
} |