public PlayMakerFsmVariable(VariableSelectionChoice variableSelectionChoice, string defaultVariableName) { this.variableSelectionChoice = variableSelectionChoice; this.defaultVariableName = defaultVariableName; }
public static VariableType GetTypeFromChoice(VariableSelectionChoice choice) { // Debug.Log("GetTypeFromChoice"+choice); if (choice == VariableSelectionChoice.Any) { return(VariableType.Unknown); } if (choice == VariableSelectionChoice.Float) { return(VariableType.Float); } if (choice == VariableSelectionChoice.Int) { return(VariableType.Int); } if (choice == VariableSelectionChoice.Bool) { return(VariableType.Bool); } if (choice == VariableSelectionChoice.GameObject) { return(VariableType.GameObject); } if (choice == VariableSelectionChoice.String) { return(VariableType.String); } if (choice == VariableSelectionChoice.Vector2) { return(VariableType.Vector2); } if (choice == VariableSelectionChoice.Vector3) { return(VariableType.Vector3); } if (choice == VariableSelectionChoice.Color) { return(VariableType.Color); } if (choice == VariableSelectionChoice.Rect) { return(VariableType.Rect); } if (choice == VariableSelectionChoice.Material) { return(VariableType.Material); } if (choice == VariableSelectionChoice.Texture) { return(VariableType.Texture); } if (choice == VariableSelectionChoice.Quaternion) { return(VariableType.Quaternion); } if (choice == VariableSelectionChoice.Object) { return(VariableType.Object); } #if PLAYMAKER_1_8 if (choice == VariableSelectionChoice.Array) { return(VariableType.Array); } if (choice == VariableSelectionChoice.Enum) { return(VariableType.Enum); } #endif return(VariableType.Unknown); }
public PlayMakerFsmVariable(VariableSelectionChoice variableSelectionChoice) { this.variableSelectionChoice = variableSelectionChoice; }
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; }
public static VariableType GetTypeFromChoice(VariableSelectionChoice choice) { // Debug.Log("GetTypeFromChoice"+choice); if (choice == VariableSelectionChoice.Any) return VariableType.Unknown; if (choice == VariableSelectionChoice.Float) return VariableType.Float; if (choice == VariableSelectionChoice.Int) return VariableType.Int; if (choice == VariableSelectionChoice.Bool) return VariableType.Bool; if (choice == VariableSelectionChoice.GameObject) return VariableType.GameObject; if (choice == VariableSelectionChoice.String) return VariableType.String; if (choice == VariableSelectionChoice.Vector2) return VariableType.Vector2; if (choice == VariableSelectionChoice.Vector3) return VariableType.Vector3; if (choice == VariableSelectionChoice.Color) return VariableType.Color; if (choice == VariableSelectionChoice.Rect) return VariableType.Rect; if (choice == VariableSelectionChoice.Material) return VariableType.Material; if (choice == VariableSelectionChoice.Texture) return VariableType.Texture; if (choice == VariableSelectionChoice.Quaternion) return VariableType.Quaternion; if (choice == VariableSelectionChoice.Object) return VariableType.Object; #if PLAYMAKER_1_8 if (choice == VariableSelectionChoice.Array) return VariableType.Array; if (choice == VariableSelectionChoice.Enum) return VariableType.Enum; #endif return VariableType.Unknown; }