Пример #1
0
        private void SetVariable(GVar var, VariableLocation location, bool doSkip)
        {
            if (var == null)
            {
                return;
            }

            if (location == VariableLocation.Global)
            {
                var.Download();
            }

            if (var.type == VariableType.Integer)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula));
                    }
                    else
                    {
                        _value = intValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value       = animator.GetInteger(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
            }
            if (var.type == VariableType.Float)
            {
                float _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (float)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula));
                    }
                    else
                    {
                        _value = floatValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value       = animator.GetFloat(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
            }
            else if (var.type == VariableType.Boolean)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    _value = (int)boolValue;
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        if (animator.GetBool(parameterName))
                        {
                            _value = 1;
                        }
                    }
                }

                var.SetValue(_value, SetVarMethod.SetValue);
            }
            else if (var.type == VariableType.PopUp)
            {
                var.SetValue(intValue);
            }
            else if (var.type == VariableType.String)
            {
                string _value = "";

                if (setVarMethodString == SetVarMethodString.EnteredHere)
                {
                    _value = AdvGame.ConvertTokens(stringValue);
                }
                else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText)
                {
                    MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName);
                    if (menuElement != null)
                    {
                        if (menuElement is MenuInput)
                        {
                            MenuInput menuInput = (MenuInput)menuElement;
                            _value = menuInput.GetContents();

                            if ((Options.GetLanguageName() == "Arabic" || Options.GetLanguageName() == "Hebrew") && _value.Length > 0)
                            {
                                // Invert
                                char[] charArray = _value.ToCharArray();
                                _value = "";
                                for (int i = charArray.Length - 1; i >= 0; i--)
                                {
                                    _value += charArray[i];
                                }
                            }
                        }
                        else
                        {
                            PlayerMenus.GetMenuWithName(menuName).Recalculate();
                            menuElement.PreDisplay(slotNumber, Options.GetLanguage(), false);
                            _value = menuElement.GetLabel(slotNumber, Options.GetLanguage());
                        }
                    }
                    else
                    {
                        Debug.LogWarning("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'");
                    }
                }

                var.SetValue(_value);
            }

            if (location == VariableLocation.Global)
            {
                var.Upload();
            }

            KickStarter.actionListManager.VariableChanged();
        }
Пример #2
0
        protected void SetVariable(GVar var, VariableLocation location, bool doSkip)
        {
            if (var == null)
            {
                return;
            }

            switch (var.type)
            {
            case VariableType.Integer:
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables));
                    }
                    else
                    {
                        _value = intValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && !string.IsNullOrEmpty(parameterName))
                    {
                        _value       = animator.GetInteger(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
                break;
            }

            case VariableType.Float:
            {
                float _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (float)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables));
                    }
                    else
                    {
                        _value = floatValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && !string.IsNullOrEmpty(parameterName))
                    {
                        _value       = animator.GetFloat(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetFloatValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }

                break;
            }

            case VariableType.Boolean:
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    _value = (int)boolValue;
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && !string.IsNullOrEmpty(parameterName))
                    {
                        if (animator.GetBool(parameterName))
                        {
                            _value = 1;
                        }
                    }
                }

                var.SetValue(_value, SetVarMethod.SetValue);
                break;
            }

            case VariableType.Vector3:
            {
                Vector3 newValue = vector3Value;
                if (setVarMethodVector == SetVarMethodVector.IncreaseByValue)
                {
                    newValue += var.vector3Val;
                }

                var.SetVector3Value(newValue);
                break;
            }

            case VariableType.PopUp:
            {
                int _value = 0;

                if (setVarMethod == SetVarMethod.Formula)
                {
                    _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables));
                }
                else if (setVarMethod == SetVarMethod.SetAsRandom)
                {
                    _value = var.GetNumPopUpValues();
                }
                else
                {
                    _value = Mathf.Clamp(intValue, 0, var.GetNumPopUpValues() - 1);
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
                break;
            }

            case VariableType.String:
            {
                string _value = string.Empty;

                if (setVarMethodString == SetVarMethodString.EnteredHere)
                {
                    _value = AdvGame.ConvertTokens(stringValue, Options.GetLanguage(), localVariables);
                }
                else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText)
                {
                    MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName);
                    if (menuElement != null)
                    {
                        if (menuElement is MenuInput)
                        {
                            MenuInput menuInput = (MenuInput)menuElement;
                            _value = menuInput.GetContents();

                            if (KickStarter.runtimeLanguages.LanguageReadsRightToLeft(Options.GetLanguage()) && _value.Length > 0)
                            {
                                // Invert
                                char[] charArray = _value.ToCharArray();
                                _value = "";
                                for (int i = charArray.Length - 1; i >= 0; i--)
                                {
                                    _value += charArray[i];
                                }
                            }
                        }
                        else
                        {
                            PlayerMenus.GetMenuWithName(menuName).Recalculate();
                            menuElement.PreDisplay(slotNumber, Options.GetLanguage(), false);
                            _value = menuElement.GetLabel(slotNumber, Options.GetLanguage());
                        }
                    }
                    else
                    {
                        LogWarning("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'");
                    }
                }

                var.SetStringValue(_value, lineID);
                break;
            }

            default:
                break;
            }

            var.Upload(location, runtimeVariables);

            KickStarter.actionListManager.VariableChanged();
        }