Пример #1
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);
            }
        }
Пример #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);
        }
Пример #3
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();
        }
Пример #4
0
    public void UpdateFlowchart(Fungus.Flowchart flowchart, Employee emp)
    {
        Fungus.StringVariable  option = (Fungus.StringVariable)flowchart.GetVariable("option");
        Fungus.BooleanVariable done   = (Fungus.BooleanVariable)flowchart.GetVariable("done");
        Fungus.BooleanVariable lunch  = (Fungus.BooleanVariable)flowchart.GetVariable("lunch");

        if (curr_state == State.LUNCH)
        {
            lunch.Value = true;
        }
        bool can_interact = (emp.GetMinDaysBetweenInteraction() >= emp.days_since_interaction);

        if (option.Evaluate(Fungus.CompareOperator.NotEquals, "default") && can_interact)
        {
            bool not_done = true;
            if (option.Evaluate(Fungus.CompareOperator.Equals, "bad"))
            {
                not_done = emp.SetCurrQuestion("bad");
            }
            else if (option.Evaluate(Fungus.CompareOperator.Equals, "good"))
            {
                not_done = emp.SetCurrQuestion("good");
            }
            if (not_done)
            {
                employee_manager.SetFlowchart(emp.curr_question, flowchart.FindBlock("Question").CommandList);
            }
            option.Value = "default";
            done.Value   = !not_done;
            emp.days_since_interaction = 0;
        }
    }
Пример #5
0
        /**
         * Sets the value of a string variable.
         * The variable must already be added to the list of variables for this Flowchart.
         */
        public virtual void SetStringVariable(string key, string value)
        {
            StringVariable variable = GetVariable <StringVariable>(key);

            if (variable != null)
            {
                variable.value = value;
            }
        }
Пример #6
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();
        }
Пример #7
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();
        }
Пример #8
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();
        }
Пример #9
0
        /**
         * Gets the value of a string variable.
         * Returns the empty string if the variable key does not exist.
         */
        public virtual string GetStringVariable(string key)
        {
            StringVariable variable = GetVariable <StringVariable>(key);

            if (variable != null)
            {
                return(GetVariable <StringVariable>(key).value);
            }
            else
            {
                return("");
            }
        }
Пример #10
0
        public override void OnEnter()
        {
            if (textObject != null)
            {
                StringVariable stringVariable = variable as StringVariable;
                if (stringVariable != null)
                {
                    stringVariable.value = textObject.text;
                }
            }

            Continue();
        }
        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
 public void RefreshVariableCacheHelper(Flowchart f, ref List <Variable> referencedVariables)
 {
     if (variable is StringVariable)
     {
         StringVariable asStringVar = variable as StringVariable;
         if (asStringVar != null && !string.IsNullOrEmpty(asStringVar.Value))
         {
             f.DetermineSubstituteVariables(asStringVar.Value, referencedVariables);
         }
     }
     if (!string.IsNullOrEmpty(data.stringData.Value))
     {
         f.DetermineSubstituteVariables(data.stringData.Value, referencedVariables);
     }
 }
Пример #14
0
 /**
  * Gets the value of a string variable.
  * Returns the empty string if the variable key does not exist.
  */
 public virtual string GetStringVariable(string key)
 {
     foreach (Variable v in variables)
     {
         if (v.key == key)
         {
             StringVariable variable = v as StringVariable;
             if (variable != null)
             {
                 return(variable.value);
             }
         }
     }
     Debug.LogWarning("String variable " + key + " not found.");
     return("");
 }
Пример #15
0
 /**
  * Sets the value of a string variable.
  * The variable must already be added to the list of variables for this Flowchart.
  */
 public virtual void SetStringVariable(string key, string value)
 {
     foreach (Variable v in variables)
     {
         if (v != null && v.key == key)
         {
             StringVariable variable = v as StringVariable;
             if (variable != null)
             {
                 variable.value = value;
                 return;
             }
         }
     }
     Debug.LogWarning("String variable " + key + " not found.");
 }
Пример #16
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);
        }
Пример #17
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;
        }
Пример #18
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();
        }
Пример #19
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;
                }
            }
        }
Пример #20
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);
            }
        }
Пример #21
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);
        }
Пример #22
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();
        }
Пример #23
0
 public StringData(string v)
 {
     stringVal = v;
     stringRef = null;
 }
Пример #24
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty referenceProp = property.FindPropertyRelative("stringReference");
            SerializedProperty valueProp     = property.FindPropertyRelative("stringValue");

            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.stringValue = EditorGUI.TextField(valueRect, valueProp.stringValue);
                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)
            {
                StringVariable selectedVariable = referenceProp.objectReferenceValue as StringVariable;

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