So I'm in the process of creating a custom action and I wanted to know if its possible to create a single action from multiple script files?
First, let me say that I'm an artist who's still learning C#, but I understand all the basics. Enough to be able to successfully write a single working custom action. The action that I'm writing is comprised of several "settings" such as check boxes, public variables, and drop drown menus. I've got each section of the action working separately (as it own "Action" for testing purposes), but instead of writing one long gigantic script file for the whole action, which would ultimately work, I would like to break it down in to smaller chunks of code (classes) that then get compiled together via the Custom Action Editor.
After studying the Quaternion Actions, I saw how each action was a child to the parent class QuaternionActionBase. Then, each action, as well as QuaternionActionBase, has it's own Custom Action Editor script, which are all children of the QuaternionCustomEditorBase class. So, with the concept of Inheritance in mind and to prevent my script from becoming massively long, I want to know if it's possible to write the entire action in separate classes. So that way I can focus on each section of the code, get it working, and then use Action Editor to arrange all the fields.
As I'm learning more about the Custom Action Editor, I'm wondering if I could write each section of the action as a separate script file, with each script using it's on custom editor, and then create a parent editor that bring all the children (fields) together in one action. Is this possible or am I going about this the wrong way?
What I've discovered thus far, is that the Action Editor only works on the script that it's pointed to. So for the Quaternions for example, GetQuaternionEulerAnglesCustomEditor.cs , will only work on GetQuaternionEulerAngles.cs, because of this line here:
[CustomActionEditor(typeof(GetQuaternionEulerAngles))]
If that's the case, will I have to suck it up and put everything into the main action and utilize 1 Custom Editor Script for the action?
Like I said, I'm learning more and more about C# and what's possible so it would awesome to create smaller modules that I could then bring all together.
Thanks in advance for any advice given.
Here's an example of what I'm trying to do
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This is the parent class. It's only job is to establish the public gameobject variable.
/// All subsequent scripts will be derived from this class, so they all will have access to the parent game object.
/// </summary>
namespace HutongGames.PlayMaker.Actions
{
public abstract class SampleActionBase : FsmStateAction
{
[RequiredField]
[Tooltip("The Game Object")]
[CheckForComponent(typeof(GameObject))]
public FsmOwnerDefault gameObject;
public GameObject go;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This is a child to SampleActionBase.
/// It would contain most of the settings,while the rest comes from another script.
/// This would be the script that actually shows up in the Action Browser
/// </summary>
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Get Some")]
[Tooltip("Tips! Tips! Tips!")]
public class SampleAction : SampleActionBase
{
public FsmFloat time;
public FsmBool looping;
public override void Reset()
{
time = null;
looping = true;
}
public override void OnEnter()
{
DoStuff();
Finish();
}
public void DoStuff()
{
go = Fsm.GetOwnerDefaultTarget(gameObject);
// Then do some stuff with this
}
}
}
using UnityEngine;
using UnityEditor;
using HutongGames.PlayMaker.Actions;
using HutongGames.PlayMakerEditor;
/// <summary>
/// Not sure what to put here. With this being the parent I thought I could
/// expose public FsmOwnerDefault gameObject; here so all children the UI would show up in a child classes,
/// but then I figured out I didn't have to do that.
/// </summary>
public class SampleActionUIBase : CustomActionEditor
{
public override bool OnGUI()
{
return false;
}
}
using UnityEngine;
using UnityEditor;
using HutongGames.PlayMaker.Actions;
using HutongGames.PlayMakerEditor;
/// <summary>
/// This script controls the interface for the SampleAction script.
/// I'd like to add Edit Fields from other scripts in this file.
/// so I could organize each section of the UI.
/// </summary>
[CustomActionEditor(typeof(SampleAction))]
public class SampleActionUI : SampleActionUIBase
{
StartDelayUI startDelayInst;
public override bool OnGUI()
{
EditField("gameObject");
EditField("time");
EditField("looping");
GUILayout.Label("Next Section");
//I'd like to place EditFields from other script files here.
//Thus giving me more control over the layout of the interface
// And making it easier to manage all the code.
;
return GUI.changed;
}
}