DebugConsole save log on quit, some work on CacheObjects, fix missing-material issue on games without default UI Shader

This commit is contained in:
sinaioutlander 2020-11-12 20:31:08 +11:00
parent 668c8f7c3f
commit dc449d4a1e
17 changed files with 336 additions and 248 deletions

View File

@ -20,6 +20,7 @@ namespace UnityExplorer.Config
public int Default_Page_Limit = 25;
public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER;
public bool Log_Unity_Debug = false;
public bool Save_Logs_To_Disk = true;
public static event Action OnConfigChanged;

View File

@ -8,6 +8,7 @@ using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityExplorer.UI.Modules;
#if CPP
using UnhollowerRuntimeLib;
using BepInEx.IL2CPP;
@ -46,6 +47,10 @@ namespace UnityExplorer
ExplorerCore.Update();
}
internal void OnApplicationQuit()
{
DebugConsole.OnQuit();
}
}
#endif
@ -108,7 +113,11 @@ namespace UnityExplorer
lastSceneName = scene.name;
DoSceneChange(scene, scene);
}
}
internal void OnApplicationQuit()
{
DebugConsole.OnQuit();
}
}
}

View File

@ -41,7 +41,7 @@ namespace UnityExplorer
}
public static bool m_showMenu;
private static bool m_doneUIInit;
private static bool s_doneUIInit;
private static float m_timeSinceStartup;
public ExplorerCore()
@ -92,25 +92,20 @@ namespace UnityExplorer
public static void Update()
{
if (!m_doneUIInit)
if (!s_doneUIInit)
CheckUIInit();
if (MouseInspector.Enabled)
{
MouseInspector.UpdateInspect();
}
else
{
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
ShowMenu = !ShowMenu;
if (ShowMenu)
{
//ForceUnlockCursor.Update();
if (ShowMenu && s_doneUIInit)
UIManager.Update();
}
}
}
private static void CheckUIInit()
{
@ -118,7 +113,7 @@ namespace UnityExplorer
if (m_timeSinceStartup > 0.1f)
{
m_doneUIInit = true;
s_doneUIInit = true;
try
{
UIManager.Init();
@ -203,5 +198,16 @@ namespace UnityExplorer
ExplorerBepInPlugin.Logging?.LogError(message?.ToString());
#endif
}
public static string RemoveInvalidFilenameChars(string s)
{
var invalid = System.IO.Path.GetInvalidFileNameChars();
foreach (var c in invalid)
{
s = s.Replace(c.ToString(), "");
}
return s;
}
}
}

View File

@ -1,5 +1,6 @@
#if ML
using MelonLoader;
using UnityExplorer.UI.Modules;
namespace UnityExplorer
{
@ -24,6 +25,11 @@ namespace UnityExplorer
ExplorerCore.Update();
}
public override void OnApplicationQuit()
{
DebugConsole.OnQuit();
}
//public override void OnGUI()
//{
// ExplorerCore.OnGUI();

View File

