Esempio n. 1
0
        private void FillOutValue(int v)
        {
            FloatVariable fvar = outValue as FloatVariable;

            if (fvar != null)
            {
                fvar.Value = v;
                return;
            }

            BooleanVariable bvar = outValue as BooleanVariable;

            if (bvar != null)
            {
                bvar.Value = v == 0 ? false : true;
                return;
            }

            IntegerVariable ivar = outValue as IntegerVariable;

            if (ivar != null)
            {
                ivar.Value = v;
                return;
            }
        }
Esempio n. 2
0
        protected virtual bool EvaluateCondition()
        {
            BooleanVariable booleanVariable = variable as BooleanVariable;
            IntegerVariable integerVariable = variable as IntegerVariable;
            FloatVariable   floatVariable   = variable as FloatVariable;
            StringVariable  stringVariable  = variable as StringVariable;

            bool condition = false;

            if (booleanVariable != null)
            {
                condition = booleanVariable.Evaluate(compareOperator, booleanData.Value);
            }
            else if (integerVariable != null)
            {
                condition = integerVariable.Evaluate(compareOperator, integerData.Value);
            }
            else if (floatVariable != null)
            {
                condition = floatVariable.Evaluate(compareOperator, floatData.Value);
            }
            else if (stringVariable != null)
            {
                condition = stringVariable.Evaluate(compareOperator, stringData.Value);
            }

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

            if (variable.GetType() == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = (variable as BooleanVariable);
                booleanVariable.Apply(setOperator, booleanData.Value);
            }
            else if (variable.GetType() == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = (variable as IntegerVariable);
                integerVariable.Apply(setOperator, integerData.Value);
            }
            else if (variable.GetType() == typeof(FloatVariable))
            {
                FloatVariable floatVariable = (variable as FloatVariable);
                floatVariable.Apply(setOperator, floatData.Value);
            }
            else if (variable.GetType() == typeof(StringVariable))
            {
                StringVariable stringVariable = (variable as StringVariable);
                var            flowchart      = GetFlowchart();
                stringVariable.Apply(setOperator, flowchart.SubstituteVariables(stringData.Value));
            }
            else if (variable.GetType() == typeof(GameObjectVariable))
            {
                GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
                gameObjectVariable.Apply(setOperator, gameObjectData.Value);
            }
        }
Esempio n. 4
0
        public override void OnEnter()
        {
            if (sourceString != null && outValue != null)
            {
                double asDouble = 0;
                try
                {
                    asDouble = System.Convert.ToDouble(sourceString.Value, System.Globalization.CultureInfo.CurrentCulture);
                }
                catch (System.Exception)
                {
                    Debug.LogWarning("Failed to parse as number: " + sourceString.Value);
                }

                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. 5
0
        public override void OnEnter()
        {
            if (key == "" ||
                variable == null)
            {
                Continue();
                return;
            }

            var flowchart = GetFlowchart();

            // Prepend the current save profile (if any)
            string prefsKey = SetSaveProfile.SaveProfile + "_" + flowchart.SubstituteVariables(key);

            System.Type variableType = variable.GetType();

            if (variableType == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = variable as BooleanVariable;
                if (booleanVariable != null)
                {
                    booleanVariable.Value = SaveSystem.GetBool(prefsKey);
                }
            }
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    integerVariable.Value = SaveSystem.GetInt(prefsKey);
                }
            }
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    //floatVariable.Value = PlayerPrefs.GetFloat(prefsKey);
                    floatVariable.Value = SaveSystem.GetFloat(prefsKey);
                }
            }
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    stringVariable.Value = SaveSystem.GetString(prefsKey);
                }
            }
            else if (variableType == typeof(Vector2Variable))
            {
                Vector2Variable vector2Variable = variable as Vector2Variable;
                if (vector2Variable != null)
                {
                    vector2Variable.Value = SaveSystem.GetVector2(prefsKey);
                }
            }

            Continue();
        }
Esempio n. 6
0
        /**
         * Sets the value of an integer variable.
         * The variable must already be added to the list of variables for this Flowchart.
         */
        public virtual void SetIntegerVariable(string key, int value)
        {
            IntegerVariable variable = GetVariable <IntegerVariable>(key);

            if (variable != null)
            {
                variable.value = value;
            }
        }
