This commit is contained in:
sinaioutlander
2020-11-05 17:33:04 +11:00
parent a46bc11e42
commit e175e9c438
47 changed files with 890 additions and 336 deletions

View File

@ -7,7 +7,7 @@
//using UnityExplorer.Helpers;
//using UnityExplorer.UI.Shared;
//namespace UnityExplorer.UI
//namespace UnityExplorer.UI.InteractiveValue
//{
// public class InteractiveValue
// {

View File

@ -1,320 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
#if CPP
#endif
namespace UnityExplorer.UI.Main.Console
{
public class AutoCompleter
{
public static AutoCompleter Instance;
public const int MAX_LABELS = 500;
private const int UPDATES_PER_BATCH = 100;
public static GameObject m_mainObj;
private static RectTransform m_thisRect;
private static readonly List<GameObject> m_suggestionButtons = new List<GameObject>();
private static readonly List<Text> m_suggestionTexts = new List<Text>();
private static readonly List<Text> m_hiddenSuggestionTexts = new List<Text>();
private static bool m_suggestionsDirty;
private static Suggestion[] m_suggestions = new Suggestion[0];
private static int m_lastBatchIndex;
private static string m_prevInput = "NULL";
private static int m_lastCaretPos;
public static void Init()
{
ConstructUI();
m_mainObj.SetActive(false);
}
public static void Update()
{
if (!m_mainObj)
{
return;
}
if (!ConsolePage.EnableSuggestions)
{
if (m_mainObj.activeSelf)
{
m_mainObj.SetActive(false);
}
return;
}
RefreshButtons();
UpdatePosition();
}
public static void SetSuggestions(Suggestion[] suggestions)
{
m_suggestions = suggestions;
m_suggestionsDirty = true;
m_lastBatchIndex = 0;
}
private static void RefreshButtons()
{
if (!m_suggestionsDirty)
{
return;
}
if (m_suggestions.Length < 1)
{
if (m_mainObj.activeSelf)
{
m_mainObj?.SetActive(false);
}
return;
}
if (!m_mainObj.activeSelf)
{
m_mainObj.SetActive(true);
}
if (m_suggestions.Length < 1 || m_lastBatchIndex >= MAX_LABELS)
{
m_suggestionsDirty = false;
return;
}
int end = m_lastBatchIndex + UPDATES_PER_BATCH;
for (int i = m_lastBatchIndex; i < end && i < MAX_LABELS; i++)
{
if (i >= m_suggestions.Length)
{
if (m_suggestionButtons[i].activeSelf)
{
m_suggestionButtons[i].SetActive(false);
}
}
else
{
if (!m_suggestionButtons[i].activeSelf)
{
m_suggestionButtons[i].SetActive(true);
}
var suggestion = m_suggestions[i];
var label = m_suggestionTexts[i];
var hiddenLabel = m_hiddenSuggestionTexts[i];
label.text = suggestion.Full;
hiddenLabel.text = suggestion.Addition;
label.color = suggestion.TextColor;
}
m_lastBatchIndex = i;
}
m_lastBatchIndex++;
}
private static void UpdatePosition()
{
var editor = ConsolePage.Instance.m_codeEditor;
if (editor.InputField.text.Length < 1)
{
return;
}
int caretPos = editor.InputField.caretPosition;
while (caretPos >= editor.inputText.textInfo.characterInfo.Length)
{
caretPos--;
}
if (caretPos == m_lastCaretPos)
{
return;
}
m_lastCaretPos = caretPos;
if (caretPos >= 0 && caretPos < editor.inputText.textInfo.characterInfo.Length)
{
var pos = editor.inputText.textInfo.characterInfo[caretPos].bottomLeft;
pos = editor.InputField.transform.TransformPoint(pos);
m_mainObj.transform.position = new Vector3(pos.x, pos.y - 3, 0);
}
}
private static readonly char[] splitChars = new[] { '{', '}', ',', ';', '<', '>', '(', ')', '[', ']', '=', '|', '&', '?' };
public static void CheckAutocomplete()
{
var m_codeEditor = ConsolePage.Instance.m_codeEditor;
string input = m_codeEditor.InputField.text;
int caretIndex = m_codeEditor.InputField.caretPosition;
if (!string.IsNullOrEmpty(input))
{
try
{
int start = caretIndex <= 0 ? 0 : input.LastIndexOfAny(splitChars, caretIndex - 1) + 1;
input = input.Substring(start, caretIndex - start).Trim();
}
catch (ArgumentException) { }
}
if (!string.IsNullOrEmpty(input) && input != m_prevInput)
{
GetAutocompletes(input);
}
else
{
ClearAutocompletes();
}
m_prevInput = input;
}
public static void ClearAutocompletes()
{
if (ConsolePage.AutoCompletes.Any())
{
ConsolePage.AutoCompletes.Clear();
}
}
public static void GetAutocompletes(string input)
{
try
{
// Credit ManylMarco
ConsolePage.AutoCompletes.Clear();
string[] completions = ConsolePage.Instance.m_evaluator.GetCompletions(input, out string prefix);
if (completions != null)
{
if (prefix == null)
{
prefix = input;
}
ConsolePage.AutoCompletes.AddRange(completions
.Where(x => !string.IsNullOrEmpty(x))
.Select(x => new Suggestion(x, prefix, Suggestion.Contexts.Other))
);
}
string trimmed = input.Trim();
if (trimmed.StartsWith("using"))
{
trimmed = trimmed.Remove(0, 5).Trim();
}
IEnumerable<Suggestion> namespaces = Suggestion.Namespaces
.Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length)
.Select(x => new Suggestion(
x.Substring(trimmed.Length),
x.Substring(0, trimmed.Length),
Suggestion.Contexts.Namespace));
ConsolePage.AutoCompletes.AddRange(namespaces);
IEnumerable<Suggestion> keywords = Suggestion.Keywords
.Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length)
.Select(x => new Suggestion(
x.Substring(trimmed.Length),
x.Substring(0, trimmed.Length),
Suggestion.Contexts.Keyword));
ConsolePage.AutoCompletes.AddRange(keywords);
}
catch (Exception ex)
{
ExplorerCore.Log("Autocomplete error:\r\n" + ex.ToString());
ClearAutocompletes();
}
}
#region UI Construction
private static void ConstructUI()
{
var parent = UIManager.CanvasRoot;
var obj = UIFactory.CreateScrollView(parent, out GameObject content, new Color(0.1f, 0.1f, 0.1f, 0.95f));
m_mainObj = obj;
var mainRect = obj.GetComponent<RectTransform>();
m_thisRect = mainRect;
mainRect.pivot = new Vector2(0f, 1f);
mainRect.anchorMin = new Vector2(0.45f, 0.45f);
mainRect.anchorMax = new Vector2(0.65f, 0.6f);
mainRect.offsetMin = Vector2.zero;
mainRect.offsetMax = Vector2.zero;
var mainGroup = content.GetComponent<VerticalLayoutGroup>();
mainGroup.childControlHeight = false;
mainGroup.childControlWidth = true;
mainGroup.childForceExpandHeight = false;
mainGroup.childForceExpandWidth = true;
for (int i = 0; i < MAX_LABELS; i++)
{
var buttonObj = UIFactory.CreateButton(content);
Button btn = buttonObj.GetComponent<Button>();
ColorBlock btnColors = btn.colors;
btnColors.normalColor = new Color(0f, 0f, 0f, 0f);
btnColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1.0f);
btn.colors = btnColors;
var nav = btn.navigation;
nav.mode = Navigation.Mode.Vertical;
btn.navigation = nav;
var btnLayout = buttonObj.AddComponent<LayoutElement>();
btnLayout.minHeight = 20;
var text = btn.GetComponentInChildren<Text>();
text.alignment = TextAnchor.MiddleLeft;
text.color = Color.white;
var hiddenChild = UIFactory.CreateUIObject("HiddenText", buttonObj);
hiddenChild.SetActive(false);
var hiddenText = hiddenChild.AddComponent<Text>();
m_hiddenSuggestionTexts.Add(hiddenText);
#if CPP
btn.onClick.AddListener(new Action(UseAutocompleteButton));
#else
btn.onClick.AddListener(UseAutocompleteButton);
#endif
void UseAutocompleteButton()
{
ConsolePage.Instance.UseAutocomplete(hiddenText.text);
EventSystem.current.SetSelectedGameObject(ConsolePage.Instance.m_codeEditor.InputField.gameObject,
null);
}
m_suggestionButtons.Add(buttonObj);
m_suggestionTexts.Add(text);
}
}
#endregion
}
}

View File

@ -1,181 +0,0 @@
using System.Collections.Generic;
using System.Text;
using UnityExplorer.UI.Main.Console.Lexer;
using UnityEngine;
namespace UnityExplorer.UI.Main.Console
{
public static class CSharpLexer
{
public static char indentIncreaseCharacter = '{';
public static char indentDecreaseCharacter = '}';
public static string delimiterSymbols = "[ ] ( ) { } ; : , .";
private static readonly StringBuilder indentBuilder = new StringBuilder();
public static CommentMatch commentMatcher = new CommentMatch();
public static SymbolMatch symbolMatcher = new SymbolMatch();
public static NumberMatch numberMatcher = new NumberMatch();
public static StringMatch stringMatcher = new StringMatch();
public static KeywordMatch validKeywordMatcher = new KeywordMatch
{
highlightColor = new Color(0.33f, 0.61f, 0.83f, 1.0f),
keywords = @"add as ascending await bool break by byte
case catch char checked const continue decimal default descending do dynamic
else equals false finally float for foreach from global goto group
if in int into is join let lock long new null object on orderby out
ref remove return sbyte select short sizeof stackalloc string
switch throw true try typeof uint ulong ushort
var where while yield"
};
public static KeywordMatch invalidKeywordMatcher = new KeywordMatch()
{
highlightColor = new Color(0.95f, 0.10f, 0.10f, 1.0f),
keywords = @"abstract async base class delegate enum explicit extern fixed get
implicit interface internal namespace operator override params private protected public
using partial readonly sealed set static struct this unchecked unsafe value virtual volatile void"
};
private static char[] delimiterSymbolCache = null;
internal static char[] DelimiterSymbols
{
get
{
if (delimiterSymbolCache == null)
{
string[] symbols = delimiterSymbols.Split(' ');
int count = 0;
for (int i = 0; i < symbols.Length; i++)
{
if (symbols[i].Length == 1)
{
count++;
}
}
delimiterSymbolCache = new char[count];
for (int i = 0, index = 0; i < symbols.Length; i++)
{
if (symbols[i].Length == 1)
{
delimiterSymbolCache[index] = symbols[i][0];
index++;
}
}
}
return delimiterSymbolCache;
}
}
private static Matcher[] matchers = null;
internal static Matcher[] Matchers
{
get
{
if (matchers == null)
{
List<Matcher> matcherList = new List<Matcher>
{
commentMatcher,
symbolMatcher,
numberMatcher,
stringMatcher,
validKeywordMatcher,
invalidKeywordMatcher,
};
matchers = matcherList.ToArray();
}
return matchers;
}
}
public static string GetIndentForInput(string input, int indent, out int caretPosition)
{
indentBuilder.Clear();
indent += 1;
bool stringState = false;
for (int i = 0; i < input.Length; i++)
{
if (input[i] == '"')
{
stringState = !stringState;
}
if (input[i] == '\n')
{
indentBuilder.Append('\n');
for (int j = 0; j < indent; j++)
{
indentBuilder.Append("\t");
}
}
else if (input[i] == '\t')
{
continue;
}
else if (!stringState && input[i] == indentIncreaseCharacter)
{
indentBuilder.Append(indentIncreaseCharacter);
indent++;
}
else if (!stringState && input[i] == indentDecreaseCharacter)
{
indentBuilder.Append(indentDecreaseCharacter);
indent--;
}
else
{
indentBuilder.Append(input[i]);
}
}
string formattedSection = indentBuilder.ToString();
caretPosition = formattedSection.Length - 1;
for (int i = formattedSection.Length - 1; i >= 0; i--)
{
if (formattedSection[i] == '\n')
{
continue;
}
caretPosition = i;
break;
}
return formattedSection;
}
public static int GetIndentLevel(string inputString, int startIndex, int endIndex)
{
int indent = 0;
for (int i = startIndex; i < endIndex; i++)
{
if (inputString[i] == '\t')
{
indent++;
}
// Check for end line or other characters
if (inputString[i] == '\n' || inputString[i] != ' ')
{
break;
}
}
return indent;
}
}
}

