Beispiel #1
0
        public override void DrawInspectorProperties(AIBehaviors fsm, SerializedObject sObject)
        {
            EditorGUILayout.Separator();

            GUILayout.Label("Properties: ", EditorStyles.boldLabel);
            GUILayout.BeginVertical(GUI.skin.box);

            string[] varNames = fsm.GetVariableNames();
            varIndex = EditorGUILayout.Popup(varIndex, varNames);
            AiBehaviorVariable selectedVar = fsm.userVariables[varIndex];

            SerializedProperty property;

            // Float and Int
            if (selectedVar.IsFloat() || selectedVar.IsInteger())
            {
                property = sObject.FindProperty("checkCondition");
                EditorGUILayout.PropertyField(property);
                property = sObject.FindProperty("numValue");
                EditorGUILayout.PropertyField(property, new GUIContent("Value"));
            }
            else if (selectedVar.IsBoolean())            // Bool
            {
                property           = sObject.FindProperty("boolValue");
                property.boolValue = EditorGUILayout.Toggle("Is: ", property.boolValue);
            }

            GUILayout.EndVertical();

            sObject.ApplyModifiedProperties();
        }
Beispiel #2
0
        protected virtual void DrawChangeVariableProperties(SerializedObject m_Object, AIBehaviors fsm)
        {
            string[]           varNames = fsm.GetVariableNames();
            SerializedProperty property = m_Object.FindProperty("variables");

            // Add button
            styles = new AIBehaviorsStyles();
            if (GUILayout.Button(styles.blankContent, styles.addStyle, GUILayout.MaxWidth(styles.addRemoveButtonWidths)))
            {
                if (varNames.Length > property.arraySize)
                {
                    property.arraySize++;
                    m_Object.ApplyModifiedProperties();
                }
                else
                {
                    Debug.LogError("You need to add more variables to edit them");
                }
            }

            for (int i = 0; i < variables.Length; i++)
            {
                SerializedProperty arrayElement  = property.GetArrayElementAtIndex(i);
                SerializedProperty selectedIndex = arrayElement.FindPropertyRelative("selectedIndex");
                GUILayout.BeginVertical(GUI.skin.box);
                {
                    // Not alowing to have the same variable selected more than once
                    int tempIndex = EditorGUILayout.Popup(selectedIndex.intValue, varNames);
                    if (CheckExistingIndex(tempIndex, i))
                    {
                        selectedIndex.intValue = FindAvaiableIndex(i);
                        GUILayout.EndVertical();
                        break;
                    }
                    else
                    {
                        selectedIndex.intValue = tempIndex;
                    }

                    AiBehaviorVariable selectedVar = fsm.userVariables[selectedIndex.intValue];

                    SerializedProperty changeVariableMode = arrayElement.FindPropertyRelative("changeVariableMode");
                    if (selectedVar.IsBoolean())
                    {
                        changeVariableMode.enumValueIndex = 0;                         // A bool can only be changed, not incremented
                    }
                    EditorGUILayout.PropertyField(changeVariableMode, new GUIContent(""));

                    SerializedProperty changingValue = arrayElement.FindPropertyRelative("changingValue");
                    if (selectedVar.IsFloat())
                    {
                        changingValue.floatValue = EditorGUILayout.FloatField(changingValue.floatValue);
                    }
                    else if (selectedVar.IsInteger())
                    {
                        changingValue.floatValue = (int)EditorGUILayout.IntField((int)changingValue.floatValue);
                    }
                    else if (selectedVar.IsBoolean())
                    {
                        changingValue.floatValue = EditorGUILayout.Toggle(changingValue.floatValue == 1f) ? 1f : 0f;
                    }

                    // Remove button
                    if (GUILayout.Button(styles.blankContent, styles.removeStyle, GUILayout.MaxWidth(styles.addRemoveButtonWidths)))
                    {
                        property.DeleteArrayElementAtIndex(i);
                        break;
                    }
                }
                GUILayout.EndVertical();
            }
        }