Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Utilities Script Inspector 3

Discussion in 'Tools In Progress' started by Flipbookee, Aug 10, 2013.

  1. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    Finally got a chance to load up the updates and review the changes... you've been very busy!

    A small inconsistency, for Dark Theme:



    Edit: ah, I see your code trying to work around a Unity bug (where they're trying to fix the spelling of a style). The FGConsole works where the FGTextEditor doesn't, because you're just extending the original Console.

    I made a couple small changes to my local copy to "uncrowd" the title bar, basically removing the Autofocus and Monospace controls which end up overlapping the other more useful things. If I weren't as lazy as I am, I would have seen about adding this as a preference setting myself.



    And lastly, both search bars seem a bit wide. I dunno if it makes sense (or is easy to implement) but they could shrink down to fit just a few characters when the text inside them is completely empty, freeing up room and not blocking as much. Otherwise, it tends to crowd and overlap.



    Awesome stuff, and long live ScriptInspector3!
     
    Last edited: Sep 11, 2023
    Lars-Steenhoff and Flipbookee like this.
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    Looks like flipping the workaround works. You were saying, "if the old style spelling exists, use it." Code below says, "if the new style spelling exists, use it." Apparently both style spellings exist while they're migrating over, but only the new one has the right values.

     
    Flipbookee likes this.
  3. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Hey, my friends, check this out! :cool:

    Script Inspector 3
    version 3.1.4

    is available on the Asset Store

    This one is kind of a small update, mainly to address a tiny bug in inferring types of some implicitly typed parameters of lambda expression, with a few small improvements suggested in the last week or so.

    However, it also contains code that integrates Si3 with the Hot Reload plugin if it's installed in your Unity project. Please note that I'm not affiliated with the authors of Hot Reload, but I tried it and I think it's a good workflow improvement for myself, so that's why I decided to add support for it in Si3. They offer a free trial version if you'd like to try it as well, and if you do so, please let me know how it works with Si3 :)

    So anyway, here's the list of changes:
    - Hot Reload plugin support & integration
    - Added OnPreSaveCSharp callback to FGTextBuffer - thanks @halley
    - Added option in Si3 Preferences to swap Shift+Enter and Ctrl+Enter hotkeys - thanks @WanAmir
    - Hide Auto-Focus and Font toolbar buttons when the SI Console is not wide enough - thanks @halley
    - Shorter toolbar search box when it's empty - thanks @halley
    - Ping the edited asset by clicking the asset path in the toolbar - thanks @halley
    - Better workaround for misspelled toolbar search field GUI styles in Unity - thanks @halley
    - Fixed inferring type of some implicitly typed lambda expression parameters - thanks @GrassWhooper

    Enjoy coding with Si3, and please don't forget to review it if you like my work! :)
     
  4. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556

    I would love to get the dark search bar back from before, The new white one looks out of place.
    I'm reverting to a previous version until that search bar is no longer white :)
     
    Flipbookee likes this.
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    The white was unintentional. Just apply the changes shown in post #2052 to your copy of FGTextEditor.cs, or download the newest whole set of changes in 3.1.4.
     
    Flipbookee and Lars-Steenhoff like this.
  6. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    It is version 3.1.4. that gives me the white search bar in the inspector.
    I'm not sure what to change in the script?


    Screenshot 2023-09-26 at 00.08.10.png
     
    Flipbookee likes this.
  7. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    The older version looks like this much better.
    In the new one on the right side the search bar white and is also cut off.
    Maybe it was not updated or I have a mac with unity 2022.3.10 and that is somehow different?

    Screenshot 2023-09-26 at 00.10.31.png
     
    Flipbookee likes this.
  8. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Ah, sorry about that - I should have checked the changes in more Unity versions. It worked just fine in those I checked...

    I checked again and this is what makes it work in all Unity versions (I didn't check all versions, but this is a much nicer workaround and it must work):
    upload_2023-9-27_9-2-38.png

    The only change I made is at line 15126 (in the latest Si3), from this:
    styles.toolbarSearchField = new GUIStyle(searchFieldStyle);
    to this:
    styles.toolbarSearchField = new GUIStyle("ToolbarSearchTextField");

    I hope that helps for now, and I'm planning another release this week with that fix and a few more improvements.
     
  9. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    Really happy with all the latest changes, I updated again and can ditch my FGConsole hacks for narrow windows.

    I have noticed an odd behaviour with breaking lines and adjusting indentation, though. Tab stops are 4, using only spaces, in case that matters. Unfortunately, I have not found a 100% reliably repeatable case. If I split code to wordwrap, e.g., inserting a newline before the second underscore:

    Code (CSharp):
    1. ....if (farthestIndex < nbStepHits)
    2. ....{
    3. ........_internalCharacterHits[farthestIndex] = _internalCharacterHits[nbStepHits];
    4. ....}
    the code will break as expected like this:

    Code (CSharp):
    1. ....if (farthestIndex < nbStepHits)
    2. ....{
    3. ........_internalCharacterHits[farthestIndex] =
    4. ........_internalCharacterHits[nbStepHits];
    5. ....}
    but if I then hit Tab to add one stop of indentation, it will sometimes insert 3 spaces instead of 4:

    Code (CSharp):
    1. ....if (farthestIndex < nbStepHits)
    2. ....{
    3. ........_internalCharacterHits[farthestIndex] =
    4. ..........._internalCharacterHits[nbStepHits];
    5. ....}
    Another Tab will add one space to bring it to the intended tabstop, but if I don't notice it, multiple lines of code that follow might end up misaligned and Shift+Tab will maintain the odd misalignment until I remove all indentations and tab it back.

    It seems like some files are more susceptible to this than others; if it happens once it will happen anywhere in that file or buffer, but other files with very similar code just never repeat the problem. I will keep trying to find a more concrete repeatable case.
     
    Flipbookee likes this.
  10. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    @halley, that might be the weirdest bug so far ;) but thanks, I'll try to reproduce that.
     
  11. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Right, I found it! I fixed that and I think I'll release it this weekend with all the other fixes collected over the last three weeks.
     
    halley and Lars-Steenhoff like this.
  12. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    Glad you found that indent quirk.

    I am not sure what the new "Auto-Fold Regions" option does... I was hoping it might allow me to turn on/off the initial folded state of regions when I open new files. I'm an ancient fuddy-duddy who'd rather not have the regions all folded most of the time, but I know you young whipper-snappers would rather them all crinkled up by default until you poke them.
     
    Flipbookee and Lars-Steenhoff like this.
  13. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    Yes a toggle Fold all / Unfold all would be good to have
     
    Flipbookee likes this.
  14. AericGames

    AericGames

    Joined:
    Aug 15, 2023
    Posts:
    9
    I wasn't aware of this asset but it looks amazing, and you've obviously put a ton of work into it!
     
    Flipbookee likes this.
  15. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Yes, it does exactly that, and I'm pretty sure about that because I just tested it. Just note that it also remembers the collapsed state across domain reloads, so the script is in its "initial" state only when its undo buffer is empty, and only then that option in Si3 Settings does get applied... However, the saved state doesn't survive restarting the Unity Editor, or forcing Unity to reimport the script (these two actions also clear the undo buffer).
     
  16. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Thanks @AericGames :rolleyes:

    Yeah, an awful lot of work actually, 11+ years so far, and there's still so much I want to do...
     
  17. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Right, I don't know why I haven't added that yet. I know I was trying to come up with a sensible keyboard shortcut for that, but nothing looked good enough. Any suggestions?
     
    Lars-Steenhoff likes this.
  18. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    I had tried the feature by turning that flag off, and then opening files with #region that I had never opened previously... and they were folded upon opening. But now I am trying the same thing and it works as expected. Gremlins.
     
    Flipbookee likes this.
  19. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    Shift + F ?
    And it could cycle between : custom folded / all unfolded / all folded

    I would also make a toggle button somewhere
     
    Flipbookee likes this.
  20. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    I like the cycling idea, but Shift+F won't work, that's reserved for typing a capital F ;), Ctrl+F for focusing the search field, and Shift+Ctrl+F for Find in Files. And any combination of Alt and F opens the File main menu, so I'll have to find something else
     
  21. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    You can add the function to a menu bar item and then users can configure a shortcut key for themselves
     
    Flipbookee likes this.
  22. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,122
    Does Script Inspector 3 have a method to Auto fill in a interface you use, so you don't have to type it manually.
    For example if I'm using events like--
    public class InventoryItem : MonoBehaviour, IPointerClickHandler


    that it would auto fill the following;

    public void OnPointerClick(PointerEventData pointerEventData)
    {

    }
     
    Flipbookee likes this.
  23. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    No, not yet, but that feature is at the top of my priority list now. If I manage to get the current release this weekend, I'll start with that right away next week.
     
    John-G likes this.
  24. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,122
    Fantastic news, have had Script Inspector a long time and love it. But only now starting to learn to code proper and following so many tutorials that all use Assembly short cuts and auto function generation. Can make it tricky to figure out manually creating them. Though learning a lot about functions this way too.

    P.S. is there a list of shortcuts and 'Code Snippets' all ready present in SI3.
    stuff like Property shortcuts that SI3 includes. for example pressing tab after typing prop...
    completes: public int MyProperty { get; set; }
     
    Last edited: Dec 9, 2023
    Flipbookee likes this.
  25. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Yes,
    prop
    is a code snippet defined as an editable prop.txt file in the Assets/Plugins/Editor/ScriptInspector3/CodeSnippets/ folder. You can edit that file to make it fit your preferences or add your own code snippets. There are more code snippets as .txt files in that folder, so check them out and see which ones you might find helpful. For me,
    nn
    is the one I use most often because it expands to
    != null
    , which is simple enough, but for me, it's hard to type without looking at the keyboard.

    You also find a few C# files in that folder, and those are more complex code generators. One of them activates on typing a space after the keyword
    override
    , and it lets you generate an override for any not-already overridden virtual method. Another code generator implements a property for an existing field. And there's another one that can generate any of the supported magic methods such as Start(), Update(), or OnFailedToConnectToMasterServer() (Unity calls those Messages, don't ask me why ;)) for all classes that support magic methods (MonoBehavious, ScriptableObject, Editor, EditorWindow, and AssetPostprocessor). The next version will include another one that implements overrides for virtual properties.
     
    John-G likes this.
  26. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    (They're called messages because they're implemented with SendMessage(), which is their magical reflection-powered ability to call *all* compliant methods throughout the object, whether public or private, in the configurable execution order, using very-non-C#-rule-following reflection.)
     
    Flipbookee likes this.
  27. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    That makes sense, and I wonder how I didn't realize that earlier... But what do you mean by "configurable execution order"? If I have class A derived from MonoBehaviour and another derived from B, both implementing a Start() method, will it call both methods or only Start() in B?
     
  28. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    If component A has the [DefaultExecutionOrder(+100)] attribute attached, component B has no such attribute, and component C has [DefaultExecutionOrder(-100)], then magic message methods will be executed in the order C, B, A. There is an "Execution Order" setup in the Project Settings too, which can implicitly set these orderings when not explicitly given in the source code.

    If classes have a virtual inheritance chain with these methods, the most-specialized class wins just like you expect in C#, and that class can choose to call the base version's method or not.
     
    Last edited: Dec 9, 2023
    Flipbookee likes this.
  29. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Ah, that execution order, okay! :)

    I was worried that maybe it calls B.Start() and then A.Start() without me explicitly making a call to base.Start() in B. My understanding is that they call the method in the most specialized class, regardless if the methods are virtual or not.
     
  30. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    If you ignore the compiler's warnings about "should use virtual/override" then C# also behaves by that rule. Reflection through the object works that way. It's just that Unity's reflection searches for private and public and calls anyway where they really shouldn't.
     
    Flipbookee likes this.
  31. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,601
    But we're offtopic now, and you've made another "hopefully by this weekend" post, so I should leave you to it. ;)
     
    Flipbookee likes this.
  32. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,122
    Nice, that's fantastic information. I shall dig into all this. Loving this more and more, can't see myself ever installing MS Visual Studio again.
     
    Flipbookee likes this.
  33. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    I'm terrible at making time estimates :oops:

    There's an elusive bug while reloading the Domain that I'm still trying to fix, so I must apologize for the delay...
     
    John-G likes this.
  34. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Ho, ho, ho! Look here, Santa has a present for you ;)

    Script Inspector 3
    version 3.1.6

    is available on the Asset Store
    New in version 3.1.6:
    - New font: JetBrains Mono
    - New option to choose the access modifier for generated Unity magic methods
    - Fixed GUIStyle of the collapsed UnityEvent property drawer header - thanks @Lars-Steenhoff
    - Fixed a null reference exception - thanks @Lars-Steenhoff
    - Fixed a null argument exception
    - Fixed a typo in the UI

    New in version 3.1.5:
    - C# support improvements:
    * infering return type of lambda expressions in block syntax - thanks @zeiksz
    * dictionary initializer lists
    * 'using' local variable declarations
    * 'private' and 'private protected' modifiers on accessors
    - Updated support for the latest version of Hot Reload plugin
    - Reload externally modified files if Auto-Refresh Assets is turned off
    - Code generator for overriding virtual properties - thanks @GrassWhooper
    - Added auto-generate for more magic methods / Unity messages
    - Ping the asset on doubleclicking its path/name in Si3 find results tabs - thanks @Lars-Steenhoff
    - Fixed displaying text with both Word Wrap and Code Folding turned off - thanks @JoeStrout
    - Fixed selecting fonts - thanks @adamgolden
    - Fixed the 'base' type of interface types - thanks @GrassWhooper
    - Fixed foreach iterator variable type inference from a generic enumerator
    - Fixed GUI style of the search bar for Unity dark theme - thanks @Lars-Steenhoff
    - Fixed indentation with spaces on pressing the tab key - thanks @halley
    - Fixed GUI error on right-clicking the SI Console - thanks @MrProtek
    - Fixed Shift+Wheel for horizontal scrolling in latest Unity - thanks @DestrucSean
    - Fixed Si3 property drawer for UnityEvent properties in Unity 2022.2+
    - Fixed showing text while loading after reloading assemblies
    - Fixed vertical text misalignment in some cases
    - Fixed showing constructor name in the code navigation toolbar
    - Fixed unwanted scrolling on changing font size
    - Fixed names of SI tabs listed in the Window->Panel main menu

    I hope this will make your holidays more enjoyable!

    Happy coding :cool:
     
  35. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    Thanks for the nice present santa!
     
    Flipbookee likes this.
  36. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    Is there a way to increase the font size a bit?
     
    Flipbookee likes this.
  37. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Yes, with Ctrl+Plus/Minus on Windows, and I believe the same is on MacOS but with the Command key. Ctrl/Command + mouse wheel should also do that, as well as zoom gestures on touch input devices.
     
  38. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,116
    Have you begun work on an equivalent for UE? Asking for a friend.
     
    Flipbookee likes this.
  39. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,556
    I have made the text patched by hot reload white in my version of SI3, green it was asking too much attention from me. I left the other colors alone, as they need attention when they show up. Screenshot 2024-01-13 at 16.53.30.png
     
    Flipbookee likes this.
  40. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,122
    Been making great use of the Override auto-Complete function. And have a new request if possible on top of the Auto fill in a interface Request I made earlier.

    Would it be possible to add in also an Auto fill in Generate Constructor method.

    For example I have a script of myClass that doesn't inherit from Monobehaviour:

    Code (CSharp):
    1. public class MyClass
    2. {
    3.     protected int myInt;
    4.     protected float myFloat;
    5.     protected bool myBool;
    6.  
    7.     public MyClass(Player _player, PlayerStateMachine _stateMachine, string _animBoolName)
    8.     {
    9.         this.myInt = _myInt;
    10.         this.myFloat = _myFloat;
    11.         this.myBool = _myBool;
    12.     }
    13. }
    The script My class, has protected variables etc that I wish to share to other scripts of my classes.

    For example: I have a second script called MyOtherClass that Inherits from my MyClass

    Code (CSharp):
    1. public class MyOtherClass : MyClass
    2. {
    3.      // Generate This Constructor Interited from MyClass
    4.     public MyOtherClass(int _myInt, float _myFloat bool _myBool) : base(_myInt, _myFloat, _myBool)
    5.     {
    6.         }
    7. }
    It would be fantastic to be able to do like in Visual Studio to Auto generate the Constructor:

    Code (CSharp):
    1.    // Generate This Constructor Interited from MyClass
    2.     public MyOtherClass(int _myInt, float _myFloat bool _myBool) : base(_myInt, _myFloat, _myBool)
    3.     {
    4.     }
     
    Flipbookee likes this.
  41. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    I trust your design skills much more than mine, so count this change as accepted. Thanks! :)
     
    Lars-Steenhoff likes this.
  42. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Cool, thanks for the feedback!

    I'm working on auto-implementing interfaces already, and I'm currently at the third approach which looks much more promising than the first two attempts. It will take some time until it's done, but it will be amazing, I believe.

    That would be another great feature, so yeah, I'll add that as well next. Thanks for this suggestion too! :)
     
    John-G likes this.
  43. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,122
    That sounds amazing, hopefully the third attempt works out. Third time the charm .
    Look forward to the addition to what already is the best plugin purchased and my first install on every project I create.
     
    Flipbookee likes this.
  44. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Yes. the third attempt seems to work very well! There's still more work to be done, though, and to make sure it covers everything of the C# specifications, which are quite complex, especially with the latest additions to the language where they expanded the rules about what an interface can do in C#.
     
  45. GrassWhooper

    GrassWhooper

    Joined:
    Mar 25, 2016
    Posts:
    114
    hey there
    small question, so i switched to linux.
    and i noticed that, when i import script inspector 3 to the project, it stays stuck at importing forever (mint 21.3) is what i use, thought i'd ask if you have any ideas
     
    Flipbookee likes this.
  46. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Hmm, I don't know why that would happen... If I had the editor log file, I'd check what is near the end of it to find out at which phase it gets stuck.

    Did you have to kill it? What happens when you open the project after you kill it? Was Si3 imported and working, or is there no trace of it? Or maybe Unity gets stuck now when you open the project? I assume you tried to import it again and it didn't work because it got stuck again.

    Maybe try importing it into a new empty project. If it works there, try copying the Si3 folder (Assets/Plugins/Editor/ScriptInspector3/) manually to the first project and see if that works.
     
  47. GrassWhooper

    GrassWhooper

    Joined:
    Mar 25, 2016
    Posts:
    114
    linux is weird xD
    so i changed from Linux Mint 21.3, to Pop Os 22.04, and now script inspector 3, imports properly ! (i can no longer reproduce it, as i changed to another variant of linux).
    the project works and everything.
    however, there is in fact, one tiny issue.
    when i press Ctrl+S after modifying a script, it won't capture the save of the script, but rather it would try to save the scene.

    i know, linux is weird, but if you have any ideas, i'd be thankful :D
    actually, i noticed Ctrl Z, Ctrl Y don't work either.

    that is weird.
     
    Last edited: Feb 20, 2024
    Flipbookee likes this.
  48. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Yes, I think I know why those hotkeys don’t work on Linux. I’ll try to fix that ASAP!
     
    GrassWhooper likes this.
  49. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    854
    hehe, been a while. was there any relevant work to allow mega projects to reload faster than VS after compilation?
    the sln/csproj files generation is what I think eats most post-compilation time.

    I might be able to do a quick test sometime these days. but was curious if you're aware of any improvements over VS since my last message
     
    Flipbookee likes this.
  50. Flipbookee

    Flipbookee

    Joined:
    Jun 2, 2012
    Posts:
    2,815
    Hi there! :) It's been a while, and Si3 received many improvements, although I can't recall any specific to your case. Except that the latest version works perfectly with Hot Reload; now it auto-recognizes when Hot Reload is active and adjusts its settings automatically.

    Have you tried Hot Reload? I think they offer a free version on their website, if you want to see how it works. I found it very helpful and wanted to use it, so I had to make Si3 work with it more closely. But I haven't tested it with hundreds of assembly definitions.

    Tell me, is there any chance for me to test Si3 and VS with your project? I'd only need the code without any other assets, and I promise it will be all deleted after the tests. Because I don't know how else I could test this case.

    What do you say? Deal or no deal?