@ -167,7 +167,7 @@ namespace UnityExplorer.Inspectors
titleLayout.minHeight = 30;
titleLayout.flexibleHeight = 0;
titleLayout.minWidth = 90;
titleLayout.flexibleWidth = 0;
titleLayout.flexibleWidth = 20000;
ConstructToolbar(topRowObj);
@ -222,84 +222,84 @@ namespace UnityExplorer.Inspectors
invisGroup.padding.right = 2;
invisGroup.spacing = 10;
// time scale group
// // time scale group
var timeGroupObj = UIFactory.CreateHorizontalGroup(invisObj, new Color(1, 1, 1, 0));
var timeGroup = timeGroupObj.GetComponent<HorizontalLayoutGroup>();
timeGroup.childForceExpandWidth = false;
timeGroup.childControlWidth = true;
timeGroup.childForceExpandHeight = false;
timeGroup.childControlHeight = true;
timeGroup.padding.top = 2;
timeGroup.padding.left = 5;
timeGroup.padding.right = 2;
timeGroup.padding.bottom = 2;
timeGroup.spacing = 5;
timeGroup.childAlignment = TextAnchor.MiddleCenter;
var timeGroupLayout = timeGroupObj.AddComponent<LayoutElement>();
timeGroupLayout.minWidth = 100;
timeGroupLayout.flexibleWidth = 300;
timeGroupLayout.minHeight = 25;
timeGroupLayout.flexibleHeight = 0;
// var timeGroupObj = UIFactory.CreateHorizontalGroup(invisObj, new Color(1, 1, 1, 0));
// var timeGroup = timeGroupObj.GetComponent<HorizontalLayoutGroup>();
// timeGroup.childForceExpandWidth = false;
// timeGroup.childControlWidth = true;
// timeGroup.childForceExpandHeight = false;
// timeGroup.childControlHeight = true;
// timeGroup.padding.top = 2;
// timeGroup.padding.left = 5;
// timeGroup.padding.right = 2;
// timeGroup.padding.bottom = 2;
// timeGroup.spacing = 5;
// timeGroup.childAlignment = TextAnchor.MiddleCenter;
// var timeGroupLayout = timeGroupObj.AddComponent<LayoutElement>();
// timeGroupLayout.minWidth = 100;
// timeGroupLayout.flexibleWidth = 300;
// timeGroupLayout.minHeight = 25;
// timeGroupLayout.flexibleHeight = 0;
// time scale title
// // time scale title
var timeTitleObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
var timeTitle = timeTitleObj.GetComponent<Text>();
timeTitle.text = "Time Scale:";
timeTitle.color = new Color(21f / 255f, 192f / 255f, 235f / 255f);
var titleLayout = timeTitleObj.AddComponent<LayoutElement>();
titleLayout.minHeight = 25;
titleLayout.minWidth = 80;
titleLayout.flexibleHeight = 0;
timeTitle.horizontalOverflow = HorizontalWrapMode.Overflow;
// var timeTitleObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
// var timeTitle = timeTitleObj.GetComponent<Text>();
// timeTitle.text = "Time Scale:";
// timeTitle.color = new Color(21f / 255f, 192f / 255f, 235f / 255f);
// var titleLayout = timeTitleObj.AddComponent<LayoutElement>();
// titleLayout.minHeight = 25;
// titleLayout.minWidth = 80;
// titleLayout.flexibleHeight = 0;
// timeTitle.horizontalOverflow = HorizontalWrapMode.Overflow;
// actual active time label
// // actual active time label
var timeLabelObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
var timeLabelLayout = timeLabelObj.AddComponent<LayoutElement>();
timeLabelLayout.minWidth = 40;
timeLabelLayout.minHeight = 25;
timeLabelLayout.flexibleHeight = 0;
// var timeLabelObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
// var timeLabelLayout = timeLabelObj.AddComponent<LayoutElement>();
// timeLabelLayout.minWidth = 40;
// timeLabelLayout.minHeight = 25;
// timeLabelLayout.flexibleHeight = 0;
// todo make static and update
var s_timeText = timeLabelObj.GetComponent<Text>();
s_timeText.text = Time.timeScale.ToString("F1");
// // todo make static and update
// var s_timeText = timeLabelObj.GetComponent<Text>();
// s_timeText.text = Time.timeScale.ToString("F1");
// time scale input
// // time scale input
var timeInputObj = UIFactory.CreateInputField(timeGroupObj);
var timeInput = timeInputObj.GetComponent<InputField>();
timeInput.characterValidation = InputField.CharacterValidation.Decimal;
var timeInputLayout = timeInputObj.AddComponent<LayoutElement>();
timeInputLayout.minWidth = 90;
timeInputLayout.flexibleWidth = 0;
timeInputLayout.minHeight = 25;
timeInputLayout.flexibleHeight = 0;
// var timeInputObj = UIFactory.CreateInputField(timeGroupObj);
// var timeInput = timeInputObj.GetComponent<InputField>();
// timeInput.characterValidation = InputField.CharacterValidation.Decimal;
// var timeInputLayout = timeInputObj.AddComponent<LayoutElement>();
// timeInputLayout.minWidth = 90;
// timeInputLayout.flexibleWidth = 0;
// timeInputLayout.minHeight = 25;
// timeInputLayout.flexibleHeight = 0;
// time scale apply button
// // time scale apply button
var applyBtnObj = UIFactory.CreateButton(timeGroupObj);
var applyBtn = applyBtnObj.GetComponent<Button>();
#if MONO
applyBtn.onClick.AddListener(SetTimeScale);
#else
applyBtn.onClick.AddListener(new Action(SetTimeScale));
#endif
var applyText = applyBtnObj.GetComponentInChildren<Text>();
applyText.text = "Apply";
applyText.fontSize = 14;
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
applyLayout.minWidth = 50;
applyLayout.minHeight = 25;
applyLayout.flexibleHeight = 0;
// var applyBtnObj = UIFactory.CreateButton(timeGroupObj);
// var applyBtn = applyBtnObj.GetComponent<Button>();
//#if MONO
// applyBtn.onClick.AddListener(SetTimeScale);
//#else
// applyBtn.onClick.AddListener(new Action(SetTimeScale));
//#endif
// var applyText = applyBtnObj.GetComponentInChildren<Text>();
// applyText.text = "Apply";
// applyText.fontSize = 14;
// var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
// applyLayout.minWidth = 50;
// applyLayout.minHeight = 25;
// applyLayout.flexibleHeight = 0;
void SetTimeScale()
{
var scale = float.Parse(timeInput.text);
Time.timeScale = scale;
s_timeText.text = Time.timeScale.ToString("F1");
}
// void SetTimeScale()
// {
// var scale = float.Parse(timeInput.text);
// Time.timeScale = scale;
// s_timeText.text = Time.timeScale.ToString("F1");
// }
// inspect under mouse button

