-
Notifications
You must be signed in to change notification settings - Fork 1
Creating a new command
Anders Magnusson edited this page Apr 24, 2020
·
2 revisions
There are two ways to create a new command: by extending the scriptable object "Command" or by implementing ICommand directly. Below follows the required steps in order to create a new command and make it available in-game.
Method 1: Scriptable object (recommended)
- Create a new script in "ScriptableObjects/Console/Commands/"
- Make it extend and implement the abstract class "Command"
- In the "Execute" method, add your own logic and send back any relevant message with "sender.SendMessage"
- Add the attribute [CreateAssetMenu(menuName = "Console/Commands/YourCommandName")] above the class
- Navigate to "Gameplay/Console/Commands/", right click and click "Create>Console>Commands>YourCommandName"
- Select the new command asset and put in appropritate values in the inspector
- Navigate to "Gameplay/Console/CommandCollection" and drag and drop in the new command asset
Method 2: Manual script
- Create a new script in "Scripts/Console/Commands/"
- Make it implement the interface "ICommand"
- Add your own logic
- Access the active "CommandManager" and call "Register(new YourCommandName())"