* Unstrip fixes and cleanups
This commit is contained in:
sinaioutlander
2020-10-14 20:47:19 +11:00
parent 680556d74e
commit 968546d43c
18 changed files with 1972 additions and 297 deletions

View File

@ -72,11 +72,11 @@ namespace Explorer.UI.Inspectors
public void DrawInstanceControls(Rect rect)
{
if (m_uObj)
{
GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
}
GUILayout.EndHorizontal();
//if (m_uObj)
//{
// GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
//}
//GUILayout.EndHorizontal();
if (m_uObj)
{
@ -89,13 +89,17 @@ namespace Explorer.UI.Inspectors
GUILayout.Label("GameObject:", new GUILayoutOption[] { GUILayout.Width(135) });
var charWidth = obj.name.Length * 15;
var maxWidth = rect.width - 350;
var labelWidth = charWidth < maxWidth ? charWidth : maxWidth;
if (GUILayout.Button("<color=#00FF00>" + obj.name + "</color>", new GUILayoutOption[] { GUILayout.Width(labelWidth) }))
var btnWidth = charWidth < maxWidth ? charWidth : maxWidth;
if (GUILayout.Button("<color=#00FF00>" + obj.name + "</color>", new GUILayoutOption[] { GUILayout.Width(btnWidth) }))
{
WindowManager.InspectObject(obj, out bool _);
}
GUI.skin.label.alignment = TextAnchor.UpperLeft;
}
else
{
GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
}
GUILayout.EndHorizontal();
}
}

View File

@ -263,15 +263,12 @@ namespace Explorer.UI.Inspectors
? new GUILayoutOption[] { GUILayout.Width(245f) }
: new GUILayoutOption[0];
GUILayout.Label("<b>Type:</b> <color=cyan>" + TargetType.FullName + "</color>", labelWidth);
GUILayout.EndHorizontal();
if (asInstance != null)
{
asInstance.DrawInstanceControls(rect);
}
else
{
GUILayout.EndHorizontal();
}
UIStyles.HorizontalLine(Color.grey);

View File

@ -6,6 +6,10 @@ using System.Reflection;
using UnityEngine;
using Explorer.UI.Shared;
using Explorer.CacheObject;
using System.Linq;
#if CPP
using UnhollowerBaseLib;
#endif
namespace Explorer.UI
{

View File

@ -33,7 +33,7 @@ namespace Explorer.UI.Main
public static TextEditor textEditor;
private bool shouldRefocus;
public static GUIStyle AutocompleteStyle => autocompleteStyle ?? GetCompletionStyle();
public static GUIStyle AutocompleteStyle => autocompleteStyle ?? GetAutocompleteStyle();
private static GUIStyle autocompleteStyle;
public static readonly string[] DefaultUsing = new string[]
@ -342,9 +342,9 @@ Help();";
}
// Credit ManlyMarco
private static GUIStyle GetCompletionStyle()
private static GUIStyle GetAutocompleteStyle()
{
return autocompleteStyle = new GUIStyle(GUI.skin.button)
var style = new GUIStyle
{
border = new RectOffset(0, 0, 0, 0),
margin = new RectOffset(0, 0, 0, 0),
@ -353,8 +353,10 @@ Help();";
normal = { background = null },
focused = { background = Texture2D.whiteTexture, textColor = Color.black },
active = { background = Texture2D.whiteTexture, textColor = Color.black },
alignment = TextAnchor.MiddleLeft,
alignment = TextAnchor.MiddleLeft
};
return autocompleteStyle = style;
}
private class VoidType

View File