View File

@ -21,8 +21,11 @@ namespace UnityExplorer.Inspectors.Reflection
public virtual bool IsStatic { get; private set; }
public override bool HasParameters => m_arguments != null && m_arguments.Length > 0;
public override bool IsMember => true;
public override bool HasParameters => ParamCount > 0;
public virtual int ParamCount => m_arguments.Length;
public override bool HasEvaluated => m_evaluated;
public string RichTextName => m_richTextName ?? GetRichTextName();
@ -47,12 +50,8 @@ namespace UnityExplorer.Inspectors.Reflection
public override void UpdateValue()
{
if (HasParameters && !m_isEvaluating)
if (!HasParameters || m_isEvaluating)
{
// need to enter args first
return;
}
try
{
#if CPP
@ -60,7 +59,6 @@ namespace UnityExplorer.Inspectors.Reflection
throw new Exception("Type not supported with Reflection");
#endif
UpdateReflection();
#if CPP
if (IValue.Value != null)
IValue.Value = IValue.Value.Il2CppCast(ReflectionHelpers.GetActualType(IValue.Value));
@ -70,6 +68,7 @@ namespace UnityExplorer.Inspectors.Reflection
{
ReflectionException = ReflectionHelpers.ExceptionToString(e, true);
}
}
base.UpdateValue();
}
@ -227,7 +226,7 @@ namespace UnityExplorer.Inspectors.Reflection
internal RectTransform m_topRowRect;
internal LayoutElement m_leftLayout;
internal LayoutElement m_rightLayout;
//internal GameObject m_subGroup;
internal GameObject m_subContent;
internal override void ConstructUI()
{
@ -272,7 +271,7 @@ namespace UnityExplorer.Inspectors.Reflection
leftRect.offsetMax = Vector2.zero;
leftRect.sizeDelta = Vector2.zero;
m_leftLayout = labelObj.AddComponent<LayoutElement>();
m_leftLayout.preferredWidth = 225;
m_leftLayout.preferredWidth = 125;
m_leftLayout.minHeight = 25;
m_leftLayout.flexibleHeight = 100;
var labelFitter = labelObj.AddComponent<ContentSizeFitter>();
@ -284,50 +283,78 @@ namespace UnityExplorer.Inspectors.Reflection
// right group
m_rightGroup = UIFactory.CreateHorizontalGroup(topGroupObj, new Color(1, 1, 1, 0));
m_rightGroup = UIFactory.CreateVerticalGroup(topGroupObj, new Color(1, 1, 1, 0));
m_rightLayout = m_rightGroup.AddComponent<LayoutElement>();
m_rightLayout.minHeight = 25;
m_rightLayout.flexibleHeight = 480;
m_rightLayout.minWidth = 300;
m_rightLayout.minWidth = 125;
m_rightLayout.flexibleWidth = 5000;
var rightGroup = m_rightGroup.GetComponent<HorizontalLayoutGroup>();
rightGroup.childForceExpandHeight = false;
rightGroup.childForceExpandWidth = true;
var rightGroup = m_rightGroup.GetComponent<VerticalLayoutGroup>();
rightGroup.childForceExpandHeight = true;
rightGroup.childForceExpandWidth = false;
rightGroup.childControlHeight = true;
rightGroup.childControlWidth = true;
rightGroup.spacing = 4;
// todo check for HasParameters, etc
if (!HasParameters && IsMember)
// evaluate button
if (this is CacheMethod || HasParameters)
{
//var refreshBtnObj = UIFactory.CreateButton(topRowObj, new Color(0.3f, 0.3f, 0.3f));
//var btnLayout = refreshBtnObj.AddComponent<LayoutElement>();
//btnLayout.minWidth = 30;
//btnLayout.minHeight = 20;
//btnLayout.flexibleWidth = 0;
//var refreshTxt = refreshBtnObj.GetComponentInChildren<Text>();
//refreshTxt.text = "⟳";
//refreshTxt.fontSize = 16;
//var refreshBtn = refreshBtnObj.GetComponent<Button>();
//refreshBtn.onClick.AddListener(() => { ExplorerCore.Log("todo Update!"); });
var color = HasParameters ? new Color(0.4f, 0.4f, 0.4f) : new Color(0.3f, 0.6f, 0.3f);
var evalButtonObj = UIFactory.CreateButton(m_rightGroup, color);
var evalLayout = evalButtonObj.AddComponent<LayoutElement>();
evalLayout.minWidth = 100;
evalLayout.minHeight = 22;
evalLayout.flexibleWidth = 0;
var evalText = evalButtonObj.GetComponentInChildren<Text>();
evalText.text = HasParameters
? $"Evaluate ({ParamCount})"
: "Evaluate";
var evalButton = evalButtonObj.GetComponent<Button>();
var colors = evalButton.colors;
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
evalButton.colors = colors;
#if CPP
evalButton.onClick.AddListener(new Action(OnMainEvaluateButton));
#else
evalButton.onClick.AddListener(OnMainEvaluateButton);
#endif
void OnMainEvaluateButton()
{
if (HasParameters)
{
// todo show parameter input
ExplorerCore.Log("TODO params");
}
else
{
// method with no parameters
(this as CacheMethod).Evaluate();
}
}
}
IValue.ConstructUI(m_rightGroup);
// subcontent
// todo subcontent
// todo check if IValue actually has subcontent
//m_subContent = UIFactory.CreateHorizontalGroup(m_parentContent, new Color(1, 1, 1, 0));
//var subGroup = m_subContent.GetComponent<HorizontalLayoutGroup>();
//subGroup.childForceExpandWidth = true;
//subGroup.childControlWidth = true;
//var subLayout = m_subContent.AddComponent<LayoutElement>();
//subLayout.minHeight = 25;
//subLayout.flexibleHeight = 500;
//subLayout.minWidth = 125;
//subLayout.flexibleWidth = 9000;
m_subContent = UIFactory.CreateHorizontalGroup(m_parentContent, new Color(1, 1, 1, 0));
var subGroup = m_subContent.GetComponent<HorizontalLayoutGroup>();
subGroup.childForceExpandWidth = true;
subGroup.childControlWidth = true;
var subLayout = m_subContent.AddComponent<LayoutElement>();
subLayout.minHeight = 50;
subLayout.flexibleHeight = 500;
subLayout.minWidth = 125;
subLayout.flexibleWidth = 9000;
//m_subContent.SetActive(false);
m_subContent.SetActive(false);
// Construct InteractiveValue UI
IValue.ConstructUI(m_rightGroup, m_subContent);
}
#endregion

