public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            _target = PlayMakerInspectorUtils.GetBaseProperty <PlayMakerFsmVariable>(property);

            // TODO: allow option to force a particular type of variable
            ScanAttributesIfNeeded(property);

            rowCount = _noVariablesSelectable?2:3;             // ideal scenario


            // we let the user choose amongst globavariables if not target attribute and when target is defined.
            // else we error out
            if (_variabletargetTarget != null && !_variabletargetTarget.isTargetAvailable)
            {
                rowCount = 1;
            }

            return(base.GetPropertyHeight(property, label) * (rowCount));
        }
		public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
		{
			_target = PlayMakerInspectorUtils.GetBaseProperty<PlayMakerFsmVariable>(property);

			// TODO: allow option to force a particular type of variable
			ScanAttributesIfNeeded(property);

			rowCount = _noVariablesSelectable?2:3; // ideal scenario


			// we let the user choose amongst globavariables if not target attribute and when target is defined.
			// else we error out
			if (_variabletargetTarget!=null && !_variabletargetTarget.isTargetAvailable )
			{
				rowCount = 1;
			}

			return base.GetPropertyHeight(property,label) * (rowCount);
		}
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            int row = 0;

            // set style to use rich text.
            if (controlLabelStyle == null)
            {
                controlLabelStyle          = GUI.skin.GetStyle("ControlLabel");
                controlLabelStyle.richText = true;
            }


            ScanAttributesIfNeeded(prop);

            // we let the user choose amongst globavariables if not target attribute and when target is defined.
            if (variableTargetVariable != null && isTargetAvailable != null && !isTargetAvailable.boolValue)
            {
                EditorGUI.LabelField(
                    GetRectforRow(pos, ++row - 1),
                    " ",
                    "<color=red>Target is undefined</color>"
                    );

                return;
            }


            variableSelectionChoice = prop.FindPropertyRelative("variableSelectionChoice");
            int _variableSelectionChoiceIndex = variableSelectionChoice.enumValueIndex;

            selectedType = prop.FindPropertyRelative("selectedType");
            VariableType _selectedType = PlayMakerInspectorUtils.GetVariableTypeFromEnumIndex(selectedType.enumValueIndex);

            //	PlayMakerInspectorUtils.GetVariableTypeFromEnumIndex(variableSelectionChoice.enumValueIndex);


            //VariableType _variableType = (VariableType)Enum.GetValues(typeof(VariableType)).GetValue(variableType.enumValueIndex);
            //Debug.Log(variableSelectionChoice.enumValueIndex+" "+_variableSelectionChoice);

            variableName = prop.FindPropertyRelative("variableName");
            string _variableName = variableName.stringValue;

            defaultVariableName      = prop.FindPropertyRelative("defaultVariableName");
            defaultVariableNameValue = defaultVariableName.stringValue;

            CacheOwnerGameObject(prop.serializedObject);


            bool _isTargetAvailable = _variabletargetTarget.isTargetAvailable;

            //Debug.Log("GetVariablesStringList _isTargetAvailable?"+_isTargetAvailable);

            if (_isTargetAvailable)
            {
                // variable type selection
                Rect _typeRect = GetRectforRow(pos, ++row - 1);

                EditorGUI.PropertyField(
                    _typeRect,
                    variableSelectionChoice, new GUIContent("Variable Type"), true);

                VariableSelectionChoice _variableSelectionChoice = VariableSelectionChoice.Any;

                if (variableSelectionChoice.enumValueIndex != _variableSelectionChoiceIndex)
                {
                    _variableSelectionChoice =
                        (VariableSelectionChoice)Enum
                        .GetValues(typeof(VariableSelectionChoice))
                        .GetValue(variableSelectionChoice.enumValueIndex);


                    _variableSelectionChoiceIndex = variableSelectionChoice.enumValueIndex;
                    //Debug.Log ("Hello _variableSelectionChoice"+_variableSelectionChoice+" _variableSelectionChoiceIndex"+_variableSelectionChoiceIndex+" _selectedType"+_selectedType+" variableType"+PlayMakerFsmVariable.GetTypeFromChoice(_variableSelectionChoice));
                    if (_variableSelectionChoiceIndex > 0 && _selectedType != PlayMakerFsmVariable.GetTypeFromChoice(_variableSelectionChoice))
                    {
                        //	Debug.Log("reset variable name");
                        _variableName            = "";
                        variableName.stringValue = _variableName;
                    }
                }
                else
                {
                    _variableSelectionChoice =
                        (VariableSelectionChoice)Enum
                        .GetValues(typeof(VariableSelectionChoice))
                        .GetValue(variableSelectionChoice.enumValueIndex);
                }


                string[] _variableList = new string[0];

                bool isVariableImplemented = false;                 // not in use, TODO: clean up


                // Get the list of events
                _variableList = PlayMakerInspectorUtils.GetVariablesStringList
                                (
                    _variabletargetTarget.FsmVariables,
                    true,
                    PlayMakerFsmVariable.GetTypeFromChoice(_variableSelectionChoice)
                                );


                _noVariablesSelectable = _variableList.Length <= 1;

                // find the index of the serialized event name in the list of events
                int selected = 0;
                if (!string.IsNullOrEmpty(_variableName))
                {
                    //Debug.Log("?!");
                    selected = ArrayUtility.IndexOf <string>(_variableList, _variableName);
                }

                // set to none if not found
                if (selected == -1)
                {
                    _variableName            = "";
                    variableName.stringValue = _variableName;
                    selected = 0;
                }



                if (!_noVariablesSelectable)
                {
                    Rect _rect = GetRectforRow(pos, ++row - 1);

                    string _popupLabel = label.text;

                    if (selected != 0 && variableTarget != null && variableTarget.enumValueIndex != 2)              // not none and not globalVariables
                    {
                        if ((selected > 0 && !isVariableImplemented) || selected == -1)
                        {
                            _popupLabel = "<color=red>" + _popupLabel + "</color>";
                        }
                    }


                    // Variable Popup
                    Rect _contentRect = EditorGUI.PrefixLabel(_rect, label);
                    //_contentRect.width -= 0;
                    if (GUI.Button(
                            _contentRect,
                            string.IsNullOrEmpty(_variableName)?"none":_variableName,
                            EditorStyles.popup))
                    {
                        GenericMenu menu = GenerateVariableMenu(_variableList, _variableName);
                        menu.DropDown(_rect);
                    }
                }

                if (_target.GetVariable(_variabletargetTarget))
                {
                    EditorGUI.LabelField(
                        GetRectforRow(pos, ++row - 1),
                        " ",
                        _target.namedVariable.ToString()
                        );
                }
                else
                {
                    string _feedbackMessage = _noVariablesSelectable?"No " + _variableSelectionChoice + "(s) variable in target":"Please Select a variable";
                    string _feedbackLabel   = _noVariablesSelectable?"":" ";
                    EditorGUI.LabelField(
                        GetRectforRow(pos, ++row - 1),
                        _feedbackLabel,
                        "<color=red>" + _feedbackMessage + "</color>"
                        );
                }
            }
            else
            {
                EditorGUI.LabelField(
                    GetRectforRow(pos, ++row - 1),
                    " ",
                    "<color=red>Select a valid target</color>"
                    );
            }
            // attempt to refresh UI and avoid glitch
            if (row != rowCount)
            {
                prop.serializedObject.ApplyModifiedProperties();
                prop.serializedObject.Update();
            }

            rowCount = row;
        }