playMaker

Author Topic: Can we disable specific fields on a custom action? [SOLVED]  (Read 4720 times)

CareLevelZero

  • Playmaker Newbie
  • *
  • Posts: 14
  • All design, all the time.
Can we disable specific fields on a custom action? [SOLVED]
« on: October 20, 2013, 03:48:41 PM »
I'll clarify what I mean by that: can we lock or otherwise disable portions of a custom action in the event that, for example, certain boxes are checked/unchecked?

This is primarily so that users don't waste time filling out fields they don't have to.  I can easily ignore extraneous data where necessary but, really, this makes for a better user experience by a wide margin.

I've done some digging around but I haven't been able to catch an answer to this yet.  Thanks for any assistance, folks.  Much obliged.   :)


SOLUTION FOUND
I was specifically looking for a way to use enums to hide/show specific fields.  It turned out to be fairly simple, in the end, once I stopped looking at all of the examples of how to edit the main Unity editor.   ;D

Code: [Select]
using HutongGames.PlayMakerEditor;

[CustomActionEditor(typeof(SimpleConditional))]
public class SimpleConditionalEditor : CustomActionEditor
{

    public override bool OnGUI()
    {
                // if you call DrawDefault Inspector, you'll see all of the fields you're trying to hide, so don't call it.
//DrawDefaultInspector();   

                // The enumerator field should always be visible for editing
EditField("conditionalType");
       
                // Make sure our variable is in the correct format for use
var _target = target as SimpleConditional;

                // Run an enum switch
switch(_target.conditionalType)
{
case SimpleConditional.ConditionalType.BooleanTest:
EditField("Field1NameHere");
EditField("Field2NameHere");
break;

case SimpleConditional.ConditionalType.IntegerComparison:
EditField("Field3NameHere");
EditField("Field4NameHere");
break;
               
                // etc. etc.
« Last Edit: October 26, 2013, 01:40:29 PM by CareLevelZero »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can we disable specific fields on a custom action?
« Reply #1 on: October 21, 2013, 02:05:02 AM »
Hi,

 this is possible if you create a custom editor for your action. you can create tabs like "expert/novice" switches and basically any regular UI you can think of.

 Have a look at the Quaternion set of actinos, they are all using custom editors.

https://hutonggames.fogbugz.com/default.asp?W967

Bye,

 Jean

CareLevelZero

  • Playmaker Newbie
  • *
  • Posts: 14
  • All design, all the time.
Re: Can we disable specific fields on a custom action?
« Reply #2 on: October 21, 2013, 08:35:02 PM »
Thanks Jean.  I took a look at those actions and they did help me narrow down on what I'm looking for but I seem to have run into a snag.  Editors for custom actions seem to require inheriting from the CustomActionEditor class, which is where my problem lies.

"using HutongGames.PlayMakerEditor" is not a valid line of code for me.  For some reason, I don't have that namespace at all.  I'm trying a re-import of my version of PlayMaker but, in the event that fails, any idea why on earth that namespace isn't present?

CareLevelZero

  • Playmaker Newbie
  • *
  • Posts: 14
  • All design, all the time.
Re: Can we disable specific fields on a custom action?
« Reply #3 on: October 21, 2013, 09:37:48 PM »
Incidentally, I found the missing DLL and added it to the solution by hand.  This allows me to make use of the missing namespace but, oddly, absolutely nothing I do in the code actually causes the editor to change appearance.  As a test, I took an example (from here) and ran with that.  Still nothing.

EDIT: I must have missed something in the documentation that would have told me to put the file in the other Assembly.  I've moved it to the Editor Assembly and now I can see changes.  Here's hoping I can finish my original goal without interruption now!
« Last Edit: October 21, 2013, 09:42:42 PM by CareLevelZero »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can we disable specific fields on a custom action?
« Reply #4 on: October 22, 2013, 12:56:47 AM »
Hi,

 With what ide are you coding?

Unity has specific folders conventions for editor scripts, it must go inside a folder called "Editor", it can be anywhere in the asset hierarchy, and custom action editor must also be within an "Editor" folder.

bye,

 Jean

CareLevelZero

  • Playmaker Newbie
  • *
  • Posts: 14
  • All design, all the time.
Re: Can we disable specific fields on a custom action?
« Reply #5 on: October 23, 2013, 04:19:20 PM »
I'm coding with MonoDevelop at the moment.  I caught the file location issue shortly after I posted and corrected that, so the changes are finally beginning to show up as expected.

Right now, I'm looking for ways to optimize the custom editor so that it isn't refreshing unless an enum popup has changed.  The example for custom editors (here) seems inefficient.  If you actually alter Debug Float that way and add it to an object, it bogs the GUI's responsiveness down, particularly when scrolling.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can we disable specific fields on a custom action?
« Reply #6 on: October 24, 2013, 01:26:51 AM »
Hi,

 Are you sure this is related? I don't see anything wrong in this CustomActionEditorTest

Have you ran the editor profiler to see what caused the slowdown?

bye,

 Jean

CareLevelZero

  • Playmaker Newbie
  • *
  • Posts: 14
  • All design, all the time.
Re: Can we disable specific fields on a custom action?
« Reply #7 on: October 24, 2013, 02:27:21 AM »
It does appear to be related.  As a test, I added several Debug Float actions to a state in order to produce a list long enough to warrant a scrollbar.  When only using the default Debug Float editor, the scrollbar continues to move smoothly.  If I implement the CustomActionEditorTest (literally copy/pasted for the sake of accuracy), scrolling becomes significantly choppier.

This doesn't appear to be affecting the game itself, fortunately, but I'm loathe to put custom editors into play that are potentially going to bog down performance within the editor itself.  It's not a major thing right now but I'd like to solve it before it leads to any other issues.  =)

If I run the Profiler and start the game up, then test the scrolling, there is a small spike in CPU and GPU usage equating to several milliseconds.

I suppose it should never become much of an issue if I don't have many of these actions active on a single selected state at once (which shouldn't happen, given the nature of the action displaying this behavior).

I'm beginning to suspect that I'm just overreacting.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Can we disable specific fields on a custom action?
« Reply #8 on: October 24, 2013, 02:42:49 AM »
Hi,

 No no, this is always good that features are stressed and challenged. I understand what you are doing, I'll see if I can repro, something may very well be not fully optimized in the rendering chain within a custom editor.

 Can you file a bug report? we'll follow up on this properly.

bye,

 Jean

CareLevelZero

  • Playmaker Newbie
  • *
  • Posts: 14
  • All design, all the time.
Re: Can we disable specific fields on a custom action?
« Reply #9 on: October 26, 2013, 01:25:12 PM »
Bug report has been filed, Jean.  Thanks a lot for all of the suggestions.  I'm going to update the original post with the solution for what I specifically was looking for and then mark this solved.  :)