Templates of commands is description for DevTool Canvas, how it should draw finded commands with specified arguments/types.
Namespace:RenownedGames.DevTool.UIElements
Create new template
Let's take it apart creation new command template type based on CommandTemplateFloat.
[AddComponentMenu("Renowned Games/DevTool/Core Modules/Developer Tools/DevTool/Template/Command Template Float")][DisallowMultipleComponent][RequiredType(typeof(float))]publicsealedclassCommandTemplateFloat:CommandTemplateSingleField<float>{ /// <summary> /// Implement this method to read parameter value from input field. /// </summary> /// <paramname="field">Edited field component.</param> /// <paramname="value">Parsed (T) value from input field.</param>protectedoverridevoidReadValue(InputField field,outfloat value) {field.text=field.text.Replace('.',','); value =Convert.ToSingle(field.text);field.text= value.ToString("0.00",System.Globalization.CultureInfo.InvariantCulture); } /// <summary> /// Called after menu was repaint. /// </summary> /// <paramname="parameter">Actual command parameters.</param> /// <paramname="text">Convert to string parameter.</param>protectedoverridevoidOnParameterUpdate(float parameter,outstring text) { text =parameter.ToString("0.00",System.Globalization.CultureInfo.InvariantCulture); }}
Class inherits from CommandTemplateSingleField which in turn inherits from CommandTemplate
CommandTemplateSingleField class allow to use commands with single argument, where <float> type of argument.
[RequiredType] attribute note DevTool engine what this template can work only with one argument type of float. If you want to create command which will work with multiple arguments add multiple[RequiredType] attributes.
Next step implementation of ReadValue and OnParameterUpdate methods
ReadValue called before execute command. In this method you need to read value from input field and parse it to required type.
protectedoverridevoidReadValue(InputField field,outfloat value){ // The field contains dots we translate them into commasfield.text=field.text.Replace('.',','); // Parse text to float and set to output value value =Convert.ToSingle(field.text); // Reduce the number of characters after the decimal point to two for easier reading.field.text= value.ToString("0.00",System.Globalization.CultureInfo.InvariantCulture);}
OnParameterUpdate called when DevTool Canvas become repaint. In this method you need to update value in input field to actual.
protectedoverridevoidOnParameterUpdate(float parameter,outstring text){ // Reduce the number of characters after the decimal point to two for easier reading.field.text= value.ToString("0.00",System.Globalization.CultureInfo.InvariantCulture);}