コード例 #1
0
ファイル: PlayerPreset.cs プロジェクト: kyapp69/Multiplier
        public void SetAttributes()
        {
            DropdownFix[] fixes  = GameObject.FindObjectsOfType <DropdownFix>();
            int           values = 0;

            for (int i = 0; i < fixes.Length; i++)
            {
                values += fixes[i].value;
            }
            if (values <= 0)
            {
                //TODO(Thompson): Need to create some sort of message box alerting the player to set the player presets first.
                return;
            }

            if (this.unitAttributes == null)
            {
                GameObject obj = GameObject.FindGameObjectWithTag("UnitAttributes");
                if (obj != null)
                {
                    this.unitAttributes = obj.GetComponent <UnitAttributes>();
                }
            }
            if (this.unitAttributes != null && this.dropdown != null && this.attributePanelUI != null)
            {
                //TODO: Make complex presets.
                int itemValue = this.dropdown.value;
                switch (itemValue)
                {
                default:
                case 0:
                    string zero1 = "y=0";
                    unitAttributes.SetHealthAttributes(zero1);
                    unitAttributes.SetAttackAttributes(zero1);
                    unitAttributes.SetSpeedAttributes(zero1);
                    unitAttributes.SetSplitAttributes(zero1);
                    unitAttributes.SetMergeAttributes(zero1);
                    unitAttributes.SetAttackCooldownAttributes(zero1);
                    this.attributePanelUI.DisableCustomEquations();
                    break;

                case 1:
                case 2:
                case 3:
                    Debug.Log("Setting expression: " + this.dropdown.options[itemValue].text);
                    string expression = this.dropdown.options[itemValue].text;
                    unitAttributes.SetHealthAttributes(expression);
                    unitAttributes.SetAttackAttributes(expression);
                    unitAttributes.SetSpeedAttributes(expression);
                    unitAttributes.SetSplitAttributes(expression);
                    unitAttributes.SetMergeAttributes(expression);
                    unitAttributes.SetAttackCooldownAttributes(expression);
                    this.attributePanelUI.DisableCustomEquations();
                    break;

                case 4:
                    unitAttributes.SetHealthAttributes("y=2*x");
                    string otherExpression = "y=1.414*x";
                    unitAttributes.SetAttackAttributes(otherExpression);
                    unitAttributes.SetSpeedAttributes(otherExpression);
                    unitAttributes.SetSplitAttributes(otherExpression);
                    unitAttributes.SetMergeAttributes(otherExpression);
                    unitAttributes.SetAttackCooldownAttributes(otherExpression);
                    this.attributePanelUI.DisableCustomEquations();
                    break;

                case 5:
                    string one = "y=1";
                    unitAttributes.SetHealthAttributes(one);
                    unitAttributes.SetAttackAttributes(one);
                    unitAttributes.SetSpeedAttributes(one);
                    unitAttributes.SetSplitAttributes(one);
                    unitAttributes.SetMergeAttributes(one);
                    unitAttributes.SetAttackCooldownAttributes(one);
                    this.attributePanelUI.EnableCustomEquations();
                    break;
                }
                this.attributePanelUI.RefreshAttributes(this.unitAttributes);
            }
        }
コード例 #2
0
        public void FinishedEditing()
        {
            try {
                GameObject obj = GameObject.FindGameObjectWithTag("UnitAttributes");
                if (obj != null)
                {
                    UnitAttributes unitAttributes = obj.GetComponent <UnitAttributes>();
                    if (unitAttributes != null)
                    {
                        foreach (Category cat in Category.Values)
                        {
                            if (cat.name.Equals(this.categoryContentObject.selectedToggle))
                            {
                                int catValue = cat.value;
                                switch (catValue)
                                {
                                default:
                                case 0:
                                    unitAttributes.SetHealthAttributes(this.equationTextObject.text);
                                    break;

                                case 1:
                                    unitAttributes.SetAttackAttributes(this.equationTextObject.text);
                                    break;

                                case 2:
                                    unitAttributes.SetAttackCooldownAttributes(this.equationTextObject.text);
                                    break;

                                case 3:
                                    unitAttributes.SetSpeedAttributes(this.equationTextObject.text);
                                    break;

                                case 4:
                                    unitAttributes.SetSplitAttributes(this.equationTextObject.text);
                                    break;

                                case 5:
                                    unitAttributes.SetMergeAttributes(this.equationTextObject.text);
                                    break;
                                }
                                List <LevelRate> tempList = this.levelingRatesObject.allAttributes[catValue];
                                for (int i = 0; i < tempList.Count; i++)
                                {
                                    bool      flag = i > 0;
                                    LevelRate rate = tempList[i];
                                    switch (cat.value)
                                    {
                                    default:
                                    case 0:
                                        rate.rate = unitAttributes.healthPrefabList[i];
                                        if (flag)
                                        {
                                            rate.isIncreasing = rate.rate > unitAttributes.healthPrefabList[i - 1] ? 1 : -1;
                                        }
                                        break;

                                    case 1:
                                        rate.rate = unitAttributes.attackPrefabList[i];
                                        if (flag)
                                        {
                                            rate.isIncreasing = rate.rate > unitAttributes.attackPrefabList[i - 1] ? 1 : -1;
                                        }
                                        break;

                                    case 2:
                                        rate.rate = unitAttributes.attackCooldownPrefabList[i];
                                        if (flag)
                                        {
                                            rate.isIncreasing = rate.rate > unitAttributes.attackCooldownPrefabList[i - 1] ? 1 : -1;
                                        }
                                        break;

                                    case 3:
                                        rate.rate = unitAttributes.speedPrefabList[i];
                                        if (flag)
                                        {
                                            rate.isIncreasing = rate.rate > unitAttributes.speedPrefabList[i - 1] ? 1 : -1;
                                        }
                                        break;

                                    case 4:
                                        if (i == 0)
                                        {
                                            rate.rate         = unitAttributes.splitPrefabFactor;
                                            rate.isIncreasing = 0;
                                        }
                                        else
                                        {
                                            rate.rate         = 0f;
                                            rate.isIncreasing = 0;
                                        }
                                        break;

                                    case 5:
                                        rate.rate = unitAttributes.mergePrefabList[i];
                                        if (flag)
                                        {
                                            rate.isIncreasing = rate.rate > unitAttributes.mergePrefabList[i - 1] ? 1 : -1;
                                        }
                                        break;
                                    }
                                    tempList[i] = rate;
                                }
                                this.levelingRatesObject.allAttributes[cat.value] = tempList;
                                break;
                            }
                        }
                        this.levelingRatesObject.UpdateAllPanelItems(this.categoryContentObject.selectedToggle);
                    }
                }
            }
            catch (System.Exception) {
                this.equationInputField.text = "[Invalid Equation.]";
            }
        }