View File

@ -1,441 +0,0 @@
using System;
using System.Linq;
using System.Text;
using UnityExplorer.Input;
using UnityExplorer.UI.Main.Console.Lexer;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UnityExplorer.UI.Main.Console
{
public class CodeEditor
{
private readonly InputLexer inputLexer = new InputLexer();
public TMP_InputField InputField { get; }
public readonly TextMeshProUGUI inputText;
private readonly TextMeshProUGUI inputHighlightText;
private readonly TextMeshProUGUI lineText;
private readonly Image background;
private readonly Image lineHighlight;
private readonly Image lineNumberBackground;
private readonly Image scrollbar;
private bool lineHighlightLocked;
private readonly RectTransform inputTextTransform;
private readonly RectTransform lineHighlightTransform;
public int LineCount { get; private set; }
public int CurrentLine { get; private set; }
public int CurrentColumn { get; private set; }
public int CurrentIndent { get; private set; }
private static readonly StringBuilder highlightedBuilder = new StringBuilder(4096);
private static readonly StringBuilder lineBuilder = new StringBuilder();
private static readonly KeyCode[] lineChangeKeys =
{
KeyCode.Return, KeyCode.Backspace, KeyCode.UpArrow,
KeyCode.DownArrow, KeyCode.LeftArrow, KeyCode.RightArrow
};
public string HighlightedText => inputHighlightText.text;
public string Text
{
get { return InputField.text; }
set
{
if (!string.IsNullOrEmpty(value))
{
InputField.text = value;
inputHighlightText.text = value;
}
else
{
InputField.text = string.Empty;
inputHighlightText.text = string.Empty;
}
inputText.ForceMeshUpdate(false);
}
}
public CodeEditor(TMP_InputField inputField, TextMeshProUGUI inputText, TextMeshProUGUI inputHighlightText, TextMeshProUGUI lineText,
Image background, Image lineHighlight, Image lineNumberBackground, Image scrollbar)
{
InputField = inputField;
this.inputText = inputText;
this.inputHighlightText = inputHighlightText;
this.lineText = lineText;
this.background = background;
this.lineHighlight = lineHighlight;
this.lineNumberBackground = lineNumberBackground;
this.scrollbar = scrollbar;
if (!AllReferencesAssigned())
{
throw new Exception("References are missing!");
}
InputField.restoreOriginalTextOnEscape = false;
inputTextTransform = inputText.GetComponent<RectTransform>();
lineHighlightTransform = lineHighlight.GetComponent<RectTransform>();
ApplyTheme();
inputLexer.UseMatchers(CSharpLexer.DelimiterSymbols, CSharpLexer.Matchers);
// subscribe to text input changing
#if CPP
InputField.onValueChanged.AddListener(new Action<string>((string s) => { OnInputChanged(); }));
#else
this.InputField.onValueChanged.AddListener((string s) => { OnInputChanged(); });
#endif
}
public void Update()
{
// Check for new line
if (ConsolePage.EnableAutoIndent && InputManager.GetKeyDown(KeyCode.Return))
{
AutoIndentCaret();
}
if (EventSystem.current?.currentSelectedGameObject?.name == "InputField (TMP)")
{
bool focusKeyPressed = false;
// Check for any focus key pressed
foreach (KeyCode key in lineChangeKeys)
{
if (InputManager.GetKeyDown(key))
{
focusKeyPressed = true;
break;
}
}
// Update line highlight
if (focusKeyPressed || InputManager.GetMouseButton(0))
{
UpdateHighlight();
ConsolePage.Instance.OnInputChanged();
}
}
}
public void OnInputChanged(bool forceUpdate = false)
{
string newText = InputField.text;
UpdateIndent();
if (!forceUpdate && string.IsNullOrEmpty(newText))
{
inputHighlightText.text = string.Empty;
}
else
{
inputHighlightText.text = SyntaxHighlightContent(newText);
}
UpdateLineNumbers();
UpdateHighlight();
ConsolePage.Instance.OnInputChanged();
}
public void SetLineHighlight(int lineNumber, bool lockLineHighlight)
{
if (lineNumber < 1 || lineNumber > LineCount)
{
return;
}
lineHighlightTransform.anchoredPosition = new Vector2(5,
(inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight *
-(lineNumber - 1)) - 4f +
inputTextTransform.anchoredPosition.y);
lineHighlightLocked = lockLineHighlight;
}
private void UpdateLineNumbers()
{
int currentLineCount = inputText.textInfo.lineCount;
int currentLineNumber = 1;
if (currentLineCount != LineCount)
{
try
{
lineBuilder.Length = 0;
for (int i = 1; i < currentLineCount + 2; i++)
{
if (i - 1 > 0 && i - 1 < currentLineCount - 1)
{
int characterStart = inputText.textInfo.lineInfo[i - 1].firstCharacterIndex;
int characterCount = inputText.textInfo.lineInfo[i - 1].characterCount;
if (characterStart >= 0 && characterStart < inputText.text.Length &&
characterCount != 0 && !inputText.text.Substring(characterStart, characterCount).Contains("\n"))
{
lineBuilder.Append("\n");
continue;
}
}
lineBuilder.Append(currentLineNumber);
lineBuilder.Append('\n');
currentLineNumber++;
if (i - 1 == 0 && i - 1 < currentLineCount - 1)
{
int characterStart = inputText.textInfo.lineInfo[i - 1].firstCharacterIndex;
int characterCount = inputText.textInfo.lineInfo[i - 1].characterCount;
if (characterStart >= 0 && characterStart < inputText.text.Length &&
characterCount != 0 && !inputText.text.Substring(characterStart, characterCount).Contains("\n"))
{
lineBuilder.Append("\n");
continue;
}
}
}
lineText.text = lineBuilder.ToString();
LineCount = currentLineCount;
}
catch { }
}
}
private void UpdateIndent()
{
int caret = InputField.caretPosition;
if (caret < 0 || caret >= inputText.textInfo.characterInfo.Length)
{
while (caret >= 0 && caret >= inputText.textInfo.characterInfo.Length)
{
caret--;
}
if (caret < 0 || caret >= inputText.textInfo.characterInfo.Length)
{
return;
}
}
CurrentLine = inputText.textInfo.characterInfo[caret].lineNumber;
int charCount = 0;
for (int i = 0; i < CurrentLine; i++)
{
charCount += inputText.textInfo.lineInfo[i].characterCount;
}
CurrentColumn = caret - charCount;
CurrentIndent = 0;
for (int i = 0; i < caret && i < InputField.text.Length; i++)
{
char character = InputField.text[i];
if (character == CSharpLexer.indentIncreaseCharacter)
{
CurrentIndent++;
}
if (character == CSharpLexer.indentDecreaseCharacter)
{
CurrentIndent--;
}
}
if (CurrentIndent < 0)
{
CurrentIndent = 0;
}
}
private void UpdateHighlight()
{
if (lineHighlightLocked)
{
return;
}
try
{
int caret = InputField.caretPosition - 1;
float lineHeight = inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight;
int lineNumber = inputText.textInfo.characterInfo[caret].lineNumber;
float offset = lineNumber + inputTextTransform.anchoredPosition.y;
lineHighlightTransform.anchoredPosition = new Vector2(5, -(offset * lineHeight));
}
catch //(Exception e)
{
//ExplorerCore.LogWarning("Exception on Update Line Highlight: " + e);
}
}
private const string CLOSE_COLOR_TAG = "</color>";
private string SyntaxHighlightContent(string inputText)
{
int offset = 0;
highlightedBuilder.Length = 0;
foreach (LexerMatchInfo match in inputLexer.LexInputString(inputText))
{
for (int i = offset; i < match.startIndex; i++)
{
highlightedBuilder.Append(inputText[i]);
}
highlightedBuilder.Append(match.htmlColor);
for (int i = match.startIndex; i < match.endIndex; i++)
{
highlightedBuilder.Append(inputText[i]);
}
highlightedBuilder.Append(CLOSE_COLOR_TAG);
offset = match.endIndex;
}
for (int i = offset; i < inputText.Length; i++)
{
highlightedBuilder.Append(inputText[i]);
}
inputText = highlightedBuilder.ToString();
return inputText;
}
private void AutoIndentCaret()
{
if (CurrentIndent > 0)
{
string indent = GetAutoIndentTab(CurrentIndent);
if (indent.Length > 0)
{
int caretPos = InputField.caretPosition;
string indentMinusOne = indent.Substring(0, indent.Length - 1);
// get last index of {
// chuck it on the next line if its not already
string text = InputField.text;
string sub = InputField.text.Substring(0, InputField.caretPosition);
int lastIndex = sub.LastIndexOf("{");
int offset = lastIndex - 1;
if (offset >= 0 && text[offset] != '\n' && text[offset] != '\t')
{
string open = "\n" + indentMinusOne;
InputField.text = text.Insert(offset + 1, open);
caretPos += open.Length;
}
// check if should add auto-close }
int numOpen = InputField.text.Where(x => x == CSharpLexer.indentIncreaseCharacter).Count();
int numClose = InputField.text.Where(x => x == CSharpLexer.indentDecreaseCharacter).Count();
if (numOpen > numClose)
{
// add auto-indent closing
indentMinusOne = $"\n{indentMinusOne}}}";
InputField.text = InputField.text.Insert(caretPos, indentMinusOne);
}
// insert the actual auto indent now
InputField.text = InputField.text.Insert(caretPos, indent);
InputField.stringPosition = caretPos + indent.Length;
}
}
// Update line column and indent positions
UpdateIndent();
inputText.text = InputField.text;
inputText.SetText(InputField.text, true);
inputText.Rebuild(CanvasUpdate.Prelayout);
InputField.ForceLabelUpdate();
InputField.Rebuild(CanvasUpdate.Prelayout);
OnInputChanged(true);
}
private string GetAutoIndentTab(int amount)
{
string tab = string.Empty;
for (int i = 0; i < amount; i++)
{
tab += "\t";
}
return tab;
}
private static Color caretColor = new Color32(255, 255, 255, 255);
private static Color textColor = new Color32(255, 255, 255, 255);
private static Color backgroundColor = new Color32(37, 37, 37, 255);
private static Color lineHighlightColor = new Color32(50, 50, 50, 255);
private static Color lineNumberBackgroundColor = new Color32(25, 25, 25, 255);
private static Color lineNumberTextColor = new Color32(180, 180, 180, 255);
private static Color scrollbarColor = new Color32(45, 50, 50, 255);
private void ApplyTheme()
{
var highlightTextRect = inputHighlightText.GetComponent<RectTransform>();
highlightTextRect.anchorMin = Vector2.zero;
highlightTextRect.anchorMax = Vector2.one;
highlightTextRect.offsetMin = Vector2.zero;
highlightTextRect.offsetMax = Vector2.zero;
InputField.caretColor = caretColor;
inputText.color = textColor;
inputHighlightText.color = textColor;
background.color = backgroundColor;
lineHighlight.color = lineHighlightColor;
lineNumberBackground.color = lineNumberBackgroundColor;
lineText.color = lineNumberTextColor;
scrollbar.color = scrollbarColor;
}
private bool AllReferencesAssigned()
{
if (!InputField ||
!inputText ||
!inputHighlightText ||
!lineText ||
!background ||
!lineHighlight ||
!lineNumberBackground ||
!scrollbar)
{
// One or more references are not assigned
return false;
}
return true;
}
}
}

View File

@ -1,49 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
namespace UnityExplorer.UI.Main.Console.Lexer
{
public sealed class CommentMatch : Matcher
{
public string lineCommentStart = @"//";
public string blockCommentStart = @"/*";
public string blockCommentEnd = @"*/";
public override Color HighlightColor => new Color(0.34f, 0.65f, 0.29f, 1.0f);
public override IEnumerable<char> StartChars => new char[] { lineCommentStart[0], blockCommentStart[0] };
public override IEnumerable<char> EndChars => new char[] { blockCommentEnd[0] };
public override bool IsImplicitMatch(InputLexer lexer) => IsMatch(lexer, lineCommentStart) || IsMatch(lexer, blockCommentStart);
private bool IsMatch(InputLexer lexer, string commentType)
{
if (!string.IsNullOrEmpty(commentType))
{
lexer.Rollback();
bool match = true;
for (int i = 0; i < commentType.Length; i++)
{
if (commentType[i] != lexer.ReadNext())
{
match = false;
break;
}
}
if (match)
{
// Read until end
while (!IsEndLineOrEndFile(lexer, lexer.ReadNext()))
{
;
}
return true;
}
}
return false;
}
private bool IsEndLineOrEndFile(InputLexer lexer, char character) => lexer.EndOfStream || character == '\n' || character == '\r';
}
}

