Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

[Released] InGame Code Editor

Discussion in 'Assets and Asset Store' started by scottyboy805, Apr 17, 2019.

  1. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor is an advanced input field for Unity that makes use of TextMesh Pro to display syntax highlighted code. Much of the inspiration for the syntax highlighting is taken from notepad++ and as a result it is extremely customizable allowing you to add syntax highlighting support for new languages.

    Requirements
    • Requires TextMesh Pro (Installable via package manager)
    Features
    • Very easy to use. Just drop the prefab into your scene and customize
    • Full text editing features that you would expect
    • Includes optional line numbers column
    • Fully customizable editor themes
    • Includes 3 pre-set themes: Light, Dark and Terminal
    • Fully customizable syntax highlighting
    • Highly optimized lexer for quick syntax highlighting of large text
    • Supports syntax highlighting of keywords, symbols, numbers, comments and quote strings
    • Keyword groups mean that you can highlight keywords in different colors
    • Built in syntax highlighting support for C# (multiple), Lua, MiniScript and JSON
    • You can easily add support for additional syntax highlighted languages
    • Supports basic auto indentation using opening and closing tags
    • Comprehensive .chm documentation of the API for quick and easy reference
    • Fully commented C# source code included

    Theme Screenshot.png
     

    Attached Files:

    Last edited: May 7, 2019
    JBR-games, OldYawn and joshcamas like this.
  2. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    We are pleased to announce that InGame Code Editor has now been approved and is live on the asset store. Check if out here!
     
  3. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor version 1.0.1 has been submitted to the asset store for review. This version fixes a minor issue where line comments and block comments starting with similar characters would not be handled correctly.
     
  4. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor version 1.0.2 has been submitted to the asset store for review. This version adds syntax highlighting for javascript core.
     
  5. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor version 1.0.3 has been submitted to the asset store for review. This version contains:
    • Fixed an auto indenting bug where deep levels of indenting were not handled correctly
    • Fixed an auto indenting bug where the closing character could exist on the same line as the caret
    • Auto indent closing characters will now be placed on a new line if required and the caret will be moved to the previous line after the auto indent tab string.
     
  6. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor version 1.0.4 has been submitted to the asset store. This version fixes a syntax highlighting bug and also adds basic auto tab support for all language themes. Adding a new line will now cause the caret to be auto tabbed based upon the previous line.
     
  7. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor version 1.0.6 has been submitted to the asset store.
    • Added a compatibility option for TMP to apply line height fix (Unity 2018.2 and newer). This may be required depending upon the TMP version you are using to correctly sync the line highlighter in the code window.
    • Fixed a bug where the line highlighter could become out of sync when some text is deleted.
    • Fixed a bug where the line numbers would not be synced correctly when deleting all text.
     
    zyzyx likes this.
  8. CommunityUS

    CommunityUS

    Joined:
    Sep 2, 2011
    Posts:
    240
    Is there a sample integration provided with support for your Roslyn asset? Esp. in 2019.3 beta now that it works. Or even better for your uMod 2?
     
  9. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi, We have not added anything like this yet. What sort of sample would you like to see? Just a demo scene using IGCE with Roslyn C# or something more? It may take a bit of work to distribute something like this as thee will be 2 asset requirements but we should be able to work something out.
     
  10. CommunityUS

    CommunityUS

    Joined:
    Sep 2, 2011
    Posts:
    240
    Correct just a simple demo. I think it helps promote sales, esp. if the integrations are tested or at least fixed when reported. I try to buy assets that work together - even better if there is a basic integration already made showing best practices between the assets I want to use.
     
  11. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Yes we can certainly add something like that to Roslyn C#. It is not something that we would add to uMod at the moment because currently uMod does not contain any means to compile code at runtime so a code editor would not be very useful.
     
  12. CommunityUS

    CommunityUS

    Joined:
    Sep 2, 2011
    Posts:
    240
    For uMod - let me paint a use case.

    Unity editor is a very powerful tool for Linux users. It can be hard for new users to figure out how to setup mono / vscode to act as an editor to a unity project with Linux Unity Editor. It is already a tough sell to convince potentional modders to dive into the Unity version madness. Near impossible to get them to buy into sorting through all the issues with Unity Editor on Linux while also getting a decent code environment setup.

    Enter ingame code. Now if there was a way to offer a lite version, something we could include in our mod kit we provide (great implementation btw) or something that let the modders code while in play mode within Unity. The user experience is far better to get started modding. (which we want to be easy to start and see the potential)

    They can get started, and when ready to mess with the editor and code env. on Linux, they can cross that bridge when they need to.

    I'm not saying solve all that. Stuff like saving and loading files etc. is not within the realm of the idea. I'm mainly just trying to see if there might be a way to offer it for the modders so when they hit play, they can start coding right in Unity to get their feet wet.
     
  13. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Thanks for the use case. I can understand how it IGCE could be useful in this situation however currently there is not real any possible interconnectability with uMod and IGCE. IE you cant just write code at runtime and pass that code to uMod so I don't think a demo scene would be very useful in this situation. You would essentially just end up with the default IGCE demo scene and nothing more. If you wanted to use IGCE along with uMod you could just import the asset and use the documentation to set it up in addition. If further down the line we added the feature you describe allowing modders to write code in playmode while developing mods then we could certainly add an extra demo at that point.
     
    CommunityUS likes this.
  14. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    In Game Code Editor version 1.0.7 has been submitted to the asset store for review and should be available for download within a few days. This version includes:
    • Added an integration demo package showing how IGCE can integrate into our other asset Rolsyn C#
    • Fixed a null reference exception which occured when the 'Text' property was assgined but the code editor component or game object was disabled.
    • Fixed a bug where the line highlight would stay fixed in position relative to the screen when scrolling via the mouse wheel or scroll bar.
    • Fixed a bug where the 'Text' property of the code editor would sometimes return a string with an additional '"' character.
     
  15. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    In Game Code Editor version 1.0.8 has been submitted to the asset store. This version allows you to move the line highlight bar to a specific line via code. You can now also lock the line highligh bar in position to prevent the user from moving it when editing text which could be useful for debug step though features or similar.
     
  16. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    In Game Code Editor version 1.0.9 has been submitted to the asset store. This version fixes an issue where setting the code editor text via script would not update the line numbers correctly.
     
  17. MrIconic

    MrIconic

    Joined:
    Apr 5, 2013
    Posts:
    239
    When I add the integration package there are errors for

    Assets\InGameCodeEditor_CompatibilityDemo\RoslynCSharp_CompatibilityDemo\Scripts\IGCEMazeCrawlerExample.cs(109,66): error CS1503: Argument 1: cannot convert from 'System.Reflection.Assembly' to 'RoslynCSharp.Compiler.IMetadataReferenceProvider'

    Repeated for each of the 4 lines there.

    (I'm using 2019.4.01f1 if that might make the difference)
     
  18. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi,
    Thanks for reporting these errors. It looks like the compatibility demo was not updated to support the latest Roslyn C# version. We have now fixed this and will be submitting an update for IGCE shortly. I have sent you a PM with the update package so you don't have to wait for the update to be released.
     
    MrIconic likes this.
  19. VpzomTrrfrt

    VpzomTrrfrt

    Joined:
    Dec 2, 2016
    Posts:
    6
    I'm running into an issue with caret placement (with Unity 2018.4.24f1 and TMP 1.4.1): If I set the Text property from another script, then the user clicks into the text field past the end of the line, the caret is placed one character before the end, while I would expect it to be at the very end of the line. Clicking again seems to place it correctly.
     
  20. VpzomTrrfrt

    VpzomTrrfrt

    Joined:
    Dec 2, 2016
    Posts:
    6
    Additionally, setting Text to an empty strings causes it to throw IndexOutOfRangeException every frame until I focus the editor
     
  21. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi,
    Thanks for reporting these issues.
    We were able to reproduce both issues after a bit of testing. The caret position issue when focusing the code editor after setting the text via script has now been fixed and now works as expected. We have also fixed the IndexOutOfRange exception when clearing the code editor text by setting the text property to an empty string. We will be releasing an update shortly with these fixes.
    Let me know if there is anything else.
     
    VpzomTrrfrt likes this.
  22. VpzomTrrfrt

    VpzomTrrfrt

    Joined:
    Dec 2, 2016
    Posts:
    6
    Now I have another issue: If I instantiate a prefab containing the CodeEditor, then set its text, the scrollbar doesn't appear, even if the text is long enough to warrant one
     
  23. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi,
    Sorry for not replying sooner. I did not recieve a notification that you had posted a message.

    We have tested this and were able to reproduce the issue in Unity 2018.3. However, after a lot of debugging and testing, it looks like the issue is with TMP not updating the scroll bar for instantiated instances. We have checked many times and we are using the API correctly, but the scroll bar is simply not updated after the code editor is instantiated. The only way we have been able to fix this is to manually call an internal TMP method using reflection which causes the scroll bar to be updated and then everything works as exepcted. It is a hack and is not ideal but it is the only option we have at this point. We will be submitting an update shortly with the changes.

    Let me know if there is anything else.
     
  24. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor 1.1.2 has been submitted. This version fixes an issue raised above where instantiating a code editor and then assigning a long text string will not update the scroll bar as expected.
     
  25. VpzomTrrfrt

    VpzomTrrfrt

    Joined:
    Dec 2, 2016
    Posts:
    6
    It looks like line wrapping is breaking line numbering. If line 1 is long enough to overflow, part of it gets labeled as line 2, even though there is no newline
     
  26. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi,
    Thanks for reporting this issue.
    We were able to replicate the problem and have now fixed the issue. Entering a long line of text will now cause a new line to be created by word wrapping but the line numbering will be blank until the next actual new line. You can see the results here:

    WordWrappedLineNumbering.png


    We will be submitting an update shortly with these changes and it should hopefully be available for download within a day or two.

    Let me know if there is anything else.
     
  27. Sandro-7

    Sandro-7

    Joined:
    May 25, 2013
    Posts:
    6
    Hello, it's the first time I use this component. So I followed the instructions included but I have a problem. When I execute my game, I see the editor GUI, but obviously my game is running back to the editor. When I click on the editor I cannot type anything, the editor does not accept any pressed key. It seems "locked".
    What can I do?
    Thank you for your help!
     
  28. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi,
    Thanks for using our asset.
    Do you mean that you cannot type into the code editor from the scene view? If so, that is correct and the component only works at runtime via the Play window.
    If you mean that you cannot type in play mode then I would check that TextMesh Pro is setup correctly. We do not handle any input our selfs, but instead built the code editor on top of a Text Mesh Pro input field.
    1. Check that TMP is setup by going to 'Window -> TextMeshPro -> Import TMP Essential Resources'. If you do not see the TMP menu under 'Window', then you likely do not have TMP installed. You can install it via the package manager.
    2. Ensure that the code editor is focused by clicking the mouse inside before typing. The code editor must be focused in order to receive input.
    3. Try creating a TMP input field to see if that works as expected (This will rule out TMP being the cause of the problem). Create a new game object in the scene and go to 'Component -> UI -> TextMeshPro - Input Field'. Test this field in game and if it works correctly, the issue will be with our asset and we will have to look into it further.
    I hope this help you. Let me know if you are still having issues.
     
  29. jamsmith

    jamsmith

    Joined:
    Sep 15, 2021
    Posts:
    1
  30. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89
    hello, does ingame code editor support right-click context menu?such as copy 、pase 、undo、redo??and IntelliSense???
     
  31. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi, In Game Code Editor is just a basic input field with syntax highlighting and some other features, so it does not have copy, paste etc by default. It is best to think of it like a replacement UI input field, a bit like TMP Input Field, with extra features like syntax highlighting.
    You can certainly add a UI context menu yourself though if you need it by building it out of other UI elements. The asset also does not have support for intellisense since that is a complex thing to implement. Only syntax highlighting for a few common languages and a few other nice features like themes.
    I hope that helps you. Let me know if there is anything else.
     
  32. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    655
    Hi, am thinking to purchase asset and have 3 questions if possible!

    1. How hard would it be to add YAML highlighting please?

    I'm using YAML as container format for a level files. Within certain multiline YAML strings, I have another syntax.

    2. Would I be able to add another embedded syntax for those?

    E.g.
    Code (CSharp):
    1.  
    2. mapLayers:
    3. - |
    4.   F  .  F  F
    5.   F  F  F  F
    6.   F  F  .  F
    7. - |
    8.   .  .  B  .
    9.   .  .  P  .
    10.   P1 .  .  P2
    11.  
    So `mapLayers` is a list of multiline strings. These strings are grids of 2 characters delimited by 1 space. Obviously I'd like to highlight when a user makes a mistake in that requirement.

    3. Can one modify syntax rules at runtime? (since the file actually defines the number of characters per grid and what characters are valid for a given tile).

    I realise they are in reducing order of viability but figured I won't find out unless I ask :)

    Thanks!
     
  33. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hi,
    Thanks for your interest in our asset.
    Unfortunately it will not be easy to add syntax highlighting for YAML because it is a contextual format and IGCE only supports basic keyword/character highlighting at the moment. I think you would probably want regex matching to achieve what you are aiming for and that is not something IGCE support yet, although we hope to in the future.

    I would say that IGCE would not be ideal for you in this case unless you feel comfortable diving in and modifying the source code a little to support you goal.

    I hope that helps you. Sorry if it was not the answer you were hoping for but I don't want to mislead you about the capabilities of IGCE. Good luck with the project and let me know if there is anything else.
     
  34. llermy

    llermy

    Joined:
    Jul 22, 2020
    Posts:
    3
    I would like to submit a bug report. The code editor does not seem to handle properly the text "</a>". When you type that, the text in the editor would break. It has happened every time I typed that text on all the cases I've tried it, so it should be easily reproduced. I'm experiencing this in version 2019.3.14f1.

    It's probably some conflict with Unity's rich text tags, as I don't have that problem using a standard TMP inputfield if I use the <noparse> tags around it. I don't know if this is the place to submit bug reports but I just haven't found other channels for this :)
     
  35. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hey, sorry for the delay.
    Thanks for reporting the issue. I will check it out but I also think that it may not be possible to support some html tags in the code editor due to the way it works, atleast not for certain language templates anyway.
    The reason for that is some characters like '<' and '/' are considered symbols by some language themes so they will be syntax highlighted. That work is hidden behind the scenes but essentially the code editor will inject its own html tags around such characters with colour information, so when you type your own tags in, it may actually look something like this which would explain why it is not working and also why it may not be posisble to get working:

    <color><</color>a<color>/</color><color>></color>

    So you can see that the </a> tag will be broken up in order to be syntax highlighted by the symbols '<' and '>' and '/' which are valid C# symbols.

    I hope that helps you, let me know if you have any questions or if there is anything else.
     
  36. mikhailtsai

    mikhailtsai

    Joined:
    Mar 16, 2019
    Posts:
    2
    Hello. I don't know what I do wrong but it is not usable at all.

    First case (works good):
    1. write some text, like "123456"
    2. set the cursor at the middle of this string like: "123|456"
    3. push Enter key

    Result (everything is ok, cursor in a right place):
    123
    |456

    Second case (problem):
    1. write some text into a class body, like:
    Code (CSharp):
    1. class A {
    2.     // 123456
    3. }
    2. set the cursor at the middle of comment string like: "// 123|456"
    3. push Enter key

    Result:
    Code (CSharp):
    1. class A {
    2.     // 123
    3. 4|    56
    4. }    
    I also have a problem with Tab. When I push Tab key it is displaying very long tab (not 4 spaces but like 12 spaces)
    Clear project, just opened a demo scene.
    I don't know what happens. Need help.
     
  37. mikhailtsai

    mikhailtsai

    Joined:
    Mar 16, 2019
    Posts:
    2
    Ok I've turned off auto indent in the language theme and ok, without this feature it is working well. Let me know if you fix it. I think one of your 2 stars review was about that problem. If you don't have time to fix it just turn off this by default...
     
  38. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    Hey, thanks for reporting.
    The auto-indent feature was created for an older version of TextMesh pro and as you can see it breaks with newer versions unfortunately. It should have been disabled by default though until we can find a solution for that, so I will add an update shortly to disable the feature.
    Glad to hear you have found the solution anyway but let me know if there is anything else.
     
  39. scottyboy805

    scottyboy805

    Joined:
    Apr 10, 2013
    Posts:
    1,200
    InGame Code Editor version 1.1.4 has been released on the asset store. This version includes the following quality of life changes:
    • Update minimum supported Unity version to 2019.4LTS
    • Disable auto indent feature by default due to incompatible TMP version until a solution can be found.
    • Adjust default tab spacing for included TMP font assets.