mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-03 20:12:33 +08:00
Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
2285a495be | |||
efdf2446bd | |||
6ad45ac8ae | |||
2d3c83cfa3 | |||
3213717ff6 | |||
a6a1a4d046 | |||
078c2e2b51 | |||
49bce650b4 | |||
bd9e80f2b4 | |||
d1eb5671bf | |||
f1ca484712 | |||
3b71b40843 | |||
1292affe6d | |||
6614762fe8 | |||
d81d6d034b | |||
5dfe3bbf0c | |||
dc81451ce5 | |||
d7ab0a23c6 | |||
1a01c740e2 | |||
040fb1f11a | |||
e44ff9e207 | |||
b5c69fc1ea | |||
4fdb2aacd8 | |||
48e688cb75 | |||
647b0d353d | |||
2b715f3dbe | |||
938a991594 | |||
f00134b283 | |||
3b6b9768fb | |||
5fbfa1b7aa | |||
7d26965c12 | |||
862523399a | |||
0afccadc64 | |||
0e37e8030c | |||
621a9cd72e | |||
56be5414f9 | |||
b8c4be473f | |||
b6966f8836 | |||
ad8c5293a0 | |||
a7165c849c | |||
79f2514109 | |||
4e76eca73a | |||
2f0876466c | |||
fdefc3d567 | |||
64193ff1b0 | |||
a90292f47f |
@ -51,6 +51,12 @@ The standalone release can be used with any injector or loader of your choice, b
|
|||||||
3. Create an instance of Unity Explorer with `UnityExplorer.ExplorerStandalone.CreateInstance();`
|
3. Create an instance of Unity Explorer with `UnityExplorer.ExplorerStandalone.CreateInstance();`
|
||||||
4. Optionally subscribe to the `ExplorerStandalone.OnLog` event to handle logging if you wish
|
4. Optionally subscribe to the `ExplorerStandalone.OnLog` event to handle logging if you wish
|
||||||
|
|
||||||
|
## Unity Editor
|
||||||
|
|
||||||
|
1. Download the [`UnityExplorer.Editor`](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Editor.zip) release.
|
||||||
|
2. Install the package, either by using the Package Manager and importing the `package.json` file, or by manually dragging the folder into your `Assets` folder.
|
||||||
|
3. Drag the `Runtime/UnityExplorer` prefab into your scene, or create a GameObject and add the `Explorer Editor Behaviour` script to it.
|
||||||
|
|
||||||
# Common issues and solutions
|
# Common issues and solutions
|
||||||
|
|
||||||
Although UnityExplorer should work out of the box for most Unity games, in some cases you may need to tweak the settings for it to work properly.
|
Although UnityExplorer should work out of the box for most Unity games, in some cases you may need to tweak the settings for it to work properly.
|
||||||
|
BIN
img/social.png
BIN
img/social.png
Binary file not shown.
Before Width: | Height: | Size: 232 KiB |
Binary file not shown.
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.AudioModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.AudioModule.dll
Normal file
Binary file not shown.
@ -414,11 +414,15 @@ namespace UnityExplorer.CSConsole
|
|||||||
|
|
||||||
static bool usingEventSystemDictionaryMembers;
|
static bool usingEventSystemDictionaryMembers;
|
||||||
|
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, GameObject> m_CurrentSelected_Handler_Normal = new("m_CurrentSelected", "m_currentSelected");
|
static readonly AmbiguousMemberHandler<EventSystem, GameObject> m_CurrentSelected_Handler_Normal
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, GameObject>> m_CurrentSelected_Handler_Dictionary = new("m_CurrentSelected", "m_currentSelected");
|
= new(true, true, "m_CurrentSelected", "m_currentSelected");
|
||||||
|
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, GameObject>> m_CurrentSelected_Handler_Dictionary
|
||||||
|
= new(true, true, "m_CurrentSelected", "m_currentSelected");
|
||||||
|
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, bool> m_SelectionGuard_Handler_Normal = new("m_SelectionGuard", "m_selectionGuard");
|
static readonly AmbiguousMemberHandler<EventSystem, bool> m_SelectionGuard_Handler_Normal
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, bool>> m_SelectionGuard_Handler_Dictionary = new("m_SelectionGuard", "m_selectionGuard");
|
= new(true, true, "m_SelectionGuard", "m_selectionGuard");
|
||||||
|
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, bool>> m_SelectionGuard_Handler_Dictionary
|
||||||
|
= new(true, true, "m_SelectionGuard", "m_selectionGuard");
|
||||||
|
|
||||||
static void SetCurrentSelectedGameObject(EventSystem instance, GameObject value)
|
static void SetCurrentSelectedGameObject(EventSystem instance, GameObject value)
|
||||||
{
|
{
|
||||||
|
@ -51,13 +51,8 @@ namespace UnityExplorer.CSConsole
|
|||||||
ReferenceAssembly(asm);
|
ReferenceAssembly(asm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CompilerContext context;
|
|
||||||
|
|
||||||
private static CompilerContext BuildContext(TextWriter tw)
|
private static CompilerContext BuildContext(TextWriter tw)
|
||||||
{
|
{
|
||||||
if (context != null)
|
|
||||||
return context;
|
|
||||||
|
|
||||||
_reportPrinter = new StreamReportPrinter(tw);
|
_reportPrinter = new StreamReportPrinter(tw);
|
||||||
|
|
||||||
var settings = new CompilerSettings
|
var settings = new CompilerSettings
|
||||||
@ -70,7 +65,7 @@ namespace UnityExplorer.CSConsole
|
|||||||
EnhancedWarnings = false
|
EnhancedWarnings = false
|
||||||
};
|
};
|
||||||
|
|
||||||
return context = new CompilerContext(settings, _reportPrinter);
|
return new CompilerContext(settings, _reportPrinter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ImportAppdomainAssemblies(Action<Assembly> import)
|
private static void ImportAppdomainAssemblies(Action<Assembly> import)
|
||||||
|
89
src/CacheObject/CacheConstructor.cs
Normal file
89
src/CacheObject/CacheConstructor.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using UnityExplorer.Inspectors;
|
||||||
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
|
namespace UnityExplorer.CacheObject
|
||||||
|
{
|
||||||
|
public class CacheConstructor : CacheMember
|
||||||
|
{
|
||||||
|
public ConstructorInfo CtorInfo { get; }
|
||||||
|
readonly Type typeForStructConstructor;
|
||||||
|
|
||||||
|
public override Type DeclaringType => typeForStructConstructor ?? CtorInfo.DeclaringType;
|
||||||
|
public override bool IsStatic => true;
|
||||||
|
public override bool ShouldAutoEvaluate => false;
|
||||||
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
|
public CacheConstructor(ConstructorInfo ci)
|
||||||
|
{
|
||||||
|
this.CtorInfo = ci;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheConstructor(Type typeForStructConstructor)
|
||||||
|
{
|
||||||
|
this.typeForStructConstructor = typeForStructConstructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
||||||
|
{
|
||||||
|
Type ctorReturnType;
|
||||||
|
// if is parameterless struct ctor
|
||||||
|
if (typeForStructConstructor != null)
|
||||||
|
{
|
||||||
|
ctorReturnType = typeForStructConstructor;
|
||||||
|
this.Owner = inspector;
|
||||||
|
|
||||||
|
// eg. Vector3.Vector3()
|
||||||
|
this.NameLabelText = SignatureHighlighter.Parse(typeForStructConstructor, false);
|
||||||
|
NameLabelText += $".{NameLabelText}()";
|
||||||
|
|
||||||
|
this.NameForFiltering = SignatureHighlighter.RemoveHighlighting(NameLabelText);
|
||||||
|
this.NameLabelTextRaw = NameForFiltering;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base.SetInspectorOwner(inspector, member);
|
||||||
|
|
||||||
|
Arguments = CtorInfo.GetParameters();
|
||||||
|
ctorReturnType = CtorInfo.DeclaringType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctorReturnType.IsGenericTypeDefinition)
|
||||||
|
GenericArguments = ctorReturnType.GetGenericArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override object TryEvaluate()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Type returnType = DeclaringType;
|
||||||
|
|
||||||
|
if (returnType.IsGenericTypeDefinition)
|
||||||
|
returnType = DeclaringType.MakeGenericType(Evaluator.TryParseGenericArguments());
|
||||||
|
|
||||||
|
object ret;
|
||||||
|
if (HasArguments)
|
||||||
|
ret = Activator.CreateInstance(returnType, Evaluator.TryParseArguments());
|
||||||
|
else
|
||||||
|
ret = Activator.CreateInstance(returnType, ArgumentUtility.EmptyArgs);
|
||||||
|
|
||||||
|
HadException = false;
|
||||||
|
LastException = null;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
HadException = true;
|
||||||
|
LastException = ex;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void TrySetValue(object value) => throw new NotImplementedException("You can't set a constructor");
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,11 @@ namespace UnityExplorer.CacheObject
|
|||||||
|
|
||||||
public override bool ShouldAutoEvaluate => true;
|
public override bool ShouldAutoEvaluate => true;
|
||||||
|
|
||||||
|
public CacheField(FieldInfo fi)
|
||||||
|
{
|
||||||
|
this.FieldInfo = fi;
|
||||||
|
}
|
||||||
|
|
||||||
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
||||||
{
|
{
|
||||||
base.SetInspectorOwner(inspector, member);
|
base.SetInspectorOwner(inspector, member);
|
||||||
|
@ -14,6 +14,8 @@ using UniverseLib.UI;
|
|||||||
using UnityExplorer.UI.Widgets;
|
using UnityExplorer.UI.Widgets;
|
||||||
using UniverseLib.Utility;
|
using UniverseLib.Utility;
|
||||||
using UniverseLib.UI.ObjectPool;
|
using UniverseLib.UI.ObjectPool;
|
||||||
|
using System.Collections;
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
namespace UnityExplorer.CacheObject
|
namespace UnityExplorer.CacheObject
|
||||||
{
|
{
|
||||||
@ -21,7 +23,7 @@ namespace UnityExplorer.CacheObject
|
|||||||
{
|
{
|
||||||
public abstract Type DeclaringType { get; }
|
public abstract Type DeclaringType { get; }
|
||||||
public string NameForFiltering { get; protected set; }
|
public string NameForFiltering { get; protected set; }
|
||||||
public object DeclaringInstance => IsStatic ? null : (m_declaringInstance ?? (m_declaringInstance = Owner.Target.TryCast(DeclaringType)));
|
public object DeclaringInstance => IsStatic ? null : (m_declaringInstance ??= Owner.Target.TryCast(DeclaringType));
|
||||||
private object m_declaringInstance;
|
private object m_declaringInstance;
|
||||||
|
|
||||||
public abstract bool IsStatic { get; }
|
public abstract bool IsStatic { get; }
|
||||||
@ -34,10 +36,14 @@ namespace UnityExplorer.CacheObject
|
|||||||
public virtual void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
public virtual void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
||||||
{
|
{
|
||||||
this.Owner = inspector;
|
this.Owner = inspector;
|
||||||
this.NameLabelText = this is CacheMethod
|
this.NameLabelText = this switch
|
||||||
? SignatureHighlighter.HighlightMethod(member as MethodInfo)
|
{
|
||||||
: SignatureHighlighter.Parse(member.DeclaringType, false, member);
|
CacheMethod => SignatureHighlighter.HighlightMethod(member as MethodInfo),
|
||||||
this.NameForFiltering = $"{member.DeclaringType.Name}.{member.Name}";
|
CacheConstructor => SignatureHighlighter.HighlightConstructor(member as ConstructorInfo),
|
||||||
|
_ => SignatureHighlighter.Parse(member.DeclaringType, false, member),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.NameForFiltering = SignatureHighlighter.RemoveHighlighting(NameLabelText);
|
||||||
this.NameLabelTextRaw = NameForFiltering;
|
this.NameLabelTextRaw = NameForFiltering;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +100,8 @@ namespace UnityExplorer.CacheObject
|
|||||||
base.SetValueState(cell, args);
|
base.SetValueState(cell, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Color evalEnabledColor = new Color(0.15f, 0.25f, 0.15f);
|
private static readonly Color evalEnabledColor = new(0.15f, 0.25f, 0.15f);
|
||||||
private static readonly Color evalDisabledColor = new Color(0.15f, 0.15f, 0.15f);
|
private static readonly Color evalDisabledColor = new(0.15f, 0.15f, 0.15f);
|
||||||
|
|
||||||
protected override bool TryAutoEvaluateIfUnitialized(CacheObjectCell objectcell)
|
protected override bool TryAutoEvaluateIfUnitialized(CacheObjectCell objectcell)
|
||||||
{
|
{
|
||||||
@ -163,184 +169,5 @@ namespace UnityExplorer.CacheObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Cache Member Util
|
|
||||||
|
|
||||||
//public static bool CanParseArgs(ParameterInfo[] parameters)
|
|
||||||
//{
|
|
||||||
// foreach (var param in parameters)
|
|
||||||
// {
|
|
||||||
// var pType = param.ParameterType;
|
|
||||||
//
|
|
||||||
// if (pType.IsByRef && pType.HasElementType)
|
|
||||||
// pType = pType.GetElementType();
|
|
||||||
//
|
|
||||||
// if (pType != null && ParseUtility.CanParse(pType))
|
|
||||||
// continue;
|
|
||||||
// else
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type _type, ReflectionInspector _inspector)
|
|
||||||
{
|
|
||||||
var list = new List<CacheMember>();
|
|
||||||
var cachedSigs = new HashSet<string>();
|
|
||||||
|
|
||||||
var types = ReflectionUtility.GetAllBaseTypes(_type);
|
|
||||||
|
|
||||||
var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
|
||||||
if (!_inspector.StaticOnly)
|
|
||||||
flags |= BindingFlags.Instance;
|
|
||||||
|
|
||||||
var infos = new List<MemberInfo>();
|
|
||||||
|
|
||||||
foreach (var declaringType in types)
|
|
||||||
{
|
|
||||||
var target = inspectorTarget;
|
|
||||||
if (!_inspector.StaticOnly)
|
|
||||||
target = target.TryCast(declaringType);
|
|
||||||
|
|
||||||
infos.Clear();
|
|
||||||
infos.AddRange(declaringType.GetProperties(flags));
|
|
||||||
infos.AddRange(declaringType.GetFields(flags));
|
|
||||||
infos.AddRange(declaringType.GetMethods(flags));
|
|
||||||
|
|
||||||
foreach (var member in infos)
|
|
||||||
{
|
|
||||||
if (member.DeclaringType != declaringType)
|
|
||||||
continue;
|
|
||||||
TryCacheMember(member, list, cachedSigs, declaringType, _inspector);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var typeList = types.ToList();
|
|
||||||
|
|
||||||
var sorted = new List<CacheMember>();
|
|
||||||
sorted.AddRange(list.Where(it => it is CacheProperty)
|
|
||||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
|
||||||
.ThenBy(it => it.NameForFiltering));
|
|
||||||
sorted.AddRange(list.Where(it => it is CacheField)
|
|
||||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
|
||||||
.ThenBy(it => it.NameForFiltering));
|
|
||||||
sorted.AddRange(list.Where(it => it is CacheMethod)
|
|
||||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
|
||||||
.ThenBy(it => it.NameForFiltering));
|
|
||||||
|
|
||||||
return sorted;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void TryCacheMember(MemberInfo member, List<CacheMember> list, HashSet<string> cachedSigs,
|
|
||||||
Type declaringType, ReflectionInspector _inspector, bool ignorePropertyMethodInfos = true)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (UERuntimeHelper.IsBlacklisted(member))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var sig = GetSig(member);
|
|
||||||
|
|
||||||
//ExplorerCore.Log($"Trying to cache member {sig}... ({member.MemberType})");
|
|
||||||
|
|
||||||
CacheMember cached;
|
|
||||||
Type returnType;
|
|
||||||
switch (member.MemberType)
|
|
||||||
{
|
|
||||||
case MemberTypes.Method:
|
|
||||||
{
|
|
||||||
var mi = member as MethodInfo;
|
|
||||||
if (ignorePropertyMethodInfos
|
|
||||||
&& (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
|
|
||||||
return;
|
|
||||||
|
|
||||||
//var args = mi.GetParameters();
|
|
||||||
//if (!CanParseArgs(args))
|
|
||||||
// return;
|
|
||||||
|
|
||||||
sig += GetArgumentString(mi.GetParameters());
|
|
||||||
if (cachedSigs.Contains(sig))
|
|
||||||
return;
|
|
||||||
|
|
||||||
cached = new CacheMethod() { MethodInfo = mi };
|
|
||||||
returnType = mi.ReturnType;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MemberTypes.Property:
|
|
||||||
{
|
|
||||||
var pi = member as PropertyInfo;
|
|
||||||
|
|
||||||
//var args = pi.GetIndexParameters();
|
|
||||||
//if (!CanParseArgs(args))
|
|
||||||
// return;
|
|
||||||
|
|
||||||
if (!pi.CanRead && pi.CanWrite)
|
|
||||||
{
|
|
||||||
// write-only property, cache the set method instead.
|
|
||||||
var setMethod = pi.GetSetMethod(true);
|
|
||||||
if (setMethod != null)
|
|
||||||
TryCacheMember(setMethod, list, cachedSigs, declaringType, _inspector, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sig += GetArgumentString(pi.GetIndexParameters());
|
|
||||||
if (cachedSigs.Contains(sig))
|
|
||||||
return;
|
|
||||||
|
|
||||||
cached = new CacheProperty() { PropertyInfo = pi };
|
|
||||||
returnType = pi.PropertyType;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MemberTypes.Field:
|
|
||||||
{
|
|
||||||
var fi = member as FieldInfo;
|
|
||||||
cached = new CacheField() { FieldInfo = fi };
|
|
||||||
returnType = fi.FieldType;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedSigs.Add(sig);
|
|
||||||
|
|
||||||
cached.SetFallbackType(returnType);
|
|
||||||
cached.SetInspectorOwner(_inspector, member);
|
|
||||||
|
|
||||||
list.Add(cached);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
|
|
||||||
ExplorerCore.Log(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string GetSig(MemberInfo member)
|
|
||||||
=> $"{member.DeclaringType.Name}.{member.Name}";
|
|
||||||
|
|
||||||
internal static string GetArgumentString(ParameterInfo[] args)
|
|
||||||
{
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(' ');
|
|
||||||
sb.Append('(');
|
|
||||||
foreach (var param in args)
|
|
||||||
{
|
|
||||||
sb.Append(param.ParameterType.Name);
|
|
||||||
sb.Append(' ');
|
|
||||||
sb.Append(param.Name);
|
|
||||||
sb.Append(',');
|
|
||||||
sb.Append(' ');
|
|
||||||
}
|
|
||||||
sb.Append(')');
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
195
src/CacheObject/CacheMemberFactory.cs
Normal file
195
src/CacheObject/CacheMemberFactory.cs
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using UnityExplorer.Inspectors;
|
||||||
|
using UnityExplorer.Runtime;
|
||||||
|
using UniverseLib;
|
||||||
|
using HarmonyLib;
|
||||||
|
using HarmonyLib.Tools;
|
||||||
|
|
||||||
|
namespace UnityExplorer.CacheObject
|
||||||
|
{
|
||||||
|
public static class CacheMemberFactory
|
||||||
|
{
|
||||||
|
public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type type, ReflectionInspector inspector)
|
||||||
|
{
|
||||||
|
//var list = new List<CacheMember>();
|
||||||
|
HashSet<string> cachedSigs = new();
|
||||||
|
List<CacheMember> props = new();
|
||||||
|
List<CacheMember> fields = new();
|
||||||
|
List<CacheMember> ctors = new();
|
||||||
|
List<CacheMember> methods = new();
|
||||||
|
|
||||||
|
var types = ReflectionUtility.GetAllBaseTypes(type);
|
||||||
|
|
||||||
|
var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
||||||
|
if (!inspector.StaticOnly)
|
||||||
|
flags |= BindingFlags.Instance;
|
||||||
|
|
||||||
|
if (!type.IsAbstract)
|
||||||
|
{
|
||||||
|
// Get non-static constructors of the main type.
|
||||||
|
// There's no reason to get the static cctor, it will be invoked when we inspect the class.
|
||||||
|
// Also no point getting ctors on inherited types.
|
||||||
|
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||||
|
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
|
||||||
|
|
||||||
|
// structs always have a parameterless constructor
|
||||||
|
if (type.IsValueType)
|
||||||
|
{
|
||||||
|
CacheConstructor cached = new(type);
|
||||||
|
cached.SetFallbackType(type);
|
||||||
|
cached.SetInspectorOwner(inspector, null);
|
||||||
|
ctors.Add(cached);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var declaringType in types)
|
||||||
|
{
|
||||||
|
var target = inspectorTarget;
|
||||||
|
if (!inspector.StaticOnly)
|
||||||
|
target = target.TryCast(declaringType);
|
||||||
|
|
||||||
|
foreach (var prop in declaringType.GetProperties(flags))
|
||||||
|
if (prop.DeclaringType == declaringType)
|
||||||
|
TryCacheMember(prop, props, cachedSigs, declaringType, inspector);
|
||||||
|
|
||||||
|
foreach (var field in declaringType.GetFields(flags))
|
||||||
|
if (field.DeclaringType == declaringType)
|
||||||
|
TryCacheMember(field, fields, cachedSigs, declaringType, inspector);
|
||||||
|
|
||||||
|
foreach (var method in declaringType.GetMethods(flags))
|
||||||
|
if (method.DeclaringType == declaringType)
|
||||||
|
TryCacheMember(method, methods, cachedSigs, declaringType, inspector);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var sorted = new List<CacheMember>();
|
||||||
|
sorted.AddRange(props.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
||||||
|
.ThenBy(it => it.NameForFiltering));
|
||||||
|
sorted.AddRange(fields.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
||||||
|
.ThenBy(it => it.NameForFiltering));
|
||||||
|
sorted.AddRange(ctors.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
||||||
|
.ThenBy(it => it.NameForFiltering));
|
||||||
|
sorted.AddRange(methods.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
||||||
|
.ThenBy(it => it.NameForFiltering));
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TryCacheMember(
|
||||||
|
MemberInfo member,
|
||||||
|
IList list,
|
||||||
|
HashSet<string> cachedSigs,
|
||||||
|
Type declaringType,
|
||||||
|
ReflectionInspector inspector,
|
||||||
|
bool ignorePropertyMethodInfos = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (UERuntimeHelper.IsBlacklisted(member))
|
||||||
|
return;
|
||||||
|
|
||||||
|
string sig = member switch
|
||||||
|
{
|
||||||
|
MethodBase mb => mb.FullDescription(),
|
||||||
|
PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}",
|
||||||
|
_ => throw new NotImplementedException(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (cachedSigs.Contains(sig))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// ExplorerCore.Log($"Trying to cache member {sig}... ({member.MemberType})");
|
||||||
|
|
||||||
|
CacheMember cached;
|
||||||
|
Type returnType;
|
||||||
|
|
||||||
|
switch (member.MemberType)
|
||||||
|
{
|
||||||
|
case MemberTypes.Constructor:
|
||||||
|
{
|
||||||
|
var ci = member as ConstructorInfo;
|
||||||
|
cached = new CacheConstructor(ci);
|
||||||
|
returnType = ci.DeclaringType;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MemberTypes.Method:
|
||||||
|
{
|
||||||
|
var mi = member as MethodInfo;
|
||||||
|
if (ignorePropertyMethodInfos
|
||||||
|
&& (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
|
||||||
|
return;
|
||||||
|
|
||||||
|
cached = new CacheMethod(mi);
|
||||||
|
returnType = mi.ReturnType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MemberTypes.Property:
|
||||||
|
{
|
||||||
|
var pi = member as PropertyInfo;
|
||||||
|
|
||||||
|
if (!pi.CanRead && pi.CanWrite)
|
||||||
|
{
|
||||||
|
// write-only property, cache the set method instead.
|
||||||
|
var setMethod = pi.GetSetMethod(true);
|
||||||
|
if (setMethod != null)
|
||||||
|
TryCacheMember(setMethod, list, cachedSigs, declaringType, inspector, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cached = new CacheProperty(pi);
|
||||||
|
returnType = pi.PropertyType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MemberTypes.Field:
|
||||||
|
{
|
||||||
|
var fi = member as FieldInfo;
|
||||||
|
cached = new CacheField(fi);
|
||||||
|
returnType = fi.FieldType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedSigs.Add(sig);
|
||||||
|
|
||||||
|
cached.SetFallbackType(returnType);
|
||||||
|
cached.SetInspectorOwner(inspector, member);
|
||||||
|
|
||||||
|
list.Add(cached);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
|
||||||
|
ExplorerCore.Log(e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//internal static string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}";
|
||||||
|
//
|
||||||
|
//internal static string GetArgumentString(ParameterInfo[] args)
|
||||||
|
//{
|
||||||
|
// var sb = new StringBuilder();
|
||||||
|
// sb.Append(' ');
|
||||||
|
// sb.Append('(');
|
||||||
|
// foreach (var param in args)
|
||||||
|
// {
|
||||||
|
// sb.Append(param.ParameterType.Name);
|
||||||
|
// sb.Append(' ');
|
||||||
|
// sb.Append(param.Name);
|
||||||
|
// sb.Append(',');
|
||||||
|
// sb.Append(' ');
|
||||||
|
// }
|
||||||
|
// sb.Append(')');
|
||||||
|
// return sb.ToString();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
@ -11,13 +11,18 @@ namespace UnityExplorer.CacheObject
|
|||||||
{
|
{
|
||||||
public class CacheMethod : CacheMember
|
public class CacheMethod : CacheMember
|
||||||
{
|
{
|
||||||
public MethodInfo MethodInfo { get; internal set; }
|
public MethodInfo MethodInfo { get; }
|
||||||
public override Type DeclaringType => MethodInfo.DeclaringType;
|
public override Type DeclaringType => MethodInfo.DeclaringType;
|
||||||
public override bool CanWrite => false;
|
public override bool CanWrite => false;
|
||||||
public override bool IsStatic => MethodInfo.IsStatic;
|
public override bool IsStatic => MethodInfo.IsStatic;
|
||||||
|
|
||||||
public override bool ShouldAutoEvaluate => false;
|
public override bool ShouldAutoEvaluate => false;
|
||||||
|
|
||||||
|
public CacheMethod (MethodInfo mi)
|
||||||
|
{
|
||||||
|
this.MethodInfo = mi;
|
||||||
|
}
|
||||||
|
|
||||||
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
||||||
{
|
{
|
||||||
base.SetInspectorOwner(inspector, member);
|
base.SetInspectorOwner(inspector, member);
|
||||||
|
@ -3,7 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
using UnityExplorer.Inspectors;
|
using UnityExplorer.Inspectors;
|
||||||
|
using UnityExplorer.Runtime;
|
||||||
|
|
||||||
namespace UnityExplorer.CacheObject
|
namespace UnityExplorer.CacheObject
|
||||||
{
|
{
|
||||||
@ -17,6 +19,11 @@ namespace UnityExplorer.CacheObject
|
|||||||
|
|
||||||
public override bool ShouldAutoEvaluate => !HasArguments;
|
public override bool ShouldAutoEvaluate => !HasArguments;
|
||||||
|
|
||||||
|
public CacheProperty(PropertyInfo pi)
|
||||||
|
{
|
||||||
|
this.PropertyInfo = pi;
|
||||||
|
}
|
||||||
|
|
||||||
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
||||||
{
|
{
|
||||||
base.SetInspectorOwner(inspector, member);
|
base.SetInspectorOwner(inspector, member);
|
||||||
|
@ -29,8 +29,11 @@ namespace UnityExplorer.CacheObject.IValues
|
|||||||
private EnumCompleter enumCompleter;
|
private EnumCompleter enumCompleter;
|
||||||
|
|
||||||
private GameObject toggleHolder;
|
private GameObject toggleHolder;
|
||||||
private readonly List<Toggle> flagToggles = new List<Toggle>();
|
private readonly List<Toggle> flagToggles = new();
|
||||||
private readonly List<Text> flagTexts = new List<Text>();
|
private readonly List<Text> flagTexts = new();
|
||||||
|
|
||||||
|
public CachedEnumValue ValueAtIndex(int idx) => (CachedEnumValue)CurrentValues[idx];
|
||||||
|
public CachedEnumValue ValueAtKey(object key) => (CachedEnumValue)CurrentValues[key];
|
||||||
|
|
||||||
// Setting value from owner
|
// Setting value from owner
|
||||||
public override void SetValue(object value)
|
public override void SetValue(object value)
|
||||||
@ -70,13 +73,8 @@ namespace UnityExplorer.CacheObject.IValues
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var split = value.ToString().Split(',');
|
|
||||||
var set = new HashSet<string>();
|
|
||||||
foreach (var s in split)
|
|
||||||
set.Add(s.Trim());
|
|
||||||
|
|
||||||
for (int i = 0; i < CurrentValues.Count; i++)
|
for (int i = 0; i < CurrentValues.Count; i++)
|
||||||
flagToggles[i].isOn = set.Contains(ValueAtIdx(i).Name);
|
flagToggles[i].isOn = (value as Enum).HasFlag(ValueAtIndex(i).ActualValue as Enum);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -116,7 +114,7 @@ namespace UnityExplorer.CacheObject.IValues
|
|||||||
for (int i = 0; i < CurrentValues.Count; i++)
|
for (int i = 0; i < CurrentValues.Count; i++)
|
||||||
{
|
{
|
||||||
if (flagToggles[i].isOn)
|
if (flagToggles[i].isOn)
|
||||||
values.Add(ValueAtIdx(i).Name);
|
values.Add(ValueAtIndex(i).Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentOwner.SetUserValue(Enum.Parse(EnumType, string.Join(", ", values.ToArray())));
|
CurrentOwner.SetUserValue(Enum.Parse(EnumType, string.Join(", ", values.ToArray())));
|
||||||
@ -166,9 +164,6 @@ namespace UnityExplorer.CacheObject.IValues
|
|||||||
return UIRoot;
|
return UIRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedEnumValue ValueAtIdx(int idx) => (CachedEnumValue)CurrentValues[idx];
|
|
||||||
public CachedEnumValue ValueAtKey(object key) => (CachedEnumValue)CurrentValues[key];
|
|
||||||
|
|
||||||
private void SetupTogglesForEnumType()
|
private void SetupTogglesForEnumType()
|
||||||
{
|
{
|
||||||
toggleHolder.SetActive(true);
|
toggleHolder.SetActive(true);
|
||||||
@ -191,7 +186,7 @@ namespace UnityExplorer.CacheObject.IValues
|
|||||||
AddToggleRow();
|
AddToggleRow();
|
||||||
|
|
||||||
flagToggles[i].isOn = false;
|
flagToggles[i].isOn = false;
|
||||||
flagTexts[i].text = ValueAtIdx(i).Name;
|
flagTexts[i].text = ValueAtIndex(i).Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ namespace UnityExplorer.Config
|
|||||||
public static ConfigElement<bool> Hide_On_Startup;
|
public static ConfigElement<bool> Hide_On_Startup;
|
||||||
public static ConfigElement<float> Startup_Delay_Time;
|
public static ConfigElement<float> Startup_Delay_Time;
|
||||||
public static ConfigElement<string> Reflection_Signature_Blacklist;
|
public static ConfigElement<string> Reflection_Signature_Blacklist;
|
||||||
|
public static ConfigElement<KeyCode> World_MouseInspect_Keybind;
|
||||||
|
public static ConfigElement<KeyCode> UI_MouseInspect_Keybind;
|
||||||
|
|
||||||
// internal configs
|
// internal configs
|
||||||
internal static InternalConfigHandler InternalHandler { get; private set; }
|
internal static InternalConfigHandler InternalHandler { get; private set; }
|
||||||
@ -93,13 +95,18 @@ namespace UnityExplorer.Config
|
|||||||
"Should UnityExplorer be hidden on startup?",
|
"Should UnityExplorer be hidden on startup?",
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
World_MouseInspect_Keybind = new("World Mouse-Inspect Keybind",
|
||||||
|
"Optional keybind to being a World-mode Mouse Inspect.",
|
||||||
|
KeyCode.None);
|
||||||
|
|
||||||
|
UI_MouseInspect_Keybind = new("UI Mouse-Inspect Keybind",
|
||||||
|
"Optional keybind to begin a UI_mode Mouse Inspect.",
|
||||||
|
KeyCode.None);
|
||||||
|
|
||||||
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
|
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
|
||||||
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
|
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
|
||||||
true);
|
true);
|
||||||
Force_Unlock_Mouse.OnValueChanged += (bool value) =>
|
Force_Unlock_Mouse.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = value;
|
||||||
{
|
|
||||||
UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = value;
|
|
||||||
};
|
|
||||||
|
|
||||||
Force_Unlock_Toggle = new ConfigElement<KeyCode>("Force Unlock Toggle Key",
|
Force_Unlock_Toggle = new ConfigElement<KeyCode>("Force Unlock Toggle Key",
|
||||||
"The keybind to toggle the 'Force Unlock Mouse' setting. Only usable when UnityExplorer is open.",
|
"The keybind to toggle the 'Force Unlock Mouse' setting. Only usable when UnityExplorer is open.",
|
||||||
@ -108,10 +115,7 @@ namespace UnityExplorer.Config
|
|||||||
Disable_EventSystem_Override = new ConfigElement<bool>("Disable EventSystem override",
|
Disable_EventSystem_Override = new ConfigElement<bool>("Disable EventSystem override",
|
||||||
"If enabled, UnityExplorer will not override the EventSystem from the game.\n<b>May require restart to take effect.</b>",
|
"If enabled, UnityExplorer will not override the EventSystem from the game.\n<b>May require restart to take effect.</b>",
|
||||||
false);
|
false);
|
||||||
Disable_EventSystem_Override.OnValueChanged += (bool value) =>
|
Disable_EventSystem_Override.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Disable_EventSystem_Override = value;
|
||||||
{
|
|
||||||
UniverseLib.Config.ConfigManager.Disable_EventSystem_Override = value;
|
|
||||||
};
|
|
||||||
|
|
||||||
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
|
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
|
||||||
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
|
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
|
||||||
|
@ -1,24 +1,18 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
using UnityExplorer.Config;
|
using UnityExplorer.Config;
|
||||||
using UnityExplorer.UI;
|
|
||||||
using UnityExplorer.ObjectExplorer;
|
using UnityExplorer.ObjectExplorer;
|
||||||
using UnityExplorer.UI.Panels;
|
|
||||||
using UnityExplorer.Runtime;
|
using UnityExplorer.Runtime;
|
||||||
|
using UnityExplorer.UI;
|
||||||
|
using UnityExplorer.UI.Panels;
|
||||||
using UniverseLib.Input;
|
using UniverseLib.Input;
|
||||||
using UniverseLib.UI;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace UnityExplorer
|
namespace UnityExplorer
|
||||||
{
|
{
|
||||||
public static class ExplorerCore
|
public static class ExplorerCore
|
||||||
{
|
{
|
||||||
public const string NAME = "UnityExplorer";
|
public const string NAME = "UnityExplorer";
|
||||||
public const string VERSION = "4.5.6";
|
public const string VERSION = "4.6.0";
|
||||||
public const string AUTHOR = "Sinai";
|
public const string AUTHOR = "Sinai";
|
||||||
public const string GUID = "com.sinai.unityexplorer";
|
public const string GUID = "com.sinai.unityexplorer";
|
||||||
|
|
||||||
@ -46,6 +40,7 @@ namespace UnityExplorer
|
|||||||
ConfigManager.Init(Loader.ConfigHandler);
|
ConfigManager.Init(Loader.ConfigHandler);
|
||||||
UERuntimeHelper.Init();
|
UERuntimeHelper.Init();
|
||||||
ExplorerBehaviour.Setup();
|
ExplorerBehaviour.Setup();
|
||||||
|
UnityCrashPrevention.Init();
|
||||||
|
|
||||||
UniverseLib.Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new()
|
UniverseLib.Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new()
|
||||||
{
|
{
|
||||||
@ -68,7 +63,7 @@ namespace UnityExplorer
|
|||||||
|
|
||||||
UIManager.InitUI();
|
UIManager.InitUI();
|
||||||
|
|
||||||
Log($"{NAME} {VERSION} initialized.");
|
Log($"{NAME} {VERSION} initialized for {UniverseLib.Universe.Context}.");
|
||||||
|
|
||||||
//InspectorManager.Inspect(typeof(Tests.TestClass));
|
//InspectorManager.Inspect(typeof(Tests.TestClass));
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
this.Target = newTarget;
|
this.Target = newTarget;
|
||||||
GOControls.UpdateGameObjectInfo(true, true);
|
GOControls.UpdateGameObjectInfo(true, true);
|
||||||
GOControls.UpdateTransformControlValues(true);
|
GOControls.UpdateTransformControlValues(true);
|
||||||
TransformTree.RefreshData(true, false);
|
TransformTree.RefreshData(true, false, true, false);
|
||||||
UpdateComponents();
|
UpdateComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
GOControls.UpdateGameObjectInfo(false, false);
|
GOControls.UpdateGameObjectInfo(false, false);
|
||||||
|
|
||||||
TransformTree.RefreshData(true, false);
|
TransformTree.RefreshData(true, false, false, false);
|
||||||
UpdateComponents();
|
UpdateComponents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
var newObject = new GameObject(input);
|
var newObject = new GameObject(input);
|
||||||
newObject.transform.parent = GOTarget.transform;
|
newObject.transform.parent = GOTarget.transform;
|
||||||
|
|
||||||
TransformTree.RefreshData(true, false);
|
TransformTree.RefreshData(true, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAddComponentClicked(string input)
|
private void OnAddComponentClicked(string input)
|
||||||
|
@ -18,7 +18,7 @@ namespace UnityExplorer
|
|||||||
{
|
{
|
||||||
public static class InspectorManager
|
public static class InspectorManager
|
||||||
{
|
{
|
||||||
public static readonly List<InspectorBase> Inspectors = new List<InspectorBase>();
|
public static readonly List<InspectorBase> Inspectors = new();
|
||||||
|
|
||||||
public static InspectorBase ActiveInspector { get; private set; }
|
public static InspectorBase ActiveInspector { get; private set; }
|
||||||
private static InspectorBase lastActiveInspector;
|
private static InspectorBase lastActiveInspector;
|
||||||
@ -94,17 +94,17 @@ namespace UnityExplorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateInspector<T>(object target, bool staticReflection = false,
|
private static void CreateInspector<T>(object target, bool staticReflection = false,
|
||||||
CacheObjectBase sourceCache = null) where T : InspectorBase
|
CacheObjectBase parentObject = null) where T : InspectorBase
|
||||||
{
|
{
|
||||||
var inspector = Pool<T>.Borrow();
|
var inspector = Pool<T>.Borrow();
|
||||||
Inspectors.Add(inspector);
|
Inspectors.Add(inspector);
|
||||||
inspector.Target = target;
|
inspector.Target = target;
|
||||||
|
|
||||||
if (sourceCache != null && sourceCache.CanWrite)
|
if (parentObject != null && parentObject.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 = sourceCache;
|
ri.ParentCacheObject = parentObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIManager.SetPanelActive(UIManager.Panels.Inspector, true);
|
UIManager.SetPanelActive(UIManager.Panels.Inspector, true);
|
||||||
|
@ -43,9 +43,10 @@ namespace UnityExplorer.Inspectors
|
|||||||
TabButton = UIFactory.CreateButton(UIRoot, "TabButton", "");
|
TabButton = UIFactory.CreateButton(UIRoot, "TabButton", "");
|
||||||
UIFactory.SetLayoutElement(TabButton.Component.gameObject, minWidth: 173, flexibleWidth: 0);
|
UIFactory.SetLayoutElement(TabButton.Component.gameObject, minWidth: 173, flexibleWidth: 0);
|
||||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(TabButton.Component.gameObject, false, false, true, true, 0, 0, 0, 3);
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(TabButton.Component.gameObject, false, false, true, true, 0, 0, 0, 3);
|
||||||
|
TabButton.GameObject.AddComponent<Mask>();
|
||||||
|
|
||||||
TabText = TabButton.Component.GetComponentInChildren<Text>();
|
TabText = TabButton.ButtonText;
|
||||||
UIFactory.SetLayoutElement(TabText.gameObject, minHeight: 25, minWidth: 173, flexibleWidth: 0);
|
UIFactory.SetLayoutElement(TabText.gameObject, minHeight: 25, minWidth: 150, flexibleWidth: 0);
|
||||||
TabText.alignment = TextAnchor.MiddleLeft;
|
TabText.alignment = TextAnchor.MiddleLeft;
|
||||||
TabText.fontSize = 12;
|
TabText.fontSize = 12;
|
||||||
TabText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
TabText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
|
@ -13,6 +13,7 @@ using UnityExplorer.UI.Panels;
|
|||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
using UniverseLib.UI;
|
using UniverseLib.UI;
|
||||||
using UniverseLib.Utility;
|
using UniverseLib.Utility;
|
||||||
|
using UnityExplorer.Config;
|
||||||
|
|
||||||
namespace UnityExplorer.Inspectors
|
namespace UnityExplorer.Inspectors
|
||||||
{
|
{
|
||||||
@ -22,9 +23,9 @@ namespace UnityExplorer.Inspectors
|
|||||||
UI
|
UI
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InspectUnderMouse : UIPanel
|
public class MouseInspector : UIPanel
|
||||||
{
|
{
|
||||||
public static InspectUnderMouse Instance { get; private set; }
|
public static MouseInspector Instance { get; private set; }
|
||||||
|
|
||||||
private readonly WorldInspector worldInspector;
|
private readonly WorldInspector worldInspector;
|
||||||
private readonly UiInspector uiInspector;
|
private readonly UiInspector uiInspector;
|
||||||
@ -58,7 +59,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
internal Text objPathLabel;
|
internal Text objPathLabel;
|
||||||
internal Text mousePosLabel;
|
internal Text mousePosLabel;
|
||||||
|
|
||||||
public InspectUnderMouse()
|
public MouseInspector()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
worldInspector = new WorldInspector();
|
worldInspector = new WorldInspector();
|
||||||
@ -116,6 +117,26 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
private static float timeOfLastRaycast;
|
private static float timeOfLastRaycast;
|
||||||
|
|
||||||
|
public bool TryUpdate()
|
||||||
|
{
|
||||||
|
if (ConfigManager.World_MouseInspect_Keybind.Value != KeyCode.None)
|
||||||
|
{
|
||||||
|
if (InputManager.GetKeyDown(ConfigManager.World_MouseInspect_Keybind.Value))
|
||||||
|
Instance.StartInspect(MouseInspectMode.World);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ConfigManager.World_MouseInspect_Keybind.Value != KeyCode.None)
|
||||||
|
{
|
||||||
|
if (InputManager.GetKeyDown(ConfigManager.World_MouseInspect_Keybind.Value))
|
||||||
|
Instance.StartInspect(MouseInspectMode.World);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Inspecting)
|
||||||
|
UpdateInspect();
|
||||||
|
|
||||||
|
return Inspecting;
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateInspect()
|
public void UpdateInspect()
|
||||||
{
|
{
|
||||||
if (InputManager.GetKeyDown(KeyCode.Escape))
|
if (InputManager.GetKeyDown(KeyCode.Escape))
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -8,6 +9,7 @@ using UnityEngine.UI;
|
|||||||
using UnityExplorer.UI;
|
using UnityExplorer.UI;
|
||||||
using UnityExplorer.UI.Panels;
|
using UnityExplorer.UI.Panels;
|
||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
|
using UniverseLib.Input;
|
||||||
|
|
||||||
namespace UnityExplorer.Inspectors.MouseInspectors
|
namespace UnityExplorer.Inspectors.MouseInspectors
|
||||||
{
|
{
|
||||||
@ -26,7 +28,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
|||||||
public override void OnBeginMouseInspect()
|
public override void OnBeginMouseInspect()
|
||||||
{
|
{
|
||||||
SetupUIRaycast();
|
SetupUIRaycast();
|
||||||
InspectUnderMouse.Instance.objPathLabel.text = "";
|
MouseInspector.Instance.objPathLabel.text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ClearHitData()
|
public override void ClearHitData()
|
||||||
@ -38,6 +40,12 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
|||||||
{
|
{
|
||||||
LastHitObjects.Clear();
|
LastHitObjects.Clear();
|
||||||
LastHitObjects.AddRange(currentHitObjects);
|
LastHitObjects.AddRange(currentHitObjects);
|
||||||
|
RuntimeHelper.StartCoroutine(SetPanelActiveCoro());
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator SetPanelActiveCoro()
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
var panel = UIManager.GetPanel<UiInspectorResultsPanel>(UIManager.Panels.UIInspectorResults);
|
var panel = UIManager.GetPanel<UiInspectorResultsPanel>(UIManager.Panels.UIInspectorResults);
|
||||||
panel.SetActive(true);
|
panel.SetActive(true);
|
||||||
panel.ShowResults();
|
panel.ShowResults();
|
||||||
@ -70,9 +78,9 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (currentHitObjects.Any())
|
if (currentHitObjects.Any())
|
||||||
InspectUnderMouse.Instance.objNameLabel.text = $"Click to view UI Objects under mouse: {currentHitObjects.Count}";
|
MouseInspector.Instance.objNameLabel.text = $"Click to view UI Objects under mouse: {currentHitObjects.Count}";
|
||||||
else
|
else
|
||||||
InspectUnderMouse.Instance.objNameLabel.text = $"No UI objects under mouse.";
|
MouseInspector.Instance.objNameLabel.text = $"No UI objects under mouse.";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetupUIRaycast()
|
private static void SetupUIRaycast()
|
||||||
|
@ -41,7 +41,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
|||||||
if (!MainCamera)
|
if (!MainCamera)
|
||||||
{
|
{
|
||||||
ExplorerCore.LogWarning("No Main Camera was found, unable to inspect world!");
|
ExplorerCore.LogWarning("No Main Camera was found, unable to inspect world!");
|
||||||
InspectUnderMouse.Instance.StopInspect();
|
MouseInspector.Instance.StopInspect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
|||||||
if (hit.transform)
|
if (hit.transform)
|
||||||
OnHitGameObject(hit.transform.gameObject);
|
OnHitGameObject(hit.transform.gameObject);
|
||||||
else if (lastHitObject)
|
else if (lastHitObject)
|
||||||
InspectUnderMouse.Instance.ClearHitData();
|
MouseInspector.Instance.ClearHitData();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnHitGameObject(GameObject obj)
|
internal void OnHitGameObject(GameObject obj)
|
||||||
@ -59,8 +59,8 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
|||||||
if (obj != lastHitObject)
|
if (obj != lastHitObject)
|
||||||
{
|
{
|
||||||
lastHitObject = obj;
|
lastHitObject = obj;
|
||||||
InspectUnderMouse.Instance.objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
|
MouseInspector.Instance.objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
|
||||||
InspectUnderMouse.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
MouseInspector.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,29 +2,34 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityExplorer.Config;
|
|
||||||
using UnityExplorer.Runtime;
|
|
||||||
using UnityExplorer.CacheObject;
|
using UnityExplorer.CacheObject;
|
||||||
using UnityExplorer.CacheObject.Views;
|
using UnityExplorer.CacheObject.Views;
|
||||||
using UnityExplorer.UI.Panels;
|
using UnityExplorer.UI.Panels;
|
||||||
using UnityExplorer.UI.Widgets;
|
using UnityExplorer.UI.Widgets;
|
||||||
using UnityExplorer.UI;
|
|
||||||
using UniverseLib.UI.Widgets;
|
|
||||||
using UniverseLib.UI;
|
|
||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
using UniverseLib.Runtime;
|
using UniverseLib.UI;
|
||||||
using UniverseLib.UI.Models;
|
using UniverseLib.UI.Models;
|
||||||
|
using UniverseLib.UI.ObjectPool;
|
||||||
using UniverseLib.UI.Widgets.ScrollView;
|
using UniverseLib.UI.Widgets.ScrollView;
|
||||||
using UniverseLib.Utility;
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
namespace UnityExplorer.Inspectors
|
namespace UnityExplorer.Inspectors
|
||||||
{
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum MemberFilter
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Property = 1,
|
||||||
|
Field = 2,
|
||||||
|
Constructor = 4,
|
||||||
|
Method = 8,
|
||||||
|
All = Property | Field | Method | Constructor,
|
||||||
|
}
|
||||||
|
|
||||||
public class ReflectionInspector : InspectorBase, ICellPoolDataSource<CacheMemberCell>, ICacheObjectController
|
public class ReflectionInspector : InspectorBase, ICellPoolDataSource<CacheMemberCell>, ICacheObjectController
|
||||||
{
|
{
|
||||||
public CacheObjectBase ParentCacheObject { get; set; }
|
public CacheObjectBase ParentCacheObject { get; set; }
|
||||||
@ -32,43 +37,52 @@ namespace UnityExplorer.Inspectors
|
|||||||
public bool StaticOnly { get; internal set; }
|
public bool StaticOnly { get; internal set; }
|
||||||
public bool CanWrite => true;
|
public bool CanWrite => true;
|
||||||
|
|
||||||
|
public bool AutoUpdateWanted => autoUpdateToggle.isOn;
|
||||||
|
|
||||||
private List<CacheMember> members = new();
|
private List<CacheMember> members = new();
|
||||||
private readonly List<CacheMember> filteredMembers = new();
|
private readonly List<CacheMember> filteredMembers = new();
|
||||||
|
|
||||||
public bool AutoUpdateWanted => autoUpdateToggle.isOn;
|
private BindingFlags scopeFlagsFilter;
|
||||||
|
private string nameFilter;
|
||||||
|
|
||||||
private BindingFlags FlagsFilter;
|
private MemberFilter MemberFilter = MemberFilter.All;
|
||||||
private string NameFilter;
|
|
||||||
|
|
||||||
private MemberFlags MemberFilter = MemberFlags.All;
|
// Updating
|
||||||
private enum MemberFlags
|
|
||||||
{
|
private bool refreshWanted;
|
||||||
None = 0,
|
private string lastNameFilter;
|
||||||
Property = 1,
|
private BindingFlags lastFlagsFilter;
|
||||||
Field = 2,
|
private MemberFilter lastMemberFilter = MemberFilter.All;
|
||||||
Method = 4,
|
private float timeOfLastAutoUpdate;
|
||||||
All = 7
|
|
||||||
}
|
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
|
|
||||||
|
internal GameObject mainContentHolder;
|
||||||
|
private static int LeftGroupWidth { get; set; }
|
||||||
|
private static int RightGroupWidth { get; set; }
|
||||||
|
|
||||||
public ScrollPool<CacheMemberCell> MemberScrollPool { get; private set; }
|
public ScrollPool<CacheMemberCell> MemberScrollPool { get; private set; }
|
||||||
|
public int ItemCount => filteredMembers.Count;
|
||||||
|
|
||||||
|
public UnityObjectWidget UnityWidget;
|
||||||
|
|
||||||
public InputFieldRef HiddenNameText;
|
public InputFieldRef HiddenNameText;
|
||||||
public Text NameText;
|
public Text NameText;
|
||||||
public Text AssemblyText;
|
public Text AssemblyText;
|
||||||
private Toggle autoUpdateToggle;
|
private Toggle autoUpdateToggle;
|
||||||
|
|
||||||
private string currentBaseTabText;
|
internal string currentBaseTabText;
|
||||||
|
|
||||||
private readonly Color disabledButtonColor = new(0.24f, 0.24f, 0.24f);
|
|
||||||
private readonly Color enabledButtonColor = new(0.2f, 0.27f, 0.2f);
|
|
||||||
|
|
||||||
private readonly Dictionary<BindingFlags, ButtonRef> scopeFilterButtons = new();
|
private readonly Dictionary<BindingFlags, ButtonRef> scopeFilterButtons = new();
|
||||||
private readonly List<Toggle> memberTypeToggles = new();
|
private readonly List<Toggle> memberTypeToggles = new();
|
||||||
private InputFieldRef filterInputField;
|
private InputFieldRef filterInputField;
|
||||||
|
|
||||||
// Setup / return
|
// const
|
||||||
|
|
||||||
|
private readonly Color disabledButtonColor = new(0.24f, 0.24f, 0.24f);
|
||||||
|
private readonly Color enabledButtonColor = new(0.2f, 0.27f, 0.2f);
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
|
||||||
public override void OnBorrowedFromPool(object target)
|
public override void OnBorrowedFromPool(object target)
|
||||||
{
|
{
|
||||||
@ -104,10 +118,12 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
autoUpdateToggle.isOn = false;
|
autoUpdateToggle.isOn = false;
|
||||||
|
|
||||||
UnityObjectRef = null;
|
if (UnityWidget != null)
|
||||||
ComponentRef = null;
|
{
|
||||||
TextureRef = null;
|
UnityWidget.OnReturnToPool();
|
||||||
CleanupTextureViewer();
|
Pool.Return(UnityWidget.GetType(), UnityWidget);
|
||||||
|
this.UnityWidget = null;
|
||||||
|
}
|
||||||
|
|
||||||
base.OnReturnToPool();
|
base.OnReturnToPool();
|
||||||
}
|
}
|
||||||
@ -133,7 +149,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
currentBaseTabText = $"{prefix} {SignatureHighlighter.Parse(TargetType, false)}";
|
currentBaseTabText = $"{prefix} {SignatureHighlighter.Parse(TargetType, false)}";
|
||||||
Tab.TabText.text = currentBaseTabText;
|
Tab.TabText.text = currentBaseTabText;
|
||||||
NameText.text = SignatureHighlighter.Parse(TargetType, true);
|
NameText.text = SignatureHighlighter.Parse(TargetType, true);
|
||||||
HiddenNameText.Text = TargetType.FullName;
|
HiddenNameText.Text = SignatureHighlighter.RemoveHighlighting(NameText.text);
|
||||||
|
|
||||||
string asmText;
|
string asmText;
|
||||||
if (TargetType.Assembly is AssemblyBuilder || string.IsNullOrEmpty(TargetType.Assembly.Location))
|
if (TargetType.Assembly is AssemblyBuilder || string.IsNullOrEmpty(TargetType.Assembly.Location))
|
||||||
@ -142,18 +158,19 @@ namespace UnityExplorer.Inspectors
|
|||||||
asmText = Path.GetFileName(TargetType.Assembly.Location);
|
asmText = Path.GetFileName(TargetType.Assembly.Location);
|
||||||
AssemblyText.text = $"<color=grey>Assembly:</color> {asmText}";
|
AssemblyText.text = $"<color=grey>Assembly:</color> {asmText}";
|
||||||
|
|
||||||
// unity helpers
|
// Unity object helper widget
|
||||||
SetUnityTargets();
|
|
||||||
|
this.UnityWidget = UnityObjectWidget.GetUnityWidget(target, TargetType, this);
|
||||||
|
|
||||||
// Get cache members
|
// Get cache members
|
||||||
|
|
||||||
this.members = CacheMember.GetCacheMembers(Target, TargetType, this);
|
this.members = CacheMemberFactory.GetCacheMembers(Target, TargetType, this);
|
||||||
|
|
||||||
// reset filters
|
// reset filters
|
||||||
|
|
||||||
this.filterInputField.Text = "";
|
this.filterInputField.Text = string.Empty;
|
||||||
|
|
||||||
SetFilter("", StaticOnly ? BindingFlags.Static : BindingFlags.Instance);
|
SetFilter(string.Empty, StaticOnly ? BindingFlags.Static : BindingFlags.Default);
|
||||||
scopeFilterButtons[BindingFlags.Default].Component.gameObject.SetActive(!StaticOnly);
|
scopeFilterButtons[BindingFlags.Default].Component.gameObject.SetActive(!StaticOnly);
|
||||||
scopeFilterButtons[BindingFlags.Instance].Component.gameObject.SetActive(!StaticOnly);
|
scopeFilterButtons[BindingFlags.Instance].Component.gameObject.SetActive(!StaticOnly);
|
||||||
|
|
||||||
@ -165,12 +182,6 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
// Updating
|
// Updating
|
||||||
|
|
||||||
private bool refreshWanted;
|
|
||||||
private string lastNameFilter;
|
|
||||||
private BindingFlags lastFlagsFilter;
|
|
||||||
private MemberFlags lastMemberFilter = MemberFlags.All;
|
|
||||||
private float timeOfLastAutoUpdate;
|
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
if (!this.IsActive)
|
if (!this.IsActive)
|
||||||
@ -183,10 +194,10 @@ namespace UnityExplorer.Inspectors
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check filter changes or force-refresh
|
// check filter changes or force-refresh
|
||||||
if (refreshWanted || NameFilter != lastNameFilter || FlagsFilter != lastFlagsFilter || lastMemberFilter != MemberFilter)
|
if (refreshWanted || nameFilter != lastNameFilter || scopeFlagsFilter != lastFlagsFilter || lastMemberFilter != MemberFilter)
|
||||||
{
|
{
|
||||||
lastNameFilter = NameFilter;
|
lastNameFilter = nameFilter;
|
||||||
lastFlagsFilter = FlagsFilter;
|
lastFlagsFilter = scopeFlagsFilter;
|
||||||
lastMemberFilter = MemberFilter;
|
lastMemberFilter = MemberFilter;
|
||||||
|
|
||||||
FilterMembers();
|
FilterMembers();
|
||||||
@ -199,11 +210,8 @@ namespace UnityExplorer.Inspectors
|
|||||||
{
|
{
|
||||||
timeOfLastAutoUpdate = Time.realtimeSinceStartup;
|
timeOfLastAutoUpdate = Time.realtimeSinceStartup;
|
||||||
|
|
||||||
if (this.UnityObjectRef)
|
if (this.UnityWidget != null)
|
||||||
{
|
UnityWidget.Update();
|
||||||
nameInput.Text = UnityObjectRef.name;
|
|
||||||
this.Tab.TabText.text = $"{currentBaseTabText} \"{UnityObjectRef.name}\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AutoUpdateWanted)
|
if (AutoUpdateWanted)
|
||||||
UpdateDisplayedMembers();
|
UpdateDisplayedMembers();
|
||||||
@ -217,26 +225,26 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
// Filtering
|
// Filtering
|
||||||
|
|
||||||
public void SetFilter(string filter) => SetFilter(filter, FlagsFilter);
|
public void SetFilter(string name) => SetFilter(name, scopeFlagsFilter);
|
||||||
|
|
||||||
public void SetFilter(BindingFlags flagsFilter) => SetFilter(NameFilter, flagsFilter);
|
public void SetFilter(BindingFlags flags) => SetFilter(nameFilter, flags);
|
||||||
|
|
||||||
public void SetFilter(string nameFilter, BindingFlags flagsFilter)
|
public void SetFilter(string name, BindingFlags flags)
|
||||||
{
|
{
|
||||||
this.NameFilter = nameFilter;
|
this.nameFilter = name;
|
||||||
|
|
||||||
if (flagsFilter != FlagsFilter)
|
if (flags != scopeFlagsFilter)
|
||||||
{
|
{
|
||||||
var btn = scopeFilterButtons[FlagsFilter].Component;
|
var btn = scopeFilterButtons[scopeFlagsFilter].Component;
|
||||||
RuntimeHelper.SetColorBlock(btn, disabledButtonColor, disabledButtonColor * 1.3f);
|
RuntimeHelper.SetColorBlock(btn, disabledButtonColor, disabledButtonColor * 1.3f);
|
||||||
|
|
||||||
this.FlagsFilter = flagsFilter;
|
this.scopeFlagsFilter = flags;
|
||||||
btn = scopeFilterButtons[FlagsFilter].Component;
|
btn = scopeFilterButtons[scopeFlagsFilter].Component;
|
||||||
RuntimeHelper.SetColorBlock(btn, enabledButtonColor, enabledButtonColor * 1.3f);
|
RuntimeHelper.SetColorBlock(btn, enabledButtonColor, enabledButtonColor * 1.3f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMemberTypeToggled(MemberFlags flag, bool val)
|
private void OnMemberTypeToggled(MemberFilter flag, bool val)
|
||||||
{
|
{
|
||||||
if (!val)
|
if (!val)
|
||||||
MemberFilter &= ~flag;
|
MemberFilter &= ~flag;
|
||||||
@ -252,19 +260,20 @@ namespace UnityExplorer.Inspectors
|
|||||||
{
|
{
|
||||||
var member = members[i];
|
var member = members[i];
|
||||||
|
|
||||||
if (FlagsFilter != BindingFlags.Default)
|
if (scopeFlagsFilter != BindingFlags.Default)
|
||||||
{
|
{
|
||||||
if (FlagsFilter == BindingFlags.Instance && member.IsStatic
|
if (scopeFlagsFilter == BindingFlags.Instance && member.IsStatic
|
||||||
|| FlagsFilter == BindingFlags.Static && !member.IsStatic)
|
|| scopeFlagsFilter == BindingFlags.Static && !member.IsStatic)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((member is CacheMethod && !MemberFilter.HasFlag(MemberFlags.Method))
|
if ((member is CacheMethod && !MemberFilter.HasFlag(MemberFilter.Method))
|
||||||
|| (member is CacheField && !MemberFilter.HasFlag(MemberFlags.Field))
|
|| (member is CacheField && !MemberFilter.HasFlag(MemberFilter.Field))
|
||||||
|| (member is CacheProperty && !MemberFilter.HasFlag(MemberFlags.Property)))
|
|| (member is CacheProperty && !MemberFilter.HasFlag(MemberFilter.Property))
|
||||||
|
|| (member is CacheConstructor && !MemberFilter.HasFlag(MemberFilter.Constructor)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(NameFilter) && !member.NameForFiltering.ContainsIgnoreCase(NameFilter))
|
if (!string.IsNullOrEmpty(nameFilter) && !member.NameForFiltering.ContainsIgnoreCase(nameFilter))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
filteredMembers.Add(member);
|
filteredMembers.Add(member);
|
||||||
@ -293,8 +302,6 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
// Member cells
|
// Member cells
|
||||||
|
|
||||||
public int ItemCount => filteredMembers.Count;
|
|
||||||
|
|
||||||
public void OnCellBorrowed(CacheMemberCell cell) { } // not needed
|
public void OnCellBorrowed(CacheMemberCell cell) { } // not needed
|
||||||
|
|
||||||
public void SetCell(CacheMemberCell cell, int index)
|
public void SetCell(CacheMemberCell cell, int index)
|
||||||
@ -304,9 +311,6 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
// Cell layout (fake table alignment)
|
// Cell layout (fake table alignment)
|
||||||
|
|
||||||
private static int LeftGroupWidth { get; set; }
|
|
||||||
private static int RightGroupWidth { get; set; }
|
|
||||||
|
|
||||||
internal void SetLayouts()
|
internal void SetLayouts()
|
||||||
{
|
{
|
||||||
CalculateLayouts();
|
CalculateLayouts();
|
||||||
@ -337,8 +341,6 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
// UI Construction
|
// UI Construction
|
||||||
|
|
||||||
private GameObject mainContentHolder;
|
|
||||||
|
|
||||||
public override GameObject CreateContent(GameObject parent)
|
public override GameObject CreateContent(GameObject parent)
|
||||||
{
|
{
|
||||||
UIRoot = UIFactory.CreateVerticalGroup(parent, "ReflectionInspector", true, true, true, true, 5,
|
UIRoot = UIFactory.CreateVerticalGroup(parent, "ReflectionInspector", true, true, true, true, 5,
|
||||||
@ -379,8 +381,6 @@ namespace UnityExplorer.Inspectors
|
|||||||
AssemblyText = UIFactory.CreateLabel(UIRoot, "AssemblyLabel", "not set", TextAnchor.MiddleLeft);
|
AssemblyText = UIFactory.CreateLabel(UIRoot, "AssemblyLabel", "not set", TextAnchor.MiddleLeft);
|
||||||
UIFactory.SetLayoutElement(AssemblyText.gameObject, minHeight: 25, flexibleWidth: 9999);
|
UIFactory.SetLayoutElement(AssemblyText.gameObject, minHeight: 25, flexibleWidth: 9999);
|
||||||
|
|
||||||
ConstructUnityObjectRow();
|
|
||||||
|
|
||||||
mainContentHolder = UIFactory.CreateVerticalGroup(UIRoot, "MemberHolder", false, false, true, true, 5, new Vector4(2, 2, 2, 2),
|
mainContentHolder = UIFactory.CreateVerticalGroup(UIRoot, "MemberHolder", false, false, true, true, 5, new Vector4(2, 2, 2, 2),
|
||||||
new Color(0.12f, 0.12f, 0.12f));
|
new Color(0.12f, 0.12f, 0.12f));
|
||||||
UIFactory.SetLayoutElement(mainContentHolder, flexibleWidth: 9999, flexibleHeight: 9999);
|
UIFactory.SetLayoutElement(mainContentHolder, flexibleWidth: 9999, flexibleHeight: 9999);
|
||||||
@ -462,6 +462,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
AddMemberTypeToggle(rowObj, MemberTypes.Property, 90);
|
AddMemberTypeToggle(rowObj, MemberTypes.Property, 90);
|
||||||
AddMemberTypeToggle(rowObj, MemberTypes.Field, 70);
|
AddMemberTypeToggle(rowObj, MemberTypes.Field, 70);
|
||||||
AddMemberTypeToggle(rowObj, MemberTypes.Method, 90);
|
AddMemberTypeToggle(rowObj, MemberTypes.Method, 90);
|
||||||
|
AddMemberTypeToggle(rowObj, MemberTypes.Constructor, 110);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddScopeFilterButton(GameObject parent, BindingFlags flags, bool setAsActive = false)
|
private void AddScopeFilterButton(GameObject parent, BindingFlags flags, bool setAsActive = false)
|
||||||
@ -480,261 +481,30 @@ namespace UnityExplorer.Inspectors
|
|||||||
{
|
{
|
||||||
var toggleObj = UIFactory.CreateToggle(parent, "Toggle_" + type, out Toggle toggle, out Text toggleText);
|
var toggleObj = UIFactory.CreateToggle(parent, "Toggle_" + type, out Toggle toggle, out Text toggleText);
|
||||||
UIFactory.SetLayoutElement(toggleObj, minHeight: 25, minWidth: width);
|
UIFactory.SetLayoutElement(toggleObj, minHeight: 25, minWidth: width);
|
||||||
var color = type switch
|
string color = type switch
|
||||||
{
|
{
|
||||||
MemberTypes.Method => SignatureHighlighter.METHOD_INSTANCE,
|
MemberTypes.Method => SignatureHighlighter.METHOD_INSTANCE,
|
||||||
MemberTypes.Field => SignatureHighlighter.FIELD_INSTANCE,
|
MemberTypes.Field => SignatureHighlighter.FIELD_INSTANCE,
|
||||||
MemberTypes.Property => SignatureHighlighter.PROP_INSTANCE,
|
MemberTypes.Property => SignatureHighlighter.PROP_INSTANCE,
|
||||||
|
MemberTypes.Constructor => SignatureHighlighter.CLASS_INSTANCE,
|
||||||
_ => throw new NotImplementedException()
|
_ => throw new NotImplementedException()
|
||||||
};
|
};
|
||||||
toggleText.text = $"<color={color}>{type}</color>";
|
toggleText.text = $"<color={color}>{type}</color>";
|
||||||
|
|
||||||
toggle.graphic.TryCast<Image>().color = color.ToColor() * 0.65f;
|
toggle.graphic.TryCast<Image>().color = color.ToColor() * 0.65f;
|
||||||
|
|
||||||
MemberFlags flag;
|
MemberFilter flag = type switch
|
||||||
switch (type)
|
|
||||||
{
|
{
|
||||||
case MemberTypes.Method: flag = MemberFlags.Method; break;
|
MemberTypes.Method => MemberFilter.Method,
|
||||||
case MemberTypes.Property: flag = MemberFlags.Property; break;
|
MemberTypes.Property => MemberFilter.Property,
|
||||||
case MemberTypes.Field: flag = MemberFlags.Field; break;
|
MemberTypes.Field => MemberFilter.Field,
|
||||||
default: return;
|
MemberTypes.Constructor => MemberFilter.Constructor,
|
||||||
}
|
_ => throw new NotImplementedException()
|
||||||
|
};
|
||||||
|
|
||||||
toggle.onValueChanged.AddListener((bool val) => { OnMemberTypeToggled(flag, val); });
|
toggle.onValueChanged.AddListener((bool val) => { OnMemberTypeToggled(flag, val); });
|
||||||
|
|
||||||
memberTypeToggles.Add(toggle);
|
memberTypeToggles.Add(toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Todo should probably put this in a separate class or maybe as a widget
|
|
||||||
|
|
||||||
#region UNITY OBJECT SPECIFIC
|
|
||||||
|
|
||||||
// Unity object helpers
|
|
||||||
|
|
||||||
private UnityEngine.Object UnityObjectRef;
|
|
||||||
private Component ComponentRef;
|
|
||||||
private Texture2D TextureRef;
|
|
||||||
private bool TextureViewerWanted;
|
|
||||||
private GameObject unityObjectRow;
|
|
||||||
private ButtonRef gameObjectButton;
|
|
||||||
private InputFieldRef nameInput;
|
|
||||||
private InputFieldRef instanceIdInput;
|
|
||||||
private ButtonRef textureButton;
|
|
||||||
private GameObject textureViewer;
|
|
||||||
|
|
||||||
private void SetUnityTargets()
|
|
||||||
{
|
|
||||||
if (StaticOnly || !typeof(UnityEngine.Object).IsAssignableFrom(TargetType))
|
|
||||||
{
|
|
||||||
unityObjectRow.SetActive(false);
|
|
||||||
textureViewer.SetActive(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UnityObjectRef = (UnityEngine.Object)Target.TryCast(typeof(UnityEngine.Object));
|
|
||||||
unityObjectRow.SetActive(true);
|
|
||||||
|
|
||||||
nameInput.Text = UnityObjectRef.name;
|
|
||||||
instanceIdInput.Text = UnityObjectRef.GetInstanceID().ToString();
|
|
||||||
|
|
||||||
if (typeof(Component).IsAssignableFrom(TargetType))
|
|
||||||
{
|
|
||||||
ComponentRef = (Component)Target.TryCast(typeof(Component));
|
|
||||||
gameObjectButton.Component.gameObject.SetActive(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
gameObjectButton.Component.gameObject.SetActive(false);
|
|
||||||
|
|
||||||
if (typeof(Texture2D).IsAssignableFrom(TargetType))
|
|
||||||
{
|
|
||||||
TextureRef = (Texture2D)Target.TryCast(typeof(Texture2D));
|
|
||||||
textureButton.Component.gameObject.SetActive(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
textureButton.Component.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGameObjectButtonClicked()
|
|
||||||
{
|
|
||||||
if (!ComponentRef)
|
|
||||||
{
|
|
||||||
ExplorerCore.LogWarning("Component reference is null or destroyed!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
InspectorManager.Inspect(ComponentRef.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ToggleTextureViewer()
|
|
||||||
{
|
|
||||||
if (TextureViewerWanted)
|
|
||||||
{
|
|
||||||
// disable
|
|
||||||
TextureViewerWanted = false;
|
|
||||||
textureViewer.SetActive(false);
|
|
||||||
mainContentHolder.SetActive(true);
|
|
||||||
textureButton.ButtonText.text = "View Texture";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!textureImage.sprite)
|
|
||||||
{
|
|
||||||
// First show, need to create sprite for displaying texture
|
|
||||||
SetTextureViewer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable
|
|
||||||
TextureViewerWanted = true;
|
|
||||||
textureViewer.SetActive(true);
|
|
||||||
mainContentHolder.gameObject.SetActive(false);
|
|
||||||
textureButton.ButtonText.text = "Hide Texture";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UI construction
|
|
||||||
|
|
||||||
private void ConstructUnityObjectRow()
|
|
||||||
{
|
|
||||||
unityObjectRow = UIFactory.CreateUIObject("UnityObjectRow", UIRoot);
|
|
||||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(unityObjectRow, false, false, true, true, 5);
|
|
||||||
UIFactory.SetLayoutElement(unityObjectRow, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999);
|
|
||||||
|
|
||||||
textureButton = UIFactory.CreateButton(unityObjectRow, "TextureButton", "View Texture", new Color(0.2f, 0.2f, 0.2f));
|
|
||||||
UIFactory.SetLayoutElement(textureButton.Component.gameObject, minHeight: 25, minWidth: 150);
|
|
||||||
textureButton.OnClick += ToggleTextureViewer;
|
|
||||||
|
|
||||||
var nameLabel = UIFactory.CreateLabel(unityObjectRow, "NameLabel", "Name:", TextAnchor.MiddleLeft, Color.grey);
|
|
||||||
UIFactory.SetLayoutElement(nameLabel.gameObject, minHeight: 25, minWidth: 45, flexibleWidth: 0);
|
|
||||||
|
|
||||||
nameInput = UIFactory.CreateInputField(unityObjectRow, "NameInput", "untitled");
|
|
||||||
UIFactory.SetLayoutElement(nameInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 1000);
|
|
||||||
nameInput.Component.readOnly = true;
|
|
||||||
|
|
||||||
gameObjectButton = UIFactory.CreateButton(unityObjectRow, "GameObjectButton", "Inspect GameObject", new Color(0.2f, 0.2f, 0.2f));
|
|
||||||
UIFactory.SetLayoutElement(gameObjectButton.Component.gameObject, minHeight: 25, minWidth: 160);
|
|
||||||
gameObjectButton.OnClick += OnGameObjectButtonClicked;
|
|
||||||
|
|
||||||
var instanceLabel = UIFactory.CreateLabel(unityObjectRow, "InstanceLabel", "Instance ID:", TextAnchor.MiddleRight, Color.grey);
|
|
||||||
UIFactory.SetLayoutElement(instanceLabel.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 0);
|
|
||||||
|
|
||||||
instanceIdInput = UIFactory.CreateInputField(unityObjectRow, "InstanceIDInput", "ERROR");
|
|
||||||
UIFactory.SetLayoutElement(instanceIdInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 0);
|
|
||||||
instanceIdInput.Component.readOnly = true;
|
|
||||||
|
|
||||||
unityObjectRow.SetActive(false);
|
|
||||||
|
|
||||||
ConstructTextureHelper();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Texture viewer helper
|
|
||||||
|
|
||||||
private InputFieldRef textureSavePathInput;
|
|
||||||
private Image textureImage;
|
|
||||||
private LayoutElement textureImageLayout;
|
|
||||||
|
|
||||||
private void CleanupTextureViewer()
|
|
||||||
{
|
|
||||||
if (textureImage.sprite)
|
|
||||||
GameObject.Destroy(textureImage.sprite);
|
|
||||||
|
|
||||||
if (TextureViewerWanted)
|
|
||||||
ToggleTextureViewer();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ConstructTextureHelper()
|
|
||||||
{
|
|
||||||
textureViewer = UIFactory.CreateVerticalGroup(UIRoot, "TextureViewer", false, false, true, true, 2, new Vector4(5, 5, 5, 5),
|
|
||||||
new Color(0.1f, 0.1f, 0.1f));
|
|
||||||
UIFactory.SetLayoutElement(textureViewer, flexibleWidth: 9999, flexibleHeight: 9999);
|
|
||||||
|
|
||||||
// Save helper
|
|
||||||
|
|
||||||
var saveRowObj = UIFactory.CreateHorizontalGroup(textureViewer, "SaveRow", false, false, true, true, 2, new Vector4(2, 2, 2, 2),
|
|
||||||
new Color(0.1f, 0.1f, 0.1f));
|
|
||||||
|
|
||||||
var saveBtn = UIFactory.CreateButton(saveRowObj, "SaveButton", "Save .PNG", new Color(0.2f, 0.25f, 0.2f));
|
|
||||||
UIFactory.SetLayoutElement(saveBtn.Component.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 0);
|
|
||||||
saveBtn.OnClick += OnSaveTextureClicked;
|
|
||||||
|
|
||||||
textureSavePathInput = UIFactory.CreateInputField(saveRowObj, "SaveInput", "...");
|
|
||||||
UIFactory.SetLayoutElement(textureSavePathInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 9999);
|
|
||||||
|
|
||||||
// Actual texture viewer
|
|
||||||
|
|
||||||
var imageViewport = UIFactory.CreateVerticalGroup(textureViewer, "Viewport", false, false, true, true);
|
|
||||||
imageViewport.GetComponent<Image>().color = Color.white;
|
|
||||||
imageViewport.AddComponent<Mask>().showMaskGraphic = false;
|
|
||||||
|
|
||||||
var imageObj = UIFactory.CreateUIObject("Image", imageViewport);
|
|
||||||
var fitter = imageObj.AddComponent<ContentSizeFitter>();
|
|
||||||
fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
|
||||||
textureImage = imageObj.AddComponent<Image>();
|
|
||||||
textureImageLayout = UIFactory.SetLayoutElement(imageObj, flexibleWidth: 1, flexibleHeight: 1);
|
|
||||||
|
|
||||||
textureViewer.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetTextureViewer()
|
|
||||||
{
|
|
||||||
if (!this.TextureRef)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var name = TextureRef.name;
|
|
||||||
if (string.IsNullOrEmpty(name))
|
|
||||||
name = "untitled";
|
|
||||||
|
|
||||||
textureSavePathInput.Text = Path.Combine(ConfigManager.Default_Output_Path.Value, $"{name}.png");
|
|
||||||
|
|
||||||
var sprite = TextureHelper.CreateSprite(TextureRef);
|
|
||||||
textureImage.sprite = sprite;
|
|
||||||
|
|
||||||
textureImageLayout.preferredHeight = sprite.rect.height;
|
|
||||||
// not really working, its always stretched horizontally for some reason.
|
|
||||||
textureImageLayout.preferredWidth = sprite.rect.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnSaveTextureClicked()
|
|
||||||
{
|
|
||||||
if (!TextureRef)
|
|
||||||
{
|
|
||||||
ExplorerCore.LogWarning("Ref Texture is null, maybe it was destroyed?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(textureSavePathInput.Text))
|
|
||||||
{
|
|
||||||
ExplorerCore.LogWarning("Save path cannot be empty!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var path = textureSavePathInput.Text;
|
|
||||||
if (!path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
ExplorerCore.LogWarning("Desired save path must end with '.png'!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
path = IOUtility.EnsureValidFilePath(path);
|
|
||||||
|
|
||||||
if (File.Exists(path))
|
|
||||||
File.Delete(path);
|
|
||||||
|
|
||||||
var tex = TextureRef;
|
|
||||||
|
|
||||||
if (!TextureHelper.IsReadable(tex))
|
|
||||||
tex = TextureHelper.ForceReadTexture(tex);
|
|
||||||
|
|
||||||
byte[] data = TextureHelper.EncodeToPNG(tex);
|
|
||||||
File.WriteAllBytes(path, data);
|
|
||||||
|
|
||||||
if (tex != TextureRef)
|
|
||||||
{
|
|
||||||
// cleanup temp texture if we had to force-read it.
|
|
||||||
GameObject.Destroy(tex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,9 @@ namespace UnityExplorer
|
|||||||
public ConfigHandler ConfigHandler => _configHandler;
|
public ConfigHandler ConfigHandler => _configHandler;
|
||||||
public MelonLoaderConfigHandler _configHandler;
|
public MelonLoaderConfigHandler _configHandler;
|
||||||
|
|
||||||
public Action<object> OnLogMessage => MelonLogger.Msg;
|
public Action<object> OnLogMessage => LoggerInstance.Msg;
|
||||||
public Action<object> OnLogWarning => MelonLogger.Warning;
|
public Action<object> OnLogWarning => LoggerInstance.Warning;
|
||||||
public Action<object> OnLogError => MelonLogger.Error;
|
public Action<object> OnLogError => LoggerInstance.Error;
|
||||||
|
|
||||||
public override void OnApplicationStart()
|
public override void OnApplicationStart()
|
||||||
{
|
{
|
||||||
|
33
src/Loader/Standalone/Editor/ExplorerEditorBehaviour.cs
Normal file
33
src/Loader/Standalone/Editor/ExplorerEditorBehaviour.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#if STANDALONE
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace UnityExplorer.Loader.Standalone
|
||||||
|
{
|
||||||
|
public class ExplorerEditorBehaviour : MonoBehaviour
|
||||||
|
{
|
||||||
|
internal void Awake()
|
||||||
|
{
|
||||||
|
ExplorerEditorLoader.Initialize();
|
||||||
|
DontDestroyOnLoad(this);
|
||||||
|
this.gameObject.hideFlags = HideFlags.HideAndDontSave;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void OnDestroy()
|
||||||
|
{
|
||||||
|
OnApplicationQuit();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void OnApplicationQuit()
|
||||||
|
{
|
||||||
|
if (UI.UIManager.UIRoot)
|
||||||
|
Destroy(UI.UIManager.UIRoot.transform.root.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
41
src/Loader/Standalone/Editor/ExplorerEditorLoader.cs
Normal file
41
src/Loader/Standalone/Editor/ExplorerEditorLoader.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#if STANDALONE
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace UnityExplorer.Loader.Standalone
|
||||||
|
{
|
||||||
|
public class ExplorerEditorLoader : ExplorerStandalone
|
||||||
|
{
|
||||||
|
public static void Initialize()
|
||||||
|
{
|
||||||
|
Instance = new ExplorerEditorLoader();
|
||||||
|
OnLog += LogHandler;
|
||||||
|
Instance.configHandler = new StandaloneConfigHandler();
|
||||||
|
|
||||||
|
ExplorerCore.Init(Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LogHandler(string message, LogType logType)
|
||||||
|
{
|
||||||
|
switch (logType)
|
||||||
|
{
|
||||||
|
case LogType.Assert: Debug.LogError(message); break;
|
||||||
|
case LogType.Error: Debug.LogError(message); break;
|
||||||
|
case LogType.Exception: Debug.LogError(message); break;
|
||||||
|
case LogType.Log: Debug.Log(message); break;
|
||||||
|
case LogType.Warning: Debug.LogWarning(message); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void CheckExplorerFolder()
|
||||||
|
{
|
||||||
|
if (explorerFolder == null)
|
||||||
|
explorerFolder = Path.Combine(Application.dataPath, "UnityExplorer~");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
@ -5,9 +5,9 @@ using System.IO;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityExplorer.Config;
|
using UnityExplorer.Config;
|
||||||
using UnityExplorer.Loader.STANDALONE;
|
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UniverseLib.Input;
|
using UniverseLib.Input;
|
||||||
|
using UnityExplorer.Loader.Standalone;
|
||||||
#if CPP
|
#if CPP
|
||||||
using UnhollowerRuntimeLib;
|
using UnhollowerRuntimeLib;
|
||||||
#endif
|
#endif
|
||||||
@ -16,6 +16,33 @@ namespace UnityExplorer
|
|||||||
{
|
{
|
||||||
public class ExplorerStandalone : IExplorerLoader
|
public class ExplorerStandalone : IExplorerLoader
|
||||||
{
|
{
|
||||||
|
public static ExplorerStandalone Instance { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked whenever Explorer logs something. Subscribe to this to handle logging.
|
||||||
|
/// </summary>
|
||||||
|
public static event Action<string, LogType> OnLog;
|
||||||
|
|
||||||
|
public string UnhollowedModulesFolder => unhollowedPath;
|
||||||
|
private string unhollowedPath;
|
||||||
|
|
||||||
|
public ConfigHandler ConfigHandler => configHandler;
|
||||||
|
internal StandaloneConfigHandler configHandler;
|
||||||
|
|
||||||
|
public string ExplorerFolder
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
CheckExplorerFolder();
|
||||||
|
return explorerFolder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected static string explorerFolder;
|
||||||
|
|
||||||
|
Action<object> IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); };
|
||||||
|
Action<object> IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); };
|
||||||
|
Action<object> IExplorerLoader.OnLogError => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Error); };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this to initialize UnityExplorer without adding a log listener or Unhollowed modules path.
|
/// Call this to initialize UnityExplorer without adding a log listener or Unhollowed modules path.
|
||||||
/// The default Unhollowed path "UnityExplorer\Modules\" will be used.
|
/// The default Unhollowed path "UnityExplorer\Modules\" will be used.
|
||||||
@ -50,60 +77,33 @@ namespace UnityExplorer
|
|||||||
OnLog += logListener;
|
OnLog += logListener;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(unhollowedModulesPath) || !Directory.Exists(unhollowedModulesPath))
|
if (string.IsNullOrEmpty(unhollowedModulesPath) || !Directory.Exists(unhollowedModulesPath))
|
||||||
instance._unhollowedPath = Path.Combine(instance.ExplorerFolder, "Modules");
|
instance.unhollowedPath = Path.Combine(instance.ExplorerFolder, "Modules");
|
||||||
else
|
else
|
||||||
instance._unhollowedPath = unhollowedModulesPath;
|
instance.unhollowedPath = unhollowedModulesPath;
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExplorerStandalone Instance { get; private set; }
|
internal void Init()
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked whenever Explorer logs something. Subscribe to this to handle logging.
|
|
||||||
/// </summary>
|
|
||||||
public static event Action<string, LogType> OnLog;
|
|
||||||
|
|
||||||
public string UnhollowedModulesFolder => _unhollowedPath;
|
|
||||||
private string _unhollowedPath;
|
|
||||||
|
|
||||||
public ConfigHandler ConfigHandler => _configHandler;
|
|
||||||
private StandaloneConfigHandler _configHandler;
|
|
||||||
|
|
||||||
public string ExplorerFolder
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
CheckExplorerFolder();
|
|
||||||
return s_explorerFolder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static string s_explorerFolder;
|
|
||||||
|
|
||||||
Action<object> IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); };
|
|
||||||
Action<object> IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); };
|
|
||||||
Action<object> IExplorerLoader.OnLogError => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Error); };
|
|
||||||
|
|
||||||
private void Init()
|
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
_configHandler = new StandaloneConfigHandler();
|
configHandler = new StandaloneConfigHandler();
|
||||||
|
|
||||||
ExplorerCore.Init(this);
|
ExplorerCore.Init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckExplorerFolder()
|
protected virtual void CheckExplorerFolder()
|
||||||
{
|
{
|
||||||
if (s_explorerFolder == null)
|
if (explorerFolder == null)
|
||||||
{
|
{
|
||||||
s_explorerFolder =
|
explorerFolder =
|
||||||
Path.Combine(
|
Path.Combine(
|
||||||
Path.GetDirectoryName(
|
Path.GetDirectoryName(
|
||||||
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath)),
|
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath)),
|
||||||
"UnityExplorer");
|
"UnityExplorer");
|
||||||
|
|
||||||
if (!Directory.Exists(s_explorerFolder))
|
if (!Directory.Exists(explorerFolder))
|
||||||
Directory.CreateDirectory(s_explorerFolder);
|
Directory.CreateDirectory(explorerFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ using UnityEngine;
|
|||||||
using Tomlet;
|
using Tomlet;
|
||||||
using Tomlet.Models;
|
using Tomlet.Models;
|
||||||
|
|
||||||
namespace UnityExplorer.Loader.STANDALONE
|
namespace UnityExplorer.Loader.Standalone
|
||||||
{
|
{
|
||||||
public class StandaloneConfigHandler : ConfigHandler
|
public class StandaloneConfigHandler : ConfigHandler
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
Parent = parent;
|
Parent = parent;
|
||||||
|
|
||||||
SceneHandler.OnInspectedSceneChanged += SceneHandler_OnInspectedSceneChanged;
|
SceneHandler.OnInspectedSceneChanged += SceneHandler_OnInspectedSceneChanged;
|
||||||
SceneHandler.OnLoadedScenesChanged += SceneHandler_OnLoadedScenesChanged;
|
SceneHandler.OnLoadedScenesUpdated += SceneHandler_OnLoadedScenesUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override GameObject UIRoot => uiRoot;
|
public override GameObject UIRoot => uiRoot;
|
||||||
@ -64,7 +64,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
public void UpdateTree()
|
public void UpdateTree()
|
||||||
{
|
{
|
||||||
SceneHandler.Update();
|
SceneHandler.Update();
|
||||||
Tree.RefreshData(true);
|
Tree.RefreshData(true, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void JumpToTransform(Transform transform)
|
public void JumpToTransform(Transform transform)
|
||||||
@ -87,21 +87,21 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
Tree.JumpAndExpandToTransform(transform);
|
Tree.JumpAndExpandToTransform(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDropdownChanged(int value)
|
private void OnSceneSelectionDropdownChanged(int value)
|
||||||
{
|
{
|
||||||
if (value < 0 || SceneHandler.LoadedScenes.Count <= value)
|
if (value < 0 || SceneHandler.LoadedScenes.Count <= value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SceneHandler.SelectedScene = SceneHandler.LoadedScenes[value];
|
SceneHandler.SelectedScene = SceneHandler.LoadedScenes[value];
|
||||||
SceneHandler.Update();
|
SceneHandler.Update();
|
||||||
Tree.RefreshData(true);
|
Tree.RefreshData(true, true, true, false);
|
||||||
OnSelectedSceneChanged(SceneHandler.SelectedScene.Value);
|
OnSelectedSceneChanged(SceneHandler.SelectedScene.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SceneHandler_OnInspectedSceneChanged(Scene scene)
|
private void SceneHandler_OnInspectedSceneChanged(Scene scene)
|
||||||
{
|
{
|
||||||
if (!sceneToDropdownOption.ContainsKey(scene))
|
if (!sceneToDropdownOption.ContainsKey(scene))
|
||||||
PopulateSceneDropdown();
|
PopulateSceneDropdown(SceneHandler.LoadedScenes);
|
||||||
|
|
||||||
if (sceneToDropdownOption.ContainsKey(scene))
|
if (sceneToDropdownOption.ContainsKey(scene))
|
||||||
{
|
{
|
||||||
@ -122,17 +122,17 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
refreshRow.SetActive(!scene.IsValid());
|
refreshRow.SetActive(!scene.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SceneHandler_OnLoadedScenesChanged(List<Scene> loadedScenes)
|
private void SceneHandler_OnLoadedScenesUpdated(List<Scene> loadedScenes)
|
||||||
{
|
{
|
||||||
PopulateSceneDropdown();
|
PopulateSceneDropdown(loadedScenes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulateSceneDropdown()
|
private void PopulateSceneDropdown(List<Scene> loadedScenes)
|
||||||
{
|
{
|
||||||
sceneToDropdownOption.Clear();
|
sceneToDropdownOption.Clear();
|
||||||
sceneDropdown.options.Clear();
|
sceneDropdown.options.Clear();
|
||||||
|
|
||||||
foreach (var scene in SceneHandler.LoadedScenes)
|
foreach (var scene in loadedScenes)
|
||||||
{
|
{
|
||||||
if (sceneToDropdownOption.ContainsKey(scene))
|
if (sceneToDropdownOption.ContainsKey(scene))
|
||||||
continue;
|
continue;
|
||||||
@ -158,7 +158,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tree.CurrentFilter = input;
|
Tree.CurrentFilter = input;
|
||||||
Tree.RefreshData(true, true);
|
Tree.RefreshData(true, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TryLoadScene(LoadSceneMode mode, Dropdown allSceneDrop)
|
private void TryLoadScene(LoadSceneMode mode, Dropdown allSceneDrop)
|
||||||
@ -198,11 +198,11 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
var dropLabel = UIFactory.CreateLabel(dropRow, "SelectorLabel", "Scene:", TextAnchor.MiddleLeft, Color.cyan, false, 15);
|
var dropLabel = UIFactory.CreateLabel(dropRow, "SelectorLabel", "Scene:", TextAnchor.MiddleLeft, Color.cyan, false, 15);
|
||||||
UIFactory.SetLayoutElement(dropLabel.gameObject, minHeight: 25, minWidth: 60, flexibleWidth: 0);
|
UIFactory.SetLayoutElement(dropLabel.gameObject, minHeight: 25, minWidth: 60, flexibleWidth: 0);
|
||||||
|
|
||||||
var dropdownObj = UIFactory.CreateDropdown(dropRow, "SceneDropdown", out sceneDropdown, "<notset>", 13, OnDropdownChanged);
|
var dropdownObj = UIFactory.CreateDropdown(dropRow, "SceneDropdown", out sceneDropdown, "<notset>", 13, OnSceneSelectionDropdownChanged);
|
||||||
UIFactory.SetLayoutElement(dropdownObj, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999);
|
UIFactory.SetLayoutElement(dropdownObj, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999);
|
||||||
|
|
||||||
SceneHandler.Update();
|
SceneHandler.Update();
|
||||||
PopulateSceneDropdown();
|
PopulateSceneDropdown(SceneHandler.LoadedScenes);
|
||||||
sceneDropdown.captionText.text = sceneToDropdownOption.First().Value.text;
|
sceneDropdown.captionText.text = sceneToDropdownOption.First().Value.text;
|
||||||
|
|
||||||
// Filter row
|
// Filter row
|
||||||
@ -239,6 +239,17 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
|
|
||||||
refreshRow.SetActive(false);
|
refreshRow.SetActive(false);
|
||||||
|
|
||||||
|
// tree labels row
|
||||||
|
|
||||||
|
var labelsRow = UIFactory.CreateHorizontalGroup(toolbar, "LabelsRow", true, true, true, true, 2, new Vector4(2, 2, 2, 2));
|
||||||
|
UIFactory.SetLayoutElement(labelsRow, minHeight: 30, flexibleHeight: 0);
|
||||||
|
|
||||||
|
var nameLabel = UIFactory.CreateLabel(labelsRow, "NameLabel", "Name", TextAnchor.MiddleLeft, color: Color.grey);
|
||||||
|
UIFactory.SetLayoutElement(nameLabel.gameObject, flexibleWidth: 9999, minHeight: 25);
|
||||||
|
|
||||||
|
var indexLabel = UIFactory.CreateLabel(labelsRow, "IndexLabel", "Sibling Index", TextAnchor.MiddleLeft, fontSize: 12, color: Color.grey);
|
||||||
|
UIFactory.SetLayoutElement(indexLabel.gameObject, minWidth: 100, flexibleWidth: 0, minHeight: 25);
|
||||||
|
|
||||||
// Transform Tree
|
// Transform Tree
|
||||||
|
|
||||||
var scrollPool = UIFactory.CreateScrollPool<TransformCell>(uiRoot, "TransformTree", out GameObject scrollObj,
|
var scrollPool = UIFactory.CreateScrollPool<TransformCell>(uiRoot, "TransformTree", out GameObject scrollObj,
|
||||||
@ -248,7 +259,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
|
|
||||||
Tree = new TransformTree(scrollPool, GetRootEntries);
|
Tree = new TransformTree(scrollPool, GetRootEntries);
|
||||||
Tree.Init();
|
Tree.Init();
|
||||||
Tree.RefreshData(true, true);
|
Tree.RefreshData(true, true, true, false);
|
||||||
//scrollPool.Viewport.GetComponent<Mask>().enabled = false;
|
//scrollPool.Viewport.GetComponent<Mask>().enabled = false;
|
||||||
//UIRoot.GetComponent<Mask>().enabled = false;
|
//UIRoot.GetComponent<Mask>().enabled = false;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
get => selectedScene;
|
get => selectedScene;
|
||||||
internal set
|
internal set
|
||||||
{
|
{
|
||||||
if (selectedScene != null && selectedScene == value)
|
if (selectedScene.HasValue && selectedScene == value)
|
||||||
return;
|
return;
|
||||||
selectedScene = value;
|
selectedScene = value;
|
||||||
OnInspectedSceneChanged?.Invoke((Scene)selectedScene);
|
OnInspectedSceneChanged?.Invoke((Scene)selectedScene);
|
||||||
@ -30,7 +30,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
|
|
||||||
/// <summary>All currently loaded Scenes.</summary>
|
/// <summary>All currently loaded Scenes.</summary>
|
||||||
public static List<Scene> LoadedScenes { get; private set; } = new();
|
public static List<Scene> LoadedScenes { get; private set; } = new();
|
||||||
private static HashSet<Scene> previousLoadedScenes;
|
//private static HashSet<Scene> previousLoadedScenes;
|
||||||
|
|
||||||
/// <summary>The names of all scenes in the build settings, if they could be retrieved.</summary>
|
/// <summary>The names of all scenes in the build settings, if they could be retrieved.</summary>
|
||||||
public static List<string> AllSceneNames { get; private set; } = new();
|
public static List<string> AllSceneNames { get; private set; } = new();
|
||||||
@ -39,7 +39,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
public static event Action<Scene> OnInspectedSceneChanged;
|
public static event Action<Scene> OnInspectedSceneChanged;
|
||||||
|
|
||||||
/// <summary>Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change.</summary>
|
/// <summary>Invoked whenever the list of currently loaded Scenes changes. The argument contains all loaded scenes after the change.</summary>
|
||||||
public static event Action<List<Scene>> OnLoadedScenesChanged;
|
public static event Action<List<Scene>> OnLoadedScenesUpdated;
|
||||||
|
|
||||||
/// <summary>Generally will be 2, unless DontDestroyExists == false, then this will be 1.</summary>
|
/// <summary>Generally will be 2, unless DontDestroyExists == false, then this will be 1.</summary>
|
||||||
internal static int DefaultSceneCount => 1 + (DontDestroyExists ? 1 : 0);
|
internal static int DefaultSceneCount => 1 + (DontDestroyExists ? 1 : 0);
|
||||||
@ -84,23 +84,20 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
|
|
||||||
internal static void Update()
|
internal static void Update()
|
||||||
{
|
{
|
||||||
// check if the loaded scenes changed. always confirm DontDestroy / HideAndDontSave
|
// Inspected scene will exist if it's DontDestroyOnLoad or HideAndDontSave
|
||||||
int confirmedCount = DefaultSceneCount;
|
bool inspectedExists =
|
||||||
bool inspectedExists = (SelectedScene.HasValue && SelectedScene.Value.handle == -12)
|
SelectedScene.HasValue
|
||||||
|| (SelectedScene.HasValue && SelectedScene.Value.handle == -1);
|
&& ((DontDestroyExists && SelectedScene.Value.handle == -12)
|
||||||
|
|| SelectedScene.Value.handle == -1);
|
||||||
|
|
||||||
LoadedScenes.Clear();
|
LoadedScenes.Clear();
|
||||||
|
|
||||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||||
{
|
{
|
||||||
Scene scene = SceneManager.GetSceneAt(i);
|
Scene scene = SceneManager.GetSceneAt(i);
|
||||||
if (scene == default || !scene.isLoaded)
|
if (scene == default || !scene.isLoaded || !scene.IsValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If no changes yet, ensure the previous list contained the scene
|
|
||||||
if (previousLoadedScenes != null && previousLoadedScenes.Contains(scene))
|
|
||||||
confirmedCount++;
|
|
||||||
|
|
||||||
// If we have not yet confirmed inspectedExists, check if this scene is our currently inspected one.
|
// If we have not yet confirmed inspectedExists, check if this scene is our currently inspected one.
|
||||||
if (!inspectedExists && scene == SelectedScene)
|
if (!inspectedExists && scene == SelectedScene)
|
||||||
inspectedExists = true;
|
inspectedExists = true;
|
||||||
@ -112,17 +109,12 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
LoadedScenes.Add(new Scene { m_Handle = -12 });
|
LoadedScenes.Add(new Scene { m_Handle = -12 });
|
||||||
LoadedScenes.Add(new Scene { m_Handle = -1 });
|
LoadedScenes.Add(new Scene { m_Handle = -1 });
|
||||||
|
|
||||||
bool anyChange = confirmedCount != LoadedScenes.Count;
|
|
||||||
|
|
||||||
previousLoadedScenes = new HashSet<Scene>(LoadedScenes);
|
|
||||||
|
|
||||||
// Default to first scene if none selected or previous selection no longer exists.
|
// Default to first scene if none selected or previous selection no longer exists.
|
||||||
if (!inspectedExists)
|
if (!inspectedExists)
|
||||||
SelectedScene = LoadedScenes.First();
|
SelectedScene = LoadedScenes.First();
|
||||||
|
|
||||||
// Notify on the list changing at all
|
// Notify on the list changing at all
|
||||||
if (anyChange)
|
OnLoadedScenesUpdated?.Invoke(LoadedScenes);
|
||||||
OnLoadedScenesChanged?.Invoke(LoadedScenes);
|
|
||||||
|
|
||||||
// Finally, update the root objects list.
|
// Finally, update the root objects list.
|
||||||
if (SelectedScene != null && ((Scene)SelectedScene).IsValid())
|
if (SelectedScene != null && ((Scene)SelectedScene).IsValid())
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#if MONO
|
#if MONO
|
||||||
using System;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace UnityExplorer.Runtime
|
namespace UnityExplorer.Runtime
|
||||||
|
38
src/Runtime/UnityCrashPrevention.cs
Normal file
38
src/Runtime/UnityCrashPrevention.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityExplorer.CacheObject;
|
||||||
|
|
||||||
|
namespace UnityExplorer.Runtime
|
||||||
|
{
|
||||||
|
internal static class UnityCrashPrevention
|
||||||
|
{
|
||||||
|
internal static void Init()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ExplorerCore.Harmony.PatchAll(typeof(UnityCrashPrevention));
|
||||||
|
ExplorerCore.Log("Initialized UnityCrashPrevention.");
|
||||||
|
}
|
||||||
|
catch //(Exception ex)
|
||||||
|
{
|
||||||
|
//ExplorerCore.Log($"Exception setting up Canvas crash prevention patch: {ex}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// In Unity 2020 they introduced "Canvas.renderingDisplaySize".
|
||||||
|
// If you try to get the value on a Canvas which has a renderMode value of WorldSpace and no worldCamera set,
|
||||||
|
// the game will Crash (I think from Unity trying to read from null ptr).
|
||||||
|
[HarmonyPatch(typeof(Canvas), "renderingDisplaySize", MethodType.Getter)]
|
||||||
|
[HarmonyPrefix]
|
||||||
|
internal static void Prefix_Canvas_renderingDisplaySize(Canvas __instance)
|
||||||
|
{
|
||||||
|
if (__instance.renderMode == RenderMode.WorldSpace && !__instance.worldCamera)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Canvas is set to RenderMode.WorldSpace but not worldCamera is set, cannot get renderingDisplaySize.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -146,22 +146,22 @@ namespace UnityExplorer.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if CPP
|
#if CPP
|
||||||
|
public static Il2CppSystem.Collections.Generic.Dictionary<string, string> IL2CPP_Dict;
|
||||||
|
public static Il2CppSystem.Collections.Generic.HashSet<string> IL2CPP_HashSet;
|
||||||
public static Il2CppSystem.Collections.Generic.List<string> IL2CPP_ListString;
|
public static Il2CppSystem.Collections.Generic.List<string> IL2CPP_ListString;
|
||||||
|
public static Il2CppSystem.Collections.Hashtable IL2CPP_HashTable;
|
||||||
public static List<Il2CppSystem.Object> IL2CPP_listOfBoxedObjects;
|
public static List<Il2CppSystem.Object> IL2CPP_listOfBoxedObjects;
|
||||||
public static Il2CppStructArray<int> IL2CPP_structArray;
|
public static Il2CppStructArray<int> IL2CPP_structArray;
|
||||||
public static Il2CppReferenceArray<Il2CppSystem.Object> IL2CPP_ReferenceArray;
|
public static Il2CppReferenceArray<Il2CppSystem.Object> IL2CPP_ReferenceArray;
|
||||||
public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict;
|
public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict;
|
||||||
public static Il2CppSystem.Collections.IList IL2CPP_IList;
|
public static Il2CppSystem.Collections.IList IL2CPP_IList;
|
||||||
public static Dictionary<Il2CppSystem.String, Il2CppSystem.Object> CppBoxedDict;
|
public static Dictionary<Il2CppSystem.Object, Il2CppSystem.Object> IL2CPP_BoxedDict;
|
||||||
|
|
||||||
public static Il2CppSystem.Collections.Generic.HashSet<string> IL2CPP_HashSet;
|
public static Il2CppSystem.Object IL2CPP_BoxedInt;
|
||||||
public static Il2CppSystem.Collections.Generic.Dictionary<string, string> IL2CPP_Dict;
|
public static Il2CppSystem.Int32 IL2CPP_Int;
|
||||||
public static Il2CppSystem.Collections.Hashtable IL2CPP_HashTable;
|
public static Il2CppSystem.Decimal IL2CPP_Decimal;
|
||||||
public static Il2CppSystem.Object cppBoxedInt;
|
public static Il2CppSystem.Object IL2CPP_DecimalBoxed;
|
||||||
public static Il2CppSystem.Int32 cppInt;
|
public static Il2CppSystem.Object IL2CPP_Vector3Boxed;
|
||||||
public static Il2CppSystem.Decimal cppDecimal;
|
|
||||||
public static Il2CppSystem.Object cppDecimalBoxed;
|
|
||||||
public static Il2CppSystem.Object cppVector3Boxed;
|
|
||||||
public static string IL2CPP_systemString = "Test";
|
public static string IL2CPP_systemString = "Test";
|
||||||
public static Il2CppSystem.Object IL2CPP_objectString = "string boxed as cpp object";
|
public static Il2CppSystem.Object IL2CPP_objectString = "string boxed as cpp object";
|
||||||
public static Il2CppSystem.String IL2CPP_il2cppString = "string boxed as cpp string";
|
public static Il2CppSystem.String IL2CPP_il2cppString = "string boxed as cpp string";
|
||||||
@ -175,40 +175,41 @@ namespace UnityExplorer.Tests
|
|||||||
IL2CPP_Dict.Add("key2", "value2");
|
IL2CPP_Dict.Add("key2", "value2");
|
||||||
IL2CPP_Dict.Add("key3", "value3");
|
IL2CPP_Dict.Add("key3", "value3");
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 2: Il2Cpp Hashtable");
|
|
||||||
IL2CPP_HashTable = new Il2CppSystem.Collections.Hashtable();
|
|
||||||
IL2CPP_HashTable.Add("key1", "value1");
|
|
||||||
IL2CPP_HashTable.Add("key2", "value2");
|
|
||||||
IL2CPP_HashTable.Add("key3", "value3");
|
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 3: Il2Cpp IDictionary");
|
|
||||||
var dict2 = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
|
|
||||||
dict2.Add("key1", "value1");
|
|
||||||
IL2CPP_IDict = dict2.TryCast<Il2CppSystem.Collections.IDictionary>();
|
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 4: Il2Cpp List of Il2Cpp Object");
|
|
||||||
var list = new Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object>(5);
|
|
||||||
list.Add("one");
|
|
||||||
list.Add("two");
|
|
||||||
IL2CPP_IList = list.TryCast<Il2CppSystem.Collections.IList>();
|
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 5: Il2Cpp List of strings");
|
|
||||||
IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List<string>();
|
|
||||||
IL2CPP_ListString.Add("hello,");
|
|
||||||
IL2CPP_ListString.Add("world!");
|
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 6: Il2Cpp HashSet of strings");
|
ExplorerCore.Log($"IL2CPP 6: Il2Cpp HashSet of strings");
|
||||||
IL2CPP_HashSet = new Il2CppSystem.Collections.Generic.HashSet<string>();
|
IL2CPP_HashSet = new Il2CppSystem.Collections.Generic.HashSet<string>();
|
||||||
IL2CPP_HashSet.Add("one");
|
IL2CPP_HashSet.Add("one");
|
||||||
IL2CPP_HashSet.Add("two");
|
IL2CPP_HashSet.Add("two");
|
||||||
|
|
||||||
|
ExplorerCore.Log($"IL2CPP 2: Il2Cpp Hashtable");
|
||||||
|
IL2CPP_HashTable = new Il2CppSystem.Collections.Hashtable();
|
||||||
|
IL2CPP_HashTable.Add("key1", "value1");
|
||||||
|
IL2CPP_HashTable.Add("key2", "value2");
|
||||||
|
IL2CPP_HashTable.Add("key3", "value3");
|
||||||
|
|
||||||
|
ExplorerCore.Log($"IL2CPP 3: Il2Cpp IDictionary");
|
||||||
|
var dict2 = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
|
||||||
|
dict2.Add("key1", "value1");
|
||||||
|
IL2CPP_IDict = dict2.TryCast<Il2CppSystem.Collections.IDictionary>();
|
||||||
|
|
||||||
|
ExplorerCore.Log($"IL2CPP 4: Il2Cpp List of Il2Cpp Object");
|
||||||
|
var list = new Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object>(5);
|
||||||
|
list.Add("one");
|
||||||
|
list.Add("two");
|
||||||
|
IL2CPP_IList = list.TryCast<Il2CppSystem.Collections.IList>();
|
||||||
|
|
||||||
|
ExplorerCore.Log($"IL2CPP 5: Il2Cpp List of strings");
|
||||||
|
IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List<string>();
|
||||||
|
IL2CPP_ListString.Add("hello,");
|
||||||
|
IL2CPP_ListString.Add("world!");
|
||||||
|
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object");
|
ExplorerCore.Log($"IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object");
|
||||||
CppBoxedDict = new Dictionary<Il2CppSystem.String, Il2CppSystem.Object>();
|
IL2CPP_BoxedDict = new();
|
||||||
CppBoxedDict.Add("1", new Il2CppSystem.Int32 { m_value = 1 }.BoxIl2CppObject());
|
IL2CPP_BoxedDict[(Il2CppSystem.String)"one"] = new Il2CppSystem.Int32 { m_value = 1 }.BoxIl2CppObject();
|
||||||
CppBoxedDict.Add("2", new Il2CppSystem.Int32 { m_value = 2 }.BoxIl2CppObject());
|
IL2CPP_BoxedDict[(Il2CppSystem.String)"two"] = new Il2CppSystem.Int32 { m_value = 2 }.BoxIl2CppObject();
|
||||||
CppBoxedDict.Add("3", new Il2CppSystem.Int32 { m_value = 3 }.BoxIl2CppObject());
|
IL2CPP_BoxedDict[(Il2CppSystem.String)"three"] = new Il2CppSystem.Int32 { m_value = 3 }.BoxIl2CppObject();
|
||||||
CppBoxedDict.Add("4", new Il2CppSystem.Int32 { m_value = 4 }.BoxIl2CppObject());
|
IL2CPP_BoxedDict[(Il2CppSystem.String)"four"] = new Il2CppSystem.Int32 { m_value = 4 }.BoxIl2CppObject();
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 8: List of boxed Il2Cpp Objects");
|
ExplorerCore.Log($"IL2CPP 8: List of boxed Il2Cpp Objects");
|
||||||
IL2CPP_listOfBoxedObjects = new List<Il2CppSystem.Object>();
|
IL2CPP_listOfBoxedObjects = new List<Il2CppSystem.Object>();
|
||||||
IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String)"boxedString");
|
IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String)"boxedString");
|
||||||
@ -223,16 +224,16 @@ namespace UnityExplorer.Tests
|
|||||||
var boxedEnum = Il2CppSystem.Enum.Parse(cppType, "Color");
|
var boxedEnum = Il2CppSystem.Enum.Parse(cppType, "Color");
|
||||||
IL2CPP_listOfBoxedObjects.Add(boxedEnum);
|
IL2CPP_listOfBoxedObjects.Add(boxedEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
var structBox = Vector3.one.BoxIl2CppObject();
|
var structBox = Vector3.one.BoxIl2CppObject();
|
||||||
IL2CPP_listOfBoxedObjects.Add(structBox);
|
IL2CPP_listOfBoxedObjects.Add(structBox);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ExplorerCore.LogWarning($"Boxed enum test fail: {ex}");
|
ExplorerCore.LogWarning($"Boxed enum test fail: {ex}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 9: Il2Cpp struct array of ints");
|
ExplorerCore.Log($"IL2CPP 9: Il2Cpp struct array of ints");
|
||||||
IL2CPP_structArray = new UnhollowerBaseLib.Il2CppStructArray<int>(5);
|
IL2CPP_structArray = new UnhollowerBaseLib.Il2CppStructArray<int>(5);
|
||||||
IL2CPP_structArray[0] = 0;
|
IL2CPP_structArray[0] = 0;
|
||||||
@ -240,19 +241,19 @@ namespace UnityExplorer.Tests
|
|||||||
IL2CPP_structArray[2] = 2;
|
IL2CPP_structArray[2] = 2;
|
||||||
IL2CPP_structArray[3] = 3;
|
IL2CPP_structArray[3] = 3;
|
||||||
IL2CPP_structArray[4] = 4;
|
IL2CPP_structArray[4] = 4;
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 10: Il2Cpp reference array of boxed objects");
|
ExplorerCore.Log($"IL2CPP 10: Il2Cpp reference array of boxed objects");
|
||||||
IL2CPP_ReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Object>(3);
|
IL2CPP_ReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Object>(3);
|
||||||
IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject();
|
IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject();
|
||||||
IL2CPP_ReferenceArray[1] = null;
|
IL2CPP_ReferenceArray[1] = null;
|
||||||
IL2CPP_ReferenceArray[2] = (Il2CppSystem.String)"whats up";
|
IL2CPP_ReferenceArray[2] = (Il2CppSystem.String)"whats up";
|
||||||
|
|
||||||
ExplorerCore.Log($"IL2CPP 11: Misc il2cpp members");
|
ExplorerCore.Log($"IL2CPP 11: Misc il2cpp members");
|
||||||
cppBoxedInt = new Il2CppSystem.Int32() { m_value = 5 }.BoxIl2CppObject();
|
IL2CPP_BoxedInt = new Il2CppSystem.Int32() { m_value = 5 }.BoxIl2CppObject();
|
||||||
cppInt = new Il2CppSystem.Int32 { m_value = 420 };
|
IL2CPP_Int = new Il2CppSystem.Int32 { m_value = 420 };
|
||||||
cppDecimal = new Il2CppSystem.Decimal(1f);
|
IL2CPP_Decimal = new Il2CppSystem.Decimal(1f);
|
||||||
cppDecimalBoxed = new Il2CppSystem.Decimal(1f).BoxIl2CppObject();
|
IL2CPP_DecimalBoxed = new Il2CppSystem.Decimal(1f).BoxIl2CppObject();
|
||||||
cppVector3Boxed = Vector3.down.BoxIl2CppObject();
|
IL2CPP_Vector3Boxed = Vector3.down.BoxIl2CppObject();
|
||||||
|
|
||||||
ExplorerCore.Log($"Finished Init_Il2Cpp");
|
ExplorerCore.Log($"Finished Init_Il2Cpp");
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,10 @@ namespace UnityExplorer.UI
|
|||||||
public static int Width => ActiveDisplay.renderingWidth;
|
public static int Width => ActiveDisplay.renderingWidth;
|
||||||
public static int Height => ActiveDisplay.renderingHeight;
|
public static int Height => ActiveDisplay.renderingHeight;
|
||||||
|
|
||||||
public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition);
|
public static Vector3 MousePosition => Application.isEditor
|
||||||
|
? InputManager.MousePosition
|
||||||
|
: Display.RelativeMouseAt(InputManager.MousePosition);
|
||||||
|
|
||||||
public static bool MouseInTargetDisplay => MousePosition.z == ActiveDisplayIndex;
|
public static bool MouseInTargetDisplay => MousePosition.z == ActiveDisplayIndex;
|
||||||
|
|
||||||
private static Camera canvasCamera;
|
private static Camera canvasCamera;
|
||||||
|
@ -30,13 +30,13 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
public override int MinWidth => -1;
|
public override int MinWidth => -1;
|
||||||
public override int MinHeight => -1;
|
public override int MinHeight => -1;
|
||||||
|
|
||||||
public override bool CanDragAndResize => false;
|
public override bool CanDragAndResize => true;
|
||||||
public override bool ShouldSaveActiveState => false;
|
public override bool ShouldSaveActiveState => false;
|
||||||
public override bool NavButtonWanted => false;
|
public override bool NavButtonWanted => false;
|
||||||
|
|
||||||
public static ISuggestionProvider CurrentHandler { get; private set; }
|
public static ISuggestionProvider CurrentHandler { get; private set; }
|
||||||
|
|
||||||
public static ButtonListHandler<Suggestion, ButtonCell> dataHandler;
|
public static ButtonListHandler<Suggestion, ButtonCell> buttonListDataHandler;
|
||||||
public static ScrollPool<ButtonCell> scrollPool;
|
public static ScrollPool<ButtonCell> scrollPool;
|
||||||
private static GameObject navigationTipRow;
|
private static GameObject navigationTipRow;
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
{
|
{
|
||||||
base.UIRoot.SetActive(true);
|
base.UIRoot.SetActive(true);
|
||||||
base.UIRoot.transform.SetAsLastSibling();
|
base.UIRoot.transform.SetAsLastSibling();
|
||||||
dataHandler.RefreshData();
|
buttonListDataHandler.RefreshData();
|
||||||
scrollPool.Refresh(true, true);
|
scrollPool.Refresh(true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,20 +294,40 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
|
|
||||||
// UI Construction
|
// UI Construction
|
||||||
|
|
||||||
|
const float MIN_X = 0.42f;
|
||||||
|
const float MAX_Y = 0.6f;
|
||||||
|
|
||||||
protected internal override void DoSetDefaultPosAndAnchors()
|
protected internal override void DoSetDefaultPosAndAnchors()
|
||||||
{
|
{
|
||||||
Rect.pivot = new Vector2(0f, 1f);
|
Rect.pivot = new Vector2(0f, 1f);
|
||||||
Rect.anchorMin = new Vector2(0.42f, 0.4f);
|
Rect.anchorMin = new Vector2(MIN_X, 0.4f);
|
||||||
Rect.anchorMax = new Vector2(0.68f, 0.6f);
|
Rect.anchorMax = new Vector2(0.68f, MAX_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnFinishResize(RectTransform panel)
|
||||||
|
{
|
||||||
|
float xDiff = panel.anchorMin.x - MIN_X;
|
||||||
|
float yDiff = panel.anchorMax.y - MAX_Y;
|
||||||
|
|
||||||
|
if (xDiff != 0 || yDiff != 0)
|
||||||
|
{
|
||||||
|
panel.anchorMin = new(MIN_X, panel.anchorMin.y - yDiff);
|
||||||
|
panel.anchorMax = new(panel.anchorMax.x - xDiff, MAX_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnFinishResize(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ConstructPanelContent()
|
public override void ConstructPanelContent()
|
||||||
{
|
{
|
||||||
dataHandler = new ButtonListHandler<Suggestion, ButtonCell>(scrollPool, GetEntries, SetCell, ShouldDisplay, OnCellClicked);
|
// hide the titlebar
|
||||||
|
this.TitleBar.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
buttonListDataHandler = new ButtonListHandler<Suggestion, ButtonCell>(scrollPool, GetEntries, SetCell, ShouldDisplay, OnCellClicked);
|
||||||
|
|
||||||
scrollPool = UIFactory.CreateScrollPool<ButtonCell>(this.uiContent, "AutoCompleter", out GameObject scrollObj,
|
scrollPool = UIFactory.CreateScrollPool<ButtonCell>(this.uiContent, "AutoCompleter", out GameObject scrollObj,
|
||||||
out GameObject scrollContent);
|
out GameObject scrollContent);
|
||||||
scrollPool.Initialize(dataHandler);
|
scrollPool.Initialize(buttonListDataHandler);
|
||||||
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
|
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
|
||||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(scrollContent, true, false, true, false);
|
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(scrollContent, true, false, true, false);
|
||||||
|
|
@ -59,7 +59,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
// Inspect under mouse dropdown on title bar
|
// Inspect under mouse dropdown on title bar
|
||||||
|
|
||||||
var mouseDropdown = UIFactory.CreateDropdown(closeHolder, "MouseInspectDropdown", out MouseInspectDropdown, "Mouse Inspect", 14,
|
var mouseDropdown = UIFactory.CreateDropdown(closeHolder, "MouseInspectDropdown", out MouseInspectDropdown, "Mouse Inspect", 14,
|
||||||
InspectUnderMouse.OnDropdownSelect);
|
MouseInspector.OnDropdownSelect);
|
||||||
UIFactory.SetLayoutElement(mouseDropdown, minHeight: 25, minWidth: 140);
|
UIFactory.SetLayoutElement(mouseDropdown, minHeight: 25, minWidth: 140);
|
||||||
MouseInspectDropdown.options.Add(new Dropdown.OptionData("Mouse Inspect"));
|
MouseInspectDropdown.options.Add(new Dropdown.OptionData("Mouse Inspect"));
|
||||||
MouseInspectDropdown.options.Add(new Dropdown.OptionData("World"));
|
MouseInspectDropdown.options.Add(new Dropdown.OptionData("World"));
|
||||||
|
@ -471,6 +471,9 @@ namespace UnityExplorer.UI.Panels
|
|||||||
{
|
{
|
||||||
var text = UIFactory.CreateLabel(UIManager.UIRoot, "ResizeCursor", "↔", TextAnchor.MiddleCenter, Color.white, true, 35);
|
var text = UIFactory.CreateLabel(UIManager.UIRoot, "ResizeCursor", "↔", TextAnchor.MiddleCenter, Color.white, true, 35);
|
||||||
resizeCursorObj = text.gameObject;
|
resizeCursorObj = text.gameObject;
|
||||||
|
var outline = text.gameObject.AddComponent<Outline>();
|
||||||
|
outline.effectColor = Color.black;
|
||||||
|
outline.effectDistance = new(1, 1);
|
||||||
|
|
||||||
RectTransform rect = resizeCursorObj.GetComponent<RectTransform>();
|
RectTransform rect = resizeCursorObj.GetComponent<RectTransform>();
|
||||||
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 64);
|
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 64);
|
||||||
|
@ -108,22 +108,27 @@ namespace UnityExplorer.UI.Panels
|
|||||||
|
|
||||||
public override void SetActive(bool active)
|
public override void SetActive(bool active)
|
||||||
{
|
{
|
||||||
if (this.Enabled == active)
|
if (this.Enabled != active)
|
||||||
return;
|
|
||||||
|
|
||||||
base.SetActive(active);
|
|
||||||
|
|
||||||
if (!ApplyingSaveData)
|
|
||||||
SaveInternalData();
|
|
||||||
|
|
||||||
if (NavButtonWanted)
|
|
||||||
{
|
{
|
||||||
var color = active ? UniversalUI.EnabledButtonColor : UniversalUI.DisabledButtonColor;
|
base.SetActive(active);
|
||||||
RuntimeHelper.SetColorBlock(NavButton.Component, color, color * 1.2f);
|
|
||||||
|
if (!ApplyingSaveData)
|
||||||
|
SaveInternalData();
|
||||||
|
|
||||||
|
if (NavButtonWanted)
|
||||||
|
{
|
||||||
|
var color = active ? UniversalUI.EnabledButtonColor : UniversalUI.DisabledButtonColor;
|
||||||
|
RuntimeHelper.SetColorBlock(NavButton.Component, color, color * 1.2f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!active)
|
if (!active)
|
||||||
this.Dragger.WasDragging = false;
|
this.Dragger.WasDragging = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.UIRoot.transform.SetAsLastSibling();
|
||||||
|
InvokeOnPanelsReordered();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Destroy()
|
public override void Destroy()
|
||||||
|
@ -73,7 +73,7 @@ namespace UnityExplorer.UI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
UniversalUI.SetUIActive(ExplorerCore.GUID, value);
|
UniversalUI.SetUIActive(ExplorerCore.GUID, value);
|
||||||
UniversalUI.SetUIActive(InspectUnderMouse.UIBaseGUID, value);
|
UniversalUI.SetUIActive(MouseInspector.UIBaseGUID, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ namespace UnityExplorer.UI
|
|||||||
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
|
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
|
||||||
UIPanels.Add(Panels.Options, new OptionsPanel());
|
UIPanels.Add(Panels.Options, new OptionsPanel());
|
||||||
UIPanels.Add(Panels.UIInspectorResults, new UiInspectorResultsPanel());
|
UIPanels.Add(Panels.UIInspectorResults, new UiInspectorResultsPanel());
|
||||||
UIPanels.Add(Panels.MouseInspector, new InspectUnderMouse());
|
UIPanels.Add(Panels.MouseInspector, new MouseInspector());
|
||||||
|
|
||||||
foreach (var panel in UIPanels.Values)
|
foreach (var panel in UIPanels.Values)
|
||||||
panel.ConstructUI();
|
panel.ConstructUI();
|
||||||
@ -135,12 +135,9 @@ namespace UnityExplorer.UI
|
|||||||
if (!UIRoot)
|
if (!UIRoot)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if doing Mouse Inspect, update that and return.
|
// If we are doing a Mouse Inspect, we don't need to update anything else.
|
||||||
if (InspectUnderMouse.Inspecting)
|
if (MouseInspector.Instance.TryUpdate())
|
||||||
{
|
|
||||||
InspectUnderMouse.Instance.UpdateInspect();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Update Notification modal
|
// Update Notification modal
|
||||||
Notification.Update();
|
Notification.Update();
|
||||||
@ -187,26 +184,21 @@ namespace UnityExplorer.UI
|
|||||||
SetPanelActive(panel, !uiPanel.Enabled);
|
SetPanelActive(panel, !uiPanel.Enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetPanelActive(Panels panel, bool active)
|
public static void SetPanelActive(Panels panelType, bool active)
|
||||||
{
|
{
|
||||||
var obj = GetPanel(panel);
|
GetPanel(panelType)
|
||||||
SetPanelActive(obj, active);
|
.SetActive(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetPanelActive(UIPanel panel, bool active)
|
public static void SetPanelActive(UIPanel panel, bool active)
|
||||||
{
|
{
|
||||||
panel.SetActive(active);
|
panel.SetActive(active);
|
||||||
if (active)
|
|
||||||
{
|
|
||||||
panel.UIRoot.transform.SetAsLastSibling();
|
|
||||||
UIPanel.InvokeOnPanelsReordered();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SetPanelActive(Transform transform, bool value)
|
internal static void SetPanelActive(Transform transform, bool value)
|
||||||
{
|
{
|
||||||
if (UIPanel.transformToPanelDict.TryGetValue(transform.GetInstanceID(), out UIPanel panel))
|
if (UIPanel.transformToPanelDict.TryGetValue(transform.GetInstanceID(), out UIPanel panel))
|
||||||
SetPanelActive(panel, value);
|
panel.SetActive(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// navbar
|
// navbar
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
using UniverseLib.UI;
|
using UniverseLib.UI;
|
||||||
using UniverseLib.UI.Models;
|
using UniverseLib.UI.Models;
|
||||||
@ -67,7 +68,17 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
{
|
{
|
||||||
allowedTypes = new();
|
allowedTypes = new();
|
||||||
foreach (var entry in ReflectionUtility.AllTypes)
|
foreach (var entry in ReflectionUtility.AllTypes)
|
||||||
allowedTypes.Add(entry.Value);
|
{
|
||||||
|
// skip <PrivateImplementationDetails> and <AnonymousClass> classes
|
||||||
|
var type = entry.Value;
|
||||||
|
if (type.FullName.Contains("PrivateImplementationDetails")
|
||||||
|
|| type.FullName.Contains("DisplayClass")
|
||||||
|
|| type.FullName.Contains('<'))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allowedTypes.Add(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ using UniverseLib.UI;
|
|||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
using UnityExplorer.CacheObject;
|
using UnityExplorer.CacheObject;
|
||||||
using UniverseLib.UI.ObjectPool;
|
using UniverseLib.UI.ObjectPool;
|
||||||
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
namespace UnityExplorer.UI.Widgets
|
namespace UnityExplorer.UI.Widgets
|
||||||
{
|
{
|
||||||
@ -76,6 +77,9 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
public object[] TryParseArguments()
|
public object[] TryParseArguments()
|
||||||
{
|
{
|
||||||
|
if (!parameters.Any())
|
||||||
|
return ArgumentUtility.EmptyArgs;
|
||||||
|
|
||||||
object[] outArgs = new object[parameters.Length];
|
object[] outArgs = new object[parameters.Length];
|
||||||
|
|
||||||
for (int i = 0; i < parameters.Length; i++)
|
for (int i = 0; i < parameters.Length; i++)
|
||||||
|
@ -17,8 +17,9 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
public int ChildCount { get; internal set; }
|
public int ChildCount { get; internal set; }
|
||||||
public string Name { get; internal set; }
|
public string Name { get; internal set; }
|
||||||
public bool Enabled { get; internal set; }
|
public bool Enabled { get; internal set; }
|
||||||
|
public int SiblingIndex { get; internal set; }
|
||||||
|
|
||||||
public bool Expanded => Tree.IsCellExpanded(InstanceID);
|
public bool Expanded => Tree.IsTransformExpanded(InstanceID);
|
||||||
|
|
||||||
public CachedTransform(TransformTree tree, Transform transform, int depth, CachedTransform parent = null)
|
public CachedTransform(TransformTree tree, Transform transform, int depth, CachedTransform parent = null)
|
||||||
{
|
{
|
||||||
@ -26,27 +27,32 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
Value = transform;
|
Value = transform;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
InstanceID = transform.GetInstanceID();
|
InstanceID = transform.GetInstanceID();
|
||||||
|
SiblingIndex = transform.GetSiblingIndex();
|
||||||
Update(transform, depth);
|
Update(transform, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(Transform transform, int depth)
|
public bool Update(Transform transform, int depth)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool changed = false;
|
||||||
|
|
||||||
if (Value != transform
|
if (Value != transform
|
||||||
|| depth != Depth
|
|| depth != Depth
|
||||||
|| ChildCount != transform.childCount
|
|| ChildCount != transform.childCount
|
||||||
|| Name != transform.name
|
|| Name != transform.name
|
||||||
|| Enabled != transform.gameObject.activeSelf)
|
|| Enabled != transform.gameObject.activeSelf
|
||||||
|
|| SiblingIndex != transform.GetSiblingIndex())
|
||||||
{
|
{
|
||||||
|
changed = true;
|
||||||
|
|
||||||
Value = transform;
|
Value = transform;
|
||||||
Depth = depth;
|
Depth = depth;
|
||||||
ChildCount = transform.childCount;
|
ChildCount = transform.childCount;
|
||||||
Name = transform.name;
|
Name = transform.name;
|
||||||
Enabled = transform.gameObject.activeSelf;
|
Enabled = transform.gameObject.activeSelf;
|
||||||
ret = true;
|
SiblingIndex = transform.GetSiblingIndex();
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ using UniverseLib.UI;
|
|||||||
using UniverseLib.UI.Models;
|
using UniverseLib.UI.Models;
|
||||||
using UniverseLib.UI.Widgets;
|
using UniverseLib.UI.Widgets;
|
||||||
using UniverseLib.UI.Widgets.ScrollView;
|
using UniverseLib.UI.Widgets.ScrollView;
|
||||||
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
namespace UnityExplorer.UI.Widgets
|
namespace UnityExplorer.UI.Widgets
|
||||||
{
|
{
|
||||||
@ -36,6 +37,7 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
public ButtonRef ExpandButton;
|
public ButtonRef ExpandButton;
|
||||||
public ButtonRef NameButton;
|
public ButtonRef NameButton;
|
||||||
public Toggle EnabledToggle;
|
public Toggle EnabledToggle;
|
||||||
|
public InputFieldRef SiblingIndex;
|
||||||
|
|
||||||
public LayoutElement spacer;
|
public LayoutElement spacer;
|
||||||
|
|
||||||
@ -77,6 +79,15 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
||||||
|
|
||||||
|
if (!cached.Value.parent)
|
||||||
|
SiblingIndex.GameObject.SetActive(false);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SiblingIndex.GameObject.SetActive(true);
|
||||||
|
if (!SiblingIndex.Component.isFocused)
|
||||||
|
SiblingIndex.Text = cached.Value.GetSiblingIndex().ToString();
|
||||||
|
}
|
||||||
|
|
||||||
int childCount = cached.Value.childCount;
|
int childCount = cached.Value.childCount;
|
||||||
if (childCount > 0)
|
if (childCount > 0)
|
||||||
{
|
{
|
||||||
@ -97,6 +108,8 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
{
|
{
|
||||||
NameButton.ButtonText.text = $"[Destroyed]";
|
NameButton.ButtonText.text = $"[Destroyed]";
|
||||||
NameButton.ButtonText.color = Color.red;
|
NameButton.ButtonText.color = Color.red;
|
||||||
|
|
||||||
|
SiblingIndex.GameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +131,17 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
OnEnableToggled?.Invoke(cachedTransform);
|
OnEnableToggled?.Invoke(cachedTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSiblingIndexEndEdit(string input)
|
||||||
|
{
|
||||||
|
if (this.cachedTransform == null || !this.cachedTransform.Value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (int.TryParse(input.Trim(), out int index))
|
||||||
|
this.cachedTransform.Value.SetSiblingIndex(index);
|
||||||
|
|
||||||
|
this.SiblingIndex.Text = this.cachedTransform.Value.GetSiblingIndex().ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public GameObject CreateContent(GameObject parent)
|
public GameObject CreateContent(GameObject parent)
|
||||||
{
|
{
|
||||||
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
||||||
@ -129,7 +153,7 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
Rect.sizeDelta = new Vector2(25, 25);
|
Rect.sizeDelta = new Vector2(25, 25);
|
||||||
UIFactory.SetLayoutElement(UIRoot, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
UIFactory.SetLayoutElement(UIRoot, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
||||||
|
|
||||||
var spacerObj = UIFactory.CreateUIObject("Spacer", UIRoot, new Vector2(0, 0));
|
GameObject spacerObj = UIFactory.CreateUIObject("Spacer", UIRoot, new Vector2(0, 0));
|
||||||
UIFactory.SetLayoutElement(spacerObj, minWidth: 0, flexibleWidth: 0, minHeight: 0, flexibleHeight: 0);
|
UIFactory.SetLayoutElement(spacerObj, minWidth: 0, flexibleWidth: 0, minHeight: 0, flexibleHeight: 0);
|
||||||
this.spacer = spacerObj.GetComponent<LayoutElement>();
|
this.spacer = spacerObj.GetComponent<LayoutElement>();
|
||||||
|
|
||||||
@ -140,22 +164,39 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
// Enabled toggle
|
// Enabled toggle
|
||||||
|
|
||||||
var toggleObj = UIFactory.CreateToggle(UIRoot, "BehaviourToggle", out EnabledToggle, out var behavText, default, 17, 17);
|
GameObject toggleObj = UIFactory.CreateToggle(UIRoot, "BehaviourToggle", out EnabledToggle, out Text behavText, default, 17, 17);
|
||||||
UIFactory.SetLayoutElement(toggleObj, minHeight: 17, flexibleHeight: 0, minWidth: 17);
|
UIFactory.SetLayoutElement(toggleObj, minHeight: 17, flexibleHeight: 0, minWidth: 17);
|
||||||
EnabledToggle.onValueChanged.AddListener(OnEnableClicked);
|
EnabledToggle.onValueChanged.AddListener(OnEnableClicked);
|
||||||
|
|
||||||
// Name button
|
// Name button
|
||||||
|
|
||||||
NameButton = UIFactory.CreateButton(this.UIRoot, "NameButton", "Name", null);
|
GameObject nameBtnHolder = UIFactory.CreateHorizontalGroup(this.UIRoot, "NameButtonHolder",
|
||||||
|
false, false, true, true, childAlignment: TextAnchor.MiddleLeft);
|
||||||
|
UIFactory.SetLayoutElement(nameBtnHolder, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
||||||
|
nameBtnHolder.AddComponent<Mask>().showMaskGraphic = false;
|
||||||
|
|
||||||
|
NameButton = UIFactory.CreateButton(nameBtnHolder, "NameButton", "Name", null);
|
||||||
UIFactory.SetLayoutElement(NameButton.Component.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
UIFactory.SetLayoutElement(NameButton.Component.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
||||||
var nameLabel = NameButton.Component.GetComponentInChildren<Text>();
|
Text nameLabel = NameButton.Component.GetComponentInChildren<Text>();
|
||||||
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
nameLabel.alignment = TextAnchor.MiddleLeft;
|
nameLabel.alignment = TextAnchor.MiddleLeft;
|
||||||
|
|
||||||
Color normal = new Color(0.11f, 0.11f, 0.11f);
|
// Sibling index input
|
||||||
Color highlight = new Color(0.25f, 0.25f, 0.25f);
|
|
||||||
Color pressed = new Color(0.05f, 0.05f, 0.05f);
|
SiblingIndex = UIFactory.CreateInputField(this.UIRoot, "SiblingIndexInput", string.Empty);
|
||||||
Color disabled = new Color(1, 1, 1, 0);
|
SiblingIndex.Component.textComponent.fontSize = 11;
|
||||||
|
SiblingIndex.Component.textComponent.alignment = TextAnchor.MiddleRight;
|
||||||
|
Image siblingImage = SiblingIndex.GameObject.GetComponent<Image>();
|
||||||
|
siblingImage.color = new(0f, 0f, 0f, 0.25f);
|
||||||
|
UIFactory.SetLayoutElement(SiblingIndex.GameObject, 35, 20, 0, 0);
|
||||||
|
SiblingIndex.Component.GetOnEndEdit().AddListener(OnSiblingIndexEndEdit);
|
||||||
|
|
||||||
|
// Setup selectables
|
||||||
|
|
||||||
|
Color normal = new(0.11f, 0.11f, 0.11f);
|
||||||
|
Color highlight = new(0.25f, 0.25f, 0.25f);
|
||||||
|
Color pressed = new(0.05f, 0.05f, 0.05f);
|
||||||
|
Color disabled = new(1, 1, 1, 0);
|
||||||
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
|
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
|
||||||
RuntimeHelper.SetColorBlock(NameButton.Component, normal, highlight, pressed, disabled);
|
RuntimeHelper.SetColorBlock(NameButton.Component, normal, highlight, pressed, disabled);
|
||||||
|
|
||||||
|
@ -2,12 +2,9 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
using UniverseLib.UI.Widgets;
|
|
||||||
using UniverseLib.UI.Widgets.ScrollView;
|
using UniverseLib.UI.Widgets.ScrollView;
|
||||||
using UniverseLib.Utility;
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
@ -20,22 +17,36 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
public ScrollPool<TransformCell> ScrollPool;
|
public ScrollPool<TransformCell> ScrollPool;
|
||||||
|
|
||||||
|
// IMPORTANT CAVEAT WITH OrderedDictionary:
|
||||||
|
// While the performance is mostly good, there are two methods we should NEVER use:
|
||||||
|
// - Remove(object)
|
||||||
|
// - set_Item[object]
|
||||||
|
// These two methods have extremely bad performance due to using IndexOfKey(), which iterates the whole dictionary.
|
||||||
|
// Currently we do not use either of these methods, so everything should be constant time hash lookups.
|
||||||
|
// We DO make use of get_Item[object], get_Item[index], Add, Insert and RemoveAt, which OrderedDictionary perfectly meets our needs for.
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Key: UnityEngine.Transform instance ID<br/>
|
/// Key: UnityEngine.Transform instance ID<br/>
|
||||||
/// Value: CachedTransform
|
/// Value: CachedTransform
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal readonly OrderedDictionary cachedTransforms = new OrderedDictionary();
|
internal readonly OrderedDictionary cachedTransforms = new();
|
||||||
|
|
||||||
// for keeping track of which actual transforms are expanded or not, outside of the cache data.
|
// for keeping track of which actual transforms are expanded or not, outside of the cache data.
|
||||||
private readonly HashSet<int> expandedInstanceIDs = new HashSet<int>();
|
private readonly HashSet<int> expandedInstanceIDs = new();
|
||||||
private readonly HashSet<int> autoExpandedIDs = new HashSet<int>();
|
private readonly HashSet<int> autoExpandedIDs = new();
|
||||||
|
|
||||||
private readonly HashSet<int> visited = new HashSet<int>();
|
// state for Traverse parse
|
||||||
private bool needRefresh;
|
private readonly HashSet<int> visited = new();
|
||||||
|
private bool needRefreshUI;
|
||||||
private int displayIndex;
|
private int displayIndex;
|
||||||
|
int prevDisplayIndex;
|
||||||
|
|
||||||
public int ItemCount => cachedTransforms.Count;
|
private Coroutine refreshCoroutine;
|
||||||
|
private readonly Stopwatch traversedThisFrame = new();
|
||||||
|
|
||||||
|
// ScrollPool item count. PrevDisplayIndex is the highest index + 1 from our last traverse.
|
||||||
|
public int ItemCount => prevDisplayIndex;
|
||||||
|
|
||||||
|
// Search filter
|
||||||
public bool Filtering => !string.IsNullOrEmpty(currentFilter);
|
public bool Filtering => !string.IsNullOrEmpty(currentFilter);
|
||||||
private bool wasFiltering;
|
private bool wasFiltering;
|
||||||
|
|
||||||
@ -62,44 +73,24 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
GetRootEntriesMethod = getRootEntriesMethod;
|
GetRootEntriesMethod = getRootEntriesMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCellBorrowed(TransformCell cell)
|
// Initialize and reset
|
||||||
{
|
|
||||||
cell.OnExpandToggled += OnCellExpandToggled;
|
|
||||||
cell.OnGameObjectClicked += OnGameObjectClicked;
|
|
||||||
cell.OnEnableToggled += OnCellEnableToggled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGameObjectClicked(GameObject obj)
|
|
||||||
{
|
|
||||||
if (OnClickOverrideHandler != null)
|
|
||||||
OnClickOverrideHandler.Invoke(obj);
|
|
||||||
else
|
|
||||||
InspectorManager.Inspect(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCellExpandToggled(CachedTransform cache)
|
|
||||||
{
|
|
||||||
var instanceID = cache.InstanceID;
|
|
||||||
if (expandedInstanceIDs.Contains(instanceID))
|
|
||||||
expandedInstanceIDs.Remove(instanceID);
|
|
||||||
else
|
|
||||||
expandedInstanceIDs.Add(instanceID);
|
|
||||||
|
|
||||||
RefreshData(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCellEnableToggled(CachedTransform cache)
|
|
||||||
{
|
|
||||||
cache.Value.gameObject.SetActive(!cache.Value.gameObject.activeSelf);
|
|
||||||
|
|
||||||
RefreshData(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Must be called externally from owner of this TransformTree
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
ScrollPool.Initialize(this);
|
ScrollPool.Initialize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called to completely reset the tree, ie. switching inspected GameObject
|
||||||
|
public void Rebuild()
|
||||||
|
{
|
||||||
|
autoExpandedIDs.Clear();
|
||||||
|
expandedInstanceIDs.Clear();
|
||||||
|
|
||||||
|
RefreshData(true, true, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called to completely wipe our data (ie, GameObject inspector returning to pool)
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
this.cachedTransforms.Clear();
|
this.cachedTransforms.Clear();
|
||||||
@ -107,14 +98,21 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
autoExpandedIDs.Clear();
|
autoExpandedIDs.Clear();
|
||||||
expandedInstanceIDs.Clear();
|
expandedInstanceIDs.Clear();
|
||||||
this.ScrollPool.Refresh(true, true);
|
this.ScrollPool.Refresh(true, true);
|
||||||
|
if (refreshCoroutine != null)
|
||||||
|
{
|
||||||
|
RuntimeHelper.StopCoroutine(refreshCoroutine);
|
||||||
|
refreshCoroutine = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCellExpanded(int instanceID)
|
// Checks if the given Instance ID is expanded or not
|
||||||
|
public bool IsTransformExpanded(int instanceID)
|
||||||
{
|
{
|
||||||
return Filtering ? autoExpandedIDs.Contains(instanceID)
|
return Filtering ? autoExpandedIDs.Contains(instanceID)
|
||||||
: expandedInstanceIDs.Contains(instanceID);
|
: expandedInstanceIDs.Contains(instanceID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Jumps to a specific Transform in the tree and highlights it.
|
||||||
public void JumpAndExpandToTransform(Transform transform)
|
public void JumpAndExpandToTransform(Transform transform)
|
||||||
{
|
{
|
||||||
// make sure all parents of the object are expanded
|
// make sure all parents of the object are expanded
|
||||||
@ -128,8 +126,9 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
parent = parent.parent;
|
parent = parent.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh cached transforms (no UI rebuild yet)
|
// Refresh cached transforms (no UI rebuild yet).
|
||||||
RefreshData(false);
|
// Stop existing coroutine and do it oneshot.
|
||||||
|
RefreshData(false, false, true, true);
|
||||||
|
|
||||||
int transformID = transform.GetInstanceID();
|
int transformID = transform.GetInstanceID();
|
||||||
|
|
||||||
@ -162,62 +161,88 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
button.OnDeselect(null);
|
button.OnDeselect(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Rebuild()
|
// Perform a Traverse and optionally refresh the ScrollPool as well.
|
||||||
|
// If oneShot, then this happens instantly with no yield.
|
||||||
|
public void RefreshData(bool andRefreshUI, bool jumpToTop, bool stopExistingCoroutine, bool oneShot)
|
||||||
{
|
{
|
||||||
autoExpandedIDs.Clear();
|
if (refreshCoroutine != null)
|
||||||
expandedInstanceIDs.Clear();
|
{
|
||||||
|
if (stopExistingCoroutine)
|
||||||
|
{
|
||||||
|
RuntimeHelper.StopCoroutine(refreshCoroutine);
|
||||||
|
refreshCoroutine = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RefreshData(true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RefreshData(bool andReload = false, bool jumpToTop = false)
|
|
||||||
{
|
|
||||||
visited.Clear();
|
visited.Clear();
|
||||||
displayIndex = 0;
|
displayIndex = 0;
|
||||||
needRefresh = false;
|
needRefreshUI = false;
|
||||||
|
traversedThisFrame.Reset();
|
||||||
|
traversedThisFrame.Start();
|
||||||
|
|
||||||
var rootObjects = GetRootEntriesMethod.Invoke();
|
IEnumerable<GameObject> rootObjects = GetRootEntriesMethod.Invoke();
|
||||||
|
|
||||||
//int displayIndex = 0;
|
refreshCoroutine = RuntimeHelper.StartCoroutine(RefreshCoroutine(rootObjects, andRefreshUI, jumpToTop, oneShot));
|
||||||
foreach (var obj in rootObjects)
|
}
|
||||||
if (obj) Traverse(obj.transform);
|
|
||||||
|
// Coroutine for batched updates, max 2000 gameobjects per frame so FPS doesn't get tanked when there is like 100k gameobjects.
|
||||||
|
// if "oneShot", then this will NOT be batched (if we need an immediate full update).
|
||||||
|
IEnumerator RefreshCoroutine(IEnumerable<GameObject> rootObjects, bool andRefreshUI, bool jumpToTop, bool oneShot)
|
||||||
|
{
|
||||||
|
foreach (var gameObj in rootObjects)
|
||||||
|
{
|
||||||
|
if (gameObj)
|
||||||
|
{
|
||||||
|
var enumerator = Traverse(gameObj.transform, null, 0, oneShot);
|
||||||
|
while (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
if (!oneShot)
|
||||||
|
yield return enumerator.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prune displayed transforms that we didnt visit in that traverse
|
// Prune displayed transforms that we didnt visit in that traverse
|
||||||
for (int i = cachedTransforms.Count - 1; i >= 0; i--)
|
for (int i = cachedTransforms.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
var obj = (CachedTransform)cachedTransforms[i];
|
var cached = (CachedTransform)cachedTransforms[i];
|
||||||
if (!visited.Contains(obj.InstanceID))
|
if (!visited.Contains(cached.InstanceID))
|
||||||
{
|
{
|
||||||
cachedTransforms.Remove(obj.InstanceID);
|
cachedTransforms.RemoveAt(i);
|
||||||
needRefresh = true;
|
needRefreshUI = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needRefresh)
|
if (andRefreshUI && needRefreshUI)
|
||||||
return;
|
ScrollPool.Refresh(true, jumpToTop);
|
||||||
|
|
||||||
//displayedObjects.Clear();
|
prevDisplayIndex = displayIndex;
|
||||||
|
refreshCoroutine = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (andReload)
|
// Recursive method to check a Transform and its children (if expanded).
|
||||||
{
|
// Parent and depth can be null/default.
|
||||||
if (!jumpToTop)
|
private IEnumerator Traverse(Transform transform, CachedTransform parent, int depth, bool oneShot)
|
||||||
ScrollPool.Refresh(true);
|
|
||||||
else
|
|
||||||
ScrollPool.Refresh(true, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Traverse(Transform transform, CachedTransform parent = null, int depth = 0)
|
|
||||||
{
|
{
|
||||||
|
// Let's only tank 2ms of each frame (60->53fps)
|
||||||
|
if (traversedThisFrame.ElapsedMilliseconds > 2)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
traversedThisFrame.Reset();
|
||||||
|
traversedThisFrame.Start();
|
||||||
|
}
|
||||||
|
|
||||||
int instanceID = transform.GetInstanceID();
|
int instanceID = transform.GetInstanceID();
|
||||||
|
|
||||||
if (visited.Contains(instanceID))
|
if (visited.Contains(instanceID))
|
||||||
return;
|
yield break;
|
||||||
|
|
||||||
if (Filtering)
|
if (Filtering)
|
||||||
{
|
{
|
||||||
if (!FilterHierarchy(transform))
|
if (!FilterHierarchy(transform))
|
||||||
return;
|
yield break;
|
||||||
|
|
||||||
visited.Add(instanceID);
|
visited.Add(instanceID);
|
||||||
|
|
||||||
@ -231,12 +256,25 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
if (cachedTransforms.Contains(instanceID))
|
if (cachedTransforms.Contains(instanceID))
|
||||||
{
|
{
|
||||||
cached = (CachedTransform)cachedTransforms[(object)instanceID];
|
cached = (CachedTransform)cachedTransforms[(object)instanceID];
|
||||||
|
int prevSiblingIdx = cached.SiblingIndex;
|
||||||
if (cached.Update(transform, depth))
|
if (cached.Update(transform, depth))
|
||||||
needRefresh = true;
|
{
|
||||||
|
needRefreshUI = true;
|
||||||
|
|
||||||
|
// If the sibling index changed, we need to shuffle it in our cached transforms list.
|
||||||
|
if (prevSiblingIdx != cached.SiblingIndex)
|
||||||
|
{
|
||||||
|
cachedTransforms.Remove(instanceID);
|
||||||
|
if (cachedTransforms.Count <= displayIndex)
|
||||||
|
cachedTransforms.Add(instanceID, cached);
|
||||||
|
else
|
||||||
|
cachedTransforms.Insert(displayIndex, instanceID, cached);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
needRefresh = true;
|
needRefreshUI = true;
|
||||||
cached = new CachedTransform(this, transform, depth, parent);
|
cached = new CachedTransform(this, transform, depth, parent);
|
||||||
if (cachedTransforms.Count <= displayIndex)
|
if (cachedTransforms.Count <= displayIndex)
|
||||||
cachedTransforms.Add(instanceID, cached);
|
cachedTransforms.Add(instanceID, cached);
|
||||||
@ -246,10 +284,17 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
displayIndex++;
|
displayIndex++;
|
||||||
|
|
||||||
if (IsCellExpanded(instanceID) && cached.Value.childCount > 0)
|
if (IsTransformExpanded(instanceID) && cached.Value.childCount > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < transform.childCount; i++)
|
for (int i = 0; i < transform.childCount; i++)
|
||||||
Traverse(transform.GetChild(i), cached, depth + 1);
|
{
|
||||||
|
var enumerator = Traverse(transform.GetChild(i), cached, depth + 1, oneShot);
|
||||||
|
while (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
if (!oneShot)
|
||||||
|
yield return enumerator.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,13 +321,44 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
if (Filtering)
|
if (Filtering)
|
||||||
{
|
{
|
||||||
if (cell.cachedTransform.Name.ContainsIgnoreCase(currentFilter))
|
if (cell.cachedTransform.Name.ContainsIgnoreCase(currentFilter))
|
||||||
{
|
|
||||||
cell.NameButton.ButtonText.color = Color.green;
|
cell.NameButton.ButtonText.color = Color.green;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cell.Disable();
|
cell.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnCellBorrowed(TransformCell cell)
|
||||||
|
{
|
||||||
|
cell.OnExpandToggled += OnCellExpandToggled;
|
||||||
|
cell.OnGameObjectClicked += OnGameObjectClicked;
|
||||||
|
cell.OnEnableToggled += OnCellEnableToggled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGameObjectClicked(GameObject obj)
|
||||||
|
{
|
||||||
|
if (OnClickOverrideHandler != null)
|
||||||
|
OnClickOverrideHandler.Invoke(obj);
|
||||||
|
else
|
||||||
|
InspectorManager.Inspect(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCellExpandToggled(CachedTransform cache)
|
||||||
|
{
|
||||||
|
var instanceID = cache.InstanceID;
|
||||||
|
if (expandedInstanceIDs.Contains(instanceID))
|
||||||
|
expandedInstanceIDs.Remove(instanceID);
|
||||||
|
else
|
||||||
|
expandedInstanceIDs.Add(instanceID);
|
||||||
|
|
||||||
|
RefreshData(true, false, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCellEnableToggled(CachedTransform cache)
|
||||||
|
{
|
||||||
|
cache.Value.gameObject.SetActive(!cache.Value.gameObject.activeSelf);
|
||||||
|
|
||||||
|
RefreshData(true, false, true, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
409
src/UI/Widgets/UnityObjects/AudioClipWidget.cs
Normal file
409
src/UI/Widgets/UnityObjects/AudioClipWidget.cs
Normal file
@ -0,0 +1,409 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Config;
|
||||||
|
using UnityExplorer.Inspectors;
|
||||||
|
using UniverseLib;
|
||||||
|
using UniverseLib.UI;
|
||||||
|
using UniverseLib.UI.Models;
|
||||||
|
using UniverseLib.UI.ObjectPool;
|
||||||
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
|
namespace UnityExplorer.UI.Widgets
|
||||||
|
{
|
||||||
|
public class AudioClipWidget : UnityObjectWidget
|
||||||
|
{
|
||||||
|
static GameObject AudioPlayerObject;
|
||||||
|
static AudioSource Source;
|
||||||
|
static AudioClipWidget CurrentlyPlaying;
|
||||||
|
static Coroutine CurrentlyPlayingCoroutine;
|
||||||
|
static readonly string zeroLengthString = GetLengthString(0f);
|
||||||
|
|
||||||
|
public AudioClip RefAudioClip;
|
||||||
|
private string fullLengthText;
|
||||||
|
|
||||||
|
private ButtonRef toggleButton;
|
||||||
|
private bool audioPlayerWanted;
|
||||||
|
|
||||||
|
private GameObject audioPlayerRoot;
|
||||||
|
private ButtonRef playStopButton;
|
||||||
|
private Text progressLabel;
|
||||||
|
private GameObject saveObjectRow;
|
||||||
|
private InputFieldRef savePathInput;
|
||||||
|
private GameObject cantSaveRow;
|
||||||
|
|
||||||
|
public override void OnBorrowed(object target, Type targetType, ReflectionInspector inspector)
|
||||||
|
{
|
||||||
|
base.OnBorrowed(target, targetType, inspector);
|
||||||
|
|
||||||
|
this.audioPlayerRoot.transform.SetParent(inspector.UIRoot.transform);
|
||||||
|
this.audioPlayerRoot.transform.SetSiblingIndex(inspector.UIRoot.transform.childCount - 2);
|
||||||
|
|
||||||
|
RefAudioClip = target.TryCast<AudioClip>();
|
||||||
|
this.fullLengthText = GetLengthString(RefAudioClip.length);
|
||||||
|
|
||||||
|
if (RefAudioClip.loadType == AudioClipLoadType.DecompressOnLoad)
|
||||||
|
{
|
||||||
|
cantSaveRow.SetActive(false);
|
||||||
|
saveObjectRow.SetActive(true);
|
||||||
|
SetDefaultSavePath();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cantSaveRow.SetActive(true);
|
||||||
|
saveObjectRow.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResetProgressLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnReturnToPool()
|
||||||
|
{
|
||||||
|
RefAudioClip = null;
|
||||||
|
|
||||||
|
if (audioPlayerWanted)
|
||||||
|
ToggleAudioWidget();
|
||||||
|
|
||||||
|
if (CurrentlyPlaying == this)
|
||||||
|
StopClip();
|
||||||
|
|
||||||
|
this.audioPlayerRoot.transform.SetParent(Pool<AudioClipWidget>.Instance.InactiveHolder.transform);
|
||||||
|
|
||||||
|
base.OnReturnToPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToggleAudioWidget()
|
||||||
|
{
|
||||||
|
if (audioPlayerWanted)
|
||||||
|
{
|
||||||
|
audioPlayerWanted = false;
|
||||||
|
|
||||||
|
toggleButton.ButtonText.text = "Show Player";
|
||||||
|
audioPlayerRoot.SetActive(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
audioPlayerWanted = true;
|
||||||
|
|
||||||
|
toggleButton.ButtonText.text = "Hide Player";
|
||||||
|
audioPlayerRoot.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetDefaultSavePath()
|
||||||
|
{
|
||||||
|
string name = RefAudioClip.name;
|
||||||
|
if (string.IsNullOrEmpty(name))
|
||||||
|
name = "untitled";
|
||||||
|
savePathInput.Text = Path.Combine(ConfigManager.Default_Output_Path.Value, $"{name}.wav");
|
||||||
|
}
|
||||||
|
|
||||||
|
static string GetLengthString(float seconds)
|
||||||
|
{
|
||||||
|
TimeSpan ts = TimeSpan.FromSeconds(seconds);
|
||||||
|
|
||||||
|
StringBuilder sb = new();
|
||||||
|
|
||||||
|
if (ts.Hours > 0)
|
||||||
|
sb.Append($"{ts.Hours}:");
|
||||||
|
|
||||||
|
sb.Append($"{ts.Minutes:00}:");
|
||||||
|
sb.Append($"{ts.Seconds:00}:");
|
||||||
|
sb.Append($"{ts.Milliseconds:000}");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetProgressLabel()
|
||||||
|
{
|
||||||
|
this.progressLabel.text = $"{zeroLengthString} / {fullLengthText}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayStopClicked()
|
||||||
|
{
|
||||||
|
SetupAudioPlayer();
|
||||||
|
|
||||||
|
if (CurrentlyPlaying == this)
|
||||||
|
{
|
||||||
|
// we are playing a clip. stop it.
|
||||||
|
StopClip();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If something else is playing a clip, stop that.
|
||||||
|
if (CurrentlyPlaying != null)
|
||||||
|
CurrentlyPlaying.StopClip();
|
||||||
|
|
||||||
|
// we want to start playing a clip.
|
||||||
|
CurrentlyPlayingCoroutine = RuntimeHelper.StartCoroutine(PlayClipCoroutine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SetupAudioPlayer()
|
||||||
|
{
|
||||||
|
if (AudioPlayerObject)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AudioPlayerObject = new GameObject("UnityExplorer.AudioPlayer");
|
||||||
|
UnityEngine.Object.DontDestroyOnLoad(AudioPlayerObject);
|
||||||
|
AudioPlayerObject.hideFlags = HideFlags.HideAndDontSave;
|
||||||
|
AudioPlayerObject.transform.position = new(int.MinValue, int.MinValue); // move it as far away as possible
|
||||||
|
#if CPP
|
||||||
|
Source = AudioPlayerObject.AddComponent(UnhollowerRuntimeLib.Il2CppType.Of<AudioSource>()).TryCast<AudioSource>();
|
||||||
|
#else
|
||||||
|
Source = AudioPlayerObject.AddComponent<AudioSource>();
|
||||||
|
#endif
|
||||||
|
AudioPlayerObject.AddComponent<AudioListener>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator PlayClipCoroutine()
|
||||||
|
{
|
||||||
|
playStopButton.ButtonText.text = "Stop Clip";
|
||||||
|
CurrentlyPlaying = this;
|
||||||
|
Source.clip = this.RefAudioClip;
|
||||||
|
Source.Play();
|
||||||
|
|
||||||
|
while (Source.isPlaying)
|
||||||
|
{
|
||||||
|
progressLabel.text = $"{GetLengthString(Source.time)} / {fullLengthText}";
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentlyPlayingCoroutine = null;
|
||||||
|
StopClip();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopClip()
|
||||||
|
{
|
||||||
|
if (CurrentlyPlayingCoroutine != null)
|
||||||
|
RuntimeHelper.StopCoroutine(CurrentlyPlayingCoroutine);
|
||||||
|
|
||||||
|
Source.Stop();
|
||||||
|
CurrentlyPlaying = null;
|
||||||
|
CurrentlyPlayingCoroutine = null;
|
||||||
|
playStopButton.ButtonText.text = "Play Clip";
|
||||||
|
|
||||||
|
ResetProgressLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSaveClipClicked()
|
||||||
|
{
|
||||||
|
if (!RefAudioClip)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning("AudioClip is null, maybe it was destroyed?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(savePathInput.Text))
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning("Save path cannot be empty!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string path = savePathInput.Text;
|
||||||
|
if (!path.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
path += ".wav";
|
||||||
|
|
||||||
|
path = IOUtility.EnsureValidFilePath(path);
|
||||||
|
|
||||||
|
if (File.Exists(path))
|
||||||
|
File.Delete(path);
|
||||||
|
|
||||||
|
SavWav.Save(RefAudioClip, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override GameObject CreateContent(GameObject uiRoot)
|
||||||
|
{
|
||||||
|
GameObject ret = base.CreateContent(uiRoot);
|
||||||
|
|
||||||
|
// Toggle Button
|
||||||
|
|
||||||
|
toggleButton = UIFactory.CreateButton(UIRoot, "AudioWidgetToggleButton", "Show Player", new Color(0.2f, 0.3f, 0.2f));
|
||||||
|
toggleButton.Transform.SetSiblingIndex(0);
|
||||||
|
UIFactory.SetLayoutElement(toggleButton.Component.gameObject, minHeight: 25, minWidth: 170);
|
||||||
|
toggleButton.OnClick += ToggleAudioWidget;
|
||||||
|
|
||||||
|
// Actual widget
|
||||||
|
|
||||||
|
audioPlayerRoot = UIFactory.CreateVerticalGroup(uiRoot, "AudioWidget", false, false, true, true, spacing: 5);
|
||||||
|
UIFactory.SetLayoutElement(audioPlayerRoot, flexibleWidth: 9999, flexibleHeight: 50);
|
||||||
|
audioPlayerRoot.SetActive(false);
|
||||||
|
|
||||||
|
// Player
|
||||||
|
|
||||||
|
GameObject playerRow = UIFactory.CreateHorizontalGroup(audioPlayerRoot, "PlayerWidget", false, false, true, true,
|
||||||
|
spacing: 5, padding: new() { x = 3f, w = 3f, y = 3f, z = 3f });
|
||||||
|
|
||||||
|
playStopButton = UIFactory.CreateButton(playerRow, "PlayerButton", "Play", normalColor: new(0.2f, 0.4f, 0.2f));
|
||||||
|
playStopButton.OnClick += OnPlayStopClicked;
|
||||||
|
UIFactory.SetLayoutElement(playStopButton.GameObject, minWidth: 60, minHeight: 25);
|
||||||
|
|
||||||
|
progressLabel = UIFactory.CreateLabel(playerRow, "ProgressLabel", "0 / 0");
|
||||||
|
UIFactory.SetLayoutElement(progressLabel.gameObject, flexibleWidth: 9999, minHeight: 25);
|
||||||
|
|
||||||
|
ResetProgressLabel();
|
||||||
|
|
||||||
|
// Save helper
|
||||||
|
|
||||||
|
saveObjectRow = UIFactory.CreateHorizontalGroup(audioPlayerRoot, "SaveRow", false, false, true, true, 2, new Vector4(2, 2, 2, 2),
|
||||||
|
new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
|
||||||
|
ButtonRef saveBtn = UIFactory.CreateButton(saveObjectRow, "SaveButton", "Save .WAV", new Color(0.2f, 0.25f, 0.2f));
|
||||||
|
UIFactory.SetLayoutElement(saveBtn.Component.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 0);
|
||||||
|
saveBtn.OnClick += OnSaveClipClicked;
|
||||||
|
|
||||||
|
savePathInput = UIFactory.CreateInputField(saveObjectRow, "SaveInput", "...");
|
||||||
|
UIFactory.SetLayoutElement(savePathInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 9999);
|
||||||
|
|
||||||
|
// cant save label
|
||||||
|
cantSaveRow = UIFactory.CreateHorizontalGroup(audioPlayerRoot, "CantSaveRow", true, true, true, true);
|
||||||
|
UIFactory.SetLayoutElement(cantSaveRow, minHeight: 25, flexibleWidth: 9999);
|
||||||
|
UIFactory.CreateLabel(
|
||||||
|
cantSaveRow,
|
||||||
|
"CantSaveLabel",
|
||||||
|
"Cannot save this AudioClip as the data is compressed or streamed. Try a tool such as AssetRipper to unpack it.",
|
||||||
|
color: Color.grey);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region SavWav
|
||||||
|
|
||||||
|
// Copyright (c) 2012 Calvin Rien
|
||||||
|
// http://the.darktable.com
|
||||||
|
//
|
||||||
|
// This software is provided 'as-is', without any express or implied warranty. In
|
||||||
|
// no event will the authors be held liable for any damages arising from the use
|
||||||
|
// of this software.
|
||||||
|
//
|
||||||
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
|
// subject to the following restrictions:
|
||||||
|
//
|
||||||
|
// 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
// that you wrote the original software. If you use this software in a product,
|
||||||
|
// an acknowledgment in the product documentation would be appreciated but is not
|
||||||
|
// required.
|
||||||
|
//
|
||||||
|
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
// misrepresented as being the original software.
|
||||||
|
//
|
||||||
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
//
|
||||||
|
// =============================================================================
|
||||||
|
//
|
||||||
|
// derived from Gregorio Zanon's script
|
||||||
|
// http://forum.unity3d.com/threads/119295-Writing-AudioListener.GetOutputData-to-wav-problem?p=806734&viewfull=1#post806734
|
||||||
|
|
||||||
|
public static class SavWav
|
||||||
|
{
|
||||||
|
public const int HEADER_SIZE = 44;
|
||||||
|
public const float RESCALE_FACTOR = 32767; // to convert float to Int16
|
||||||
|
|
||||||
|
public static void Save(AudioClip clip, string filepath)
|
||||||
|
{
|
||||||
|
using FileStream fileStream = CreateEmpty(filepath);
|
||||||
|
|
||||||
|
ConvertAndWrite(fileStream, clip);
|
||||||
|
WriteHeader(fileStream, clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FileStream CreateEmpty(string filepath)
|
||||||
|
{
|
||||||
|
FileStream fileStream = new(filepath, FileMode.Create);
|
||||||
|
byte emptyByte = default;
|
||||||
|
|
||||||
|
for (int i = 0; i < HEADER_SIZE; i++) //preparing the header
|
||||||
|
fileStream.WriteByte(emptyByte);
|
||||||
|
|
||||||
|
return fileStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ConvertAndWrite(FileStream fileStream, AudioClip clip)
|
||||||
|
{
|
||||||
|
#if CPP
|
||||||
|
UnhollowerBaseLib.Il2CppStructArray<float> samples = new float[clip.samples * clip.channels];
|
||||||
|
AudioClip.GetData(clip, samples, clip.samples, 0);
|
||||||
|
#else
|
||||||
|
float[] samples = new float[clip.samples * clip.channels];
|
||||||
|
clip.GetData(samples, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int len = samples.Length;
|
||||||
|
|
||||||
|
// converting in 2 float[] steps to Int16[], then Int16[] to Byte[]
|
||||||
|
short[] intData = new short[len];
|
||||||
|
|
||||||
|
// bytesData array is twice the size of dataSource array because a float converted in Int16 is 2 bytes.
|
||||||
|
byte[] bytesData = new byte[len * 2];
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
intData[i] = (short)(samples[i] * RESCALE_FACTOR);
|
||||||
|
byte[] byteArr = BitConverter.GetBytes(intData[i]);
|
||||||
|
byteArr.CopyTo(bytesData, i * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileStream.Write(bytesData, 0, bytesData.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteHeader(FileStream stream, AudioClip clip)
|
||||||
|
{
|
||||||
|
int hz = clip.frequency;
|
||||||
|
int channels = clip.channels;
|
||||||
|
int samples = clip.samples;
|
||||||
|
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
byte[] riff = Encoding.UTF8.GetBytes("RIFF");
|
||||||
|
stream.Write(riff, 0, 4);
|
||||||
|
|
||||||
|
byte[] chunkSize = BitConverter.GetBytes(stream.Length - 8);
|
||||||
|
stream.Write(chunkSize, 0, 4);
|
||||||
|
|
||||||
|
byte[] wave = Encoding.ASCII.GetBytes("WAVE");
|
||||||
|
stream.Write(wave, 0, 4);
|
||||||
|
|
||||||
|
byte[] fmt = Encoding.ASCII.GetBytes("fmt ");
|
||||||
|
stream.Write(fmt, 0, 4);
|
||||||
|
|
||||||
|
byte[] subChunk1 = BitConverter.GetBytes(16);
|
||||||
|
stream.Write(subChunk1, 0, 4);
|
||||||
|
|
||||||
|
byte[] audioFormat = BitConverter.GetBytes(1);
|
||||||
|
stream.Write(audioFormat, 0, 2);
|
||||||
|
|
||||||
|
byte[] numChannels = BitConverter.GetBytes(channels);
|
||||||
|
stream.Write(numChannels, 0, 2);
|
||||||
|
|
||||||
|
byte[] sampleRate = BitConverter.GetBytes(hz);
|
||||||
|
stream.Write(sampleRate, 0, 4);
|
||||||
|
|
||||||
|
byte[] byteRate = BitConverter.GetBytes(hz * channels * 2); // sampleRate * bytesPerSample*number of channels, here 44100*2*2
|
||||||
|
stream.Write(byteRate, 0, 4);
|
||||||
|
|
||||||
|
ushort blockAlign = (ushort)(channels * 2);
|
||||||
|
stream.Write(BitConverter.GetBytes(blockAlign), 0, 2);
|
||||||
|
|
||||||
|
ushort bps = 16;
|
||||||
|
byte[] bitsPerSample = BitConverter.GetBytes(bps);
|
||||||
|
stream.Write(bitsPerSample, 0, 2);
|
||||||
|
|
||||||
|
byte[] datastring = Encoding.UTF8.GetBytes("data");
|
||||||
|
stream.Write(datastring, 0, 4);
|
||||||
|
|
||||||
|
byte[] subChunk2 = BitConverter.GetBytes(samples * channels * 2);
|
||||||
|
stream.Write(subChunk2, 0, 4);
|
||||||
|
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
244
src/UI/Widgets/UnityObjects/Texture2DWidget.cs
Normal file
244
src/UI/Widgets/UnityObjects/Texture2DWidget.cs
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Config;
|
||||||
|
using UnityExplorer.Inspectors;
|
||||||
|
using UnityExplorer.UI.Panels;
|
||||||
|
using UniverseLib;
|
||||||
|
using UniverseLib.Runtime;
|
||||||
|
using UniverseLib.UI;
|
||||||
|
using UniverseLib.UI.Models;
|
||||||
|
using UniverseLib.UI.ObjectPool;
|
||||||
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
|
namespace UnityExplorer.UI.Widgets
|
||||||
|
{
|
||||||
|
public class Texture2DWidget : UnityObjectWidget
|
||||||
|
{
|
||||||
|
private Texture2D TextureRef;
|
||||||
|
private float realWidth;
|
||||||
|
private float realHeight;
|
||||||
|
|
||||||
|
private bool textureViewerWanted;
|
||||||
|
private ButtonRef toggleButton;
|
||||||
|
|
||||||
|
private GameObject textureViewerRoot;
|
||||||
|
private InputFieldRef savePathInput;
|
||||||
|
private Image image;
|
||||||
|
private LayoutElement imageLayout;
|
||||||
|
|
||||||
|
public override void OnBorrowed(object target, Type targetType, ReflectionInspector inspector)
|
||||||
|
{
|
||||||
|
base.OnBorrowed(target, targetType, inspector);
|
||||||
|
|
||||||
|
TextureRef = target.TryCast<Texture2D>();
|
||||||
|
|
||||||
|
realWidth = TextureRef.width;
|
||||||
|
realHeight = TextureRef.height;
|
||||||
|
|
||||||
|
if (this.textureViewerRoot)
|
||||||
|
this.textureViewerRoot.transform.SetParent(inspector.UIRoot.transform);
|
||||||
|
|
||||||
|
InspectorPanel.Instance.Dragger.OnFinishResize += OnInspectorFinishResize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnReturnToPool()
|
||||||
|
{
|
||||||
|
InspectorPanel.Instance.Dragger.OnFinishResize -= OnInspectorFinishResize;
|
||||||
|
|
||||||
|
TextureRef = null;
|
||||||
|
|
||||||
|
if (image.sprite)
|
||||||
|
GameObject.Destroy(image.sprite);
|
||||||
|
|
||||||
|
if (textureViewerWanted)
|
||||||
|
ToggleTextureViewer();
|
||||||
|
|
||||||
|
if (this.textureViewerRoot)
|
||||||
|
this.textureViewerRoot.transform.SetParent(Pool<Texture2DWidget>.Instance.InactiveHolder.transform);
|
||||||
|
|
||||||
|
base.OnReturnToPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToggleTextureViewer()
|
||||||
|
{
|
||||||
|
if (textureViewerWanted)
|
||||||
|
{
|
||||||
|
// disable
|
||||||
|
textureViewerWanted = false;
|
||||||
|
textureViewerRoot.SetActive(false);
|
||||||
|
toggleButton.ButtonText.text = "View Texture";
|
||||||
|
|
||||||
|
ParentInspector.mainContentHolder.SetActive(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// enable
|
||||||
|
if (!image.sprite)
|
||||||
|
SetupTextureViewer();
|
||||||
|
|
||||||
|
SetImageSize();
|
||||||
|
|
||||||
|
textureViewerWanted = true;
|
||||||
|
textureViewerRoot.SetActive(true);
|
||||||
|
toggleButton.ButtonText.text = "Hide Texture";
|
||||||
|
|
||||||
|
ParentInspector.mainContentHolder.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupTextureViewer()
|
||||||
|
{
|
||||||
|
if (!this.TextureRef)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string name = TextureRef.name;
|
||||||
|
if (string.IsNullOrEmpty(name))
|
||||||
|
name = "untitled";
|
||||||
|
savePathInput.Text = Path.Combine(ConfigManager.Default_Output_Path.Value, $"{name}.png");
|
||||||
|
|
||||||
|
Sprite sprite = TextureHelper.CreateSprite(TextureRef);
|
||||||
|
image.sprite = sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInspectorFinishResize(RectTransform _)
|
||||||
|
{
|
||||||
|
SetImageSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetImageSize()
|
||||||
|
{
|
||||||
|
if (!imageLayout)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RuntimeHelper.StartCoroutine(SetImageSizeCoro());
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator SetImageSizeCoro()
|
||||||
|
{
|
||||||
|
// let unity rebuild layout etc
|
||||||
|
yield return null;
|
||||||
|
|
||||||
|
RectTransform imageRect = InspectorPanel.Instance.Rect;
|
||||||
|
|
||||||
|
float rectWidth = imageRect.rect.width - 25;
|
||||||
|
float rectHeight = imageRect.rect.height - 196;
|
||||||
|
|
||||||
|
// If our image is smaller than the viewport, just use 100% scaling
|
||||||
|
if (realWidth < rectWidth && realHeight < rectHeight)
|
||||||
|
{
|
||||||
|
imageLayout.minWidth = realWidth;
|
||||||
|
imageLayout.minHeight = realHeight;
|
||||||
|
}
|
||||||
|
else // we will need to scale down the image to fit
|
||||||
|
{
|
||||||
|
// get the ratio of our viewport dimensions to width and height
|
||||||
|
float viewWidthRatio = (float)((decimal)rectWidth / (decimal)realWidth);
|
||||||
|
float viewHeightRatio = (float)((decimal)rectHeight / (decimal)realHeight);
|
||||||
|
|
||||||
|
// if width needs to be scaled more than height
|
||||||
|
if (viewWidthRatio < viewHeightRatio)
|
||||||
|
{
|
||||||
|
imageLayout.minWidth = realWidth * viewWidthRatio;
|
||||||
|
imageLayout.minHeight = realHeight * viewWidthRatio;
|
||||||
|
}
|
||||||
|
else // if height needs to be scaled more than width
|
||||||
|
{
|
||||||
|
imageLayout.minWidth = realWidth * viewHeightRatio;
|
||||||
|
imageLayout.minHeight = realHeight * viewHeightRatio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSaveTextureClicked()
|
||||||
|
{
|
||||||
|
if (!TextureRef)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning("Texture is null, maybe it was destroyed?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(savePathInput.Text))
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning("Save path cannot be empty!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string path = savePathInput.Text;
|
||||||
|
if (!path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
path += ".png";
|
||||||
|
|
||||||
|
path = IOUtility.EnsureValidFilePath(path);
|
||||||
|
|
||||||
|
if (File.Exists(path))
|
||||||
|
File.Delete(path);
|
||||||
|
|
||||||
|
Texture2D tex = TextureRef;
|
||||||
|
if (!TextureHelper.IsReadable(tex))
|
||||||
|
tex = TextureHelper.ForceReadTexture(tex);
|
||||||
|
|
||||||
|
byte[] data = TextureHelper.EncodeToPNG(tex);
|
||||||
|
File.WriteAllBytes(path, data);
|
||||||
|
|
||||||
|
if (tex != TextureRef)
|
||||||
|
{
|
||||||
|
// cleanup temp texture if we had to force-read it.
|
||||||
|
GameObject.Destroy(tex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override GameObject CreateContent(GameObject uiRoot)
|
||||||
|
{
|
||||||
|
GameObject ret = base.CreateContent(uiRoot);
|
||||||
|
|
||||||
|
// Button
|
||||||
|
|
||||||
|
toggleButton = UIFactory.CreateButton(UIRoot, "TextureButton", "View Texture", new Color(0.2f, 0.3f, 0.2f));
|
||||||
|
toggleButton.Transform.SetSiblingIndex(0);
|
||||||
|
UIFactory.SetLayoutElement(toggleButton.Component.gameObject, minHeight: 25, minWidth: 150);
|
||||||
|
toggleButton.OnClick += ToggleTextureViewer;
|
||||||
|
|
||||||
|
// Texture viewer
|
||||||
|
|
||||||
|
textureViewerRoot = UIFactory.CreateVerticalGroup(uiRoot, "TextureViewer", false, false, true, true, 2, new Vector4(5, 5, 5, 5),
|
||||||
|
new Color(0.1f, 0.1f, 0.1f), childAlignment: TextAnchor.UpperLeft);
|
||||||
|
UIFactory.SetLayoutElement(textureViewerRoot, flexibleWidth: 9999, flexibleHeight: 9999);
|
||||||
|
|
||||||
|
// Save helper
|
||||||
|
|
||||||
|
GameObject saveRowObj = UIFactory.CreateHorizontalGroup(textureViewerRoot, "SaveRow", false, false, true, true, 2, new Vector4(2, 2, 2, 2),
|
||||||
|
new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
|
||||||
|
ButtonRef saveBtn = UIFactory.CreateButton(saveRowObj, "SaveButton", "Save .PNG", new Color(0.2f, 0.25f, 0.2f));
|
||||||
|
UIFactory.SetLayoutElement(saveBtn.Component.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 0);
|
||||||
|
saveBtn.OnClick += OnSaveTextureClicked;
|
||||||
|
|
||||||
|
savePathInput = UIFactory.CreateInputField(saveRowObj, "SaveInput", "...");
|
||||||
|
UIFactory.SetLayoutElement(savePathInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 9999);
|
||||||
|
|
||||||
|
// Actual texture viewer
|
||||||
|
|
||||||
|
GameObject imageViewport = UIFactory.CreateVerticalGroup(textureViewerRoot, "ImageViewport", false, false, true, true,
|
||||||
|
bgColor: new(1,1,1,0), childAlignment: TextAnchor.MiddleCenter);
|
||||||
|
UIFactory.SetLayoutElement(imageViewport, flexibleWidth: 9999, flexibleHeight: 9999);
|
||||||
|
|
||||||
|
GameObject imageHolder = UIFactory.CreateUIObject("ImageHolder", imageViewport);
|
||||||
|
imageLayout = UIFactory.SetLayoutElement(imageHolder, 1, 1, 0, 0);
|
||||||
|
|
||||||
|
var actualImageObj = UIFactory.CreateUIObject("ActualImage", imageHolder);
|
||||||
|
var actualRect = actualImageObj.GetComponent<RectTransform>();
|
||||||
|
actualRect.anchorMin = new(0, 0);
|
||||||
|
actualRect.anchorMax = new(1, 1);
|
||||||
|
image = actualImageObj.AddComponent<Image>();
|
||||||
|
|
||||||
|
textureViewerRoot.SetActive(false);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
src/UI/Widgets/UnityObjects/UnityObjectWidget.cs
Normal file
132
src/UI/Widgets/UnityObjects/UnityObjectWidget.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Inspectors;
|
||||||
|
using UniverseLib;
|
||||||
|
using UniverseLib.UI;
|
||||||
|
using UniverseLib.UI.Models;
|
||||||
|
using UniverseLib.UI.ObjectPool;
|
||||||
|
|
||||||
|
namespace UnityExplorer.UI.Widgets
|
||||||
|
{
|
||||||
|
public class UnityObjectWidget : IPooledObject
|
||||||
|
{
|
||||||
|
public UnityEngine.Object UnityObjectRef;
|
||||||
|
public Component ComponentRef;
|
||||||
|
public ReflectionInspector ParentInspector;
|
||||||
|
|
||||||
|
protected ButtonRef gameObjectButton;
|
||||||
|
protected InputFieldRef nameInput;
|
||||||
|
protected InputFieldRef instanceIdInput;
|
||||||
|
|
||||||
|
// IPooledObject
|
||||||
|
public GameObject UIRoot { get; set; }
|
||||||
|
public float DefaultHeight => -1;
|
||||||
|
|
||||||
|
public static UnityObjectWidget GetUnityWidget(object target, Type targetType, ReflectionInspector inspector)
|
||||||
|
{
|
||||||
|
if (!typeof(UnityEngine.Object).IsAssignableFrom(targetType))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
UnityObjectWidget ret;
|
||||||
|
|
||||||
|
if (targetType == typeof(Texture2D))
|
||||||
|
ret = Pool<Texture2DWidget>.Borrow();
|
||||||
|
else if (targetType == typeof(AudioClip))
|
||||||
|
ret = Pool<AudioClipWidget>.Borrow();
|
||||||
|
else
|
||||||
|
ret = Pool<UnityObjectWidget>.Borrow();
|
||||||
|
|
||||||
|
ret.OnBorrowed(target, targetType, inspector);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnBorrowed(object target, Type targetType, ReflectionInspector inspector)
|
||||||
|
{
|
||||||
|
this.ParentInspector = inspector ?? throw new ArgumentNullException(nameof(inspector));
|
||||||
|
|
||||||
|
if (!this.UIRoot)
|
||||||
|
CreateContent(inspector.UIRoot);
|
||||||
|
else
|
||||||
|
this.UIRoot.transform.SetParent(inspector.UIRoot.transform);
|
||||||
|
|
||||||
|
this.UIRoot.transform.SetSiblingIndex(inspector.UIRoot.transform.childCount - 2);
|
||||||
|
|
||||||
|
UnityObjectRef = (UnityEngine.Object)target.TryCast(typeof(UnityEngine.Object));
|
||||||
|
UIRoot.SetActive(true);
|
||||||
|
|
||||||
|
nameInput.Text = UnityObjectRef.name;
|
||||||
|
instanceIdInput.Text = UnityObjectRef.GetInstanceID().ToString();
|
||||||
|
|
||||||
|
if (typeof(Component).IsAssignableFrom(targetType))
|
||||||
|
{
|
||||||
|
ComponentRef = (Component)target.TryCast(typeof(Component));
|
||||||
|
gameObjectButton.Component.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gameObjectButton.Component.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnReturnToPool()
|
||||||
|
{
|
||||||
|
UnityObjectRef = null;
|
||||||
|
ComponentRef = null;
|
||||||
|
ParentInspector = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
|
||||||
|
public virtual void Update()
|
||||||
|
{
|
||||||
|
if (this.UnityObjectRef)
|
||||||
|
{
|
||||||
|
nameInput.Text = UnityObjectRef.name;
|
||||||
|
ParentInspector.Tab.TabText.text = $"{ParentInspector.currentBaseTabText} \"{UnityObjectRef.name}\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UI Listeners
|
||||||
|
|
||||||
|
private void OnGameObjectButtonClicked()
|
||||||
|
{
|
||||||
|
if (!ComponentRef)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning("Component reference is null or destroyed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InspectorManager.Inspect(ComponentRef.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// UI construction
|
||||||
|
|
||||||
|
public virtual GameObject CreateContent(GameObject uiRoot)
|
||||||
|
{
|
||||||
|
UIRoot = UIFactory.CreateUIObject("UnityObjectRow", uiRoot);
|
||||||
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(UIRoot, false, false, true, true, 5);
|
||||||
|
UIFactory.SetLayoutElement(UIRoot, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999);
|
||||||
|
|
||||||
|
var nameLabel = UIFactory.CreateLabel(UIRoot, "NameLabel", "Name:", TextAnchor.MiddleLeft, Color.grey);
|
||||||
|
UIFactory.SetLayoutElement(nameLabel.gameObject, minHeight: 25, minWidth: 45, flexibleWidth: 0);
|
||||||
|
|
||||||
|
nameInput = UIFactory.CreateInputField(UIRoot, "NameInput", "untitled");
|
||||||
|
UIFactory.SetLayoutElement(nameInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 1000);
|
||||||
|
nameInput.Component.readOnly = true;
|
||||||
|
|
||||||
|
gameObjectButton = UIFactory.CreateButton(UIRoot, "GameObjectButton", "Inspect GameObject", new Color(0.2f, 0.2f, 0.2f));
|
||||||
|
UIFactory.SetLayoutElement(gameObjectButton.Component.gameObject, minHeight: 25, minWidth: 160);
|
||||||
|
gameObjectButton.OnClick += OnGameObjectButtonClicked;
|
||||||
|
|
||||||
|
var instanceLabel = UIFactory.CreateLabel(UIRoot, "InstanceLabel", "Instance ID:", TextAnchor.MiddleRight, Color.grey);
|
||||||
|
UIFactory.SetLayoutElement(instanceLabel.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 0);
|
||||||
|
|
||||||
|
instanceIdInput = UIFactory.CreateInputField(UIRoot, "InstanceIDInput", "ERROR");
|
||||||
|
UIFactory.SetLayoutElement(instanceIdInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 0);
|
||||||
|
instanceIdInput.Component.readOnly = true;
|
||||||
|
|
||||||
|
UIRoot.SetActive(false);
|
||||||
|
|
||||||
|
return UIRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -175,13 +175,13 @@
|
|||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UniverseLib.Mono">
|
<Reference Include="UniverseLib.Mono">
|
||||||
<HintPath>packages\UniverseLib.1.2.8\lib\net35\UniverseLib.Mono.dll</HintPath>
|
<HintPath>packages\UniverseLib.1.2.16\lib\net35\UniverseLib.Mono.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- Il2Cpp refs -->
|
<!-- Il2Cpp refs -->
|
||||||
<ItemGroup Condition="'$(IsCpp)'=='true'">
|
<ItemGroup Condition="'$(IsCpp)'=='true'">
|
||||||
<Reference Include="UniverseLib.IL2CPP">
|
<Reference Include="UniverseLib.IL2CPP">
|
||||||
<HintPath>packages\UniverseLib.1.2.8\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
|
<HintPath>packages\UniverseLib.1.2.16\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath>
|
<HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath>
|
||||||
@ -199,6 +199,10 @@
|
|||||||
<HintPath>..\lib\unhollowed\UnityEngine.dll</HintPath>
|
<HintPath>..\lib\unhollowed\UnityEngine.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.AudioModule">
|
||||||
|
<HintPath>..\lib\unhollowed\UnityEngine.AudioModule.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="UnityEngine.CoreModule">
|
<Reference Include="UnityEngine.CoreModule">
|
||||||
<HintPath>..\lib\unhollowed\UnityEngine.CoreModule.dll</HintPath>
|
<HintPath>..\lib\unhollowed\UnityEngine.CoreModule.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
@ -225,6 +229,8 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="CacheObject\CacheConstructor.cs" />
|
||||||
|
<Compile Include="CacheObject\CacheMemberFactory.cs" />
|
||||||
<Compile Include="Hooks\HookCell.cs" />
|
<Compile Include="Hooks\HookCell.cs" />
|
||||||
<Compile Include="Hooks\HookInstance.cs" />
|
<Compile Include="Hooks\HookInstance.cs" />
|
||||||
<Compile Include="Hooks\HookManager.cs" />
|
<Compile Include="Hooks\HookManager.cs" />
|
||||||
@ -246,7 +252,7 @@
|
|||||||
<Compile Include="Inspectors\GameObjectWidgets\ComponentCell.cs" />
|
<Compile Include="Inspectors\GameObjectWidgets\ComponentCell.cs" />
|
||||||
<Compile Include="Inspectors\GameObjectWidgets\ComponentList.cs" />
|
<Compile Include="Inspectors\GameObjectWidgets\ComponentList.cs" />
|
||||||
<Compile Include="Inspectors\GameObjectWidgets\GameObjectControls.cs" />
|
<Compile Include="Inspectors\GameObjectWidgets\GameObjectControls.cs" />
|
||||||
<Compile Include="Inspectors\InspectUnderMouse.cs" />
|
<Compile Include="Inspectors\MouseInspector.cs" />
|
||||||
<Compile Include="CSConsole\ConsoleController.cs" />
|
<Compile Include="CSConsole\ConsoleController.cs" />
|
||||||
<Compile Include="CacheObject\CacheField.cs" />
|
<Compile Include="CacheObject\CacheField.cs" />
|
||||||
<Compile Include="CacheObject\CacheKeyValuePair.cs" />
|
<Compile Include="CacheObject\CacheKeyValuePair.cs" />
|
||||||
@ -259,6 +265,9 @@
|
|||||||
<Compile Include="CacheObject\Views\CacheListEntryCell.cs" />
|
<Compile Include="CacheObject\Views\CacheListEntryCell.cs" />
|
||||||
<Compile Include="CacheObject\Views\CacheMemberCell.cs" />
|
<Compile Include="CacheObject\Views\CacheMemberCell.cs" />
|
||||||
<Compile Include="CacheObject\Views\CacheObjectCell.cs" />
|
<Compile Include="CacheObject\Views\CacheObjectCell.cs" />
|
||||||
|
<Compile Include="Loader\Standalone\Editor\ExplorerEditorBehaviour.cs" />
|
||||||
|
<Compile Include="Loader\Standalone\Editor\ExplorerEditorLoader.cs" />
|
||||||
|
<Compile Include="Runtime\UnityCrashPrevention.cs" />
|
||||||
<Compile Include="UI\DisplayManager.cs" />
|
<Compile Include="UI\DisplayManager.cs" />
|
||||||
<Compile Include="UI\Notification.cs" />
|
<Compile Include="UI\Notification.cs" />
|
||||||
<Compile Include="UI\Panels\ClipboardPanel.cs" />
|
<Compile Include="UI\Panels\ClipboardPanel.cs" />
|
||||||
@ -311,7 +320,7 @@
|
|||||||
<Compile Include="UI\Panels\ObjectExplorerPanel.cs" />
|
<Compile Include="UI\Panels\ObjectExplorerPanel.cs" />
|
||||||
<Compile Include="UI\UIManager.cs" />
|
<Compile Include="UI\UIManager.cs" />
|
||||||
<Compile Include="UI\Panels\PanelDragger.cs" />
|
<Compile Include="UI\Panels\PanelDragger.cs" />
|
||||||
<Compile Include="UI\Widgets\AutoComplete\AutoCompleteModal.cs" />
|
<Compile Include="UI\Panels\AutoCompleteModal.cs" />
|
||||||
<Compile Include="UI\Widgets\AutoComplete\TypeCompleter.cs" />
|
<Compile Include="UI\Widgets\AutoComplete\TypeCompleter.cs" />
|
||||||
<Compile Include="ObjectExplorer\ObjectSearch.cs" />
|
<Compile Include="ObjectExplorer\ObjectSearch.cs" />
|
||||||
<Compile Include="ObjectExplorer\SceneExplorer.cs" />
|
<Compile Include="ObjectExplorer\SceneExplorer.cs" />
|
||||||
@ -321,6 +330,9 @@
|
|||||||
<Compile Include="UI\Widgets\TransformTree\CachedTransform.cs" />
|
<Compile Include="UI\Widgets\TransformTree\CachedTransform.cs" />
|
||||||
<Compile Include="UI\Widgets\TransformTree\TransformCell.cs" />
|
<Compile Include="UI\Widgets\TransformTree\TransformCell.cs" />
|
||||||
<Compile Include="UI\Widgets\TransformTree\TransformTree.cs" />
|
<Compile Include="UI\Widgets\TransformTree\TransformTree.cs" />
|
||||||
|
<Compile Include="UI\Widgets\UnityObjects\AudioClipWidget.cs" />
|
||||||
|
<Compile Include="UI\Widgets\UnityObjects\Texture2DWidget.cs" />
|
||||||
|
<Compile Include="UI\Widgets\UnityObjects\UnityObjectWidget.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="ILRepack.targets" />
|
<None Include="ILRepack.targets" />
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
|
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
|
||||||
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
|
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
|
||||||
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
|
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
|
||||||
<package id="UniverseLib" version="1.2.8" targetFramework="net35" />
|
<package id="UniverseLib" version="1.2.16" targetFramework="net35" />
|
||||||
<package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" />
|
<package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" />
|
||||||
</packages>
|
</packages>
|
Reference in New Issue
Block a user