/// <summary> /// Block to display on the canvas. /// </summary> /// <param name="heroKitAction">Hero kit action to display in the block.</param> public static void Block(HeroKitAction heroKitAction) { // exit early if object is null if (heroKitAction == null) { return; } // assign hero object to this class heroAction = heroKitAction; // draw components DrawBlock(); }
/// <summary> /// Build the fields in the form. /// </summary> /// <param name="heroObject">The hero object that contains the action.</param> /// <param name="heroAction">The action on the hero object.</param> /// <param name="template">The action form.</param> /// <param name="oldTemplate">The last action form loaded by this script.</param> public static void BuildFields(HeroObject heroObject, HeroAction heroAction, HeroKitAction template, HeroKitAction oldTemplate) { // exit early if template does not exist if (template == null) { Debug.Log("template does not exist."); return; } if (template.actionFields == null) { Debug.Log("action fields for " + template.name + " do not exist."); return; } // if the hero action attached to the hero object has changed, reset the fields for the hero action on the hero object if (template != oldTemplate) { heroAction.actionFields = new List <HeroActionField>(); } // get the name of the class to use Type type = Type.GetType("HeroKit.Editor.ActionBlockFields." + template.actionFields.name); // if class exists, get the BuildField method inside the class if (type != null) { // get the name of the method to use MethodInfo method = type.GetMethod("BuildField"); // if method exists, invoke it if (method != null) { // get the parameters to pass into the method HeroActionParams actionParams = new HeroActionParams(heroObject, heroAction); // create a delegate to represent the method (note: 300x faster than method.Invoke) Action <HeroActionParams> buildForm = (Action <HeroActionParams>)Delegate.CreateDelegate(typeof(Action <HeroActionParams>), method); // execute the delegate buildForm(actionParams); } } }
/// <summary> /// Draw the body of the block. /// </summary> private static void DrawBody() { SimpleLayout.BeginVertical(Box.StyleCanvasBox); // draw name of the block action.name = HeroKitCommon.DrawBlockName(action.name); SimpleLayout.Line(); // get current action template on hero object HeroKitAction oldTemplate = action.actionTemplate; // draw action field for block SimpleLayout.Space(5); SimpleLayout.BeginHorizontal(); SimpleLayout.Label("Action:"); action.actionTemplate = SimpleLayout.ObjectField(action.actionTemplate, HeroKitCommon.GetWidthForField(85)); SimpleLayout.Space(); SimpleLayout.EndHorizontal(); // SHOW FIELDS FOR SPECIFIC ACTION if (action.actionTemplate != null) { SimpleLayout.Space(5); SimpleLayout.Line(); SimpleLayout.Space(5); // build fields ActionBlockBuilder.BuildFields(heroObject, action, action.actionTemplate, oldTemplate); // build description for action SimpleLayout.Space(5); SimpleLayout.Line(); SimpleLayout.Label("Description:"); SimpleLayout.Label(action.actionTemplate.description, true); } SimpleLayout.EndVertical(); }
/// <summary> /// Click Edit button in hero kit action inspector. /// </summary> /// <param name="selectedAsset"></param> public static void ButtonClickHeroActionAsset(HeroKitAction selectedAsset) { heroType = 1; heroKitAction = selectedAsset; ShowWindow(); }
/// <summary> /// Actions to perform when the hero kit action is enabled. /// </summary> private void OnEnable() { heroKitAction = (HeroKitAction)target; }