Esempio n. 1
0
 /**
  * Gets the value of a float variable.
  * Returns 0 if the variable key does not exist.
  */
 public virtual float GetFloatVariable(string key)
 {
     foreach (Variable v in variables)
     {
         if (v.key == key)
         {
             FloatVariable variable = v as FloatVariable;
             if (variable != null)
             {
                 return(variable.value);
             }
         }
     }
     Debug.LogWarning("Float variable " + key + " not found.");
     return(0f);
 }
Esempio n. 2
0
 /**
  * Sets the value of a float variable.
  * The variable must already be added to the list of variables for this Flowchart.
  */
 public virtual void SetFloatVariable(string key, float value)
 {
     foreach (Variable v in variables)
     {
         if (v != null && v.key == key)
         {
             FloatVariable variable = v as FloatVariable;
             if (variable != null)
             {
                 variable.value = value;
                 return;
             }
         }
     }
     Debug.LogWarning("Float variable " + key + " not found.");
 }
Esempio n. 3
0
        public override void OnEnter()
        {
            if (sourceString != null && outValue != null)
            {
                double asDouble = System.Convert.ToDouble(sourceString.Value, System.Globalization.CultureInfo.CurrentCulture);

                IntegerVariable intOutVar = outValue as IntegerVariable;
                if (intOutVar != null)
                {
                    intOutVar.Value = (int)asDouble;
                }
                else
                {
                    FloatVariable floatOutVar = outValue as FloatVariable;
                    if (floatOutVar != null)
                    {
                        floatOutVar.Value = (float)asDouble;
                    }
                }
            }

            Continue();
        }
Esempio n. 4
0
        protected override bool EvaluateCondition()
        {
            if (variable == null)
            {
                return(false);
            }

            bool condition = false;

            if (variable.GetType() == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = (variable as BooleanVariable);
                condition = booleanVariable.Evaluate(compareOperator, booleanData.Value);
            }
            else if (variable.GetType() == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = (variable as IntegerVariable);
                condition = integerVariable.Evaluate(compareOperator, integerData.Value);
            }
            else if (variable.GetType() == typeof(FloatVariable))
            {
                FloatVariable floatVariable = (variable as FloatVariable);
                condition = floatVariable.Evaluate(compareOperator, floatData.Value);
            }
            else if (variable.GetType() == typeof(StringVariable))
            {
                StringVariable stringVariable = (variable as StringVariable);
                condition = stringVariable.Evaluate(compareOperator, stringData.Value);
            }
            else if (variable.GetType() == typeof(GameObjectVariable))
            {
                GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
                condition = gameObjectVariable.Evaluate(compareOperator, gameObjectData.Value);
            }

            return(condition);
        }
Esempio n. 5
0
        public override void OnEnter()
        {
            if (variable == null)
            {
                Continue();
                return;
            }

            if (variable.GetType() == typeof(BooleanVariable))
            {
                BooleanVariable lhs = (variable as BooleanVariable);
                bool            rhs = booleanData.Value;

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;

                case SetOperator.Negate:
                    lhs.Value = !rhs;
                    break;
                }
            }
            else if (variable.GetType() == typeof(IntegerVariable))
            {
                IntegerVariable lhs = (variable as IntegerVariable);
                int             rhs = integerData.Value;

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;

                case SetOperator.Add:
                    lhs.Value += rhs;
                    break;

                case SetOperator.Subtract:
                    lhs.Value -= rhs;
                    break;

                case SetOperator.Multiply:
                    lhs.Value *= rhs;
                    break;

                case SetOperator.Divide:
                    lhs.Value /= rhs;
                    break;
                }
            }
            else if (variable.GetType() == typeof(FloatVariable))
            {
                FloatVariable lhs = (variable as FloatVariable);
                float         rhs = floatData.Value;

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;

                case SetOperator.Add:
                    lhs.Value += rhs;
                    break;

                case SetOperator.Subtract:
                    lhs.Value -= rhs;
                    break;

                case SetOperator.Multiply:
                    lhs.Value *= rhs;
                    break;

                case SetOperator.Divide:
                    lhs.Value /= rhs;
                    break;
                }
            }
            else if (variable.GetType() == typeof(StringVariable))
            {
                StringVariable lhs = (variable as StringVariable);
                string         rhs = stringData.Value;

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;
                }
            }

            Continue();
        }