View File

@ -10,12 +10,14 @@ namespace UnityExplorer.Inspectors.Reflection
{
public class CacheMethod : CacheMember
{
private CacheObjectBase m_cachedReturnValue;
//private CacheObjectBase m_cachedReturnValue;
public override bool HasParameters => base.HasParameters || GenericArgs.Length > 0;
public override bool IsStatic => (MemInfo as MethodInfo).IsStatic;
public override int ParamCount => base.ParamCount + m_genericArgInput.Length;
public Type[] GenericArgs { get; private set; }
public Type[][] GenericConstraints { get; private set; }
@ -38,7 +40,7 @@ namespace UnityExplorer.Inspectors.Reflection
public override void UpdateValue()
{
// CacheMethod cannot UpdateValue directly. Need to Evaluate.
base.UpdateValue();
}
public override void UpdateReflection()
@ -74,17 +76,20 @@ namespace UnityExplorer.Inspectors.Reflection
ReflectionException = ReflectionHelpers.ExceptionToString(e);
}
if (ret != null)
{
//m_cachedReturnValue = CacheFactory.GetTypeAndCacheObject(ret);
IValue.Value = ret;
IValue.UpdateValue();
//m_cachedReturnValue = CacheFactory.GetCacheObject(ret);
m_cachedReturnValue.UpdateValue();
}
else
{
m_cachedReturnValue = null;
}
//if (ret != null)
//{
// //m_cachedReturnValue = CacheFactory.GetTypeAndCacheObject(ret);
// //m_cachedReturnValue = CacheFactory.GetCacheObject(ret);
// // m_cachedReturnValue.UpdateValue();
//}
//else
//{
// m_cachedReturnValue = null;
//}
}
private MethodInfo MakeGenericMethodFromInput()