Esempio n. 7
0
        public override void OnEnter()
        {
            if (key == "" ||
                variable == null)
            {
                Continue();
                return;
            }

            var flowchart = GetFlowchart();

            // Prepend the current save profile (if any)
            string prefsKey = SetSaveProfile.SaveProfile + "_" + flowchart.SubstituteVariables(key);

            System.Type variableType = variable.GetType();

            // 使用PlayerPrefs
            // 读取SaveVariable保存的变量值

            if (variableType == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = variable as BooleanVariable;
                if (booleanVariable != null)
                {
                    // PlayerPrefs does not have bool accessors, so just use int
                    booleanVariable.Value = (PlayerPrefs.GetInt(prefsKey) == 1);
                }
            }
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    integerVariable.Value = PlayerPrefs.GetInt(prefsKey);
                }
            }
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    floatVariable.Value = PlayerPrefs.GetFloat(prefsKey);
                }
            }
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    stringVariable.Value = PlayerPrefs.GetString(prefsKey);
                }
            }

            Continue();
        }
Esempio n. 8
0
        public override void OnEnter()
        {
            var flowchart = GetFlowchart();

            // Prepend the current save profile (if any) and make sure all inputs are valid
            string prefsKey      = SetSaveProfile.SaveProfile + "_" + flowchart.SubstituteVariables(key);
            bool   validKey      = key != "" && PlayerPrefs.HasKey(prefsKey);
            bool   validVariable = variable != null;

            if (!validKey || !validVariable)
            {
                Continue();
                return;
            }

            System.Type variableType = variable.GetType();

            if (variableType == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = variable as BooleanVariable;
                if (booleanVariable != null)
                {
                    // PlayerPrefs does not have bool accessors, so just use int
                    booleanVariable.Value = (PlayerPrefs.GetInt(prefsKey) == 1);
                }
            }
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    integerVariable.Value = PlayerPrefs.GetInt(prefsKey);
                }
            }
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    floatVariable.Value = PlayerPrefs.GetFloat(prefsKey);
                }
            }
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    stringVariable.Value = PlayerPrefs.GetString(prefsKey);
                }
            }

            Continue();
        }
Esempio n. 9
0
        public override void OnEnter()
        {
            if (key == "" ||
                variable == null)
            {
                Continue();
                return;
            }

            FungusScript fungusScript = GetFungusScript();

            // Prepend the current save profile (if any)
            string prefsKey = SetSaveProfile.saveProfile + "_" + fungusScript.SubstituteVariables(key);

            System.Type variableType = variable.GetType();

            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);
                }
            }
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    PlayerPrefs.SetInt(prefsKey, integerVariable.value);
                }
            }
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    PlayerPrefs.SetFloat(prefsKey, floatVariable.value);
                }
            }
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    PlayerPrefs.SetString(prefsKey, stringVariable.value);
                }
            }

            Continue();
        }