Esempio n. 6
0
 public FloatData(float v)
 {
     floatVal = v;
     floatRef = null;
 }
Esempio n. 7
0
        public override void OnEnter()
        {
            // 如果没有key
            // 没有变量
            // 返回
            if (key == "" ||
                variable == null)
            {
                Continue();
                return;
            }

            var flowchart = GetFlowchart();

            // Prepend the current save profile (if any)

            // 从SetSaveProfile命令中,获取设置的前缀
            // key: 中也支持变量展开
            string prefsKey = SetSaveProfile.SaveProfile + "_" + flowchart.SubstituteVariables(key);

            System.Type variableType = variable.GetType();

            //
            // 使用PlayerPrefs保存变量的值
            //

            // bool类型
            if (variableType == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = variable as BooleanVariable;
                if (booleanVariable != null)
                {
                    // PlayerPrefs does not have bool accessors, so just use int
                    PlayerPrefs.SetInt(prefsKey, booleanVariable.Value ? 1 : 0);
                }
            }

            // int类型
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    PlayerPrefs.SetInt(prefsKey, integerVariable.Value);
                }
            }

            // float类型
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    PlayerPrefs.SetFloat(prefsKey, floatVariable.Value);
                }
            }
            // string类型
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    PlayerPrefs.SetString(prefsKey, stringVariable.Value);
                }
            }

            Continue();
        }
Esempio n. 8
0
        protected virtual void DoSetOperation()
        {
            if (variable == null)
            {
                return;
            }

            if (variable.GetType() == typeof(BooleanVariable))
            {
                BooleanVariable lhs = (variable as BooleanVariable);
                bool            rhs = booleanData.Value;

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;

                case SetOperator.Negate:
                    lhs.Value = !rhs;
                    break;
                }
            }
            else if (variable.GetType() == typeof(IntegerVariable))
            {
                IntegerVariable lhs = (variable as IntegerVariable);
                int             rhs = integerData.Value;

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;

                case SetOperator.Add:
                    lhs.Value += rhs;
                    break;

                case SetOperator.Subtract:
                    lhs.Value -= rhs;
                    break;

                case SetOperator.Multiply:
                    lhs.Value *= rhs;
                    break;

                case SetOperator.Divide:
                    lhs.Value /= rhs;
                    break;
                }
            }
            else if (variable.GetType() == typeof(FloatVariable))
            {
                FloatVariable lhs = (variable as FloatVariable);
                float         rhs = floatData.Value;

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;

                case SetOperator.Add:
                    lhs.Value += rhs;
                    break;

                case SetOperator.Subtract:
                    lhs.Value -= rhs;
                    break;

                case SetOperator.Multiply:
                    lhs.Value *= rhs;
                    break;

                case SetOperator.Divide:
                    lhs.Value /= rhs;
                    break;
                }
            }
            else if (variable.GetType() == typeof(StringVariable))
            {
                StringVariable lhs = (variable as StringVariable);
                string         rhs = stringData.Value;

                var flowchart = GetFlowchart();
                rhs = flowchart.SubstituteVariables(rhs);

                switch (setOperator)
                {
                default:
                case SetOperator.Assign:
                    lhs.Value = rhs;
                    break;
                }
            }
        }
