Removed TextMeshPro dependency, using only vanilla UI now. Also fixes for games which dont ship with Default UI Shader.

This commit is contained in:
sinaioutlander
2020-11-10 20:18:14 +11:00
parent 6766a8cf4c
commit f87b06989d
23 changed files with 337 additions and 598 deletions

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using UnityExplorer.Unstrip;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
@ -19,7 +19,7 @@ namespace UnityExplorer.UI.PageModel
internal static readonly List<string> s_preInitMessages = new List<string>();
private TMP_InputField m_textInput;
private InputField m_textInput;
public DebugConsole(GameObject parent)
{
@ -98,7 +98,7 @@ namespace UnityExplorer.UI.PageModel
logAreaLayout.preferredHeight = 190;
logAreaLayout.flexibleHeight = 0;
var inputObj = UIFactory.CreateTMPInput(logAreaObj);
var inputObj = UIFactory.CreateInputField(logAreaObj, 14, 0, 1);
var mainInputGroup = inputObj.GetComponent<VerticalLayoutGroup>();
mainInputGroup.padding.left = 8;
@ -125,23 +125,24 @@ namespace UnityExplorer.UI.PageModel
scrollColors.normalColor = new Color(0.5f, 0.5f, 0.5f, 1.0f);
scroller.colors = scrollColors;
var tmpInput = inputObj.GetComponent<TMP_InputField>();
tmpInput.scrollSensitivity = 15;
tmpInput.verticalScrollbar = scroller;
var tmpInput = inputObj.GetComponent<InputField>();
//tmpInput.scrollSensitivity = 15;
//tmpInput.verticalScrollbar = scroller;
tmpInput.readOnly = true;
if (UIManager.ConsoleFont != null)
{
tmpInput.textComponent.font = UIManager.ConsoleFont;
#if MONO
(tmpInput.placeholder as TextMeshProUGUI).font = UIManager.ConsoleFont;
(tmpInput.placeholder as Text).font = UIManager.ConsoleFont;
#else
tmpInput.placeholder.TryCast<TextMeshProUGUI>().font = UIManager.ConsoleFont;
tmpInput.placeholder.TryCast<Text>().font = UIManager.ConsoleFont;
#endif
}
tmpInput.readOnly = true;
m_textInput = inputObj.GetComponent<TMP_InputField>();
m_textInput = inputObj.GetComponent<InputField>();
#endregion

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
@ -14,10 +14,10 @@ namespace UnityExplorer.UI.PageModel
{
public override string Name => "Options";
private TMP_InputField m_keycodeInput;
private InputField m_keycodeInput;
private Toggle m_unlockMouseToggle;
private TMP_InputField m_pageLimitInput;
private TMP_InputField m_defaultOutputInput;
private InputField m_pageLimitInput;
private InputField m_defaultOutputInput;
public override void Init()
{
@ -138,12 +138,12 @@ namespace UnityExplorer.UI.PageModel
labelLayout.minWidth = 150;
labelLayout.minHeight = 25;
var keycodeInputObj = UIFactory.CreateTMPInput(rowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var keycodeInputObj = UIFactory.CreateInputField(rowObj);
m_keycodeInput = keycodeInputObj.GetComponent<TMP_InputField>();
m_keycodeInput = keycodeInputObj.GetComponent<InputField>();
m_keycodeInput.text = ModConfig.Instance.Main_Menu_Toggle.ToString();
m_keycodeInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = "KeyCode, eg. F7";
m_keycodeInput.placeholder.gameObject.GetComponent<Text>().text = "KeyCode, eg. F7";
}
internal void ConstructMouseUnlockOpt(GameObject parent)
@ -197,12 +197,12 @@ namespace UnityExplorer.UI.PageModel
labelLayout.minWidth = 150;
labelLayout.minHeight = 25;
var inputObj = UIFactory.CreateTMPInput(rowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var inputObj = UIFactory.CreateInputField(rowObj);
m_pageLimitInput = inputObj.GetComponent<TMP_InputField>();
m_pageLimitInput = inputObj.GetComponent<InputField>();
m_pageLimitInput.text = ModConfig.Instance.Default_Page_Limit.ToString();
m_pageLimitInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = "Integer, eg. 20";
m_pageLimitInput.placeholder.gameObject.GetComponent<Text>().text = "Integer, eg. 20";
}
internal void ConstructOutputPathOpt(GameObject parent)
@ -228,12 +228,12 @@ namespace UnityExplorer.UI.PageModel
labelLayout.minWidth = 150;
labelLayout.minHeight = 25;
var inputObj = UIFactory.CreateTMPInput(rowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var inputObj = UIFactory.CreateInputField(rowObj);
m_defaultOutputInput = inputObj.GetComponent<TMP_InputField>();
m_defaultOutputInput = inputObj.GetComponent<InputField>();
m_defaultOutputInput.text = ModConfig.Instance.Default_Output_Path.ToString();
m_defaultOutputInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = @"Directory, eg. Mods\UnityExplorer";
m_defaultOutputInput.placeholder.gameObject.GetComponent<Text>().text = @"Directory, eg. Mods\UnityExplorer";
}
#endregion

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
@ -51,9 +51,9 @@ namespace UnityExplorer.UI.PageModel
private Text m_resultCountText;
internal SearchContext m_context;
private TMP_InputField m_customTypeInput;
private InputField m_customTypeInput;
private TMP_InputField m_nameInput;
private InputField m_nameInput;
private Button m_selectedContextButton;
private readonly Dictionary<SearchContext, Button> m_contextButtons = new Dictionary<SearchContext, Button>();
@ -94,11 +94,15 @@ namespace UnityExplorer.UI.PageModel
public override void Update()
{
// todo update scene filter options
if (HaveScenesChanged())
{
RefreshSceneDropdown();
}
if (m_customTypeInput.isFocused && m_context != SearchContext.Custom)
{
OnContextButtonClicked(SearchContext.Custom);
}
}
// Updating result list content
@ -480,20 +484,20 @@ namespace UnityExplorer.UI.PageModel
// custom type input
var customTypeObj = UIFactory.CreateTMPInput(contextRowObj, 13, 0, (int)TextAlignmentOptions.MidlineLeft);
var customTypeObj = UIFactory.CreateInputField(contextRowObj);
var customTypeLayout = customTypeObj.AddComponent<LayoutElement>();
customTypeLayout.minWidth = 250;
customTypeLayout.flexibleWidth = 2000;
customTypeLayout.minHeight = 25;
customTypeLayout.flexibleHeight = 0;
m_customTypeInput = customTypeObj.GetComponent<TMP_InputField>();
m_customTypeInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = "eg. UnityEngine.Texture2D, etc...";
m_customTypeInput.onFocusSelectAll = true;
#if MONO
m_customTypeInput.onSelect.AddListener((string val) => { OnContextButtonClicked(SearchContext.Custom); });
#else
m_customTypeInput.onSelect.AddListener(new Action<string>((string val) => { OnContextButtonClicked(SearchContext.Custom); }));
#endif
m_customTypeInput = customTypeObj.GetComponent<InputField>();
m_customTypeInput.placeholder.gameObject.GetComponent<Text>().text = "eg. UnityEngine.Texture2D, etc...";
//m_customTypeInput.onFocusSelectAll = true;
//#if MONO
// m_customTypeInput.onSelect.AddListener((string val) => { OnContextButtonClicked(SearchContext.Custom); });
//#else
// m_customTypeInput.onSelect.AddListener(new Action<string>((string val) => { OnContextButtonClicked(SearchContext.Custom); }));
//#endif
// search input
@ -515,8 +519,8 @@ namespace UnityExplorer.UI.PageModel
nameLabelLayout.minWidth = 125;
nameLabelLayout.minHeight = 25;
var nameInputObj = UIFactory.CreateTMPInput(nameRowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
m_nameInput = nameInputObj.GetComponent<TMP_InputField>();
var nameInputObj = UIFactory.CreateInputField(nameRowObj);
m_nameInput = nameInputObj.GetComponent<InputField>();
//m_nameInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = "";
var nameInputLayout = nameInputObj.AddComponent<LayoutElement>();
nameInputLayout.minWidth = 150;

View File

@ -336,20 +336,22 @@ namespace UnityExplorer.UI
{
try
{
string path = ExplorerCore.EXPLORER_FOLDER + @"\cursor.png";
byte[] data = File.ReadAllBytes(path);
//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);
//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);
//Sprite sprite = UIManager.CreateSprite(tex, new Rect(0, 0, 32, 32));
//UnityEngine.Object.DontDestroyOnLoad(sprite);
var sprite = UIManager.ResizeCursor;
m_resizeCursorImage = new GameObject("ResizeCursorImage");
m_resizeCursorImage.transform.SetParent(UIManager.CanvasRoot.transform);
Image image = m_resizeCursorImage.AddComponent<Image>();
Image image = m_resizeCursorImage.AddGraphic<Image>();
image.sprite = sprite;
RectTransform rect = image.transform.GetComponent<RectTransform>();
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 32);

View File

@ -35,6 +35,17 @@ public class SliderScrollbar
this.m_slider.Set(1f, false);
}
internal bool CheckDestroyed()
{
if (!m_slider || !m_scrollbar)
{
Instances.Remove(this);
return true;
}
return false;
}
internal void Update()
{
this.RefreshVisibility();
@ -42,11 +53,8 @@ public class SliderScrollbar
internal void RefreshVisibility()
{
if (!m_slider || !m_scrollbar)
{
Instances.Remove(this);
if (!m_slider.gameObject.activeInHierarchy)
return;
}
bool shouldShow = !Mathf.Approximately(this.m_scrollbar.size, 1);
var obj = this.m_slider.handleRect.gameObject;
@ -85,7 +93,7 @@ public class SliderScrollbar
GameObject handleSlideAreaObj = UIFactory.CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = UIFactory.CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddComponent<Image>();
Image bgImage = bgObj.AddGraphic<Image>();
bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
@ -101,7 +109,7 @@ public class SliderScrollbar
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddComponent<Image>();
Image fillImage = fillObj.AddGraphic<Image>();
fillImage.type = Image.Type.Sliced;
fillImage.color = Color.clear;
@ -114,7 +122,7 @@ public class SliderScrollbar
handleSlideRect.offsetMax = new Vector2(-15f, 0f);
handleSlideRect.sizeDelta = new Vector2(-30f, -30f);
Image handleImage = handleObj.AddComponent<Image>();
Image handleImage = handleObj.AddGraphic<Image>();
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
var handleRect = handleObj.GetComponent<RectTransform>();

View File

@ -1,5 +1,5 @@
using System;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.UI;
@ -10,7 +10,7 @@ namespace UnityExplorer.UI
internal static Vector2 thickSize = new Vector2(160f, 30f);
internal static Vector2 thinSize = new Vector2(160f, 20f);
internal static Color defaultTextColor = new Color(0.95f, 0.95f, 0.95f, 1f);
internal static Font m_defaultFont;
internal static Font s_defaultFont;
public static GameObject CreateUIObject(string name, GameObject parent, Vector2 size = default)
{
@ -47,16 +47,22 @@ namespace UnityExplorer.UI
}
}
public static T AddGraphic<T>(this GameObject obj) where T : Graphic
{
var ret = obj.AddComponent<T>();
ret.material = UIManager.UIMaterial;
return ret;
}
private static void SetDefaultTextValues(Text lbl)
{
lbl.color = defaultTextColor;
if (!m_defaultFont)
{
m_defaultFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
}
if (!s_defaultFont)
s_defaultFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
lbl.font = m_defaultFont;
if (s_defaultFont)
lbl.font = s_defaultFont;
}
public static void SetDefaultColorTransitionValues(Selectable selectable)
@ -99,7 +105,7 @@ namespace UnityExplorer.UI
rect.anchoredPosition = Vector2.zero;
rect.sizeDelta = Vector2.zero;
Image image = panelObj.AddComponent<Image>();
Image image = panelObj.AddGraphic<Image>();
image.type = Image.Type.Filled;
image.color = new Color(0.05f, 0.05f, 0.05f);
@ -116,7 +122,7 @@ namespace UnityExplorer.UI
content = new GameObject("Content");
content.transform.parent = panelObj.transform;
Image image2 = content.AddComponent<Image>();
Image image2 = content.AddGraphic<Image>();
image2.type = Image.Type.Filled;
image2.color = new Color(0.1f, 0.1f, 0.1f);
@ -143,7 +149,7 @@ namespace UnityExplorer.UI
gridGroup.cellSize = cellSize;
gridGroup.spacing = spacing;
Image image = groupObj.AddComponent<Image>();
Image image = groupObj.AddGraphic<Image>();
if (color != default)
{
image.color = color;
@ -164,7 +170,7 @@ namespace UnityExplorer.UI
horiGroup.childAlignment = TextAnchor.UpperLeft;
horiGroup.childControlWidth = false;
Image image = groupObj.AddComponent<Image>();
Image image = groupObj.AddGraphic<Image>();
if (color != default)
{
image.color = color;
@ -185,7 +191,7 @@ namespace UnityExplorer.UI
horiGroup.childAlignment = TextAnchor.UpperLeft;
horiGroup.childControlWidth = false;
Image image = groupObj.AddComponent<Image>();
Image image = groupObj.AddGraphic<Image>();
if (color != default)
{
image.color = color;
@ -198,23 +204,23 @@ namespace UnityExplorer.UI
return groupObj;
}
public static GameObject CreateTMPLabel(GameObject parent, TextAlignmentOptions alignment)
{
GameObject labelObj = CreateUIObject("Label", parent, thinSize);
//public static GameObject CreateTMPLabel(GameObject parent, TextAlignmentOptions alignment)
//{
// GameObject labelObj = CreateUIObject("Label", parent, thinSize);
TextMeshProUGUI text = labelObj.AddComponent<TextMeshProUGUI>();
// TextMeshProUGUI text = labelObj.AddGraphic<TextMeshProUGUI>();
text.alignment = alignment;
text.richText = true;
// text.alignment = alignment;
// text.richText = true;
return labelObj;
}
// return labelObj;
//}
public static GameObject CreateLabel(GameObject parent, TextAnchor alignment)
{
GameObject labelObj = CreateUIObject("Label", parent, thinSize);
Text text = labelObj.AddComponent<Text>();
Text text = labelObj.AddGraphic<Text>();
SetDefaultTextValues(text);
text.alignment = alignment;
text.supportRichText = true;
@ -230,7 +236,7 @@ namespace UnityExplorer.UI
textObj.AddComponent<RectTransform>();
SetParentAndAlign(textObj, buttonObj);
Image image = buttonObj.AddComponent<Image>();
Image image = buttonObj.AddGraphic<Image>();
image.type = Image.Type.Sliced;
image.color = new Color(1, 1, 1, 0.75f);
@ -244,7 +250,7 @@ namespace UnityExplorer.UI
btn.colors = colors;
}
Text text = textObj.AddComponent<Text>();
Text text = textObj.AddGraphic<Text>();
text.text = "Button";
SetDefaultTextValues(text);
text.alignment = TextAnchor.MiddleCenter;
@ -267,7 +273,7 @@ namespace UnityExplorer.UI
GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddComponent<Image>();
Image bgImage = bgObj.AddGraphic<Image>();
bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
@ -282,7 +288,7 @@ namespace UnityExplorer.UI
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddComponent<Image>();
Image fillImage = fillObj.AddGraphic<Image>();
fillImage.type = Image.Type.Sliced;
fillImage.color = new Color(0.3f, 0.3f, 0.3f, 1.0f);
@ -293,7 +299,7 @@ namespace UnityExplorer.UI
handleSlideRect.anchorMin = new Vector2(0f, 0f);
handleSlideRect.anchorMax = new Vector2(1f, 1f);
Image handleImage = handleObj.AddComponent<Image>();
Image handleImage = handleObj.AddGraphic<Image>();
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
handleObj.GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 0f);
@ -315,11 +321,11 @@ namespace UnityExplorer.UI
GameObject slideAreaObj = CreateUIObject("Sliding Area", scrollObj);
GameObject handleObj = CreateUIObject("Handle", slideAreaObj);
Image scrollImage = scrollObj.AddComponent<Image>();
Image scrollImage = scrollObj.AddGraphic<Image>();
scrollImage.type = Image.Type.Sliced;
scrollImage.color = new Color(0.1f, 0.1f, 0.1f);
Image handleImage = handleObj.AddComponent<Image>();
Image handleImage = handleObj.AddGraphic<Image>();
handleImage.type = Image.Type.Sliced;
handleImage.color = new Color(0.4f, 0.4f, 0.4f);
@ -364,14 +370,14 @@ namespace UnityExplorer.UI
}
#endif
Image bgImage = bgObj.AddComponent<Image>();
Image bgImage = bgObj.AddGraphic<Image>();
bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.1f, 0.1f, 0.1f, 1.0f);
Image checkImage = checkObj.AddComponent<Image>();
Image checkImage = checkObj.AddGraphic<Image>();
checkImage.color = new Color(90f / 255f, 115f / 255f, 90f / 255f, 1.0f);
text = labelObj.AddComponent<Text>();
text = labelObj.AddGraphic<Text>();
text.text = "Toggle";
SetDefaultTextValues(text);
@ -399,24 +405,21 @@ namespace UnityExplorer.UI
return toggleObj;
}
public static GameObject CreateTMPInput(GameObject parent, int fontSize = 16, int overflowMode = 0, int alignment = 257)
public static GameObject CreateInputField(GameObject parent, int fontSize = 14, int alignment = 3, int wrap = 0)
{
GameObject mainObj = CreateUIObject("InputField (TMP)", parent);
GameObject mainObj = CreateUIObject("InputField", parent);
Image mainImage = mainObj.AddComponent<Image>();
Image mainImage = mainObj.AddGraphic<Image>();
mainImage.type = Image.Type.Sliced;
mainImage.color = new Color(38f / 255f, 38f / 255f, 38f / 255f, 1.0f);
TMP_InputField mainInput = mainObj.AddComponent<TMP_InputField>();
InputField mainInput = mainObj.AddComponent<InputField>();
Navigation nav = mainInput.navigation;
nav.mode = Navigation.Mode.None;
mainInput.navigation = nav;
mainInput.richText = true;
mainInput.isRichTextEditingAllowed = true;
mainInput.lineType = TMP_InputField.LineType.MultiLineNewline;
mainInput.lineType = InputField.LineType.MultiLineNewline;
mainInput.interactable = true;
mainInput.transition = Selectable.Transition.ColorTint;
mainInput.onFocusSelectAll = false;
ColorBlock mainColors = mainInput.colors;
mainColors.normalColor = new Color(1, 1, 1, 1);
@ -435,21 +438,21 @@ namespace UnityExplorer.UI
textArea.AddComponent<RectMask2D>();
RectTransform textAreaRect = textArea.GetComponent<RectTransform>();
textAreaRect.anchorMin = new Vector2(0, 0);
textAreaRect.anchorMax = new Vector2(1, 1);
textAreaRect.offsetMin = new Vector2(10, 7);
textAreaRect.offsetMax = new Vector2(10, 6);
textAreaRect.anchorMin = Vector2.zero;
textAreaRect.anchorMax = Vector2.one;
textAreaRect.offsetMin = Vector2.zero;
textAreaRect.offsetMax = Vector2.zero;
mainInput.textViewport = textArea.GetComponent<RectTransform>();
// mainInput.textViewport = textArea.GetComponent<RectTransform>();
GameObject placeHolderObj = CreateUIObject("Placeholder", textArea);
TextMeshProUGUI placeholderText = placeHolderObj.AddComponent<TextMeshProUGUI>();
placeholderText.fontSize = fontSize;
placeholderText.fontSizeMax = fontSize;
Text placeholderText = placeHolderObj.AddGraphic<Text>();
SetDefaultTextValues(placeholderText);
placeholderText.text = "...";
placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
placeholderText.overflowMode = (TextOverflowModes)overflowMode;
placeholderText.alignment = (TextAlignmentOptions)alignment;
placeholderText.horizontalOverflow = (HorizontalWrapMode)wrap;
placeholderText.alignment = (TextAnchor)alignment;
placeholderText.fontSize = fontSize;
RectTransform placeHolderRect = placeHolderObj.GetComponent<RectTransform>();
placeHolderRect.anchorMin = Vector2.zero;
@ -464,13 +467,13 @@ namespace UnityExplorer.UI
mainInput.placeholder = placeholderText;
GameObject inputTextObj = CreateUIObject("Text", textArea);
TextMeshProUGUI inputText = inputTextObj.AddComponent<TextMeshProUGUI>();
inputText.fontSize = fontSize;
inputText.fontSizeMax = fontSize;
Text inputText = inputTextObj.AddGraphic<Text>();
SetDefaultTextValues(inputText);
inputText.text = "";
inputText.color = new Color(1f, 1f, 1f, 1f);
inputText.overflowMode = (TextOverflowModes)overflowMode;
inputText.alignment = (TextAlignmentOptions)alignment;
inputText.horizontalOverflow = (HorizontalWrapMode)wrap;
inputText.alignment = (TextAnchor)alignment;
inputText.fontSize = fontSize;
RectTransform inputTextRect = inputTextObj.GetComponent<RectTransform>();
inputTextRect.anchorMin = Vector2.zero;
@ -487,51 +490,6 @@ namespace UnityExplorer.UI
return mainObj;
}
public static GameObject CreateInputField(GameObject parent)
{
GameObject inputObj = CreateUIObject("InputField", parent, thickSize);
GameObject placeholderObj = CreateUIObject("Placeholder", inputObj);
GameObject textObj = CreateUIObject("Text", inputObj);
Image inputImage = inputObj.AddComponent<Image>();
inputImage.type = Image.Type.Sliced;
inputImage.color = new Color(0.1f, 0.1f, 0.1f, 1.0f);
InputField inputField = inputObj.AddComponent<InputField>();
SetDefaultColorTransitionValues(inputField);
Text text = textObj.AddComponent<Text>();
text.text = "";
text.supportRichText = false;
SetDefaultTextValues(text);
Text placeholderText = placeholderObj.AddComponent<Text>();
placeholderText.text = "Enter text...";
placeholderText.fontStyle = FontStyle.Italic;
Color color = text.color;
color.a *= 0.5f;
placeholderText.color = color;
RectTransform textRect = textObj.GetComponent<RectTransform>();
textRect.anchorMin = Vector2.zero;
textRect.anchorMax = Vector2.one;
textRect.sizeDelta = Vector2.zero;
textRect.offsetMin = new Vector2(10f, 6f);
textRect.offsetMax = new Vector2(-10f, -7f);
RectTransform placeholderRect = placeholderObj.GetComponent<RectTransform>();
placeholderRect.anchorMin = Vector2.zero;
placeholderRect.anchorMax = Vector2.one;
placeholderRect.sizeDelta = Vector2.zero;
placeholderRect.offsetMin = new Vector2(10f, 6f);
placeholderRect.offsetMax = new Vector2(-10f, -7f);
inputField.textComponent = text;
inputField.placeholder = placeholderText;
return inputObj;
}
public static GameObject CreateDropdown(GameObject parent, out Dropdown dropdown)
{
GameObject dropdownObj = CreateUIObject("Dropdown", parent, thickSize);
@ -557,11 +515,11 @@ namespace UnityExplorer.UI
scrollRectTransform.pivot = Vector2.one;
scrollRectTransform.sizeDelta = new Vector2(scrollRectTransform.sizeDelta.x, 0f);
Text itemLabelText = itemLabelObj.AddComponent<Text>();
Text itemLabelText = itemLabelObj.AddGraphic<Text>();
SetDefaultTextValues(itemLabelText);
itemLabelText.alignment = TextAnchor.MiddleLeft;
var arrowText = arrowObj.AddComponent<Text>();
var arrowText = arrowObj.AddGraphic<Text>();
SetDefaultTextValues(arrowText);
arrowText.text = "▼";
var arrowRect = arrowObj.GetComponent<RectTransform>();
@ -570,7 +528,7 @@ namespace UnityExplorer.UI
arrowRect.sizeDelta = new Vector2(20f, 20f);
arrowRect.anchoredPosition = new Vector2(-15f, 0f);
Image itemBgImage = itemBgObj.AddComponent<Image>();
Image itemBgImage = itemBgObj.AddGraphic<Image>();
itemBgImage.color = new Color(0.25f, 0.45f, 0.25f, 1.0f);
Toggle itemToggle = itemObj.AddComponent<Toggle>();
@ -586,7 +544,7 @@ namespace UnityExplorer.UI
#else
itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });
#endif
Image templateImage = templateObj.AddComponent<Image>();
Image templateImage = templateObj.AddGraphic<Image>();
templateImage.type = Image.Type.Sliced;
templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
@ -602,14 +560,14 @@ namespace UnityExplorer.UI
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
Image viewportImage = viewportObj.AddComponent<Image>();
Image viewportImage = viewportObj.AddGraphic<Image>();
viewportImage.type = Image.Type.Sliced;
Text labelText = labelObj.AddComponent<Text>();
Text labelText = labelObj.AddGraphic<Text>();
SetDefaultTextValues(labelText);
labelText.alignment = TextAnchor.MiddleLeft;
Image dropdownImage = dropdownObj.AddComponent<Image>();
Image dropdownImage = dropdownObj.AddGraphic<Image>();
dropdownImage.color = new Color(0.2f, 0.2f, 0.2f, 1);
dropdownImage.type = Image.Type.Sliced;
@ -678,7 +636,7 @@ namespace UnityExplorer.UI
mainLayout.flexibleWidth = 5000;
mainLayout.flexibleHeight = 5000;
Image mainImage = mainObj.AddComponent<Image>();
Image mainImage = mainObj.AddGraphic<Image>();
mainImage.type = Image.Type.Filled;
mainImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
@ -691,7 +649,7 @@ namespace UnityExplorer.UI
viewportRect.sizeDelta = new Vector2(-15.0f, 0.0f);
viewportRect.offsetMax = new Vector2(-20.0f, 0.0f);
viewportObj.AddComponent<Image>().color = Color.white;
viewportObj.AddGraphic<Image>().color = Color.white;
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
content = CreateUIObject("Content", viewportObj);

View File

@ -4,7 +4,7 @@ using UnityEngine.UI;
using UnityExplorer.Inspectors;
using UnityExplorer.UI.PageModel;
using System.IO;
using TMPro;
//using TMPro;
using System.Reflection;
using UnityExplorer.Helpers;
#if CPP
@ -19,36 +19,29 @@ 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; }
internal static Material UIMaterial { get; private set; }
internal static Sprite ResizeCursor { get; private set; }
internal static Font ConsoleFont { get; private set; }
internal static Font DefaultFont { get; private set; }
public static void Init()
{
var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\tmp.bundle";
var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\explorerui.bundle";
if (File.Exists(bundlePath))
{
var bundle = AssetBundle.LoadFromFile(bundlePath);
bundle.LoadAllAssets();
ExplorerCore.Log("Loaded TMP bundle");
UIMaterial = bundle.LoadAsset<Material>("UIMaterial");
ResizeCursor = bundle.LoadAsset<Sprite>("cursor");
if (TMP_Settings.instance == null)
{
var settings = bundle.LoadAsset<TMP_Settings>("TMP Settings");
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
DefaultFont = bundle.LoadAsset<Font>("CONSOLA");
#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");
ExplorerCore.Log("Loaded UI bundle");
}
else if (TMP_Settings.instance == null)
else
{
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\'!");
ExplorerCore.LogWarning("Could not find the ExplorerUI Bundle! It should exist at '" + bundlePath + "'");
return;
}
@ -107,12 +100,14 @@ namespace UnityExplorer.UI
PanelDragger.Instance.Update();
}
foreach (var slider in SliderScrollbar.Instances)
for (int i = 0; i < SliderScrollbar.Instances.Count; i++)
{
if (slider.m_slider.gameObject.activeInHierarchy)
{
var slider = SliderScrollbar.Instances[i];
if (slider.CheckDestroyed())
i--;
else
slider.Update();
}
}
}