View File

@ -1,4 +1,5 @@
using System;
using UnityEngine;
using UnityExplorer.Helpers;
namespace UnityExplorer.Inspectors.Reflection
@ -9,17 +10,16 @@ namespace UnityExplorer.Inspectors.Reflection
public InstanceInspector(object target) : base(target)
{
// needed?
}
public override void Update()
public void ConstructInstanceHelpers(GameObject parent)
{
base.Update();
if (m_pendingDestroy || InspectorManager.Instance.m_activeInspector != this)
{
return;
// todo
}
public void ConstructInstanceFilters(GameObject parent)
{
// todo
}
}

View File

@ -19,6 +19,9 @@ namespace UnityExplorer.Inspectors.Reflection
public object Value { get; set; }
public Type ValueType;
// might not need
public virtual bool HasSubContent => false;
public string RichTextValue => m_richValue ?? GetRichTextValue();
internal string m_richValue;
internal string m_richValueType;
@ -69,7 +72,6 @@ namespace UnityExplorer.Inspectors.Reflection
return m_toStringMethod;
}
public string GetRichTextValue()
{
if (Value != null)
@ -77,14 +79,15 @@ namespace UnityExplorer.Inspectors.Reflection
m_richValueType = UISyntaxHighlight.GetHighlight(ValueType, true);
if (OwnerCacheObject is CacheMember cm && !cm.HasEvaluated)
return $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
if (Value == null) return $"<color=grey>null</color> ({m_richValueType})";
string label;
if (ValueType == typeof(TextAsset))
if (ValueType == typeof(TextAsset) && Value is TextAsset textAsset)
{
var textAsset = Value as TextAsset;
label = textAsset.text;
if (label.Length > 10)
@ -128,8 +131,9 @@ namespace UnityExplorer.Inspectors.Reflection
internal GameObject m_UIContent;
internal Text m_text;
internal GameObject m_subContentParent;
public void ConstructUI(GameObject parent)
public virtual void ConstructUI(GameObject parent, GameObject subGroup)
{
m_UIContent = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft);
var mainLayout = m_UIContent.AddComponent<LayoutElement>();
@ -138,8 +142,7 @@ namespace UnityExplorer.Inspectors.Reflection
mainLayout.minHeight = 25;
m_text = m_UIContent.GetComponent<Text>();
GetRichTextValue();
m_text.text = $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
m_subContentParent = subGroup;
}
#endregion

View File

@ -8,19 +8,7 @@ namespace UnityExplorer.Inspectors.Reflection
public StaticInspector(Type type) : base(type)
{
// TODO
}
public override void Update()
{
base.Update();
if (m_pendingDestroy || InspectorManager.Instance.m_activeInspector != this)
{
return;
}
// todo
// needed?
}
}
}

View File

