JohnBaracuda / com.baracuda.runtime-monitoring

Runtime Monitoring is an easy way for you to monitor the value or state of custom C# members during runtime. Just add the 'Monitor' attribute to a field, property, event, method or even class and get its value or state displayed automatically in a customizable and extendable debug UI.
MIT License
408 stars 22 forks source link

Issue with conditional display code #29

Closed PooperPig closed 2 months ago

PooperPig commented 3 months ago

I took the code from the documentation public class PlayerAccelerate : MonoBehaviour

{

    [Monitor]
    [MShowIf(monitor)]
    private bool IsAlive { get; }

    [SerializeField] private bool monitor = true;

which gives me an error on the 'monitor' field "An object reference is required for the non-static field, method, or property 'PlayerAccelerate.monitor'"

It would be great if it did work, as I want to be able to turn monitoring on and off for various classes in my game...

JohnBaracuda commented 3 months ago

I think this is just an issue with the documentation. It should use the nameof() keyword to pass in the name of the monitor bool instead of passing in the bool directly. This should work:

[Monitor]
[MShowIf(nameof(monitor))]
private bool IsAlive { get; }

[SerializeField] private bool monitor = true;
PooperPig commented 3 months ago

Brilliant, I'll give it a go.

On Sat, Jun 1, 2024, 5:29 PM John Baracuda @.***> wrote:

I think this is just an issue with the documentation. It should use the nameof() keyword to pass in the name of the monitor bool instead of passing in the bool directly. This should work:

[Monitor][MShowIf(nameof(monitor))]private bool IsAlive { get; } [SerializeField] private bool monitor = true;

— Reply to this email directly, view it on GitHub https://github.com/JohnBaracuda/com.baracuda.runtime-monitoring/issues/29#issuecomment-2143341226, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASMXYKILZW4I6CL7RSMRETZFFZ4RAVCNFSM6AAAAABIT3ZK2CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBTGM2DCMRSGY . You are receiving this because you authored the thread.Message ID: @.*** com>