2020-10-28 06:39:26 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
using System.Text;
|
|
|
|
|
using ExplorerBeta.Input;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
using ExplorerBeta.UI.Main.Console.Lexer;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
using UnityEngine.EventSystems;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
using UnityEngine.UI;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
namespace ExplorerBeta.UI.Main.Console
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
|
|
|
|
public class CodeEditor
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
private readonly InputLexer inputLexer = new InputLexer();
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
public TMP_InputField InputField { get; }
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
public readonly TextMeshProUGUI inputText;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
private readonly TextMeshProUGUI inputHighlightText;
|
|
|
|
|
private readonly TextMeshProUGUI lineText;
|
|
|
|
|
private readonly Image background;
|
|
|
|
|
private readonly Image lineHighlight;
|
|
|
|
|
private readonly Image lineNumberBackground;
|
|
|
|
|
private readonly Image scrollbar;
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
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
|
|
|
|
|
};
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
public string HighlightedText => inputHighlightText.text;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
public CodeEditor(TMP_InputField inputField, TextMeshProUGUI inputText, TextMeshProUGUI inputHighlightText, TextMeshProUGUI lineText,
|
|
|
|
|
Image background, Image lineHighlight, Image lineNumberBackground, Image scrollbar)
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-28 06:39:26 +11:00
|
|
|
|
InputField = inputField;
|
2020-10-26 01:07:59 +11:00
|
|
|
|
this.inputText = inputText;
|
|
|
|
|
this.inputHighlightText = inputHighlightText;
|
|
|
|
|
this.lineText = lineText;
|
|
|
|
|
this.background = background;
|
|
|
|
|
this.lineHighlight = lineHighlight;
|
|
|
|
|
this.lineNumberBackground = lineNumberBackground;
|
|
|
|
|
this.scrollbar = scrollbar;
|
|
|
|
|
|
|
|
|
|
if (!AllReferencesAssigned())
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
throw new Exception("References are missing!");
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 20:52:40 +11:00
|
|
|
|
InputField.restoreOriginalTextOnEscape = false;
|
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
inputTextTransform = inputText.GetComponent<RectTransform>();
|
|
|
|
|
lineHighlightTransform = lineHighlight.GetComponent<RectTransform>();
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
ApplyTheme();
|
|
|
|
|
inputLexer.UseMatchers(CSharpLexer.DelimiterSymbols, CSharpLexer.Matchers);
|
|
|
|
|
|
|
|
|
|
// subscribe to text input changing
|
2020-10-27 00:54:08 +11:00
|
|
|
|
#if CPP
|
2020-10-28 06:39:26 +11:00
|
|
|
|
InputField.onValueChanged.AddListener(new Action<string>((string s) => { OnInputChanged(); }));
|
2020-10-27 00:54:08 +11:00
|
|
|
|
#else
|
|
|
|
|
this.InputField.onValueChanged.AddListener((string s) => { OnInputChanged(); });
|
|
|
|
|
#endif
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
// Check for new line
|
2020-10-27 00:54:08 +11:00
|
|
|
|
if (ConsolePage.EnableAutoIndent && InputManager.GetKeyDown(KeyCode.Return))
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
AutoIndentCaret();
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
if (EventSystem.current?.currentSelectedGameObject?.name == "InputField (TMP)")
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
bool focusKeyPressed = false;
|
|
|
|
|
|
|
|
|
|
// Check for any focus key pressed
|
|
|
|
|
foreach (KeyCode key in lineChangeKeys)
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
if (InputManager.GetKeyDown(key))
|
|
|
|
|
{
|
|
|
|
|
focusKeyPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
// Update line highlight
|
|
|
|
|
if (focusKeyPressed || InputManager.GetMouseButton(0))
|
|
|
|
|
{
|
|
|
|
|
UpdateHighlight();
|
|
|
|
|
ConsolePage.Instance.OnInputChanged();
|
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
public void OnInputChanged(bool forceUpdate = false)
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-28 06:39:26 +11:00
|
|
|
|
string newText = InputField.text;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
UpdateIndent();
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
if (!forceUpdate && string.IsNullOrEmpty(newText))
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
inputHighlightText.text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inputHighlightText.text = SyntaxHighlightContent(newText);
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
UpdateLineNumbers();
|
|
|
|
|
UpdateHighlight();
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
ConsolePage.Instance.OnInputChanged();
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
public void SetLineHighlight(int lineNumber, bool lockLineHighlight)
|
|
|
|
|
{
|
|
|
|
|
if (lineNumber < 1 || lineNumber > LineCount)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
return;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-26 01:07:59 +11:00
|
|
|
|
|
|
|
|
|
lineHighlightTransform.anchoredPosition = new Vector2(5,
|
|
|
|
|
(inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight *
|
2020-10-28 06:39:26 +11:00
|
|
|
|
-(lineNumber - 1)) - 4f +
|
2020-10-26 01:07:59 +11:00
|
|
|
|
inputTextTransform.anchoredPosition.y);
|
|
|
|
|
|
|
|
|
|
lineHighlightLocked = lockLineHighlight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateLineNumbers()
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
|
|
|
|
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 { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
private void UpdateIndent()
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
|
|
|
|
int caret = InputField.caretPosition;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
if (caret < 0 || caret >= inputText.textInfo.characterInfo.Length)
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
while (caret >= 0 && caret >= inputText.textInfo.characterInfo.Length)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
caret--;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
if (caret < 0 || caret >= inputText.textInfo.characterInfo.Length)
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CurrentLine = inputText.textInfo.characterInfo[caret].lineNumber;
|
|
|
|
|
|
|
|
|
|
int charCount = 0;
|
|
|
|
|
for (int i = 0; i < CurrentLine; i++)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
charCount += inputText.textInfo.lineInfo[i].characterCount;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
CurrentColumn = caret - charCount;
|
|
|
|
|
CurrentIndent = 0;
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
for (int i = 0; i < caret && i < InputField.text.Length; i++)
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
char character = InputField.text[i];
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
if (character == CSharpLexer.indentIncreaseCharacter)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
CurrentIndent++;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
if (character == CSharpLexer.indentDecreaseCharacter)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
CurrentIndent--;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
2020-10-26 01:07:59 +11:00
|
|
|
|
|
|
|
|
|
if (CurrentIndent < 0)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
CurrentIndent = 0;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
private void UpdateHighlight()
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
|
|
|
|
if (lineHighlightLocked)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
return;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int caret = InputField.caretPosition - 1;
|
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
float lineHeight = inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight;
|
|
|
|
|
int lineNumber = inputText.textInfo.characterInfo[caret].lineNumber;
|
|
|
|
|
float offset = lineNumber + inputTextTransform.anchoredPosition.y;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
foreach (LexerMatchInfo match in inputLexer.LexInputString(inputText))
|
2020-10-25 20:57:34 +11:00
|
|
|
|
{
|
|
|
|
|
for (int i = offset; i < match.startIndex; i++)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
highlightedBuilder.Append(inputText[i]);
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
highlightedBuilder.Append(match.htmlColor);
|
|
|
|
|
|
|
|
|
|
for (int i = match.startIndex; i < match.endIndex; i++)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
highlightedBuilder.Append(inputText[i]);
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
highlightedBuilder.Append(CLOSE_COLOR_TAG);
|
|
|
|
|
|
|
|
|
|
offset = match.endIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = offset; i < inputText.Length; i++)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
highlightedBuilder.Append(inputText[i]);
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
inputText = highlightedBuilder.ToString();
|
|
|
|
|
|
|
|
|
|
return inputText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AutoIndentCaret()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentIndent > 0)
|
|
|
|
|
{
|
2020-10-28 06:39:26 +11:00
|
|
|
|
string indent = GetAutoIndentTab(CurrentIndent);
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
if (indent.Length > 0)
|
|
|
|
|
{
|
2020-10-28 06:39:26 +11:00
|
|
|
|
int caretPos = InputField.caretPosition;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
string indentMinusOne = indent.Substring(0, indent.Length - 1);
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
// get last index of {
|
2020-10-26 01:07:59 +11:00
|
|
|
|
// chuck it on the next line if its not already
|
2020-10-28 06:39:26 +11:00
|
|
|
|
string text = InputField.text;
|
|
|
|
|
string sub = InputField.text.Substring(0, InputField.caretPosition);
|
|
|
|
|
int lastIndex = sub.LastIndexOf("{");
|
|
|
|
|
int offset = lastIndex - 1;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
if (offset >= 0 && text[offset] != '\n' && text[offset] != '\t')
|
|
|
|
|
{
|
2020-10-28 06:39:26 +11:00
|
|
|
|
string open = "\n" + indentMinusOne;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
InputField.text = text.Insert(offset + 1, open);
|
|
|
|
|
|
|
|
|
|
caretPos += open.Length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if should add auto-close }
|
2020-10-26 01:07:59 +11:00
|
|
|
|
int numOpen = InputField.text.Where(x => x == CSharpLexer.indentIncreaseCharacter).Count();
|
|
|
|
|
int numClose = InputField.text.Where(x => x == CSharpLexer.indentDecreaseCharacter).Count();
|
|
|
|
|
|
2020-10-25 20:57:34 +11:00
|
|
|
|
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
|
2020-10-26 01:07:59 +11:00
|
|
|
|
UpdateIndent();
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
inputText.text = InputField.text;
|
|
|
|
|
inputText.SetText(InputField.text, true);
|
|
|
|
|
inputText.Rebuild(CanvasUpdate.Prelayout);
|
|
|
|
|
InputField.ForceLabelUpdate();
|
|
|
|
|
InputField.Rebuild(CanvasUpdate.Prelayout);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
OnInputChanged(true);
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetAutoIndentTab(int amount)
|
|
|
|
|
{
|
|
|
|
|
string tab = string.Empty;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < amount; i++)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
tab += "\t";
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
return tab;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 01:07:59 +11:00
|
|
|
|
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);
|
|
|
|
|
|
2020-10-25 20:57:34 +11:00
|
|
|
|
private void ApplyTheme()
|
|
|
|
|
{
|
2020-10-26 01:07:59 +11:00
|
|
|
|
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;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool AllReferencesAssigned()
|
|
|
|
|
{
|
|
|
|
|
if (!InputField ||
|
|
|
|
|
!inputText ||
|
|
|
|
|
!inputHighlightText ||
|
|
|
|
|
!lineText ||
|
|
|
|
|
!background ||
|
|
|
|
|
!lineHighlight ||
|
|
|
|
|
!lineNumberBackground ||
|
|
|
|
|
!scrollbar)
|
|
|
|
|
{
|
|
|
|
|
// One or more references are not assigned
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|