mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 06:08:16 +08:00
a few tidy ups
This commit is contained in:
parent
c228d29707
commit
4aefe1c5a3
@ -56,10 +56,6 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
// note: "ValueType" is the Dictionary itself, TypeOfValues is the 'Dictionary.Values' type.
|
// note: "ValueType" is the Dictionary itself, TypeOfValues is the 'Dictionary.Values' type.
|
||||||
|
|
||||||
// make generic dictionary from key and value type
|
|
||||||
var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>)
|
|
||||||
.MakeGenericType(TypeOfKeys, TypeOfValues));
|
|
||||||
|
|
||||||
// get keys and values
|
// get keys and values
|
||||||
var keys = ValueType.GetProperty("Keys") .GetValue(Value);
|
var keys = ValueType.GetProperty("Keys") .GetValue(Value);
|
||||||
var values = ValueType.GetProperty("Values").GetValue(Value);
|
var values = ValueType.GetProperty("Values").GetValue(Value);
|
||||||
@ -68,27 +64,15 @@ namespace Explorer
|
|||||||
var keyList = new List<object>();
|
var keyList = new List<object>();
|
||||||
var valueList = new List<object>();
|
var valueList = new List<object>();
|
||||||
|
|
||||||
// get keys enumerator and store keys
|
// store entries with reflection
|
||||||
var keyEnumerator = keys.GetType().GetMethod("GetEnumerator").Invoke(keys, null);
|
EnumerateWithReflection(keys, keyList);
|
||||||
var keyCollectionType = keyEnumerator.GetType();
|
EnumerateWithReflection(values, valueList);
|
||||||
var keyMoveNext = keyCollectionType.GetMethod("MoveNext");
|
|
||||||
var keyCurrent = keyCollectionType.GetProperty("Current");
|
|
||||||
while ((bool)keyMoveNext.Invoke(keyEnumerator, null))
|
|
||||||
{
|
|
||||||
keyList.Add(keyCurrent.GetValue(keyEnumerator));
|
|
||||||
}
|
|
||||||
|
|
||||||
// get values enumerator and store values
|
// make actual mono dictionary
|
||||||
var valueEnumerator = values.GetType().GetMethod("GetEnumerator").Invoke(values, null);
|
var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>)
|
||||||
var valueCollectionType = valueEnumerator.GetType();
|
.MakeGenericType(TypeOfKeys, TypeOfValues));
|
||||||
var valueMoveNext = valueCollectionType.GetMethod("MoveNext");
|
|
||||||
var valueCurrent = valueCollectionType.GetProperty("Current");
|
|
||||||
while ((bool)valueMoveNext.Invoke(valueEnumerator, null))
|
|
||||||
{
|
|
||||||
valueList.Add(valueCurrent.GetValue(valueEnumerator));
|
|
||||||
}
|
|
||||||
|
|
||||||
// finally iterate into actual dictionary
|
// finally iterate into dictionary
|
||||||
for (int i = 0; i < keyList.Count; i++)
|
for (int i = 0; i < keyList.Count; i++)
|
||||||
{
|
{
|
||||||
dict.Add(keyList[i], valueList[i]);
|
dict.Add(keyList[i], valueList[i]);
|
||||||
@ -97,6 +81,22 @@ namespace Explorer
|
|||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EnumerateWithReflection(object collection, List<object> list)
|
||||||
|
{
|
||||||
|
// invoke GetEnumerator
|
||||||
|
var enumerator = collection.GetType().GetMethod("GetEnumerator").Invoke(collection, null);
|
||||||
|
// get the type of it
|
||||||
|
var enumeratorType = enumerator.GetType();
|
||||||
|
// reflect MoveNext and Current
|
||||||
|
var moveNext = enumeratorType.GetMethod("MoveNext");
|
||||||
|
var current = enumeratorType.GetProperty("Current");
|
||||||
|
// iterate
|
||||||
|
while ((bool)moveNext.Invoke(enumerator, null))
|
||||||
|
{
|
||||||
|
list.Add(current.GetValue(enumerator));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void GetGenericArguments()
|
private void GetGenericArguments()
|
||||||
{
|
{
|
||||||
if (this.MemInfo != null)
|
if (this.MemInfo != null)
|
||||||
|
@ -50,7 +50,7 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||||
if (GUILayout.Button("<color=yellow>" + label + "</color>", new GUILayoutOption[] { GUILayout.Width(width) }))
|
if (GUILayout.Button("<color=yellow>" + label + "</color>", new GUILayoutOption[] { GUILayout.Width(width - 15) }))
|
||||||
{
|
{
|
||||||
WindowManager.InspectObject(Value, out bool _);
|
WindowManager.InspectObject(Value, out bool _);
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,7 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static PropertyInfo m_scrollViewStatesInfo;
|
private static PropertyInfo m_scrollViewStatesInfo;
|
||||||
|
|
||||||
// ======= public methods ======= //
|
|
||||||
|
|
||||||
public static Rect GetLastRect()
|
public static Rect GetLastRect()
|
||||||
{
|
{
|
||||||
@ -73,7 +72,6 @@ namespace Explorer
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
ScrollFailed = true;
|
ScrollFailed = true;
|
||||||
return scroll;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,10 +84,8 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MelonLogger.Log("Exception on GUIUnstrip.BeginScrollView_ImplLayout: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace);
|
MelonLogger.Log("Exception on manual BeginScrollView: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace);
|
||||||
|
|
||||||
ManualUnstripFailed = true;
|
ManualUnstripFailed = true;
|
||||||
return scroll;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +109,6 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======= private methods ======= //
|
|
||||||
|
|
||||||
private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical,
|
private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical,
|
||||||
GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options)
|
GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user