View File

@ -1,201 +0,0 @@
using System.Collections.Generic;
namespace UnityExplorer.UI.Main.Console.Lexer
{
public struct LexerMatchInfo
{
public int startIndex;
public int endIndex;
public string htmlColor;
}
public enum SpecialCharacterPosition
{
Start,
End,
};
public class InputLexer
{
private string inputString = null;
private Matcher[] matchers = null;
private readonly HashSet<char> specialStartSymbols = new HashSet<char>();
private readonly HashSet<char> specialEndSymbols = new HashSet<char>();
private int currentIndex = 0;
private int currentLookaheadIndex = 0;
private char current = ' ';
public char Previous { get; private set; } = ' ';
public bool EndOfStream
{
get { return currentLookaheadIndex >= inputString.Length; }
}
public void UseMatchers(char[] delimiters, Matcher[] matchers)
{
this.matchers = matchers;
specialStartSymbols.Clear();
specialEndSymbols.Clear();
if (delimiters != null)
{
foreach (char character in delimiters)
{
if (!specialStartSymbols.Contains(character))
{
specialStartSymbols.Add(character);
}
if (!specialEndSymbols.Contains(character))
{
specialEndSymbols.Add(character);
}
}
}
if (matchers != null)
{
foreach (Matcher lexer in matchers)
{
foreach (char special in lexer.StartChars)
{
if (!specialStartSymbols.Contains(special))
{
specialStartSymbols.Add(special);
}
}
foreach (char special in lexer.EndChars)
{
if (!specialEndSymbols.Contains(special))
{
specialEndSymbols.Add(special);
}
}
}
}
}
public IEnumerable<LexerMatchInfo> LexInputString(string input)
{
if (input == null || matchers == null || matchers.Length == 0)
{
yield break;
}
inputString = input;
current = ' ';
Previous = ' ';
currentIndex = 0;
currentLookaheadIndex = 0;
while (!EndOfStream)
{
bool didMatchLexer = false;
ReadWhiteSpace();
foreach (Matcher matcher in matchers)
{
int startIndex = currentIndex;
bool isMatched = matcher.IsMatch(this);
if (isMatched)
{
int endIndex = currentIndex;
didMatchLexer = true;
yield return new LexerMatchInfo
{
startIndex = startIndex,
endIndex = endIndex,
htmlColor = matcher.HexColor,
};
break;
}
}
if (!didMatchLexer)
{
ReadNext();
Commit();
}
}
}
public char ReadNext()
{
if (EndOfStream)
{
return '\0';
}
Previous = current;
current = inputString[currentLookaheadIndex];
currentLookaheadIndex++;
return current;
}
public void Rollback(int amount = -1)
{
if (amount == -1)
{
currentLookaheadIndex = currentIndex;
}
else
{
if (currentLookaheadIndex > currentIndex)
{
currentLookaheadIndex -= amount;
}
}
int previousIndex = currentLookaheadIndex - 1;
if (previousIndex >= inputString.Length)
{
Previous = inputString[inputString.Length - 1];
}
else if (previousIndex >= 0)
{
Previous = inputString[previousIndex];
}
else
{
Previous = ' ';
}
}
public void Commit()
{
currentIndex = currentLookaheadIndex;
}
public bool IsSpecialSymbol(char character, SpecialCharacterPosition position = SpecialCharacterPosition.Start)
{
if (position == SpecialCharacterPosition.Start)
{
return specialStartSymbols.Contains(character);
}
return specialEndSymbols.Contains(character);
}
private void ReadWhiteSpace()
{
while (char.IsWhiteSpace(ReadNext()) == true)
{
Commit();
}
Rollback();
}
}
}

View File

@ -1,116 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
namespace UnityExplorer.UI.Main.Console.Lexer
{
public sealed class KeywordMatch : Matcher
{
public string keywords;
public override Color HighlightColor => highlightColor;
public Color highlightColor;
private readonly HashSet<string> shortlist = new HashSet<string>();
private readonly Stack<string> removeList = new Stack<string>();
public string[] keywordCache = null;
public override bool IsImplicitMatch(InputLexer lexer)
{
BuildKeywordCache();
if (!char.IsWhiteSpace(lexer.Previous) &&
!lexer.IsSpecialSymbol(lexer.Previous, SpecialCharacterPosition.End))
{
return false;
}
shortlist.Clear();
int currentIndex = 0;
char currentChar = lexer.ReadNext();
for (int i = 0; i < keywordCache.Length; i++)
{
if (keywordCache[i][0] == currentChar)
{
shortlist.Add(keywordCache[i]);
}
}
if (shortlist.Count == 0)
{
return false;
}
do
{
if (lexer.EndOfStream)
{
RemoveLongStrings(currentIndex + 1);
break;
}
currentChar = lexer.ReadNext();
currentIndex++;
if (char.IsWhiteSpace(currentChar) ||
lexer.IsSpecialSymbol(currentChar, SpecialCharacterPosition.Start))
{
RemoveLongStrings(currentIndex);
lexer.Rollback(1);
break;
}
foreach (string keyword in shortlist)
{
if (currentIndex >= keyword.Length || keyword[currentIndex] != currentChar)
{
removeList.Push(keyword);
}
}
while (removeList.Count > 0)
{
shortlist.Remove(removeList.Pop());
}
}
while (shortlist.Count > 0);
return shortlist.Count > 0;
}
private void RemoveLongStrings(int length)
{
foreach (string keyword in shortlist)
{
if (keyword.Length > length)
{
removeList.Push(keyword);
}
}
while (removeList.Count > 0)
{
shortlist.Remove(removeList.Pop());
}
}
private void BuildKeywordCache()
{
if (keywordCache == null)
{
string[] kwSplit = keywords.Split(' ');
List<string> list = new List<string>();
foreach (string kw in kwSplit)
{
if (!string.IsNullOrEmpty(kw) && kw.Length > 0)
{
list.Add(kw);
}
}
keywordCache = list.ToArray();
}
}
}
}

View File

@ -1,31 +0,0 @@
using System.Collections.Generic;
using UnityExplorer.Unstrip.ColorUtility;
using UnityEngine;
namespace UnityExplorer.UI.Main.Console.Lexer
{
public abstract class Matcher
{
public abstract Color HighlightColor { get; }
public string HexColor => htmlColor ?? (htmlColor = "<#" + HighlightColor.ToHex() + ">");
private string htmlColor = null;
public virtual IEnumerable<char> StartChars { get { yield break; } }
public virtual IEnumerable<char> EndChars { get { yield break; } }
public abstract bool IsImplicitMatch(InputLexer lexer);
public bool IsMatch(InputLexer lexer)
{
if (IsImplicitMatch(lexer))
{
lexer.Commit();
return true;
}
lexer.Rollback();
return false;
}
}
}

View File

@ -1,39 +0,0 @@
using UnityEngine;
namespace UnityExplorer.UI.Main.Console.Lexer
{
public sealed class NumberMatch : Matcher
{
public override Color HighlightColor => new Color(0.58f, 0.33f, 0.33f, 1.0f);
public override bool IsImplicitMatch(InputLexer lexer)
{
if (!char.IsWhiteSpace(lexer.Previous) &&
!lexer.IsSpecialSymbol(lexer.Previous, SpecialCharacterPosition.End))
{
return false;
}
bool matchedNumber = false;
while (!lexer.EndOfStream)
{
if (IsNumberOrDecimalPoint(lexer.ReadNext()))
{
matchedNumber = true;
lexer.Commit();
}
else
{
lexer.Rollback();
break;
}
}
return matchedNumber;
}
private bool IsNumberOrDecimalPoint(char character) => char.IsNumber(character) || character == '.';
}
}

View File

@ -1,37 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
namespace UnityExplorer.UI.Main.Console.Lexer
{
public sealed class StringMatch : Matcher
{
public override Color HighlightColor => new Color(0.79f, 0.52f, 0.32f, 1.0f);
public override IEnumerable<char> StartChars { get { yield return '"'; } }
public override IEnumerable<char> EndChars { get { yield return '"'; } }
public override bool IsImplicitMatch(InputLexer lexer)
{
if (lexer.ReadNext() == '"')
{
while (!IsClosingQuoteOrEndFile(lexer, lexer.ReadNext()))
{
;
}
return true;
}
return false;
}
private bool IsClosingQuoteOrEndFile(InputLexer lexer, char character)
{
if (lexer.EndOfStream == true ||
character == '"')
{
return true;
}
return false;
}
}
}

View File

@ -1,151 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityExplorer.UI.Main.Console.Lexer
{
public sealed class SymbolMatch : Matcher
{
public override Color HighlightColor => new Color(0.58f, 0.47f, 0.37f, 1.0f);
public string Symbols => @"[ ] ( ) . ? : + - * / % & | ^ ~ = < > ++ -- && || << >> == != <= >=
+= -= *= /= %= &= |= ^= <<= >>= -> ?? =>";
private static readonly List<string> shortlist = new List<string>();
private static readonly Stack<string> removeList = new Stack<string>();
private string[] symbolCache = null;
public override IEnumerable<char> StartChars
{
get
{
BuildSymbolCache();
foreach (string symbol in symbolCache.Where(x => x.Length > 0))
{
yield return symbol[0];
}
}
}
public override IEnumerable<char> EndChars
{
get
{
BuildSymbolCache();
foreach (string symbol in symbolCache.Where(x => x.Length > 0))
{
yield return symbol[0];
}
}
}
public override bool IsImplicitMatch(InputLexer lexer)
{
if (lexer == null)
{
return false;
}
BuildSymbolCache();
if (!char.IsWhiteSpace(lexer.Previous) &&
!char.IsLetter(lexer.Previous) &&
!char.IsDigit(lexer.Previous) &&
!lexer.IsSpecialSymbol(lexer.Previous, SpecialCharacterPosition.End))
{
return false;
}
shortlist.Clear();
int currentIndex = 0;
char currentChar = lexer.ReadNext();
for (int i = symbolCache.Length - 1; i >= 0; i--)
{
if (symbolCache[i][0] == currentChar)
{
shortlist.Add(symbolCache[i]);
}
}
if (shortlist.Count == 0)
{
return false;
}
do
{
if (lexer.EndOfStream)
{
RemoveLongStrings(currentIndex + 1);
break;
}
currentChar = lexer.ReadNext();
currentIndex++;
if (char.IsWhiteSpace(currentChar) ||
char.IsLetter(currentChar) ||
char.IsDigit(currentChar) ||
lexer.IsSpecialSymbol(currentChar, SpecialCharacterPosition.Start))
{
RemoveLongStrings(currentIndex);
lexer.Rollback(1);
break;
}
foreach (string symbol in shortlist)
{
if (currentIndex >= symbol.Length || symbol[currentIndex] != currentChar)
{
removeList.Push(symbol);
}
}
while (removeList.Count > 0)
{
shortlist.Remove(removeList.Pop());
}
}
while (shortlist.Count > 0);
return shortlist.Count > 0;
}
private void RemoveLongStrings(int length)
{
foreach (string keyword in shortlist)
{
if (keyword.Length > length)
{
removeList.Push(keyword);
}
}
while (removeList.Count > 0)
{
shortlist.Remove(removeList.Pop());
}
}
private void BuildSymbolCache()
{
if (symbolCache != null)
{
return;
}
string[] symSplit = Symbols.Split(' ');
List<string> list = new List<string>();
foreach (string sym in symSplit)
{
if (!string.IsNullOrEmpty(sym) && sym.Length > 0)
{
list.Add(sym);
}
}
symbolCache = list.ToArray();
}
}
}

View File

