Code Editor / Syntax Highlighting

Hello!

I’m wanting to create a code editor in unity using UIElements. However, I do not want to start from scratch. (Build a text editor with all of the features such as select and such). In other words, I’d like to modify the built in text field.

Any ideas on how I should begin? I’m new to UIElements, I understand the basics but I’m not intuitive at it

Thank you

Textfield does not support text styling at the moment. You can only apply styles with USS on the whole text field.

1 Like

Alright, makes sense :slight_smile:

I’ve managed to get a nice editor up and running by using uGUI by having a transparent text area as the input, and a text area on top of that with rich text / syntax applied as the visual. It works pretty well :slight_smile:

1 Like

I had to do the same thing a couple of years ago in IMGUI, and wound up layering a label over a textbox, or something like that. Please think about adding support for this. We make heavy use of custom editors, for Dialogs, Quests, Scene logic, to a load of other things. We don’t want a custom scripting language since we want the compiler to catch every error it can (makes my life debugging everyone elses scripting much easier), so I have editors that allow you to write your custom scripts in c#, and then the editors create c# files from their data when saved.

I really just want to have a single textfield / textbox that I can style however I want as needed … it would clean things up tremendously in the future.

1 Like

If anyone is wondering how to achieve this in IMGUI, here’s what I’ve come up with: GitHub - joshcamas/UnityCodeEditor: A generic syntax highlighter / code editor built into Unity

2 Likes

Hello! Can you give an example how to add C# syntax highlight to it?

That repo is pretty out of date, looks like I never included actual syntax highlighting, and instead just included the base editor. I’ll update it with syntax highlighting support in the next few days. It won’t come with C# highlighting out of the box, though.

1 Like

Hi, did you made syntax highlighting?

Something like that ?

9494119--1336717--Capture d’écran 2023-11-26 à 17.48.16.jpg

GitHub - yliasou/SyntaxHighlighter: Syntax Highlighter Asset Enhance code visibility in Unity with Syntax Highlighter. Apply color-coded syntax to keywords for improved readability. Ideal for educational projects. Requires Unity 2018.3+, TextMeshPro. here’s something for you hope it help