* Created a TMP AssetBundle for games which don't have the default TextMeshPro Resources package. This also allows us to use a custom monospace font for the Console and Debug window.
* Unstripped the AssetBundle class (just the stuff we need)
* Finished Search Page
* Finished Options Page (very simple)
* Various refactoring and restructuring of the project
* cleanups
This commit is contained in:
sinaioutlander
2020-11-08 21:04:41 +11:00
parent 2efc3f6578
commit d038d13867
25 changed files with 1604 additions and 947 deletions

View File

@ -2,6 +2,14 @@
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityExplorer.Inspectors;
using UnityExplorer.UI.PageModel;
using System.IO;
using TMPro;
using System.Reflection;
using UnityExplorer.Helpers;
#if CPP
using UnityExplorer.Unstrip.AssetBundle;
#endif
namespace UnityExplorer.UI
{
@ -11,19 +19,48 @@ namespace UnityExplorer.UI
public static EventSystem EventSys { get; private set; }
public static StandaloneInputModule InputModule { get; private set; }
public static TMP_FontAsset ConsoleFont { get; private set; }
public static void Init()
{
var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\tmp.bundle";
if (File.Exists(bundlePath))
{
var bundle = AssetBundle.LoadFromFile(bundlePath);
bundle.LoadAllAssets();
ExplorerCore.Log("Loaded TMP bundle");
if (TMP_Settings.instance == null)
{
var settings = bundle.LoadAsset<TMP_Settings>("TMP Settings");
#if MONO
typeof(TMP_Settings)
.GetField("s_Instance", ReflectionHelpers.CommonFlags)
.SetValue(null, settings);
#else
TMP_Settings.s_Instance = settings;
#endif
}
ConsoleFont = bundle.LoadAsset<TMP_FontAsset>("CONSOLA SDF");
}
else if (TMP_Settings.instance == null)
{
ExplorerCore.LogWarning(@"This game does not seem to have the TMP Resources package, and the TMP AssetBundle was not found at 'Mods\UnityExplorer\tmp.bundle\'!");
return;
}
// Create core UI Canvas and Event System handler
CreateRootCanvas();
// Create submodules
new MainMenu();
MouseInspector.ConstructUI();
// Force refresh of anchors
Canvas.ForceUpdateCanvases();
CanvasRoot.SetActive(false);
CanvasRoot.SetActive(true);
}
@ -34,32 +71,10 @@ namespace UnityExplorer.UI
InputModule.ActivateModule();
}
private static GameObject CreateRootCanvas()
public static void OnSceneChange()
{
GameObject rootObj = new GameObject("ExplorerCanvas");
UnityEngine.Object.DontDestroyOnLoad(rootObj);
rootObj.layer = 5;
CanvasRoot = rootObj;
CanvasRoot.transform.position = new Vector3(0f, 0f, 1f);
EventSys = rootObj.AddComponent<EventSystem>();
InputModule = rootObj.AddComponent<StandaloneInputModule>();
InputModule.ActivateModule();
Canvas canvas = rootObj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.referencePixelsPerUnit = 100;
canvas.sortingOrder = 999;
canvas.pixelPerfect = false;
CanvasScaler scaler = rootObj.AddComponent<CanvasScaler>();
scaler.referenceResolution = new Vector2(1920, 1080);
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
rootObj.AddComponent<GraphicRaycaster>();
return rootObj;
SceneExplorer.Instance?.OnSceneChange();
SearchPage.Instance?.OnSceneChange();
}
public static void Update()
@ -101,10 +116,32 @@ namespace UnityExplorer.UI
}
}
public static void OnSceneChange()
private static GameObject CreateRootCanvas()
{
// todo
SceneExplorer.Instance?.OnSceneChange();
GameObject rootObj = new GameObject("ExplorerCanvas");
UnityEngine.Object.DontDestroyOnLoad(rootObj);
rootObj.layer = 5;
CanvasRoot = rootObj;
CanvasRoot.transform.position = new Vector3(0f, 0f, 1f);
EventSys = rootObj.AddComponent<EventSystem>();
InputModule = rootObj.AddComponent<StandaloneInputModule>();
InputModule.ActivateModule();
Canvas canvas = rootObj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.referencePixelsPerUnit = 100;
canvas.sortingOrder = 999;
canvas.pixelPerfect = false;
CanvasScaler scaler = rootObj.AddComponent<CanvasScaler>();
scaler.referenceResolution = new Vector2(1920, 1080);
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
rootObj.AddComponent<GraphicRaycaster>();
return rootObj;
}
public static Sprite CreateSprite(Texture2D tex, Rect size = default)