Esempio n. 10
0
        /**
         * Gets the value of an integer variable.
         * Returns 0 if the variable key does not exist.
         */
        public virtual int GetIntegerVariable(string key)
        {
            IntegerVariable variable = GetVariable <IntegerVariable>(key);

            if (variable != null)
            {
                return(GetVariable <IntegerVariable>(key).value);
            }
            else
            {
                return(0);
            }
        }
        void SaveVariable(string saveProfileKey, Flowchart flowchart, Variable variable)
        {
            //  // Prepend the current save profile (if any)
            //string prefsKey = saveProfileKey + "_" + flowchart.SubstituteVariables(variable.Key);
            string prefsKey = GetVariableKeyName(saveProfileKey, flowchart, variable);

            //Debug.Log("Save " + prefsKey);
            System.Type variableType = variable.GetType();

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

                    //Debug.Log("Saving: " + variable.Key + "\t" + flowchart.name + "\t" + prefsKey + "\t" + booleanVariable.Value);
                }
            }
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    PlayerPrefs.SetInt(prefsKey, integerVariable.Value);

                    //Debug.Log("Saving: " + variable.Key + "\t" + flowchart.name + "\t" + prefsKey + "\t" + integerVariable.Value);
                }
            }
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    PlayerPrefs.SetFloat(prefsKey, floatVariable.Value);

                    //Debug.Log("Saving: " + variable.Key + "\t" + flowchart.name + "\t" + prefsKey + "\t" + floatVariable.Value);
                }
            }
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    PlayerPrefs.SetString(prefsKey, stringVariable.Value);

                    //Debug.Log("Saving: " + variable.Key + "\t" + flowchart.name + "\t" + prefsKey + "\t" + stringVariable.Value);
                }
            }
        }
        void LoadVariable(string saveProfileKey, Flowchart flowchart, Variable variable)
        {
            // // Prepend the current save profile (if any)
            //string prefsKey = saveProfileKey + "_" + flowchart.SubstituteVariables(variable.Key);
            string prefsKey = GetVariableKeyName(saveProfileKey, flowchart, variable);

            System.Type variableType = variable.GetType();

            if (variableType == typeof(BooleanVariable))
            {
                BooleanVariable booleanVariable = variable as BooleanVariable;
                if (booleanVariable != null)
                {
                    // PlayerPrefs does not have bool accessors, so just use int
                    booleanVariable.Value = (PlayerPrefs.GetInt(prefsKey) == 1);

                    //Debug.Log("Loading '" + variable.Key + "' in '" + flowchart.name + "' with value '" + booleanVariable.Value + "'\t" + prefsKey);
                }
            }
            else if (variableType == typeof(IntegerVariable))
            {
                IntegerVariable integerVariable = variable as IntegerVariable;
                if (integerVariable != null)
                {
                    integerVariable.Value = PlayerPrefs.GetInt(prefsKey);

                    //Debug.Log("Loading '" + variable.Key + "' in '" + flowchart.name + "' with value '" + integerVariable.Value + "'\t" + prefsKey);
                }
            }
            else if (variableType == typeof(FloatVariable))
            {
                FloatVariable floatVariable = variable as FloatVariable;
                if (floatVariable != null)
                {
                    floatVariable.Value = PlayerPrefs.GetFloat(prefsKey);

                    //Debug.Log("Loading '" + variable.Key + "' in '" + flowchart.name + "' with value '" + floatVariable.Value + "'\t" + prefsKey);
                }
            }
            else if (variableType == typeof(StringVariable))
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    stringVariable.Value = PlayerPrefs.GetString(prefsKey);

                    //Debug.Log("Loading '" + variable.Key + "' in '" + flowchart.name + "' with value '" + stringVariable.Value + "'\t" + prefsKey);
                }
            }
        } // LoadVariable
Esempio n. 13
0
 /**
  * Sets the value of an integer variable.
  * The variable must already be added to the list of variables for this Flowchart.
  */
 public virtual void SetIntegerVariable(string key, int value)
 {
     foreach (Variable v in variables)
     {
         if (v != null && v.key == key)
         {
             IntegerVariable variable = v as IntegerVariable;
             if (variable != null)
             {
                 variable.value = value;
                 return;
             }
         }
     }
     Debug.LogWarning("Integer variable " + key + " not found.");
 }
Esempio n. 14
0
    public void BattleDone(int gold, int xp)
    {
        inBattle         = false;
        party.partyGold += gold;
        //pretend xp is stored somehow

        Fungus.IntegerVariable iv = systemChat.GetVariable <Fungus.IntegerVariable>("gold");
        iv.Value = gold;

        Fungus.IntegerVariable iv_XP = systemChat.GetVariable <Fungus.IntegerVariable>("xp");
        iv_XP.Value = xp;

        showSystemChat = true;

        StartCoroutine(HandleBattleDone());
    }
Esempio n. 15
0
 /**
  * Gets the value of an integer variable.
  * Returns 0 if the variable key does not exist.
  */
 public virtual int GetIntegerVariable(string key)
 {
     foreach (Variable v in variables)
     {
         if (v.key == key)
         {
             IntegerVariable variable = v as IntegerVariable;
             if (variable != null)
             {
                 return(variable.value);
             }
         }
     }
     Debug.LogWarning("Integer variable " + key + " not found.");
     return(0);
 }
Esempio n. 16
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. 17
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. 18
0
 public IntegerData(int v)
 {
     integerVal = v;
     integerRef = null;
 }
Esempio n. 19
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. 20
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. 21
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. 22
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. 23
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. 24
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. 25
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty referenceProp = property.FindPropertyRelative("integerReference");
            SerializedProperty valueProp     = property.FindPropertyRelative("integerValue");

            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.intValue = EditorGUI.IntField(valueRect, valueProp.intValue);
                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)
            {
                IntegerVariable selectedVariable = referenceProp.objectReferenceValue as IntegerVariable;

                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(IntegerVariable))
                    {
                        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();
        }