@ -158,7 +158,7 @@ namespace UnityExplorer.Inspectors
RefreshDisplay();
}
public void RefreshDisplay(bool fast = false)
public void RefreshDisplay()
{
// temp because not doing filtering yet
m_membersFiltered = m_allMembers;
@ -166,8 +166,6 @@ namespace UnityExplorer.Inspectors
var members = m_membersFiltered;
m_pageHandler.ListCount = members.Length;
if (!fast)
{
// disable current members
for (int i = 0; i < m_displayedMembers.Length; i++)
{
@ -177,7 +175,6 @@ namespace UnityExplorer.Inspectors
else
break;
}
}
if (members.Length < 1)
return;
@ -188,7 +185,6 @@ namespace UnityExplorer.Inspectors
break;
CacheMember member = members[itemIndex];
m_displayedMembers[itemIndex - m_pageHandler.StartIndex] = member;
member.Enable();
}
@ -211,7 +207,7 @@ namespace UnityExplorer.Inspectors
labelWidth = width;
}
float valueWidth = m_scrollContentRect.rect.width - labelWidth - 10;
float valueWidth = m_scrollContentRect.rect.width - labelWidth - 20;
foreach (var cache in m_displayedMembers)
{
@ -382,6 +378,7 @@ namespace UnityExplorer.Inspectors
var typeLabel = UIFactory.CreateLabel(typeRowObj, TextAnchor.MiddleLeft);
var typeLabelText = typeLabel.GetComponent<Text>();
typeLabelText.text = "Type:";
typeLabelText.horizontalOverflow = HorizontalWrapMode.Overflow;
var typeLabelTextLayout = typeLabel.AddComponent<LayoutElement>();
typeLabelTextLayout.minWidth = 60;
typeLabelTextLayout.flexibleWidth = 0;
@ -395,15 +392,40 @@ namespace UnityExplorer.Inspectors
typeLabelLayout.flexibleWidth = 5000;
typeLabelInput.text = UISyntaxHighlight.GetHighlight(m_targetType, true);
// Helper tools
if (this is InstanceInspector ii)
{
ii.ConstructInstanceHelpers(Content);
}
}
internal void ConstructFilterArea()
{
var filterAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
var filterLayout = filterAreaObj.AddComponent<LayoutElement>();
filterLayout.minHeight = 25;
var filterGroup = filterAreaObj.GetComponent<VerticalLayoutGroup>();
filterGroup.childForceExpandWidth = true;
filterGroup.childForceExpandHeight = false;
filterGroup.childControlWidth = true;
filterGroup.childControlHeight = true;
// name filter
// todo instance inspector has extra filters
// todo instance inspector "helper tools"
// membertype filter
// Instance filters
if (this is InstanceInspector ii)
{
ii.ConstructInstanceFilters(filterAreaObj);
}
}
internal void ConstructMemberList()

View File