Esempio n. 9
0
        public void DrawItem(Rect position, int index)
        {
            Variable variable = this[index].objectReferenceValue as Variable;

            if (variable == null)
            {
                return;
            }

            float width1 = 100;
            float width3 = 50;
            float width2 = Mathf.Max(position.width - width1 - width3, 60);

            Rect keyRect = position;

            keyRect.width = width1;

            Rect valueRect = position;

            valueRect.x    += width1 + 5;
            valueRect.width = width2 - 5;

            Rect scopeRect = position;

            scopeRect.x    += width1 + width2 + 5;
            scopeRect.width = width3 - 5;

            string type = "";

            if (variable.GetType() == typeof(BooleanVariable))
            {
                type = "Boolean";
            }
            else if (variable.GetType() == typeof(IntegerVariable))
            {
                type = "Integer";
            }
            else if (variable.GetType() == typeof(FloatVariable))
            {
                type = "Float";
            }
            else if (variable.GetType() == typeof(StringVariable))
            {
                type = "String";
            }

            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            bool highlight = false;

            // Is an executing command referencing this variable?
            if (Application.isPlaying)
            {
                if (fungusScript.executingSequence != null &&
                    fungusScript.executingSequence.activeCommand != null)
                {
                    if (fungusScript.executingSequence.activeCommand.HasReference(variable))
                    {
                        highlight = true;
                    }
                }
            }
            else
            {
                // Is an expanded command referencing this variable?
                if (fungusScript.selectedSequence != null &&
                    fungusScript.selectedCommand != null)
                {
                    foreach (Command command in fungusScript.selectedSequence.commandList)
                    {
                        if (fungusScript.selectedCommand == command &&
                            command.HasReference(variable))
                        {
                            highlight = true;
                        }
                    }
                }
            }

            if (highlight)
            {
                GUI.backgroundColor = Color.green;
                GUI.Box(position, "");
            }

            string        key   = variable.key;
            VariableScope scope = variable.scope;

            if (Application.isPlaying)
            {
                GUI.Label(keyRect, variable.key);

                if (variable.GetType() == typeof(BooleanVariable))
                {
                    BooleanVariable v = variable as BooleanVariable;
                    v.Value = EditorGUI.Toggle(valueRect, v.Value);
                }
                else if (variable.GetType() == typeof(IntegerVariable))
                {
                    IntegerVariable v = variable as IntegerVariable;
                    v.Value = EditorGUI.IntField(valueRect, v.Value);
                }
                else if (variable.GetType() == typeof(FloatVariable))
                {
                    FloatVariable v = variable as FloatVariable;
                    v.Value = EditorGUI.FloatField(valueRect, v.Value);
                }
                else if (variable.GetType() == typeof(StringVariable))
                {
                    StringVariable v = variable as StringVariable;
                    v.Value = EditorGUI.TextField(valueRect, v.Value);
                }

                if (scope == VariableScope.Local)
                {
                    GUI.Label(scopeRect, "Local");
                }
                else if (scope == VariableScope.Global)
                {
                    GUI.Label(scopeRect, "Global");
                }
            }
            else
            {
                key = EditorGUI.TextField(keyRect, variable.key);
                GUI.Label(valueRect, type);
                scope = (VariableScope)EditorGUI.EnumPopup(scopeRect, variable.scope);

                // To access properties in a monobehavior, you have new a SerializedObject
                // http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html
                SerializedObject   variableObject = new SerializedObject(this[index].objectReferenceValue);
                SerializedProperty keyProp        = variableObject.FindProperty("key");
                SerializedProperty scopeProp      = variableObject.FindProperty("scope");

                variableObject.Update();
                keyProp.stringValue      = fungusScript.GetUniqueVariableKey(key, variable);
                scopeProp.enumValueIndex = (int)scope;
                variableObject.ApplyModifiedProperties();
            }

            GUI.backgroundColor = Color.white;
        }
Esempio n. 10
0
        public override void OnEnter()
        {
            if (key == "" ||
                variable == null)
            {
                Continue();
                return;
            }

            var flowchart = GetFlowchart();

            string prefsKey = SetSaveProfile.SaveProfile + "_" + flowchart.SubstituteVariables(key);

            System.Type variableType = variable.GetType();

            if (variableType == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = variable as BooleanVariable;
                if (booleanVariable != null)
                {
                    //PlayerPrefs.SetInt(prefsKey, booleanVariable.Value ? 1 : 0);
                    SaveSystem.SetBool(prefsKey, booleanVariable.Value);
                }
            }
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    //PlayerPrefs.SetInt(prefsKey, integerVariable.Value);
                    SaveSystem.SetInt(prefsKey, integerVariable.Value);
                }
            }
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    //PlayerPrefs.SetFloat(prefsKey, floatVariable.Value);
                    SaveSystem.SetFloat(prefsKey, floatVariable.Value);
                }
            }
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    //PlayerPrefs.SetString(prefsKey, stringVariable.Value);
                    SaveSystem.SetString(prefsKey, stringVariable.Value);
                }
            }
            else if (variableType == typeof(Vector2Variable))
            {
                Vector2Variable vector2Variable = variable as Vector2Variable;
                if (vector2Variable != null)
                {
                    SaveSystem.SetVector2(prefsKey, vector2Variable.Value);
                }
            }

            Continue();
        }