@ -1,76 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Mono.CSharp;
// Thanks to ManlyMarco for this
namespace UnityExplorer.UI.Main.Console
{
public class ScriptEvaluator : Evaluator, IDisposable
{
private static readonly HashSet<string> StdLib = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
{
"mscorlib", "System.Core", "System", "System.Xml"
};
private readonly TextWriter _logger;
public ScriptEvaluator(TextWriter logger) : base(BuildContext(logger))
{
_logger = logger;
ImportAppdomainAssemblies(ReferenceAssembly);
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
}
public void Dispose()
{
AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
_logger.Dispose();
}
private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
string name = args.LoadedAssembly.GetName().Name;
if (StdLib.Contains(name))
{
return;
}
ReferenceAssembly(args.LoadedAssembly);
}
private static CompilerContext BuildContext(TextWriter tw)
{
var reporter = new StreamReportPrinter(tw);
var settings = new CompilerSettings
{
Version = LanguageVersion.Experimental,
GenerateDebugInfo = false,
StdLib = true,
Target = Target.Library,
WarningLevel = 0,
EnhancedWarnings = false
};
return new CompilerContext(settings, reporter);
}
private static void ImportAppdomainAssemblies(Action<Assembly> import)
{
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
string name = assembly.GetName().Name;
if (StdLib.Contains(name))
{
continue;
}
import(assembly);
}
}
}
}

View File

@ -1,54 +0,0 @@
using System;
using Mono.CSharp;
namespace UnityExplorer.UI.Main.Console
{
public class ScriptInteraction : InteractiveBase
{
public static void Log(object message)
{
ExplorerCore.Log(message);
}
public static void AddUsing(string directive)
{
ConsolePage.Instance.AddUsing(directive);
}
public static void GetUsing()
{
ExplorerCore.Log(ConsolePage.Instance.m_evaluator.GetUsing());
}
public static void Reset()
{
ConsolePage.Instance.ResetConsole();
}
public static object CurrentTarget()
{
return InspectorManager.Instance?.m_activeInspector?.Target;
}
public static object[] AllTargets()
{
int count = InspectorManager.Instance?.m_currentInspectors.Count ?? 0;
object[] ret = new object[count];
for (int i = 0; i < count; i++)
{
ret[i] = InspectorManager.Instance?.m_currentInspectors[i].Target;
}
return ret;
}
public static void Inspect(object obj)
{
InspectorManager.Instance.Inspect(obj);
}
public static void Inspect(Type type)
{
InspectorManager.Instance.Inspect(type);
}
}
}

View File

@ -1,81 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace UnityExplorer.UI.Main.Console
{
public struct Suggestion
{
public string Full => Prefix + Addition;
public readonly string Prefix;
public readonly string Addition;
public readonly Contexts Context;
public Color TextColor
{
get
{
switch (Context)
{
case Contexts.Namespace: return Color.grey;
case Contexts.Keyword: return systemBlue;
default: return Color.white;
}
}
}
private static readonly Color systemBlue = new Color(80f / 255f, 150f / 255f, 215f / 255f);
public Suggestion(string addition, string prefix, Contexts type)
{
Addition = addition;
Prefix = prefix;
Context = type;
}
public enum Contexts
{
Namespace,
Keyword,
Other
}
public static HashSet<string> Namespaces => m_namspaces ?? GetNamespaces();
private static HashSet<string> m_namspaces;
private static HashSet<string> GetNamespaces()
{
HashSet<string> set = new HashSet<string>(
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(GetTypes)
.Where(x => x.IsPublic && !string.IsNullOrEmpty(x.Namespace))
.Select(x => x.Namespace));
return m_namspaces = set;
IEnumerable<Type> GetTypes(Assembly asm) => asm.TryGetTypes();
}
public static HashSet<string> Keywords => m_keywords ?? GetKeywords();
private static HashSet<string> m_keywords;
private static HashSet<string> GetKeywords()
{
if (CSharpLexer.validKeywordMatcher.keywordCache == null)
{
return new HashSet<string>();
}
HashSet<string> set = new HashSet<string>();
foreach (string keyword in CSharpLexer.validKeywordMatcher.keywordCache)
{
set.Add(keyword);
}
return m_keywords = set;
}
}
}

View File

@ -1,185 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityExplorer.Helpers;
using UnityExplorer.UI.Main.Inspectors;
using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip.Scenes;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace UnityExplorer.UI.Main
{
public class InspectorManager
{
public static InspectorManager Instance { get; private set; }
public InspectorManager()
{
Instance = this;
ConstructInspectorPane();
}
public InspectorBase m_activeInspector;
public readonly List<InspectorBase> m_currentInspectors = new List<InspectorBase>();
public GameObject m_tabBarContent;
public GameObject m_inspectorContent;
public void Update()
{
for (int i = 0; i < m_currentInspectors.Count; i++)
{
if (i >= m_currentInspectors.Count)
break;
m_currentInspectors[i].Update();
}
}
public void Inspect(object obj)
{
#if CPP
obj = obj.Il2CppCast(ReflectionHelpers.GetActualType(obj));
#endif
UnityEngine.Object unityObj = obj as UnityEngine.Object;
if (InspectorBase.ObjectNullOrDestroyed(obj, unityObj))
{
return;
}
MainMenu.Instance.SetPage(HomePage.Instance);
// check if currently inspecting this object
foreach (InspectorBase tab in m_currentInspectors)
{
if (ReferenceEquals(obj, tab.Target))
{
SetInspectorTab(tab);
return;
}
#if CPP
else if (unityObj && tab.Target is UnityEngine.Object uTabObj)
{
if (unityObj.m_CachedPtr == uTabObj.m_CachedPtr)
{
SetInspectorTab(tab);
return;
}
}
#endif
}
InspectorBase inspector;
if (obj is GameObject go)
{
inspector = new GameObjectInspector(go);
}
else
{
inspector = new InstanceInspector(obj);
}
m_currentInspectors.Add(inspector);
inspector.Content?.SetActive(false);
SetInspectorTab(inspector);
}
public void Inspect(Type type)
{
// TODO static type inspection
}
public void SetInspectorTab(InspectorBase inspector)
{
UnsetInspectorTab();
m_activeInspector = inspector;
m_activeInspector.Content?.SetActive(true);
Color activeColor = new Color(0, 0.25f, 0, 1);
ColorBlock colors = inspector.tabButton.colors;
colors.normalColor = activeColor;
colors.highlightedColor = activeColor;
inspector.tabButton.colors = colors;
}
public void UnsetInspectorTab()
{
if (m_activeInspector == null)
{
return;
}
m_activeInspector.Content?.SetActive(false);
ColorBlock colors = m_activeInspector.tabButton.colors;
colors.normalColor = new Color(0.2f, 0.2f, 0.2f, 1);
colors.highlightedColor = new Color(0.1f, 0.3f, 0.1f, 1);
m_activeInspector.tabButton.colors = colors;
m_activeInspector = null;
}
#region INSPECTOR PANE
public void ConstructInspectorPane()
{
var mainObj = UIFactory.CreateVerticalGroup(HomePage.Instance.Content, new Color(72f / 255f, 72f / 255f, 72f / 255f));
LayoutElement rightLayout = mainObj.AddComponent<LayoutElement>();
rightLayout.flexibleWidth = 999999;
var rightGroup = mainObj.GetComponent<VerticalLayoutGroup>();
rightGroup.childForceExpandHeight = true;
rightGroup.childForceExpandWidth = true;
rightGroup.childControlHeight = true;
rightGroup.childControlWidth = true;
rightGroup.spacing = 10;
rightGroup.padding.left = 8;
rightGroup.padding.right = 8;
rightGroup.padding.top = 8;
rightGroup.padding.bottom = 8;
var inspectorTitle = UIFactory.CreateLabel(mainObj, TextAnchor.UpperLeft);
Text title = inspectorTitle.GetComponent<Text>();
title.text = "Inspector";
title.fontSize = 20;
var titleLayout = inspectorTitle.AddComponent<LayoutElement>();
titleLayout.minHeight = 30;
titleLayout.flexibleHeight = 0;
m_tabBarContent = UIFactory.CreateGridGroup(mainObj, new Vector2(185, 20), new Vector2(5, 2), new Color(0.1f, 0.1f, 0.1f, 1));
var gridGroup = m_tabBarContent.GetComponent<GridLayoutGroup>();
gridGroup.padding.top = 4;
gridGroup.padding.left = 4;
gridGroup.padding.right = 4;
gridGroup.padding.bottom = 4;
// inspector content area
m_inspectorContent = UIFactory.CreateVerticalGroup(mainObj, new Color(0.1f, 0.1f, 0.1f, 1.0f));
var contentGroup = m_inspectorContent.GetComponent<VerticalLayoutGroup>();
contentGroup.childForceExpandHeight = true;
contentGroup.childForceExpandWidth = true;
contentGroup.childControlHeight = true;
contentGroup.childControlWidth = true;
contentGroup.spacing = 5;
contentGroup.padding.top = 5;
contentGroup.padding.left = 5;
contentGroup.padding.right = 5;
contentGroup.padding.bottom = 5;
var contentLayout = m_inspectorContent.AddComponent<LayoutElement>();
contentLayout.preferredHeight = 900;
contentLayout.flexibleHeight = 10000;
}
#endregion
}
}

View File

