Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Code Editor / Syntax Highlighting

Discussion in 'UI Toolkit' started by joshcamas, Jul 7, 2019.

  1. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,268
    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
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    57
    Textfield does not support text styling at the moment. You can only apply styles with USS on the whole text field.
     
    joshcamas likes this.
  3. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,268
    Alright, makes sense :)

    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 ^_^
     
    Vedran_M likes this.
  4. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    643
    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.
     
    joshcamas likes this.
  5. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,268
  6. alternativevisual

    alternativevisual

    Joined:
    Apr 16, 2015
    Posts:
    75
    Hello! Can you give an example how to add C# syntax highlight to it?
     
  7. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,268
    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.
     
    alternativevisual likes this.
  8. vizgl

    vizgl

    Joined:
    Nov 4, 2014
    Posts:
    61
    Hi, did you made syntax highlighting?