示例#1
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            SetVariable t = target as SetVariable;

            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> operatorsList = new List <GUIContent>();

            operatorsList.Add(new GUIContent("="));
            if (variableType == typeof(BooleanVariable))
            {
                operatorsList.Add(new GUIContent("=!"));
            }
            else if (variableType == typeof(IntegerVariable) ||
                     variableType == typeof(FloatVariable))
            {
                operatorsList.Add(new GUIContent("+="));
                operatorsList.Add(new GUIContent("-="));
                operatorsList.Add(new GUIContent("*="));
                operatorsList.Add(new GUIContent("/="));
            }

            int selectedIndex = 0;

            switch (t._SetOperator)
            {
            default:
            case SetOperator.Assign:
                selectedIndex = 0;
                break;

            case SetOperator.Negate:
                selectedIndex = 1;
                break;

            case SetOperator.Add:
                selectedIndex = 1;
                break;

            case SetOperator.Subtract:
                selectedIndex = 2;
                break;

            case SetOperator.Multiply:
                selectedIndex = 3;
                break;

            case SetOperator.Divide:
                selectedIndex = 4;
                break;
            }

            selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());

            SetOperator setOperator = SetOperator.Assign;

            if (variableType == typeof(BooleanVariable) ||
                variableType == typeof(StringVariable))
            {
                switch (selectedIndex)
                {
                default:
                case 0:
                    setOperator = SetOperator.Assign;
                    break;

                case 1:
                    setOperator = SetOperator.Negate;
                    break;
                }
            }
            else if (variableType == typeof(IntegerVariable) ||
                     variableType == typeof(FloatVariable))
            {
                switch (selectedIndex)
                {
                default:
                case 0:
                    setOperator = SetOperator.Assign;
                    break;

                case 1:
                    setOperator = SetOperator.Add;
                    break;

                case 2:
                    setOperator = SetOperator.Subtract;
                    break;

                case 3:
                    setOperator = SetOperator.Multiply;
                    break;

                case 4:
                    setOperator = SetOperator.Divide;
                    break;
                }
            }

            setOperatorProp.enumValueIndex = (int)setOperator;

            if (variableType == typeof(BooleanVariable))
            {
                EditorGUILayout.PropertyField(booleanDataProp, new GUIContent("Boolean"));
            }
            else if (variableType == typeof(IntegerVariable))
            {
                EditorGUILayout.PropertyField(integerDataProp, new GUIContent("Integer"));
            }
            else if (variableType == typeof(FloatVariable))
            {
                EditorGUILayout.PropertyField(floatDataProp, new GUIContent("Float"));
            }
            else if (variableType == typeof(StringVariable))
            {
                EditorGUILayout.PropertyField(stringDataProp, new GUIContent("String"));
            }

            serializedObject.ApplyModifiedProperties();
        }
示例#2
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            SetVariable t = target as SetVariable;

            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
            SetOperator[] setOperators = SetVariable.operatorsByVariableType[variableType];

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

            foreach (var setOperator in setOperators)
            {
                switch (setOperator)
                {
                case SetOperator.Assign:
                    operatorsList.Add(new GUIContent("="));
                    break;

                case SetOperator.Negate:
                    operatorsList.Add(new GUIContent("=!"));
                    break;

                case SetOperator.Add:
                    operatorsList.Add(new GUIContent("+="));
                    break;

                case SetOperator.Subtract:
                    operatorsList.Add(new GUIContent("-="));
                    break;

                case SetOperator.Multiply:
                    operatorsList.Add(new GUIContent("*="));
                    break;

                case SetOperator.Divide:
                    operatorsList.Add(new GUIContent("\\="));
                    break;

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

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

            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;
            }

            // Get next selected operator
            selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());


            setOperatorProp.enumValueIndex = (int)setOperators[selectedIndex];


            VariablePropertyInfo propertyInfo = propertyInfoByVariableType[variableType];

            EditorGUILayout.PropertyField(propertyInfo.dataProp, new GUIContent(propertyInfo.name));


            serializedObject.ApplyModifiedProperties();
        }
示例#3
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            SetVariable t = target as SetVariable;

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

            if (flowchart == null)
            {
                return;
            }

            // Select Variable
            EditorGUILayout.PropertyField(anyVarProp, true);

            //fetching every draw to ensure we don't have stale data based on types that have changed by user selection,
            //  without us noticing.

            // Get selected variable
            Variable          selectedVariable = anyVarProp.FindPropertyRelative("variable").objectReferenceValue as Variable;
            List <GUIContent> operatorsList    = new List <GUIContent>();

            if (selectedVariable != null)
            {
                if (selectedVariable.IsArithmeticSupported(SetOperator.Assign))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Assign)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Negate))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Negate)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Add))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Add)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Subtract))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Subtract)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Multiply))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Multiply)));
                }
                if (selectedVariable.IsArithmeticSupported(SetOperator.Divide))
                {
                    operatorsList.Add(new GUIContent(VariableUtil.GetSetOperatorDescription(SetOperator.Divide)));
                }
            }
            else
            {
                operatorsList.Add(VariableConditionEditor.None);
            }

            // Get previously selected operator
            int selectedIndex = (int)t._SetOperator;

            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;
            }

            // Get next selected operator
            selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());

            if (selectedVariable != null)
            {
                setOperatorProp.enumValueIndex = selectedIndex;
            }

            serializedObject.ApplyModifiedProperties();
        }