@ -19,8 +19,6 @@ namespace Explorer.UI.Main
private float m_timeOfLastUpdate = -1f;
private const int PASSIVE_UPDATE_INTERVAL = 1;
private static bool m_getRootObjectsFailed;
private static string m_currentScene = "";
// gameobject list
@ -50,7 +48,7 @@ namespace Explorer.UI.Main
if (m_searching)
CancelSearch();
Update_Impl(true);
Update_Impl();
}
public void TraverseUp()
@ -75,11 +73,6 @@ namespace Explorer.UI.Main
public void CancelSearch()
{
m_searching = false;
if (m_getRootObjectsFailed && !m_currentTransform)
{
GetRootObjectsManual_Impl();
}
}
public List<CacheObjectBase> SearchSceneObjects(string _search)
@ -112,7 +105,7 @@ namespace Explorer.UI.Main
Update_Impl();
}
private void Update_Impl(bool manual = false)
private void Update_Impl()
{
List<Transform> allTransforms = new List<Transform>();
@ -126,39 +119,23 @@ namespace Explorer.UI.Main
}
else
{
if (!m_getRootObjectsFailed)
for (int i = 0; i < SceneManager.sceneCount; i++)
{
try
var scene = SceneManager.GetSceneAt(i);
if (scene.name == m_currentScene)
{
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
var rootObjects =
#if CPP
Unstrip.Scenes.SceneUnstrip.GetRootGameObjects(scene)
.Select(it => it.transform);
#else
scene.GetRootGameObjects().Select(it => it.transform);
#endif
allTransforms.AddRange(rootObjects);
if (scene.name == m_currentScene)
{
allTransforms.AddRange(scene.GetRootGameObjects()
.Select(it => it.transform));
break;
}
}
break;
}
catch
{
ExplorerCore.Log("Exception getting root scene objects, falling back to backup method...");
m_getRootObjectsFailed = true;
allTransforms.AddRange(GetRootObjectsManual_Impl());
}
}
else
{
if (!manual)
{
return;
}
allTransforms.AddRange(GetRootObjectsManual_Impl());
}
}
@ -178,36 +155,6 @@ namespace Explorer.UI.Main
}
}
private IEnumerable<Transform> GetRootObjectsManual_Impl()
{
try
{
var array = Resources.FindObjectsOfTypeAll(ReflectionHelpers.TransformType);
var list = new List<Transform>();
foreach (var obj in array)
{
#if CPP
var transform = obj.TryCast<Transform>();
#else
var transform = obj as Transform;
#endif
if (transform.parent == null && transform.gameObject.scene.name == m_currentScene)
{
list.Add(transform);
}
}
return list;
}
catch (Exception e)
{
ExplorerCore.Log("Exception getting root scene objects (manual): "
+ e.GetType() + ", " + e.Message + "\r\n"
+ e.StackTrace);
return new Transform[0];
}
}
// --------- GUI Draw Function --------- //
public override void DrawWindow()
@ -292,15 +239,12 @@ namespace Explorer.UI.Main
{
int index = names.IndexOf(m_currentScene);
index += changeWanted;
if (index > scenes.Count - 1)
if (index >= 0 && index < SceneManager.sceneCount)
{
index = 0;
m_currentScene = scenes[index].name;
Update_Impl();
}
else if (index < 0)
{
index = scenes.Count - 1;
}
m_currentScene = scenes[index].name;
}
}
}
@ -317,7 +261,7 @@ namespace Explorer.UI.Main
{
Pages.TurnPage(Turn.Left, ref this.scroll);
Update_Impl(true);
Update_Impl();
}
Pages.CurrentPageLabel();
@ -326,7 +270,7 @@ namespace Explorer.UI.Main
{
Pages.TurnPage(Turn.Right, ref this.scroll);
Update_Impl(true);
Update_Impl();
}
}
@ -356,14 +300,6 @@ namespace Explorer.UI.Main
else
{
GUILayout.Label("Scene Root GameObjects:", new GUILayoutOption[0]);
if (m_getRootObjectsFailed)
{
if (GUILayout.Button("Update Root Object List (auto-update failed!)", new GUILayoutOption[0]))
{
Update_Impl(true);
}
}
}
if (m_objectList.Count > 0)

View File

@ -117,13 +117,6 @@ namespace Explorer.UI.Main
Pages.PageOffset = 0;
// Would use Task, but Explorer is .NET 3.5-compatible.
var objectsOfType = FindAllObjectsOfType(m_searchInput, m_typeInput);
CacheResults(objectsOfType);
}
private List<object> FindAllObjectsOfType(string searchQuery, string typeName)
{
#if CPP
Il2CppSystem.Type searchType = null;
@ -132,24 +125,18 @@ namespace Explorer.UI.Main
#endif
if (TypeMode == TypeFilter.Custom)
{
try
if (ReflectionHelpers.GetTypeByName(m_typeInput) is Type t)
{
if (ReflectionHelpers.GetTypeByName(typeName) is Type t)
{
#if CPP
searchType = Il2CppSystem.Type.GetType(t.AssemblyQualifiedName);
searchType = Il2CppSystem.Type.GetType(t.AssemblyQualifiedName);
#else
searchType = t;
searchType = t;
#endif
}
else
{
throw new Exception($"Could not find a Type by the name of '{typeName}'!");
}
}
catch (Exception e)
else
{
ExplorerCore.Log("Exception getting Search Type: " + e.GetType() + ", " + e.Message);
ExplorerCore.Log($"Could not find a Type by the name of '{m_typeInput}'!");
return;
}
}
else if (TypeMode == TypeFilter.Object)
@ -171,7 +158,7 @@ namespace Explorer.UI.Main
{
ExplorerCore.LogWarning("Your Custom Class Type must inherit from UnityEngine.Object!");
}
return new List<object>();
return;
}
var matches = new List<object>();
@ -185,7 +172,7 @@ namespace Explorer.UI.Main
{
if (i >= MaxSearchResults) break;
if (searchQuery != "" && !obj.name.ToLower().Contains(searchQuery.ToLower()))
if (m_searchInput != "" && !obj.name.ToLower().Contains(m_searchInput.ToLower()))
{
continue;
}
@ -215,11 +202,7 @@ namespace Explorer.UI.Main
i++;
}
allObjectsOfType = null;
searchType = null;
searchQuery = null;
return matches;
CacheResults(matches);
}
public static bool FilterScene(object obj, SceneFilter filter)

View File

@ -66,7 +66,7 @@ namespace Explorer.UI
GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null);
GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]);
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
int tabPerRow = Mathf.FloorToInt((float)((decimal)m_rect.width / 238));
int tabPerRow = (int)Math.Floor((float)((decimal)m_rect.width / 238));
int rowCount = 0;
for (int i = 0; i < WindowManager.Windows.Count; i++)
{