mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-15 22:07:48 +08:00
1.3.5
- Project structure cleanup - Code refactoring - Adding some extension methods for cleaner looking code - Performance improvements on Object Reflection window
This commit is contained in:
parent
153ad2268b
commit
72c222d59a
@ -137,6 +137,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CppExplorer.cs" />
|
||||
<Compile Include="Extensions\ReflectionExtensions.cs" />
|
||||
<Compile Include="Extensions\UnityExtensions.cs" />
|
||||
<Compile Include="Helpers\ReflectionHelpers.cs" />
|
||||
<Compile Include="Helpers\UIHelpers.cs" />
|
||||
<Compile Include="Helpers\UnityHelpers.cs" />
|
||||
|
16
src/Extensions/ReflectionExtensions.cs
Normal file
16
src/Extensions/ReflectionExtensions.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
public static object Il2CppCast(this object obj, Type castTo)
|
||||
{
|
||||
return ReflectionHelpers.Il2CppCast(obj, castTo);
|
||||
}
|
||||
}
|
||||
}
|
29
src/Extensions/UnityExtensions.cs
Normal file
29
src/Extensions/UnityExtensions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public static class UnityExtensions
|
||||
{
|
||||
public static string GetGameObjectPath(this Transform _transform)
|
||||
{
|
||||
return GetGameObjectPath(_transform, true);
|
||||
}
|
||||
|
||||
public static string GetGameObjectPath(this Transform _transform, bool _includeThisName)
|
||||
{
|
||||
string path = _includeThisName ? ("/" + _transform.name) : "";
|
||||
GameObject gameObject = _transform.gameObject;
|
||||
while (gameObject.transform.parent != null)
|
||||
{
|
||||
gameObject = gameObject.transform.parent.gameObject;
|
||||
path = "/" + gameObject.name + path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public static class UnityHelpers
|
||||
public class UnityHelpers
|
||||
{
|
||||
private static Camera m_mainCamera;
|
||||
|
||||
@ -30,22 +30,5 @@ namespace Explorer
|
||||
return UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetGameObjectPath(this Transform _transform)
|
||||
{
|
||||
return GetGameObjectPath(_transform, true);
|
||||
}
|
||||
|
||||
public static string GetGameObjectPath(this Transform _transform, bool _includeThisName)
|
||||
{
|
||||
string path = _includeThisName ? ("/" + _transform.name) : "";
|
||||
GameObject gameObject = _transform.gameObject;
|
||||
while (gameObject.transform.parent != null)
|
||||
{
|
||||
gameObject = gameObject.transform.parent.gameObject;
|
||||
path = "/" + gameObject.name + path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ namespace Explorer
|
||||
{
|
||||
var declaringType = this.fieldInfo.DeclaringType;
|
||||
|
||||
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
|
||||
//var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
|
||||
var cast = obj.Il2CppCast(declaringType);
|
||||
m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : cast);
|
||||
}
|
||||
else
|
||||
@ -103,7 +104,8 @@ namespace Explorer
|
||||
{
|
||||
var declaringType = this.fieldInfo.DeclaringType;
|
||||
|
||||
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
|
||||
//var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
|
||||
var cast = obj.Il2CppCast(declaringType);
|
||||
fieldInfo.SetValue(fieldInfo.IsStatic ? null : cast, m_value);
|
||||
}
|
||||
else
|
||||
|
@ -40,7 +40,8 @@ namespace Explorer
|
||||
}
|
||||
else
|
||||
{
|
||||
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
|
||||
//var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
|
||||
var cast = obj.Il2CppCast(declaringType);
|
||||
m_value = this.propInfo.GetValue(this.propInfo.GetAccessors()[0].IsStatic ? null : cast, null);
|
||||
}
|
||||
}
|
||||
@ -49,19 +50,19 @@ namespace Explorer
|
||||
m_value = this.propInfo.GetValue(obj, null);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch //(Exception e)
|
||||
{
|
||||
MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name);
|
||||
MelonLogger.Log(e.GetType() + ", " + e.Message);
|
||||
//MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name);
|
||||
//MelonLogger.Log(e.GetType() + ", " + e.Message);
|
||||
|
||||
var inner = e.InnerException;
|
||||
while (inner != null)
|
||||
{
|
||||
MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message);
|
||||
inner = inner.InnerException;
|
||||
}
|
||||
//var inner = e.InnerException;
|
||||
//while (inner != null)
|
||||
//{
|
||||
// MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message);
|
||||
// inner = inner.InnerException;
|
||||
//}
|
||||
|
||||
m_value = null;
|
||||
//m_value = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,9 +114,7 @@ namespace Explorer
|
||||
}
|
||||
}
|
||||
|
||||
var declaring = propInfo.DeclaringType;
|
||||
var cast = ReflectionHelpers.Il2CppCast(obj, declaring);
|
||||
|
||||
var cast = obj.Il2CppCast(propInfo.DeclaringType);
|
||||
propInfo.SetValue(propInfo.GetAccessors()[0].IsStatic ? null : cast, m_value, null);
|
||||
}
|
||||
catch
|
||||
|
@ -48,8 +48,6 @@ namespace Explorer
|
||||
CacheFields(types);
|
||||
CacheProperties(types);
|
||||
|
||||
MelonLogger.Log("Cached properties: " + m_PropertyInfos.Length);
|
||||
|
||||
UpdateValues(true);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user