Wiki

Case Status
Log In

Wiki

 
Home ยป API Reference»ObjectPropertyDrawer
Index
Navigation
Community Wiki

ObjectPropertyDrawer

HutongGames.PlayMakerEditor.ObjectPropertyDrawer

Extend this class to make a custom property drawer for an FsmObject variable of a specific type.

The property drawer will be used in Action Editors and Variable Editors.

  • NOTE: This is an Editor script, and should be in an Editor folder.
  • Use the ObjectPropertyDrawerAttribute to define the Object type to edit.

C# Example:

This example defines a custom property drawer for any AudioClip parameter. 

Save the script as ObjectPropertyDrawerTest.cs in an Editor folder and look at any AudioClip parameter in an action.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
using System;
using UnityEngine;
using UnityEditor;
using HutongGames.PlayMakerEditor;
using Object = UnityEngine.Object;

// Test with action that uses an FsmObject variable of AudioClip type. E.g., Set Audio Clip

[ObjectPropertyDrawer(typeof(AudioClip))]
public class ObjectPropertyDrawerTest : ObjectPropertyDrawer 
{
    public override Object OnGUI(GUIContent label, Object obj, bool isSceneObject, params object[] attributes)
    {
        GUILayout.BeginVertical();

        obj = EditorGUILayout.ObjectField(label, obj, typeof(AudioClip), isSceneObject);

        GUILayout.Label("This is a custom object property drawer!");

        GUILayout.EndVertical();

        return obj;
    }
}

Object OnGUI(GUIContent label, Object obj, bool isSceneObject, params object[] attributes)

Use EditorGUILayout and GUILayout controls to build the property drawer.

Return the modified Object.

Parameter Description
GUIContent label A label that includes a tooltip.
Object obj The object to edit.
bool isSceneObject

Is obj a scene object. If false, it is used in a prefab, template, or global variables asset.

This is good to know if you're going to use an ObjectField with allowSceneObjects.

object[] attributes

The custom attributes defined for this parameter.

You can use custom attributes for formatting etc.

 

Tags:

Last modified on 5/17/2013 9:00 PM by User.

  • RSS Feed