Skip to content

Create a simple command

PostCyberPunk edited this page Sep 15, 2023 · 1 revision

image

SimpleCmd.cs
using UnityEngine;
using PCP.WhichKey.Types;
public class SimpleCmd : WKCommand
{
	private string mArg;

	public SimpleCmd(string arg)
	{
		mArg = arg;
	}
	public void Execute()
	{
		Debug.Log(mArg);
	}
}
public class SimpleCmdFactory : WKCommandFactory
{
	//the id of this Factory, must be unique,this is the CmdType of keyset.
	//since i may develop some addtinal commands,so lets start from 101
	public override int TID => 100;
	//the name of the command, the name that shows in Type Dropdown
	public override string CommandName => "SimpleCmd";
	//we dont need arg for this command,i mean you can set Commaand save or load by using arg,but lets keep arg empty in case we may need it later
	//i will add some serialization later,so you can use multiple arg with defined type,stay tune for update notes
	public override WKCommand CreateCommand(string arg)
	{
		return new SimpleCmd(arg);
	}
}
Clone this wiki locally