Search Unity

Inspector buttons for any method - Free package for testers

Discussion in 'Assets and Asset Store' started by Ali_V_Quest, Jan 25, 2023.

  1. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Hi,
    I'm building an asset to create inspector buttons for methods with parameters simply by adding [ProButton], for example:


    [ProButton]
    float Add2Numbers(int a, int b)
    {
    return a + b;
    }




    use cases

    1. test every method you write as you are building it, without hooking it to the Start() or Update()
    2. quickly test your game by calling RestartLevel() or RespawnPlayer() & other methods directly from the inspector ...
    3. quickly build simple editor tools without creating editor scripts ...
    4. see the return values of the methods you call, without adding Debug.Log()

    main features:

    1. shows the method and the parameters in the inspector
    2. prints the return values ( no more debug logs )
    3. [ProPlayButton] only works in Unity playmode ( avoid changing scene data )


    if you are interested in testing it & providing feedback, simply fill this google form:

    https://docs.google.com/forms/d/e/1...w9GZkH0WUt2uQiH-yasGMckw/viewform?usp=sf_link



    Thanks
     

    Attached Files:

    Last edited: Jan 25, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    What are the use cases for this?
     
    Ali_V_Quest likes this.
  3. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138

    you can call any method you write from the inspector with a single [ProButton] attribute, so the common use cases are:

    1. test every method you write as you are building it, without hooking it to the Start() or Update()
    2. quickly test your game by calling RestartLevel() or RespawnPlayer() ...
    3. quickly build simple editor tools without creating editor scripts ...
    4. see the return values of the methods you call, without adding Debug.Log()

    Your scripts will have very helpful buttons, without reducing your productivity, this is what your script might look like:
    upload_2023-1-25_19-22-32.png
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    #1 and #4 are useful but for method testing one should write tests for TestRunner instead. This has the benefit of being able to re-run all tests regularly at any point. Unit tests also make it easy to step through the code execution path with the debugger in case there are any issues.

    I can see limited value for this by making a utility method appear in the Inspector, for example to reset an object's stats to defaults, or to insta-kill it. Limited because it's still not much work to do something like that without a dedicated asset. Especially for utilities that don't require context such as reload/restart scene => just add a static method with [MenuItem] attribute and it's available in the menu, rather than on a specific object's Inspector in the scene.
     
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,443
    These are very useful.

    I use the NaughtyAttribute [Button] ALL THE TIME for runtime and editor assists. I'm sure that Odin has similar. I far prefer this to wiring up crap to a UI button, to be able to execute functionality before I write the "real" UI or gameplay that can trigger things. I also hate adding more garbage to the menus or trying to find them. This only shows up when I'm actually looking at my classes in the Inspector.

    Sure, a dedicated Test case is valuable as a regression protection, but many times I don't yet know all the capabilities of a new class or system and want to expose parts of it for experimentation in the editor.
     
    CodeSmile and Ali_V_Quest like this.
  6. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138

    do Naughty Attributes serialize the method parameters ? Thanks
     
  7. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Thanks for the feedback & you're right about the very general methods & the reload scene is possibly a bad example
    but it's more about adding health to any object without any extra code
    or enabling special abilities at any time in the editor
    without modifying any of your code
     
  8. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,443
    No, NaughtyAttributes [Button] functions have no arguments or return values, and there's no specialized versions to run only in-Play or out-of-Play. It only supports changing the name of a button [Button("do something cool")]. You should keep developing your version, it looks useful.
     
    Ali_V_Quest likes this.
  9. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Thanks for the info
     
  10. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    As to adding health or abilities: this is also possible through debugger. Changing variables at runtime is trivial, it requires typing some code in the immediate window in order to instantiate a class and add it to a collection, but it‘s also possible.

    I‘m starting to see some value in it but when I keep thinking about it, one way to achieve the same is the debugger as mentioned above and the other is using a console command asset. I believe they work in the same way that you attribute a method to flag it as a console command, and you run them by typing it once like in immediate window. And subsequently you can select it via command history (keyboard driven or context menu). I believe some also offer the option of making debug menus from commands, or maybe those are separate assets. Either way, benefit of that approach is that it also works within standalone builds, not just play mode.
     
  11. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    it's ready for testing, if anyone is interested in testing it & getting a free copy just reply letting me know

    Thanks
     
    Last edited: Jan 31, 2023
  12. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    finally the asset is ready :)
    it's awaiting asset store review
    if you're interested in a free copy in exchange for an honest review, just let me know

    Thanks
     
  13. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    halley likes this.