Esempio n. 11
0
        protected override bool EvaluateCondition()
        {
            if (variable == null)
            {
                return(false);
            }

            bool condition = false;

            if (variable.GetType() == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = (variable as BooleanVariable);
                condition = booleanVariable.Evaluate(compareOperator, booleanData.Value);
            }
            else if (variable.GetType() == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = (variable as IntegerVariable);
                condition = integerVariable.Evaluate(compareOperator, integerData.Value);
            }
            else if (variable.GetType() == typeof(FloatVariable))
            {
                FloatVariable floatVariable = (variable as FloatVariable);
                condition = floatVariable.Evaluate(compareOperator, floatData.Value);
            }
            else if (variable.GetType() == typeof(StringVariable))
            {
                StringVariable stringVariable = (variable as StringVariable);
                condition = stringVariable.Evaluate(compareOperator, stringData.Value);
            }
            else if (variable.GetType() == typeof(AnimatorVariable))
            {
                AnimatorVariable animatorVariable = (variable as AnimatorVariable);
                condition = animatorVariable.Evaluate(compareOperator, animatorData.Value);
            }
            else if (variable.GetType() == typeof(AudioSourceVariable))
            {
                AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable);
                condition = audioSourceVariable.Evaluate(compareOperator, audioSourceData.Value);
            }
            else if (variable.GetType() == typeof(ColorVariable))
            {
                ColorVariable colorVariable = (variable as ColorVariable);
                condition = colorVariable.Evaluate(compareOperator, colorData.Value);
            }
            else if (variable.GetType() == typeof(GameObjectVariable))
            {
                GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
                condition = gameObjectVariable.Evaluate(compareOperator, gameObjectData.Value);
            }
            else if (variable.GetType() == typeof(MaterialVariable))
            {
                MaterialVariable materialVariable = (variable as MaterialVariable);
                condition = materialVariable.Evaluate(compareOperator, materialData.Value);
            }
            else if (variable.GetType() == typeof(ObjectVariable))
            {
                ObjectVariable objectVariable = (variable as ObjectVariable);
                condition = objectVariable.Evaluate(compareOperator, objectData.Value);
            }
            else if (variable.GetType() == typeof(Rigidbody2DVariable))
            {
                Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable);
                condition = rigidbody2DVariable.Evaluate(compareOperator, rigidbody2DData.Value);
            }
            else if (variable.GetType() == typeof(SpriteVariable))
            {
                SpriteVariable spriteVariable = (variable as SpriteVariable);
                condition = spriteVariable.Evaluate(compareOperator, spriteData.Value);
            }
            else if (variable.GetType() == typeof(TextureVariable))
            {
                TextureVariable textureVariable = (variable as TextureVariable);
                condition = textureVariable.Evaluate(compareOperator, textureData.Value);
            }
            else if (variable.GetType() == typeof(TransformVariable))
            {
                TransformVariable transformVariable = (variable as TransformVariable);
                condition = transformVariable.Evaluate(compareOperator, transformData.Value);
            }
            else if (variable.GetType() == typeof(Vector2Variable))
            {
                Vector2Variable vector2Variable = (variable as Vector2Variable);
                condition = vector2Variable.Evaluate(compareOperator, vector2Data.Value);
            }
            else if (variable.GetType() == typeof(Vector3Variable))
            {
                Vector3Variable vector3Variable = (variable as Vector3Variable);
                condition = vector3Variable.Evaluate(compareOperator, vector3Data.Value);
            }

            return(condition);
        }
