Skip to content

A tool used to add custom commands to a developer menu in Unity for quick testing and debugging

License

Notifications You must be signed in to change notification settings

hibzzgames/Hibzz.DevMenu

Repository files navigation

Hibzz.DevMenu

LICENSE Twitter Follow Discord Unity C#

A tool used to add custom commands to a developer menu for quick testing and debugging

Installation

Via Github This package can be installed in the Unity Package Manager using the following git URL.

https://github.com/hibzzgames/Hibzz.DevMenu.git

Alternatively, you can download the latest release from the releases page and manually import the package into your project. The dependencies will also have to be imported manually from the respective releases page.

Dependencies

The package manager unfortunately doesn't support dependencies automatically. Hopefully, 2023 is the year that Unity fixes this. So, until then, you will have to install the following packages manually:

https://github.com/hibzzgames/Hibzz.Singletons.git

How to access?

The DevMenu is a singleton that can be accessed from anywhere in your project. By default, the DevMenu is hidden and you must manually open it from somewhere in your project. The DevMenu can be opened by calling the DevMenu.Open() method and closed by calling the DevMenu.Close() method.

using Hibzz.DevMenu;

// in update
if(Input.GetKeyDown(KeyCode.BackQuote))
{
    if(DevMenu.IsOpen) 
    { 
        DevMenu.Close(); 
    }
    else 
    { 
        DevMenu.Open();
    }
}

How to add commands?

The DevMenu uses a card system to display commands. Each card can have a title and the action to be performed when the card is clicked. The DevMenu can be populated with cards by calling the DevMenu.Add(string title) function. This function returns a card object which can be used to add the callback function to be called when the card is clicked.

// create the card
Card invincibleCard = DevMenu.Add("Invincible");

// add the callback
invincibleCard.OnApply = () =>
{
    // invincible code goes here
}

How to add fields to a card?

The DevMenu also supports adding fields to a card. This can be used to get input from the user and to use that input in the callback function. A card can be populated with fields by calling the Card.Add<T>(string title) function where T is the type of the field. The DevMenu currently supports the following field types and more will be added in the future (feel free to suggest more field types if you have a use case for them).

  • int
  • float
  • string
  • bool
  • enum (any enum type works!)

Here's an example of how to add a field to a card and access the value of the field in the callback function:

// create the card
Card healthCard = DevMenu.Add("Set Health");

// add the fields
healthCard.Add<int>("Health");
healthCard.Add<float>("TimeToHeal");

// add the callback
healthCard.OnApply = () =>
{
    // get the values of the fields
    int health = healthCard.Get<int>("Health");
    float timeToHeal = healthCard.Get<float>("TimeToHeal");

    // some code to set the health of the player in the given time goes here
}

API Reference

For more details on what's possible, here's the link to the API reference.

Conclusion

That's all for now and I hope you find this tool useful. It's pretty flexible and can be used anywhere in your script to dynamically add commands and remove them depending on context.

Have a question or want to contribute?

If you have any questions or want to contribute, feel free to join the Discord server or Twitter. I'm always looking for feedback and ways to improve this tool. Thanks!

Additionally, you can support the development of these open-source projects via GitHub Sponsors and gain early access to the projects.

About

A tool used to add custom commands to a developer menu in Unity for quick testing and debugging

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages