playMaker

Author Topic: CustomActionEditor for custom object class  (Read 1232 times)

K

  • Playmaker Newbie
  • *
  • Posts: 2
CustomActionEditor for custom object class
« on: September 27, 2018, 05:08:20 AM »
Hi, this is what I want to do:

First, in a custom action, a serializable sub-class is contained, with fields which can be set in FSM editor inspector. With the default action editor, the fields are shown perfectly alright (with the little buttons next to the FSM variables being shown, etc.).

Now I would like to change the inspector layout (such as indentation, show/hide particular fields in the inspector under certain conditions). I have been trying to use CustomActionEditor and ObjectPropertyDrawer, but I do not seem to find a way which works properly.
- I can't use the convenient method "CustomActionEditor.EditField" method to draw the fields within the sub-class
- ObjectPropertyDrawer needs FSMGameObject instead of ordinary class to work. However even if it works, I am not sure how to draw the default editor view for FSM variables like I could with the EditField() method

I have tried to look through the api docs, examples and search in the web but I can't find any related solutions.
Could anyone give me some hints? Thank you.
(I'm using PlayMaker v1.8.9 in Unity 2018.1.5f1)

Sample codes:
Code: [Select]
// the base action class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions {
  public class ActionA : FsmStateAction {
    [System.Serializable]
    public class SubClass {
      [RequiredField]
      public string str1;
      public bool bool1;
      public FsmGameObject obj1;
    }

    public SubClass subClassObj1;
    public string otherField1;
    public FsmGameObject otherField2;
  }
}

Code: [Select]
// the editor class
using HutongGames.PlayMaker.Actions;
using HutongGames.PlayMakerEditor;
using UnityEditor;
using UnityEngine;

[CustomActionEditor(typeof(ActionA))]
public class ActionAEditor : CustomActionEditor {
  public override bool OnGUI() {
    ActionA a = target as ActionA;

    EditField("otherField1"); // OK
    EditField("otherField2"); // OK

    EditorGUILayout.Space();
    EditorGUI.indentLevel++;
    // EditField("subClassObj1"); // it works, but I can't custom the inspector layout inside the subclass
    EditField("subClassObj1.str1"); // ??, not working
    EditField("subClassObj1.bool1"); // ??, not working
    if (a.subClassObj1.bool1) {
      EditField("subClassObj1.obj1"); // ??, not working
    }
    EditorGUI.indentLevel--;

    return GUI.changed;
  }
}