@ -34,7 +34,7 @@ namespace UnityExplorer.Tests
}
private static bool m_setOnlyProperty;
public Texture2D TestTexture = UIManager.MakeSolidTexture(Color.white, 200, 200);
public Texture2D TestTexture;
public static Sprite TestSprite;
public static int StaticProperty => 5;
@ -48,12 +48,13 @@ namespace UnityExplorer.Tests
public TestClass()
{
#if CPP
TestTexture = UIManager.MakeSolidTexture(Color.white, 200, 200);
TestTexture.name = "TestTexture";
//var r = new Rect(0, 0, TestTexture.width, TestTexture.height);
//var v2 = Vector2.zero;
//var v4 = Vector4.zero;
//TestSprite = Sprite.CreateSprite_Injected(TestTexture, ref r, ref v2, 100f, 0u, SpriteMeshType.Tight, ref v4, false);
var r = new Rect(0, 0, TestTexture.width, TestTexture.height);
var v2 = Vector2.zero;
var v4 = Vector4.zero;
TestSprite = Sprite.CreateSprite_Injected(TestTexture, ref r, ref v2, 100f, 0u, SpriteMeshType.Tight, ref v4, false);
GameObject.DontDestroyOnLoad(TestTexture);
GameObject.DontDestroyOnLoad(TestSprite);

View File

@ -6,6 +6,8 @@ using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
using UnityExplorer.UI.Shared;
using System.IO;
using System.Linq;
namespace UnityExplorer.UI.Modules
{
@ -14,10 +16,14 @@ namespace UnityExplorer.UI.Modules
public static DebugConsole Instance { get; private set; }
public static bool LogUnity { get; set; } = ModConfig.Instance.Log_Unity_Debug;
public static bool SaveToDisk { get; set; } = ModConfig.Instance.Save_Logs_To_Disk;
internal static bool m_savedToDiskChecked;
public static readonly List<string> AllMessages = new List<string>();
public static readonly List<Text> MessageHolders = new List<Text>();
// logs that occured before the actual UI was ready.
internal static readonly List<string> s_preInitMessages = new List<string>();
private InputField m_textInput;
@ -26,9 +32,6 @@ namespace UnityExplorer.UI.Modules
{
Instance = this;
//AllMessages = new List<string>();
//MessageHolders = new List<Text>();
ConstructUI(parent);
string preAppend = "";
@ -42,6 +45,37 @@ namespace UnityExplorer.UI.Modules
m_textInput.text = preAppend;
}
public static void OnQuit()
{
if (m_savedToDiskChecked)
return;
m_savedToDiskChecked = true;
if (!SaveToDisk)
return;
var path = ExplorerCore.EXPLORER_FOLDER + @"\Logs";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
// delete oldest log
var files = Directory.GetFiles(path);
if (files.Length >= 10)
{
var sorted = files.ToList();
// sort by datetime.ToString will put the oldest one first
sorted.Sort();
File.Delete(sorted[0]);
}
var fileName = "UnityExplorer " + DateTime.Now.ToString("u") + ".txt";
fileName = ExplorerCore.RemoveInvalidFilenameChars(fileName);
File.WriteAllText(path + @"\" + fileName, Instance.m_textInput.text);
}
public static void Log(string message)
{
Log(message, null);
@ -99,43 +133,6 @@ namespace UnityExplorer.UI.Modules
logAreaLayout.preferredHeight = 190;
logAreaLayout.flexibleHeight = 0;
//var inputObj = UIFactory.CreateInputField(logAreaObj, 14, 0, 1);
//var mainInputGroup = inputObj.GetComponent<VerticalLayoutGroup>();
//mainInputGroup.padding.left = 8;
//mainInputGroup.padding.right = 8;
//mainInputGroup.padding.top = 5;
//mainInputGroup.padding.bottom = 5;
//var inputLayout = inputObj.AddComponent<LayoutElement>();
//inputLayout.preferredWidth = 500;
//inputLayout.flexibleWidth = 9999;
//var inputImage = inputObj.GetComponent<Image>();
//inputImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
//var scroll = UIFactory.CreateScrollbar(logAreaObj);
//var scrollLayout = scroll.AddComponent<LayoutElement>();
//scrollLayout.preferredWidth = 25;
//scrollLayout.flexibleWidth = 0;
//var scroller = scroll.GetComponent<Scrollbar>();
//scroller.direction = Scrollbar.Direction.TopToBottom;
//var scrollColors = scroller.colors;
//scrollColors.normalColor = new Color(0.5f, 0.5f, 0.5f, 1.0f);
//scroller.colors = scrollColors;
//var tmpInput = inputObj.GetComponent<InputField>();
//tmpInput.readOnly = true;
//if (UIManager.ConsoleFont)
//{
// tmpInput.textComponent.font = UIManager.ConsoleFont;
//}
//tmpInput.readOnly = true;
var inputScrollerObj = UIFactory.CreateSrollInputField(logAreaObj, out InputFieldScroller inputScroll, 14, new Color(0.05f, 0.05f, 0.05f));
inputScroll.inputField.textComponent.font = UIManager.ConsoleFont;
@ -260,7 +257,7 @@ namespace UnityExplorer.UI.Modules
}
var unityToggleLayout = unityToggleObj.AddComponent<LayoutElement>();
unityToggleLayout.minWidth = 200;
unityToggleLayout.minWidth = 170;
unityToggleLayout.flexibleWidth = 0;
var unityToggleRect = unityToggleObj.transform.Find("Background").GetComponent<RectTransform>();
@ -268,7 +265,35 @@ namespace UnityExplorer.UI.Modules
pos.y = -8;
unityToggleRect.localPosition = pos;
#endregion
// // Save to disk button
// var saveToDiskObj = UIFactory.CreateToggle(bottomBarObj, out Toggle diskToggle, out Text diskToggleText);
//#if CPP
// diskToggle.onValueChanged.AddListener(new Action<bool>(ToggleDisk));
//#else
// diskToggle.onValueChanged.AddListener(ToggleDisk);
//#endif
// diskToggle.isOn = SaveToDisk;
// diskToggleText.text = "Save logs to 'Mods\\UnityExplorer\\Logs'?";
// diskToggleText.alignment = TextAnchor.MiddleLeft;
// void ToggleDisk(bool val)
// {
// SaveToDisk = val;
// ModConfig.Instance.Save_Logs_To_Disk = val;
// ModConfig.SaveSettings();
// }
// var diskToggleLayout = saveToDiskObj.AddComponent<LayoutElement>();
// diskToggleLayout.minWidth = 340;
// diskToggleLayout.flexibleWidth = 0;
// var saveToDiskRect = saveToDiskObj.transform.Find("Background").GetComponent<RectTransform>();
// pos = unityToggleRect.localPosition;
// pos.y = -8;
// saveToDiskRect.localPosition = pos;
#endregion
}
}
}

