Esempio n. 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            VariablePropertyAttribute variableProperty = attribute as VariablePropertyAttribute;

            EditorGUI.BeginProperty(position, label, property);

            // Filter the variables by the types listed in the VariableProperty attribute
            Func <Variable, bool> compare = v =>
            {
                if (variableProperty.VariableTypes.Length == 0)
                {
                    return(true);
                }
                DebugLog.print(variableProperty.ToString());
                return(variableProperty.VariableTypes.Contains <System.Type>(v.GetType()));
            };

            VariableEditor.VariableField(property,
                                         label,
                                         FungusScriptWindow.GetFungusScript(),
                                         compare,
                                         (s, t, u) => (EditorGUI.Popup(position, s, t, u)));

            EditorGUI.EndProperty();
        }
Esempio n. 2
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            RandomInteger t = target as RandomInteger;

            FungusScript fungusScript = t.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            VariableEditor.VariableField(variableProp,
                                         new GUIContent("Variable", "Variable to use in operation"),
                                         t.GetFungusScript(),
                                         (v) => (v.GetType() == typeof(IntegerVariable)));

            EditorGUILayout.PropertyField(minValueProp);
            EditorGUILayout.PropertyField(maxValueProp);

            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            VariablePropertyAttribute variableProperty = attribute as VariablePropertyAttribute;

            if (variableProperty == null)
            {
                return;
            }

            EditorGUI.BeginProperty(position, label, property);

            // Filter the variables by the types listed in the VariableProperty attribute
            Func <Variable, bool> compare = v =>
            {
                if (v == null)
                {
                    return(false);
                }

                if (variableProperty.VariableTypes.Length == 0)
                {
                    return(true);
                }

                return(variableProperty.VariableTypes.Contains <System.Type>(v.GetType()));
            };

            VariableEditor.VariableField(property,
                                         label,
                                         FlowchartWindow.GetFlowchart(),
                                         variableProperty.defaultText,
                                         compare,
                                         (s, t, u) => (EditorGUI.Popup(position, s, t, u)));

            EditorGUI.EndProperty();
        }
Esempio n. 4
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            SetVariable t = target as SetVariable;

            FungusScript fungusScript = t.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            VariableEditor.VariableField(variableProp,
                                         new GUIContent("Variable", "Variable to set"),
                                         fungusScript);


            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 SetVariable.SetOperator.Assign:
                selectedIndex = 0;
                break;

            case SetVariable.SetOperator.Negate:
                selectedIndex = 1;
                break;

            case SetVariable.SetOperator.Add:
                selectedIndex = 1;
                break;

            case SetVariable.SetOperator.Subtract:
                selectedIndex = 2;
                break;

            case SetVariable.SetOperator.Multiply:
                selectedIndex = 3;
                break;

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

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

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

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

                case 1:
                    setOperator = SetVariable.SetOperator.Add;
                    break;

                case 2:
                    setOperator = SetVariable.SetOperator.Subtract;
                    break;

                case 3:
                    setOperator = SetVariable.SetOperator.Multiply;
                    break;

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

            setOperatorProp.enumValueIndex = (int)setOperator;

            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();
        }
Esempio n. 5
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            If t = target as If;

            FungusScript fungusScript = t.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            VariableEditor.VariableField(variableProp,
                                         new GUIContent("Variable", "Variable to use in operation"),
                                         t.GetFungusScript(),
                                         null);

            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(booleanValueProp);
            }
            else if (variableType == typeof(IntegerVariable))
            {
                EditorGUILayout.PropertyField(integerValueProp);
            }
            else if (variableType == typeof(FloatVariable))
            {
                EditorGUILayout.PropertyField(floatValueProp);
            }
            else if (variableType == typeof(StringVariable))
            {
                EditorGUILayout.PropertyField(stringValueProp);
            }

            serializedObject.ApplyModifiedProperties();
        }