Exemplo n.º 1
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("anyOrAllConditions"));

            conditions.arraySize = EditorGUILayout.IntField("Size", conditions.arraySize);
            GUILayout.Label("Conditions", EditorStyles.boldLabel);

            VariableCondition t = target as VariableCondition;

            var flowchart = (Flowchart)t.GetFlowchart();

            if (flowchart == null)
            {
                return;
            }

            EditorGUI.indentLevel++;
            for (int i = 0; i < conditions.arraySize; i++)
            {
                var conditionAnyVar  = conditions.GetArrayElementAtIndex(i).FindPropertyRelative("anyVar");
                var conditionCompare = conditions.GetArrayElementAtIndex(i).FindPropertyRelative("compareOperator");

                EditorGUILayout.PropertyField(conditionAnyVar, new GUIContent("Variable"), true);

                // Get selected variable
                Variable selectedVariable = conditionAnyVar.FindPropertyRelative("variable").objectReferenceValue as Variable;

                if (selectedVariable == null)
                {
                    continue;
                }

                GUIContent[] operatorsList = emptyList;
                operatorsList = selectedVariable.IsComparisonSupported() ? compareListAll : compareListEqualOnly;

                // Get previously selected operator
                int selectedIndex = conditionCompare.enumValueIndex;
                if (selectedIndex < 0 || selectedIndex >= operatorsList.Length)
                {
                    // Default to first index if the operator is not found in the available operators list
                    // This can occur when changing between variable types
                    selectedIndex = 0;
                }

                selectedIndex = EditorGUILayout.Popup(
                    new GUIContent("Compare", "The comparison operator to use when comparing values"),
                    selectedIndex,
                    operatorsList);

                conditionCompare.enumValueIndex = selectedIndex;

                EditorGUILayout.Separator();
            }
            EditorGUI.indentLevel--;
            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 2
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            VariableCondition t = target as VariableCondition;

            var flowchart = (Flowchart)t.GetFlowchart();

            if (flowchart == null)
            {
                return;
            }

            EditorGUILayout.PropertyField(variableProp);

            if (variableProp.objectReferenceValue == null)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            Variable selectedVariable = variableProp.objectReferenceValue as Variable;

            System.Type variableType = selectedVariable.GetType();

            List <GUIContent> operatorList = new List <GUIContent>();

            operatorList.Add(new GUIContent("=="));
            operatorList.Add(new GUIContent("!="));
            if (variableType == typeof(IntegerVariable) ||
                variableType == typeof(FloatVariable))
            {
                operatorList.Add(new GUIContent("<"));
                operatorList.Add(new GUIContent(">"));
                operatorList.Add(new GUIContent("<="));
                operatorList.Add(new GUIContent(">="));
            }

            compareOperatorProp.enumValueIndex = EditorGUILayout.Popup(new GUIContent("Compare", "The comparison operator to use when comparing values"),
                                                                       compareOperatorProp.enumValueIndex,
                                                                       operatorList.ToArray());

            if (variableType == typeof(BooleanVariable))
            {
                EditorGUILayout.PropertyField(booleanDataProp);
            }
            else if (variableType == typeof(IntegerVariable))
            {
                EditorGUILayout.PropertyField(integerDataProp);
            }
            else if (variableType == typeof(FloatVariable))
            {
                EditorGUILayout.PropertyField(floatDataProp);
            }
            else if (variableType == typeof(StringVariable))
            {
                EditorGUILayout.PropertyField(stringDataProp);
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 3
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            VariableCondition t = target as VariableCondition;

            var flowchart = (Flowchart)t.GetFlowchart();

            if (flowchart == null)
            {
                return;
            }

            // Select Variable
            EditorGUILayout.PropertyField(variableProp);

            if (variableProp.objectReferenceValue == null)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            // Get selected variable
            Variable selectedVariable = variableProp.objectReferenceValue as Variable;

            System.Type variableType = selectedVariable.GetType();

            // Get operators for the variable
            CompareOperator[] compareOperators = VariableCondition.operatorsByVariableType[variableType];

            // Create operator list
            List <GUIContent> operatorsList = new List <GUIContent>();

            foreach (var compareOperator in compareOperators)
            {
                switch (compareOperator)
                {
                case CompareOperator.Equals:
                    operatorsList.Add(new GUIContent("=="));
                    break;

                case CompareOperator.NotEquals:
                    operatorsList.Add(new GUIContent("!="));
                    break;

                case CompareOperator.LessThan:
                    operatorsList.Add(new GUIContent("<"));
                    break;

                case CompareOperator.GreaterThan:
                    operatorsList.Add(new GUIContent(">"));
                    break;

                case CompareOperator.LessThanOrEquals:
                    operatorsList.Add(new GUIContent("<="));
                    break;

                case CompareOperator.GreaterThanOrEquals:
                    operatorsList.Add(new GUIContent(">="));
                    break;

                default:
                    Debug.LogError("The " + compareOperator.ToString() + " operator has no matching GUIContent.");
                    break;
                }
            }

            // Get previously selected operator
            int selectedIndex = System.Array.IndexOf(compareOperators, t._CompareOperator);

            if (selectedIndex < 0)
            {
                // Default to first index if the operator is not found in the available operators list
                // This can occur when changing between variable types
                selectedIndex = 0;
            }

            selectedIndex = EditorGUILayout.Popup(
                new GUIContent("Compare", "The comparison operator to use when comparing values"),
                selectedIndex,
                operatorsList.ToArray());

            compareOperatorProp.enumValueIndex = (int)compareOperators[selectedIndex];

            EditorGUILayout.PropertyField(propByVariableType[variableType]);

            serializedObject.ApplyModifiedProperties();
        }