View File

@ -131,9 +131,9 @@ namespace UnityExplorer.UI
#region RESIZE
private const int RESIZE_THICKNESS = 10;
private const int RESIZE_THICKNESS = 15;
private readonly Vector2 minResize = new Vector2(733, 542);
private readonly Vector2 minResize = new Vector2(630, 540);
private bool WasResizing { get; set; }
private ResizeTypes m_currentResizeType = ResizeTypes.NONE;
@ -339,16 +339,6 @@ namespace UnityExplorer.UI
{
try
{
//string path = ExplorerCore.EXPLORER_FOLDER + @"\cursor.png";
//byte[] data = File.ReadAllBytes(path);
//Texture2D tex = new Texture2D(32, 32);
//tex.LoadImage(data, false);
//UnityEngine.Object.DontDestroyOnLoad(tex);
//Sprite sprite = UIManager.CreateSprite(tex, new Rect(0, 0, 32, 32));
//UnityEngine.Object.DontDestroyOnLoad(sprite);
var sprite = UIManager.ResizeCursor;
m_resizeCursorImage = new GameObject("ResizeCursorImage");
@ -356,6 +346,7 @@ namespace UnityExplorer.UI
Image image = m_resizeCursorImage.AddComponent<Image>();
image.sprite = sprite;
image.material = Graphic.defaultGraphicMaterial;
RectTransform rect = image.transform.GetComponent<RectTransform>();
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 32);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 32);

View File

@ -559,7 +559,7 @@ namespace UnityExplorer.UI
templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
ScrollRect scrollRect = templateObj.AddComponent<ScrollRect>();
scrollRect.scrollSensitivity = 25;
scrollRect.scrollSensitivity = 35;
scrollRect.content = contentObj.GetComponent<RectTransform>();
scrollRect.viewport = viewportObj.GetComponent<RectTransform>();
scrollRect.horizontal = false;
@ -715,7 +715,7 @@ namespace UnityExplorer.UI
scrollRect.vertical = true;
scrollRect.verticalScrollbar = hiddenScroll;
scrollRect.movementType = ScrollRect.MovementType.Clamped;
scrollRect.scrollSensitivity = 25;
scrollRect.scrollSensitivity = 35;
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.Permanent;

View File

@ -32,7 +32,11 @@ namespace UnityExplorer.UI
var bundle = AssetBundle.LoadFromFile(bundlePath);
// Fix for games which don't ship with 'UI/Default' shader.
if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default")
{
ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader...");
Graphic.defaultGraphicMaterial.shader = bundle.LoadAsset<Shader>("DefaultUI");
}
ResizeCursor = bundle.LoadAsset<Sprite>("cursor");

View File

@ -42,7 +42,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_ML_Cpp|AnyCPU' ">
<!-- <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> -->
<OutputPath>..\Release\Explorer.MelonLoader.Il2Cpp\</OutputPath>
<OutputPath>..\Release\UnityExplorer.MelonLoader.Il2Cpp\</OutputPath>
<DefineConstants>CPP,ML</DefineConstants>
<IsCpp>true</IsCpp>
<IsMelonLoader>true</IsMelonLoader>
@ -50,7 +50,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_ML_Mono|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OutputPath>..\Release\Explorer.MelonLoader.Mono\</OutputPath>
<OutputPath>..\Release\UnityExplorer.MelonLoader.Mono\</OutputPath>
<DefineConstants>MONO,ML</DefineConstants>
<Prefer32Bit>false</Prefer32Bit>
<IsCpp>false</IsCpp>
@ -59,7 +59,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_BIE_Cpp|AnyCPU' ">
<!-- <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> -->
<OutputPath>..\Release\Explorer.BepInEx.Il2Cpp\</OutputPath>
<OutputPath>..\Release\UnityExplorer.BepInEx.Il2Cpp\</OutputPath>
<DefineConstants>CPP,BIE</DefineConstants>
<IsCpp>true</IsCpp>
<IsMelonLoader>false</IsMelonLoader>
@ -67,7 +67,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_BIE_Mono|AnyCPU' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OutputPath>..\Release\Explorer.BepInEx.Mono\</OutputPath>
<OutputPath>..\Release\UnityExplorer.BepInEx.Mono\</OutputPath>
<DefineConstants>MONO,BIE</DefineConstants>
<IsCpp>false</IsCpp>
<IsMelonLoader>false</IsMelonLoader>