@ -1,847 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityExplorer.Helpers;
using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip.ColorUtility;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Unstrip.LayerMasks;
namespace UnityExplorer.UI.Main.Inspectors
{
// TODO:
// fix path and name input for very long input (use content size fitter + preffered size + vert layout group)
// make back button (inspect parent button)
// make controls panel (transform controls, set parent, etc)
public class GameObjectInspector : InspectorBase
{
public override string TabLabel => $" [G] {TargetGO?.name}";
// just to help with casting in il2cpp
public GameObject TargetGO;
// static UI elements (only constructed once)
private static bool m_UIConstructed;
private static GameObject m_content;
public override GameObject Content
{
get => m_content;
set => m_content = value;
}
// cached ui elements
public static TMP_InputField m_nameInput;
private static string m_lastName;
public static TMP_InputField m_pathInput;
private static string m_lastPath;
private static GameObject m_pathGroupObj;
private static Text m_hiddenPathText;
private static Toggle m_enabledToggle;
private static Text m_enabledText;
private static bool? m_lastEnabledState;
private static Dropdown m_layerDropdown;
private static int m_lastLayer = -1;
private static Text m_sceneText;
private static string m_lastScene;
// children list
public static PageHandler s_childListPageHandler;
private static GameObject[] s_allChildren = new GameObject[0];
private static readonly List<GameObject> s_childrenShortlist = new List<GameObject>();
private static GameObject s_childListContent;
private static readonly List<Text> s_childListTexts = new List<Text>();
private static int s_lastChildCount;
// comp list
public static PageHandler s_compListPageHandler;
private static Component[] s_allComps = new Component[0];
private static readonly List<Component> s_compShortlist = new List<Component>();
private static GameObject s_compListContent;
private static readonly List<Text> s_compListTexts = new List<Text>();
private static int s_lastCompCount;
public static readonly List<Toggle> s_compToggles = new List<Toggle>();
public GameObjectInspector(GameObject target) : base(target)
{
TargetGO = target;
if (!TargetGO)
{
ExplorerCore.LogWarning("GameObjectInspector cctor: Target GameObject is null!");
return;
}
// one UI is used for all gameobject inspectors. no point recreating it.
if (!m_UIConstructed)
{
ConstructUI();
m_UIConstructed = true;
}
}
public override void Update()
{
base.Update();
if (m_pendingDestroy || InspectorManager.Instance.m_activeInspector != this)
{
return;
}
RefreshTopInfo();
RefreshChildObjectList();
RefreshComponentList();
}
private void RefreshTopInfo()
{
if (m_lastName != TargetGO.name)
{
m_lastName = TargetGO.name;
m_nameInput.text = m_lastName;
}
if (TargetGO.transform.parent)
{
if (!m_pathGroupObj.activeSelf)
m_pathGroupObj.SetActive(true);
var path = TargetGO.transform.GetTransformPath(true);
if (m_lastPath != path)
{
m_lastPath = path;
m_pathInput.text = path;
m_hiddenPathText.text = path;
}
}
else if (m_pathGroupObj.activeSelf)
m_pathGroupObj.SetActive(false);
if (m_lastEnabledState != TargetGO.activeSelf)
{
m_lastEnabledState = TargetGO.activeSelf;
m_enabledToggle.isOn = TargetGO.activeSelf;
m_enabledText.text = TargetGO.activeSelf ? "Enabled" : "Disabled";
m_enabledText.color = TargetGO.activeSelf ? Color.green : Color.red;
}
if (m_lastLayer != TargetGO.layer)
{
m_lastLayer = TargetGO.layer;
m_layerDropdown.value = TargetGO.layer;
}
if (m_lastScene != TargetGO.scene.name)
{
m_lastScene = TargetGO.scene.name;
if (!string.IsNullOrEmpty(TargetGO.scene.name))
m_sceneText.text = m_lastScene;
else
m_sceneText.text = "None (Asset/Resource)";
}
}
private void RefreshChildObjectList()
{
s_allChildren = new GameObject[TargetGO.transform.childCount];
for (int i = 0; i < TargetGO.transform.childCount; i++)
{
var child = TargetGO.transform.GetChild(i);
s_allChildren[i] = child.gameObject;
}
var objects = s_allChildren;
s_childListPageHandler.ListCount = objects.Length;
//int startIndex = m_sceneListPageHandler.StartIndex;
int newCount = 0;
foreach (var itemIndex in s_childListPageHandler)
{
newCount++;
// normalized index starting from 0
var i = itemIndex - s_childListPageHandler.StartIndex;
if (itemIndex >= objects.Length)
{
if (i > s_lastChildCount || i >= s_childListTexts.Count)
break;
GameObject label = s_childListTexts[i].transform.parent.parent.gameObject;
if (label.activeSelf)
label.SetActive(false);
}
else
{
GameObject obj = objects[itemIndex];
if (!obj)
continue;
if (i >= s_childrenShortlist.Count)
{
s_childrenShortlist.Add(obj);
AddChildListButton();
}
else
{
s_childrenShortlist[i] = obj;
}
var text = s_childListTexts[i];
var name = obj.name;
if (obj.transform.childCount > 0)
name = $"<color=grey>[{obj.transform.childCount}]</color> {name}";
text.text = name;
text.color = obj.activeSelf ? Color.green : Color.red;
var label = text.transform.parent.parent.gameObject;
if (!label.activeSelf)
{
label.SetActive(true);
}
}
}
s_lastChildCount = newCount;
}
private void RefreshComponentList()
{
s_allComps = TargetGO.GetComponents<Component>().ToArray();
var components = s_allComps;
s_compListPageHandler.ListCount = components.Length;
//int startIndex = m_sceneListPageHandler.StartIndex;
int newCount = 0;
foreach (var itemIndex in s_compListPageHandler)
{
newCount++;
// normalized index starting from 0
var i = itemIndex - s_compListPageHandler.StartIndex;
if (itemIndex >= components.Length)
{
if (i > s_lastCompCount || i >= s_compListTexts.Count)
break;
GameObject label = s_compListTexts[i].transform.parent.parent.gameObject;
if (label.activeSelf)
label.SetActive(false);
}
else
{
Component comp = components[itemIndex];
if (!comp)
continue;
if (i >= s_compShortlist.Count)
{
s_compShortlist.Add(comp);
AddCompListButton();
}
else
{
s_compShortlist[i] = comp;
}
var text = s_compListTexts[i];
text.text = ReflectionHelpers.GetActualType(comp).FullName;
var toggle = s_compToggles[i];
if (comp is Behaviour behaviour)
{
if (!toggle.gameObject.activeSelf)
toggle.gameObject.SetActive(true);
toggle.isOn = behaviour.enabled;
}
else
{
if (toggle.gameObject.activeSelf)
toggle.gameObject.SetActive(false);
}
var label = text.transform.parent.parent.gameObject;
if (!label.activeSelf)
{
label.SetActive(true);
}
}
}
s_lastCompCount = newCount;
}
private void ChangeInspectorTarget(GameObject newTarget)
{
if (!newTarget)
return;
this.Target = this.TargetGO = newTarget;
}
private static void ApplyNameClicked()
{
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
instance.TargetGO.name = m_nameInput.text;
}
private static void OnEnableToggled(bool enabled)
{
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
instance.TargetGO.SetActive(enabled);
}
private static void OnLayerSelected(int layer)
{
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
instance.TargetGO.layer = layer;
}
private static void OnCompToggleClicked(int index, bool value)
{
var comp = s_compShortlist[index];
(comp as Behaviour).enabled = value;
}
#region CHILD LIST
private static void OnChildListObjectClicked(int index)
{
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
if (index >= s_childrenShortlist.Count || !s_childrenShortlist[index])
{
return;
}
instance.ChangeInspectorTarget(s_childrenShortlist[index]);
instance.Update();
}
private static void OnBackButtonClicked()
{
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
instance.ChangeInspectorTarget(instance.TargetGO.transform.parent.gameObject);
}
private static void OnChildListPageTurn()
{
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
instance.RefreshChildObjectList();
}
#endregion
#region COMPONENT LIST
private static void OnCompListObjectClicked(int index)
{
if (index >= s_compShortlist.Count || !s_compShortlist[index])
{
return;
}
InspectorManager.Instance.Inspect(s_compShortlist[index]);
}
private static void OnCompListPageTurn()
{
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
instance.RefreshComponentList();
}
#endregion
#region UI CONSTRUCTION
private void ConstructUI()
{
var parent = InspectorManager.Instance.m_inspectorContent;
m_content = UIFactory.CreateScrollView(parent, out GameObject scrollContent, new Color(0.1f, 0.1f, 0.1f));
var scrollGroup = scrollContent.GetComponent<VerticalLayoutGroup>();
scrollGroup.childForceExpandHeight = false;
scrollGroup.childControlHeight = true;
scrollGroup.spacing = 5;
ConstructTopArea(scrollContent);
var midGroupObj = UIFactory.CreateHorizontalGroup(scrollContent, new Color(1,1,1,0));
var midGroup = midGroupObj.GetComponent<HorizontalLayoutGroup>();
midGroup.spacing = 5;
midGroup.childForceExpandWidth = true;
midGroup.childControlWidth = true;
var midlayout = midGroupObj.AddComponent<LayoutElement>();
midlayout.minHeight = 40;
midlayout.flexibleHeight = 10000;
midlayout.flexibleWidth = 25000;
midlayout.minWidth = 200;
ConstructChildList(midGroupObj);
ConstructCompList(midGroupObj);
ConstructControls(scrollContent);
}
private void ConstructTopArea(GameObject scrollContent)
{
// path row
m_pathGroupObj = UIFactory.CreateHorizontalGroup(scrollContent, new Color(0.1f, 0.1f, 0.1f));
var pathGroup = m_pathGroupObj.GetComponent<HorizontalLayoutGroup>();
pathGroup.childForceExpandHeight = false;
pathGroup.childForceExpandWidth = false;
pathGroup.childControlHeight = false;
pathGroup.childControlWidth = true;
pathGroup.spacing = 5;
var pathRect = m_pathGroupObj.GetComponent<RectTransform>();
pathRect.sizeDelta = new Vector2(pathRect.sizeDelta.x, 20);
var pathLayout = m_pathGroupObj.AddComponent<LayoutElement>();
pathLayout.minHeight = 20;
pathLayout.flexibleHeight = 75;
var backButtonObj = UIFactory.CreateButton(m_pathGroupObj);
var backButton = backButtonObj.GetComponent<Button>();
#if CPP
backButton.onClick.AddListener(new Action(OnBackButtonClicked));
#else
backButton.onClick.AddListener(OnBackButtonClicked());
#endif
var backText = backButtonObj.GetComponentInChildren<Text>();
backText.text = "<";
var backLayout = backButtonObj.AddComponent<LayoutElement>();
backLayout.minWidth = 55;
backLayout.flexibleWidth = 0;
backLayout.minHeight = 25;
backLayout.flexibleHeight = 0;
var pathHiddenTextObj = UIFactory.CreateLabel(m_pathGroupObj, TextAnchor.MiddleLeft);
m_hiddenPathText = pathHiddenTextObj.GetComponent<Text>();
m_hiddenPathText.color = Color.clear;
m_hiddenPathText.fontSize = 14;
m_hiddenPathText.raycastTarget = false;
var hiddenFitter = pathHiddenTextObj.AddComponent<ContentSizeFitter>();
hiddenFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
var hiddenLayout = pathHiddenTextObj.AddComponent<LayoutElement>();
hiddenLayout.minHeight = 25;
hiddenLayout.flexibleHeight = 75;
hiddenLayout.minWidth = 400;
hiddenLayout.flexibleWidth = 9000;
var hiddenGroup = pathHiddenTextObj.AddComponent<HorizontalLayoutGroup>();
hiddenGroup.childForceExpandWidth = true;
hiddenGroup.childControlWidth = true;
hiddenGroup.childForceExpandHeight = true;
hiddenGroup.childControlHeight = true;
var pathInputObj = UIFactory.CreateTMPInput(pathHiddenTextObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var pathInputRect = pathInputObj.GetComponent<RectTransform>();
pathInputRect.sizeDelta = new Vector2(pathInputRect.sizeDelta.x, 25);
m_pathInput = pathInputObj.GetComponent<TMP_InputField>();
m_pathInput.text = TargetGO.transform.GetTransformPath();
m_pathInput.readOnly = true;
var pathInputLayout = pathInputObj.AddComponent<LayoutElement>();
pathInputLayout.minHeight = 25;
pathInputLayout.flexibleHeight = 75;
pathInputLayout.preferredWidth = 400;
pathInputLayout.flexibleWidth = 9999;
// name row
var nameRowObj = UIFactory.CreateHorizontalGroup(scrollContent, new Color(0.1f, 0.1f, 0.1f));
var nameGroup = nameRowObj.GetComponent<HorizontalLayoutGroup>();
nameGroup.childForceExpandHeight = false;
nameGroup.childForceExpandWidth = false;
nameGroup.childControlHeight = false;
nameGroup.childControlWidth = true;
nameGroup.spacing = 5;
var nameRect = nameRowObj.GetComponent<RectTransform>();
nameRect.sizeDelta = new Vector2(nameRect.sizeDelta.x, 25);
var nameLayout = nameRowObj.AddComponent<LayoutElement>();
nameLayout.minHeight = 25;
nameLayout.flexibleHeight = 0;
var nameTextObj = UIFactory.CreateTMPLabel(nameRowObj, TextAlignmentOptions.Midline);
var nameTextText = nameTextObj.GetComponent<TextMeshProUGUI>();
nameTextText.text = "Name:";
nameTextText.fontSize = 14;
nameTextText.color = Color.grey;
var nameTextLayout = nameTextObj.AddComponent<LayoutElement>();
nameTextLayout.minHeight = 25;
nameTextLayout.flexibleHeight = 0;
nameTextLayout.minWidth = 55;
nameTextLayout.flexibleWidth = 0;
var nameInputObj = UIFactory.CreateTMPInput(nameRowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var nameInputRect = nameInputObj.GetComponent<RectTransform>();
nameInputRect.sizeDelta = new Vector2(nameInputRect.sizeDelta.x, 25);
m_nameInput = nameInputObj.GetComponent<TMP_InputField>();
m_nameInput.text = TargetGO.name;
m_nameInput.lineType = TMP_InputField.LineType.SingleLine;
var applyNameBtnObj = UIFactory.CreateButton(nameRowObj);
var applyNameBtn = applyNameBtnObj.GetComponent<Button>();
#if CPP
applyNameBtn.onClick.AddListener(new Action(() => { ApplyNameClicked(); }));
#else
applyNameBtn.onClick.AddListener(() => { ApplyNameClicked(); });
#endif
var applyNameText = applyNameBtnObj.GetComponentInChildren<Text>();
applyNameText.text = "Apply";
applyNameText.fontSize = 14;
var applyNameLayout = applyNameBtnObj.AddComponent<LayoutElement>();
applyNameLayout.minWidth = 65;
applyNameLayout.minHeight = 25;
applyNameLayout.flexibleHeight = 0;
var applyNameRect = applyNameBtnObj.GetComponent<RectTransform>();
applyNameRect.sizeDelta = new Vector2(applyNameRect.sizeDelta.x, 25);
var activeLabel = UIFactory.CreateLabel(nameRowObj, TextAnchor.MiddleCenter);
var activeLabelLayout = activeLabel.AddComponent<LayoutElement>();
activeLabelLayout.minWidth = 55;
activeLabelLayout.minHeight = 25;
var activeText = activeLabel.GetComponent<Text>();
activeText.text = "Active:";
activeText.color = Color.grey;
activeText.fontSize = 14;
var enabledToggleObj = UIFactory.CreateToggle(nameRowObj, out m_enabledToggle, out m_enabledText);
var toggleLayout = enabledToggleObj.AddComponent<LayoutElement>();
toggleLayout.minHeight = 25;
toggleLayout.minWidth = 100;
toggleLayout.flexibleWidth = 0;
m_enabledText.text = "Enabled";
m_enabledText.color = Color.green;
#if CPP
m_enabledToggle.onValueChanged.AddListener(new Action<bool>(OnEnableToggled));
#else
m_enabledToggle.onValueChanged.AddListener(OnEnableToggled);
#endif
// layer and scene row
var sceneLayerRow = UIFactory.CreateHorizontalGroup(scrollContent, new Color(0.1f, 0.1f, 0.1f));
var sceneLayerGroup = sceneLayerRow.GetComponent<HorizontalLayoutGroup>();
sceneLayerGroup.childForceExpandWidth = false;
sceneLayerGroup.childControlWidth = true;
sceneLayerGroup.spacing = 5;
var layerLabel = UIFactory.CreateLabel(sceneLayerRow, TextAnchor. MiddleCenter);
var layerText = layerLabel.GetComponent<Text>();
layerText.text = "Layer:";
layerText.fontSize = 14;
layerText.color = Color.grey;
var layerTextLayout = layerLabel.AddComponent<LayoutElement>();
layerTextLayout.minWidth = 55;
layerTextLayout.flexibleWidth = 0;
var layerDropdownObj = UIFactory.CreateDropdown(sceneLayerRow, out m_layerDropdown);
m_layerDropdown.options.Clear();
for (int i = 0; i < 32; i++)
{
var layer = LayerMaskUnstrip.LayerToName(i);
m_layerDropdown.options.Add(new Dropdown.OptionData { text = $"{i}: {layer}" });
}
var itemText = layerDropdownObj.transform.Find("Label").GetComponent<Text>();
itemText.resizeTextForBestFit = true;
var layerDropdownLayout = layerDropdownObj.AddComponent<LayoutElement>();
layerDropdownLayout.minWidth = 120;
layerDropdownLayout.flexibleWidth = 2000;
layerDropdownLayout.minHeight = 25;
#if CPP
m_layerDropdown.onValueChanged.AddListener(new Action<int>(OnLayerSelected));
#else
m_layerDropdown.onValueChanged.AddListener(OnLayerSelected);
#endif
var scenelabelObj = UIFactory.CreateLabel(sceneLayerRow, TextAnchor.MiddleCenter);
var sceneLabel = scenelabelObj.GetComponent<Text>();
sceneLabel.text = "Scene:";
sceneLabel.color = Color.grey;
sceneLabel.fontSize = 14;
var sceneLabelLayout = scenelabelObj.AddComponent<LayoutElement>();
sceneLabelLayout.minWidth = 55;
sceneLabelLayout.flexibleWidth = 0;
var objectSceneText = UIFactory.CreateLabel(sceneLayerRow, TextAnchor.MiddleLeft);
m_sceneText = objectSceneText.GetComponent<Text>();
m_sceneText.fontSize = 14;
m_sceneText.horizontalOverflow = HorizontalWrapMode.Overflow;
var sceneTextLayout = objectSceneText.AddComponent<LayoutElement>();
sceneTextLayout.minWidth = 120;
sceneTextLayout.flexibleWidth = 2000;
}
private void ConstructChildList(GameObject parent)
{
var vertGroupObj = UIFactory.CreateVerticalGroup(parent, new Color(1,1,1,0));
var vertGroup = vertGroupObj.GetComponent<VerticalLayoutGroup>();
vertGroup.childForceExpandHeight = false;
vertGroup.childForceExpandWidth = false;
vertGroup.childControlWidth = true;
var vertLayout = vertGroupObj.AddComponent<LayoutElement>();
vertLayout.minWidth = 120;
vertLayout.flexibleWidth = 25000;
var childTitleObj = UIFactory.CreateLabel(vertGroupObj, TextAnchor.MiddleLeft);
var childTitleText = childTitleObj.GetComponent<Text>();
childTitleText.text = "Children";
childTitleText.color = Color.grey;
childTitleText.fontSize = 14;
var childTitleLayout = childTitleObj.AddComponent<LayoutElement>();
childTitleLayout.minHeight = 30;
var childrenScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_childListContent, new Color(0.07f, 0.07f, 0.07f));
var contentLayout = childrenScrollObj.AddComponent<LayoutElement>();
contentLayout.minHeight = 50;
contentLayout.flexibleHeight = 10000;
var horiScroll = childrenScrollObj.transform.Find("Scrollbar Horizontal");
horiScroll.gameObject.SetActive(false);
var scrollRect = childrenScrollObj.GetComponentInChildren<ScrollRect>();
scrollRect.horizontalScrollbar = null;
var childGroup = s_childListContent.GetComponent<VerticalLayoutGroup>();
childGroup.childControlHeight = true;
childGroup.spacing = 2;
s_childListPageHandler = new PageHandler();
s_childListPageHandler.ConstructUI(vertGroupObj);
s_childListPageHandler.OnPageChanged += OnChildListPageTurn;
}
private void AddChildListButton()
{
int thisIndex = s_childListTexts.Count;
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_childListContent, new Color(0.1f, 0.1f, 0.1f));
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
btnGroup.childForceExpandWidth = true;
btnGroup.childControlWidth = true;
btnGroup.childForceExpandHeight = false;
btnGroup.childControlHeight = true;
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
btnLayout.flexibleWidth = 320;
btnLayout.minHeight = 25;
btnLayout.flexibleHeight = 0;
btnGroupObj.AddComponent<Mask>();
GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj);
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
mainBtnLayout.minHeight = 25;
mainBtnLayout.flexibleHeight = 0;
mainBtnLayout.minWidth = 240;
mainBtnLayout.flexibleWidth = 0;
Button mainBtn = mainButtonObj.GetComponent<Button>();
ColorBlock mainColors = mainBtn.colors;
mainColors.normalColor = new Color(0.07f, 0.07f, 0.07f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
mainBtn.colors = mainColors;
#if CPP
mainBtn.onClick.AddListener(new Action(() => { OnChildListObjectClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { OnChildListObjectClicked(thisIndex); });
#endif
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
mainText.alignment = TextAnchor.MiddleLeft;
mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
s_childListTexts.Add(mainText);
}
private void ConstructCompList(GameObject parent)
{
var vertGroupObj = UIFactory.CreateVerticalGroup(parent, new Color(1, 1, 1, 0));
var vertGroup = vertGroupObj.GetComponent<VerticalLayoutGroup>();
vertGroup.childForceExpandHeight = false;
vertGroup.childForceExpandWidth = false;
vertGroup.childControlWidth = true;
var vertLayout = vertGroupObj.AddComponent<LayoutElement>();
vertLayout.minWidth = 120;
vertLayout.flexibleWidth = 25000;
var compTitleObj = UIFactory.CreateLabel(vertGroupObj, TextAnchor.MiddleLeft);
var compTitleText = compTitleObj.GetComponent<Text>();
compTitleText.text = "Components";
compTitleText.color = Color.grey;
compTitleText.fontSize = 14;
var childTitleLayout = compTitleObj.AddComponent<LayoutElement>();
childTitleLayout.minHeight = 30;
var compScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_compListContent, new Color(0.07f, 0.07f, 0.07f));
var contentLayout = compScrollObj.AddComponent<LayoutElement>();
contentLayout.minHeight = 50;
contentLayout.flexibleHeight = 10000;
var contentGroup = s_compListContent.GetComponent<VerticalLayoutGroup>();
contentGroup.childControlHeight = true;
contentGroup.spacing = 2;
var horiScroll = compScrollObj.transform.Find("Scrollbar Horizontal");
horiScroll.gameObject.SetActive(false);
var scrollRect = compScrollObj.GetComponentInChildren<ScrollRect>();
scrollRect.horizontalScrollbar = null;
s_compListPageHandler = new PageHandler();
s_compListPageHandler.ConstructUI(vertGroupObj);
s_compListPageHandler.OnPageChanged += OnCompListPageTurn;
}
private void AddCompListButton()
{
int thisIndex = s_compListTexts.Count;
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_compListContent, new Color(0.07f, 0.07f, 0.07f));
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
btnGroup.childForceExpandWidth = false;
btnGroup.childControlWidth = true;
btnGroup.childForceExpandHeight = false;
btnGroup.childControlHeight = true;
btnGroup.childAlignment = TextAnchor.MiddleLeft;
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
btnLayout.flexibleWidth = 320;
btnLayout.minHeight = 25;
btnLayout.flexibleHeight = 0;
btnGroupObj.AddComponent<Mask>();
var toggleObj = UIFactory.CreateToggle(btnGroupObj, out Toggle toggle, out Text toggleText);
var togBg = toggleObj.transform.Find("Background").GetComponent<Image>();
togBg.color = new Color(0.1f, 0.1f, 0.1f, 1);
var toggleLayout = toggleObj.AddComponent<LayoutElement>();
toggleLayout.minWidth = 25;
toggleLayout.flexibleWidth = 0;
toggleLayout.minHeight = 25;
toggleLayout.flexibleHeight = 0;
#if CPP
toggle.onValueChanged.AddListener(new Action<bool>((bool val) => { OnCompToggleClicked(thisIndex, val); }));
#else
toggle.onValueChanged.AddListener((bool val) => { OnCompToggleClicked(thisIndex, val); });
#endif
toggleText.text = "";
s_compToggles.Add(toggle);
GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj);
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
mainBtnLayout.minHeight = 25;
mainBtnLayout.flexibleHeight = 0;
mainBtnLayout.minWidth = 240;
mainBtnLayout.flexibleWidth = 999;
Button mainBtn = mainButtonObj.GetComponent<Button>();
ColorBlock mainColors = mainBtn.colors;
mainColors.normalColor = new Color(0.07f, 0.07f, 0.07f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
mainBtn.colors = mainColors;
#if CPP
mainBtn.onClick.AddListener(new Action(() => { OnCompListObjectClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { OnCompListObjectClicked(thisIndex); });
#endif
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
mainText.alignment = TextAnchor.MiddleLeft;
mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
mainText.color = Syntax.Class_Instance.ToColor();
s_compListTexts.Add(mainText);
}
private const int CONTROLS_MAX_HEIGHT = 220;
private void ConstructControls(GameObject scrollContent)
{
var controlsObj = UIFactory.CreateVerticalGroup(scrollContent, new Color(0.07f, 0.07f, 0.07f));
var controlsGroup = controlsObj.GetComponent<VerticalLayoutGroup>();
controlsGroup.childForceExpandWidth = false;
controlsGroup.childControlWidth = true;
controlsGroup.childForceExpandHeight = false;
var controlsLayout = controlsObj.AddComponent<LayoutElement>();
controlsLayout.minHeight = CONTROLS_MAX_HEIGHT;
controlsLayout.flexibleHeight = 0;
controlsLayout.minWidth = 250;
controlsLayout.flexibleWidth = 9000;
// ~~~~~~ Top row ~~~~~~
var topRow = UIFactory.CreateHorizontalGroup(controlsObj, new Color(1, 1, 1, 0));
var topRowGroup = topRow.GetComponent<HorizontalLayoutGroup>();
topRowGroup.childForceExpandWidth = false;
topRowGroup.childControlWidth = true;
topRowGroup.childForceExpandHeight = false;
topRowGroup.childControlHeight = true;
topRowGroup.spacing = 5;
var hideButtonObj = UIFactory.CreateButton(topRow);
var hideButton = hideButtonObj.GetComponent<Button>();
var hideText = hideButtonObj.GetComponentInChildren<Text>();
hideText.text = "v";
var hideButtonLayout = hideButtonObj.AddComponent<LayoutElement>();
hideButtonLayout.minWidth = 40;
hideButtonLayout.flexibleWidth = 0;
hideButtonLayout.minHeight = 25;
hideButtonLayout.flexibleHeight = 0;
#if CPP
hideButton.onClick.AddListener(new Action(OnHideClicked));
#else
hideButton.onClick.AddListener(OnHideClicked);
#endif
void OnHideClicked()
{
if (controlsLayout.minHeight > 25)
{
hideText.text = "^";
controlsLayout.minHeight = 25;
}
else
{
hideText.text = "v";
controlsLayout.minHeight = CONTROLS_MAX_HEIGHT;
}
}
var topTitle = UIFactory.CreateLabel(topRow, TextAnchor.MiddleLeft);
var topText = topTitle.GetComponent<Text>();
topText.text = "GameObject Controls";
var titleLayout = topTitle.AddComponent<LayoutElement>();
titleLayout.minWidth = 100;
titleLayout.flexibleWidth = 9500;
titleLayout.minHeight = 25;
}
#endregion
}
}

View File

@ -1,159 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace UnityExplorer.UI.Main.Inspectors
{
public abstract class InspectorBase
{
public object Target;
// just to cache a cast
public UnityEngine.Object UnityTarget;
public abstract string TabLabel { get; }
public abstract GameObject Content { get; set; }
public Button tabButton;
public Text tabText;
internal bool m_pendingDestroy;
public InspectorBase(object target)
{
Target = target;
UnityTarget = target as UnityEngine.Object;
if (ObjectNullOrDestroyed(Target, UnityTarget))
{
Destroy();
return;
}
AddInspectorTab();
}
public virtual void Update()
{
if (ObjectNullOrDestroyed(Target, UnityTarget))
{
Destroy();
return;
}
tabText.text = TabLabel;
}
public virtual void Destroy()
{
m_pendingDestroy = true;
GameObject tabGroup = tabButton?.transform.parent.gameObject;
if (tabGroup)
{
GameObject.Destroy(tabGroup);
}
//if (Content)
//{
// GameObject.Destroy(Content);
//}
int thisIndex = -1;
if (InspectorManager.Instance.m_currentInspectors.Contains(this))
{
thisIndex = InspectorManager.Instance.m_currentInspectors.IndexOf(this);
InspectorManager.Instance.m_currentInspectors.Remove(this);
}
if (ReferenceEquals(InspectorManager.Instance.m_activeInspector, this))
{
InspectorManager.Instance.UnsetInspectorTab();
if (InspectorManager.Instance.m_currentInspectors.Count > 0)
{
var prevTab = InspectorManager.Instance.m_currentInspectors[thisIndex > 0 ? thisIndex - 1 : 0];
InspectorManager.Instance.SetInspectorTab(prevTab);
}
}
}
public static bool ObjectNullOrDestroyed(object obj, UnityEngine.Object unityObj, bool suppressWarning = false)
{
if (obj == null)
{
if (!suppressWarning)
{
ExplorerCore.LogWarning("The target instance is null!");
}
return true;
}
else if (obj is UnityEngine.Object)
{
if (!unityObj)
{
if (!suppressWarning)
{
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
}
return true;
}
}
return false;
}
#region UI CONSTRUCTION
public void AddInspectorTab()
{
var tabContent = InspectorManager.Instance.m_tabBarContent;
var tabGroupObj = UIFactory.CreateHorizontalGroup(tabContent);
var tabGroup = tabGroupObj.GetComponent<HorizontalLayoutGroup>();
tabGroup.childForceExpandWidth = true;
tabGroup.childControlWidth = true;
var tabLayout = tabGroupObj.AddComponent<LayoutElement>();
tabLayout.minWidth = 185;
tabLayout.flexibleWidth = 0;
tabGroupObj.AddComponent<Mask>();
var targetButtonObj = UIFactory.CreateButton(tabGroupObj);
var targetButtonLayout = targetButtonObj.AddComponent<LayoutElement>();
targetButtonLayout.minWidth = 165;
targetButtonLayout.flexibleWidth = 0;
tabText = targetButtonObj.GetComponentInChildren<Text>();
tabText.horizontalOverflow = HorizontalWrapMode.Overflow;
tabText.alignment = TextAnchor.MiddleLeft;
tabButton = targetButtonObj.GetComponent<Button>();
#if CPP
tabButton.onClick.AddListener(new Action(() => { InspectorManager.Instance.SetInspectorTab(this); }));
#else
tabButton.onClick.AddListener(() => { InspectorManager.Instance.SetInspectorTab(this); });
#endif
var closeBtnObj = UIFactory.CreateButton(tabGroupObj);
var closeBtnLayout = closeBtnObj.AddComponent<LayoutElement>();
closeBtnLayout.minWidth = 20;
closeBtnLayout.flexibleWidth = 0;
var closeBtnText = closeBtnObj.GetComponentInChildren<Text>();
closeBtnText.text = "X";
closeBtnText.color = new Color(1, 0, 0, 1);
var closeBtn = closeBtnObj.GetComponent<Button>();
#if CPP
closeBtn.onClick.AddListener(new Action(() => { Destroy(); }));
#else
closeBtn.onClick.AddListener(() => { Destroy(); });
#endif
var closeColors = closeBtn.colors;
closeColors.normalColor = new Color(0.2f, 0.2f, 0.2f, 1);
closeBtn.colors = closeColors;
}
#endregion
}
}

View File

@ -1,28 +0,0 @@
using System;
using UnityExplorer.Helpers;
namespace UnityExplorer.UI.Main.Inspectors
{
public class InstanceInspector : ReflectionInspector
{
// todo
public override string TabLabel => $" [R] {base.TabLabel}";
public InstanceInspector(object target) : base(target)
{
}
public override void Update()
{
base.Update();
if (m_pendingDestroy || InspectorManager.Instance.m_activeInspector != this)
{
return;
}
// todo
}
}
}

View File

@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityExplorer.Helpers;
using UnityEngine;
namespace UnityExplorer.UI.Main.Inspectors
{
public class ReflectionInspector : InspectorBase
{
public override string TabLabel => m_targetTypeShortName;
private GameObject m_content;
public override GameObject Content
{
get => m_content;
set => m_content = value;
}
private readonly string m_targetTypeShortName;
public ReflectionInspector(object target) : base(target)
{
Type type = ReflectionHelpers.GetActualType(target);
if (type == null)
{
// TODO
return;
}
m_targetTypeShortName = type.Name;
}
}
}

View File

@ -1,26 +0,0 @@
using System;
namespace UnityExplorer.UI.Main.Inspectors
{
public class StaticInspector : ReflectionInspector
{
public override string TabLabel => $" [S] {base.TabLabel}";
public StaticInspector(Type type) : base(type)
{
// TODO
}
public override void Update()
{
base.Update();
if (m_pendingDestroy || InspectorManager.Instance.m_activeInspector != this)
{
return;
}
// todo
}
}
}

View File

@ -1,488 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityExplorer.Helpers;
using UnityExplorer.UI.Main.Inspectors;
using UnityExplorer.UI.Shared;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityExplorer.Unstrip.Scenes;
namespace UnityExplorer.UI.Main
{
public class SceneExplorer
{
public static SceneExplorer Instance;
public SceneExplorer()
{
Instance = this;
ConstructScenePane();
}
private const float UPDATE_INTERVAL = 1f;
private float m_timeOfLastSceneUpdate;
private GameObject m_selectedSceneObject;
private int m_currentSceneHandle = -1;
private int m_lastCount;
private Dropdown m_sceneDropdown;
private Text m_scenePathText;
private GameObject m_mainInspectBtn;
private GameObject m_backButtonObj;
public PageHandler m_sceneListPageHandler;
private GameObject[] m_allSceneListObjects = new GameObject[0];
private readonly List<GameObject> m_sceneShortList = new List<GameObject>();
private GameObject m_sceneListContent;
private readonly List<Text> m_sceneListTexts = new List<Text>();
public static int DontDestroyHandle => DontDestroyObject.scene.handle;
internal static GameObject DontDestroyObject
{
get
{
if (!m_dontDestroyObject)
{
m_dontDestroyObject = new GameObject("DontDestroyMe");
GameObject.DontDestroyOnLoad(m_dontDestroyObject);
}
return m_dontDestroyObject;
}
}
internal static GameObject m_dontDestroyObject;
public void Init()
{
RefreshActiveScenes();
}
public void Update()
{
if (Time.realtimeSinceStartup - m_timeOfLastSceneUpdate < UPDATE_INTERVAL)
{
return;
}
RefreshActiveScenes();
if (!m_selectedSceneObject)
{
if (m_currentSceneHandle != -1)
{
SetSceneObjectList(SceneUnstrip.GetRootGameObjects(m_currentSceneHandle));
}
}
else
{
RefreshSelectedSceneObject();
}
}
public int GetSceneHandle(string sceneName)
{
if (sceneName == "DontDestroyOnLoad")
return DontDestroyHandle;
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
if (scene.name == sceneName)
return scene.handle;
}
return -1;
}
internal void OnSceneChange()
{
m_sceneDropdown.OnCancel(null);
RefreshActiveScenes();
}
private void RefreshActiveScenes()
{
var names = new List<string>();
var handles = new List<int>();
for (int i = 0; i < SceneManager.sceneCount; i++)
{
Scene scene = SceneManager.GetSceneAt(i);
int handle = scene.handle;
if (scene == null || handle == -1 || string.IsNullOrEmpty(scene.name))
continue;
handles.Add(handle);
names.Add(scene.name);
}
names.Add("DontDestroyOnLoad");
handles.Add(DontDestroyHandle);
m_sceneDropdown.options.Clear();
foreach (string scene in names)
{
m_sceneDropdown.options.Add(new Dropdown.OptionData
{
text = scene
});
}
if (!handles.Contains(m_currentSceneHandle))
{
m_sceneDropdown.transform.Find("Label").GetComponent<Text>().text = names[0];
SetTargetScene(handles[0]);
}
}
public void SetTargetScene(string name) => SetTargetScene(GetSceneHandle(name));
public void SetTargetScene(int handle)
{
if (handle == -1)
return;
m_currentSceneHandle = handle;
GameObject[] rootObjs = SceneUnstrip.GetRootGameObjects(handle);
SetSceneObjectList(rootObjs);
m_selectedSceneObject = null;
if (m_backButtonObj.activeSelf)
{
m_backButtonObj.SetActive(false);
m_mainInspectBtn.SetActive(false);
}
m_scenePathText.text = "Scene root:";
//m_scenePathText.ForceMeshUpdate();
}
public void SetTargetObject(GameObject obj)
{
if (!obj)
return;
m_scenePathText.text = obj.name;
//m_scenePathText.ForceMeshUpdate();
m_selectedSceneObject = obj;
RefreshSelectedSceneObject();
if (!m_backButtonObj.activeSelf)
{
m_backButtonObj.SetActive(true);
m_mainInspectBtn.SetActive(true);
}
}
private void RefreshSelectedSceneObject()
{
GameObject[] list = new GameObject[m_selectedSceneObject.transform.childCount];
for (int i = 0; i < m_selectedSceneObject.transform.childCount; i++)
{
list[i] = m_selectedSceneObject.transform.GetChild(i).gameObject;
}
SetSceneObjectList(list);
}
private void SetSceneObjectList(GameObject[] objects)
{
m_allSceneListObjects = objects;
RefreshSceneObjectList();
}
private void SceneListObjectClicked(int index)
{
if (index >= m_sceneShortList.Count || !m_sceneShortList[index])
{
return;
}
SetTargetObject(m_sceneShortList[index]);
}
private void OnSceneListPageTurn()
{
RefreshSceneObjectList();
}
private void RefreshSceneObjectList()
{
m_timeOfLastSceneUpdate = Time.realtimeSinceStartup;
var objects = m_allSceneListObjects;
m_sceneListPageHandler.ListCount = objects.Length;
//int startIndex = m_sceneListPageHandler.StartIndex;
int newCount = 0;
foreach (var itemIndex in m_sceneListPageHandler)
{
newCount++;
// normalized index starting from 0
var i = itemIndex - m_sceneListPageHandler.StartIndex;
if (itemIndex >= objects.Length)
{
if (i > m_lastCount || i >= m_sceneListTexts.Count)
break;
GameObject label = m_sceneListTexts[i].transform.parent.parent.gameObject;
if (label.activeSelf)
label.SetActive(false);
}
else
{
GameObject obj = objects[itemIndex];
if (!obj)
continue;
if (i >= m_sceneShortList.Count)
{
m_sceneShortList.Add(obj);
AddObjectListButton();
}
else
{
m_sceneShortList[i] = obj;
}
var text = m_sceneListTexts[i];
var name = obj.name;
if (obj.transform.childCount > 0)
name = $"<color=grey>[{obj.transform.childCount}]</color> {name}";
text.text = name;
text.color = obj.activeSelf ? Color.green : Color.red;
var label = text.transform.parent.parent.gameObject;
if (!label.activeSelf)
{
label.SetActive(true);
}
}
}
m_lastCount = newCount;
}
#region UI CONSTRUCTION
public void ConstructScenePane()
{
GameObject leftPane = UIFactory.CreateVerticalGroup(HomePage.Instance.Content, new Color(72f / 255f, 72f / 255f, 72f / 255f));
LayoutElement leftLayout = leftPane.AddComponent<LayoutElement>();
leftLayout.minWidth = 350;
leftLayout.flexibleWidth = 0;
VerticalLayoutGroup leftGroup = leftPane.GetComponent<VerticalLayoutGroup>();
leftGroup.padding.left = 8;
leftGroup.padding.right = 8;
leftGroup.padding.top = 8;
leftGroup.padding.bottom = 8;
leftGroup.spacing = 5;
leftGroup.childControlWidth = true;
leftGroup.childControlHeight = true;
leftGroup.childForceExpandWidth = true;
leftGroup.childForceExpandHeight = true;
GameObject titleObj = UIFactory.CreateLabel(leftPane, TextAnchor.UpperLeft);
Text titleLabel = titleObj.GetComponent<Text>();
titleLabel.text = "Scene Explorer";
titleLabel.fontSize = 20;
LayoutElement titleLayout = titleObj.AddComponent<LayoutElement>();
titleLayout.minHeight = 30;
titleLayout.flexibleHeight = 0;
GameObject sceneDropdownObj = UIFactory.CreateDropdown(leftPane, out m_sceneDropdown);
LayoutElement dropdownLayout = sceneDropdownObj.AddComponent<LayoutElement>();
dropdownLayout.minHeight = 40;
dropdownLayout.flexibleHeight = 0;
dropdownLayout.minWidth = 320;
dropdownLayout.flexibleWidth = 2;
#if CPP
m_sceneDropdown.onValueChanged.AddListener(new Action<int>((int val) => { SetSceneFromDropdown(val); }));
#else
m_sceneDropdown.onValueChanged.AddListener((int val) => { SetSceneFromDropdown(val); });
#endif
void SetSceneFromDropdown(int val)
{
string scene = m_sceneDropdown.options[val].text;
SetTargetScene(scene);
}
GameObject scenePathGroupObj = UIFactory.CreateHorizontalGroup(leftPane, new Color(1, 1, 1, 0f));
HorizontalLayoutGroup scenePathGroup = scenePathGroupObj.GetComponent<HorizontalLayoutGroup>();
scenePathGroup.childControlHeight = true;
scenePathGroup.childControlWidth = true;
scenePathGroup.childForceExpandHeight = true;
scenePathGroup.childForceExpandWidth = true;
scenePathGroup.spacing = 5;
LayoutElement scenePathLayout = scenePathGroupObj.AddComponent<LayoutElement>();
scenePathLayout.minHeight = 20;
scenePathLayout.minWidth = 335;
scenePathLayout.flexibleWidth = 0;
m_backButtonObj = UIFactory.CreateButton(scenePathGroupObj);
Text backButtonText = m_backButtonObj.GetComponentInChildren<Text>();
backButtonText.text = "<";
LayoutElement backButtonLayout = m_backButtonObj.AddComponent<LayoutElement>();
backButtonLayout.minWidth = 40;
backButtonLayout.flexibleWidth = 0;
Button backButton = m_backButtonObj.GetComponent<Button>();
#if CPP
backButton.onClick.AddListener(new Action(() => { SetSceneObjectParent(); }));
#else
backButton.onClick.AddListener(() => { SetSceneObjectParent(); });
#endif
void SetSceneObjectParent()
{
if (!m_selectedSceneObject || !m_selectedSceneObject.transform.parent?.gameObject)
{
m_selectedSceneObject = null;
SetTargetScene(m_currentSceneHandle);
}
else
{
SetTargetObject(m_selectedSceneObject.transform.parent.gameObject);
}
}
GameObject scenePathLabel = UIFactory.CreateHorizontalGroup(scenePathGroupObj);
Image image = scenePathLabel.GetComponent<Image>();
image.color = Color.white;
LayoutElement scenePathLabelLayout = scenePathLabel.AddComponent<LayoutElement>();
scenePathLabelLayout.minWidth = 210;
scenePathLabelLayout.minHeight = 20;
scenePathLabelLayout.flexibleHeight = 0;
scenePathLabelLayout.flexibleWidth = 120;
scenePathLabel.AddComponent<Mask>().showMaskGraphic = false;
GameObject scenePathLabelText = UIFactory.CreateLabel(scenePathLabel, TextAnchor.MiddleLeft);
m_scenePathText = scenePathLabelText.GetComponent<Text>();
m_scenePathText.text = "Scene root:";
m_scenePathText.fontSize = 15;
m_scenePathText.horizontalOverflow = HorizontalWrapMode.Overflow;
LayoutElement textLayout = scenePathLabelText.gameObject.AddComponent<LayoutElement>();
textLayout.minWidth = 210;
textLayout.flexibleWidth = 120;
textLayout.minHeight = 20;
textLayout.flexibleHeight = 0;
m_mainInspectBtn = UIFactory.CreateButton(scenePathGroupObj);
Text inspectButtonText = m_mainInspectBtn.GetComponentInChildren<Text>();
inspectButtonText.text = "Inspect";
LayoutElement inspectButtonLayout = m_mainInspectBtn.AddComponent<LayoutElement>();
inspectButtonLayout.minWidth = 65;
inspectButtonLayout.flexibleWidth = 0;
Button inspectButton = m_mainInspectBtn.GetComponent<Button>();
#if CPP
inspectButton.onClick.AddListener(new Action(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); }));
#else
inspectButton.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); });
#endif
GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_sceneListContent, new Color(0.1f, 0.1f, 0.1f));
Scrollbar scroll = scrollObj.transform.Find("Scrollbar Vertical").GetComponent<Scrollbar>();
ColorBlock colors = scroll.colors;
colors.normalColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
scroll.colors = colors;
var horiScroll = scrollObj.transform.Find("Scrollbar Horizontal");
horiScroll.gameObject.SetActive(false);
var scrollRect = scrollObj.GetComponentInChildren<ScrollRect>();
scrollRect.horizontalScrollbar = null;
var sceneGroup = m_sceneListContent.GetComponent<VerticalLayoutGroup>();
sceneGroup.childControlHeight = true;
sceneGroup.spacing = 2;
m_sceneListPageHandler = new PageHandler();
m_sceneListPageHandler.ConstructUI(leftPane);
m_sceneListPageHandler.OnPageChanged += OnSceneListPageTurn;
}
private void AddObjectListButton()
{
int thisIndex = m_sceneListTexts.Count();
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(m_sceneListContent, new Color(0.1f, 0.1f, 0.1f));
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
btnGroup.childForceExpandWidth = true;
btnGroup.childControlWidth = true;
btnGroup.childForceExpandHeight = false;
btnGroup.childControlHeight = true;
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
btnLayout.flexibleWidth = 320;
btnLayout.minHeight = 25;
btnLayout.flexibleHeight = 0;
btnGroupObj.AddComponent<Mask>();
GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj);
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
mainBtnLayout.minHeight = 25;
mainBtnLayout.flexibleHeight = 0;
mainBtnLayout.minWidth = 240;
mainBtnLayout.flexibleWidth = 0;
Button mainBtn = mainButtonObj.GetComponent<Button>();
ColorBlock mainColors = mainBtn.colors;
mainColors.normalColor = new Color(0.1f, 0.1f, 0.1f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
mainBtn.colors = mainColors;
#if CPP
mainBtn.onClick.AddListener(new Action(() => { SceneListObjectClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { SceneListObjectClicked(thisIndex); });
#endif
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
mainText.alignment = TextAnchor.MiddleLeft;
mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
m_sceneListTexts.Add(mainText);
GameObject inspectBtnObj = UIFactory.CreateButton(btnGroupObj);
LayoutElement inspectBtnLayout = inspectBtnObj.AddComponent<LayoutElement>();
inspectBtnLayout.minWidth = 60;
inspectBtnLayout.flexibleWidth = 0;
inspectBtnLayout.minHeight = 25;
inspectBtnLayout.flexibleHeight = 0;
Text inspectText = inspectBtnObj.GetComponentInChildren<Text>();
inspectText.text = "Inspect";
inspectText.color = Color.white;
Button inspectBtn = inspectBtnObj.GetComponent<Button>();
ColorBlock inspectColors = inspectBtn.colors;
inspectColors.normalColor = new Color(0.15f, 0.15f, 0.15f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 0.5f);
inspectBtn.colors = inspectColors;
#if CPP
inspectBtn.onClick.AddListener(new Action(() => { InspectorManager.Instance.Inspect(m_sceneShortList[thisIndex]); }));
#else
inspectBtn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_sceneShortList[thisIndex]); });
#endif
}
#endregion
}
}