Esempio n. 12
0
        // 执行操作运算
        protected virtual void DoSetOperation()
        {
            if (variable == null)
            {
                return;
            }

            // 调用各类型的
            // Apply()函数

            var t = variable.GetType();

            if (t == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = (variable as BooleanVariable);
                booleanVariable.Apply(setOperator, booleanData.Value);
            }
            else if (t == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = (variable as IntegerVariable);
                integerVariable.Apply(setOperator, integerData.Value);
            }
            else if (t == typeof(FloatVariable))
            {
                FloatVariable floatVariable = (variable as FloatVariable);
                floatVariable.Apply(setOperator, floatData.Value);
            }
            else if (t == typeof(StringVariable))
            {
                StringVariable stringVariable = (variable as StringVariable);
                var            flowchart      = GetFlowchart();
                stringVariable.Apply(setOperator, flowchart.SubstituteVariables(stringData.Value));
            }
            else if (t == typeof(AnimatorVariable))
            {
                AnimatorVariable animatorVariable = (variable as AnimatorVariable);
                animatorVariable.Apply(setOperator, animatorData.Value);
            }
            else if (t == typeof(AudioSourceVariable))
            {
                AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable);
                audioSourceVariable.Apply(setOperator, audioSourceData.Value);
            }
            else if (t == typeof(ColorVariable))
            {
                ColorVariable colorVariable = (variable as ColorVariable);
                colorVariable.Apply(setOperator, colorData.Value);
            }
            else if (t == typeof(GameObjectVariable))
            {
                GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
                gameObjectVariable.Apply(setOperator, gameObjectData.Value);
            }
            else if (t == typeof(MaterialVariable))
            {
                MaterialVariable materialVariable = (variable as MaterialVariable);
                materialVariable.Apply(setOperator, materialData.Value);
            }
            else if (t == typeof(ObjectVariable))
            {
                ObjectVariable objectVariable = (variable as ObjectVariable);
                objectVariable.Apply(setOperator, objectData.Value);
            }
            else if (t == typeof(Rigidbody2DVariable))
            {
                Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable);
                rigidbody2DVariable.Apply(setOperator, rigidbody2DData.Value);
            }
            else if (t == typeof(SpriteVariable))
            {
                SpriteVariable spriteVariable = (variable as SpriteVariable);
                spriteVariable.Apply(setOperator, spriteData.Value);
            }
            else if (t == typeof(TextureVariable))
            {
                TextureVariable textureVariable = (variable as TextureVariable);
                textureVariable.Apply(setOperator, textureData.Value);
            }
            else if (t == typeof(TransformVariable))
            {
                TransformVariable transformVariable = (variable as TransformVariable);
                transformVariable.Apply(setOperator, transformData.Value);
            }
            else if (t == typeof(Vector2Variable))
            {
                Vector2Variable vector2Variable = (variable as Vector2Variable);
                vector2Variable.Apply(setOperator, vector2Data.Value);
            }
            else if (t == typeof(Vector3Variable))
            {
                Vector3Variable vector3Variable = (variable as Vector3Variable);
                vector3Variable.Apply(setOperator, vector3Data.Value);
            }
        }
Esempio n. 13
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty referenceProp = property.FindPropertyRelative("floatReference");
            SerializedProperty valueProp     = property.FindPropertyRelative("floatValue");

            const int popupWidth = 65;

            Rect controlRect = EditorGUI.PrefixLabel(position, label);
            Rect valueRect   = controlRect;

            valueRect.width = controlRect.width - popupWidth - 5;
            Rect popupRect = controlRect;

            if (referenceProp.objectReferenceValue == null)
            {
                valueProp.floatValue = EditorGUI.FloatField(valueRect, valueProp.floatValue);
                popupRect.x         += valueRect.width + 5;
                popupRect.width      = popupWidth;
            }

            FungusScript fungusScript = property.serializedObject.targetObject as FungusScript;

            if (fungusScript == null)
            {
                Command command = property.serializedObject.targetObject as Command;
                if (command != null)
                {
                    fungusScript = command.GetFungusScript();
                }
            }

            if (fungusScript != null)
            {
                FloatVariable selectedVariable = referenceProp.objectReferenceValue as FloatVariable;

                List <string>   variableKeys    = new List <string>();
                List <Variable> variableObjects = new List <Variable>();

                variableKeys.Add("<Value>");
                variableObjects.Add(null);

                int index         = 0;
                int selectedIndex = 0;
                foreach (Variable v in fungusScript.variables)
                {
                    if (v.GetType() != typeof(FloatVariable))
                    {
                        continue;
                    }

                    variableKeys.Add(v.key);
                    variableObjects.Add(v);

                    index++;

                    if (v == selectedVariable)
                    {
                        selectedIndex = index;
                    }
                }

                selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray());
                referenceProp.objectReferenceValue = variableObjects[selectedIndex];
            }

            EditorGUI.EndProperty();
        }