View File

@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using UnityExplorer.UI.Main.Console;
using UnityExplorer.Console;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.UI.PageModel;
namespace UnityExplorer.UI.Main
namespace UnityExplorer.UI
{
public class MainMenu
{

View File

@ -3,16 +3,17 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using UnityExplorer.UI.Main.Console;
using UnityExplorer.Console;
using UnityExplorer.Unstrip.Resources;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Helpers;
#if CPP
using UnhollowerRuntimeLib;
#endif
namespace UnityExplorer.UI.Main
namespace UnityExplorer.UI.PageModel
{
public class ConsolePage : MainMenu.Page
{

View File

@ -4,10 +4,8 @@ using UnityExplorer.Unstrip.ColorUtility;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
#if CPP
#endif
namespace UnityExplorer.UI.Main
namespace UnityExplorer.UI.PageModel
{
public class DebugConsole
{

View File

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Inspectors;
namespace UnityExplorer.UI.Main
namespace UnityExplorer.UI.PageModel
{
public class HomePage : MainMenu.Page
{

View File

@ -1,4 +1,10 @@
namespace UnityExplorer.UI.Main
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace UnityExplorer.UI.PageModel
{
public class OptionsPage : MainMenu.Page
{

View File

@ -1,4 +1,10 @@
namespace UnityExplorer.UI.Main
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace UnityExplorer.UI.PageModel
{
public class SearchPage : MainMenu.Page
{

View File

@ -8,7 +8,7 @@ using System.IO;
using UnityExplorer.Unstrip.ImageConversion;
#endif
namespace UnityExplorer.UI.Main
namespace UnityExplorer.UI
{
// Handles dragging and resizing for the main explorer window.

View File

@ -1,6 +1,6 @@
namespace UnityExplorer.UI.Shared
{
public class Syntax
public class SyntaxColors
{
public const string Field_Static = "#8d8dc6";
public const string Field_Instance = "#c266ff";

View File

@ -437,6 +437,7 @@ namespace UnityExplorer.UI
GameObject placeHolderObj = CreateUIObject("Placeholder", textArea);
TextMeshProUGUI placeholderText = placeHolderObj.AddComponent<TextMeshProUGUI>();
placeholderText.fontSize = fontSize;
placeholderText.fontSizeMax = fontSize;
placeholderText.text = "...";
placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
placeholderText.overflowMode = (TextOverflowModes)overflowMode;
@ -457,6 +458,7 @@ namespace UnityExplorer.UI
GameObject inputTextObj = CreateUIObject("Text", textArea);
TextMeshProUGUI inputText = inputTextObj.AddComponent<TextMeshProUGUI>();
inputText.fontSize = fontSize;
inputText.fontSizeMax = fontSize;
inputText.text = "";
inputText.color = new Color(1f, 1f, 1f, 1f);
inputText.overflowMode = (TextOverflowModes)overflowMode;

View File

@ -1,7 +1,7 @@
using UnityExplorer.UI.Main;
using UnityEngine;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityExplorer.Inspectors;
namespace UnityExplorer.UI
{