Ejemplo n.º 1
0
        /**
         * <summary>Sets the value of a global Vector3 variable.</summary>
         * <param name = "_id">The ID number of the variable</param>
         * <param name = "_value">The new float value of the variable</param>
         * <param name = "synchronise">If True, then the variable's value will be synchronised with any external link it may have.</param>
         */
        public static void SetVector3Value(int _id, Vector3 _value, bool synchronise = true)
        {
            GVar var = GetVariable(_id);

            if (var != null)
            {
                var.SetVector3Value(_value);

                if (synchronise)
                {
                    var.Upload(VariableLocation.Global);
                }
            }
        }
        override public float Run()
        {
            if (obToRead != null)
            {
                GVar variable = null;
                if (variableLocation == VariableLocation.Global)
                {
                    variable = GlobalVariables.GetVariable(variableID);
                }
                else if (variableLocation == VariableLocation.Local && !isAssetFile)
                {
                    variable = LocalVariables.GetVariable(variableID);
                }

                if (variable != null)
                {
                    switch (transformRecordType)
                    {
                    case TransformRecordType.Position:
                        if (transformLocation == VariableLocation.Global)
                        {
                            variable.SetVector3Value(obToRead.transform.position);
                        }
                        else if (transformLocation == VariableLocation.Local)
                        {
                            variable.SetVector3Value(obToRead.transform.localPosition);
                        }
                        break;

                    case TransformRecordType.Rotation:
                        if (transformLocation == VariableLocation.Global)
                        {
                            variable.SetVector3Value(obToRead.transform.eulerAngles);
                        }
                        else if (transformLocation == VariableLocation.Local)
                        {
                            variable.SetVector3Value(obToRead.transform.localEulerAngles);
                        }
                        break;

                    case TransformRecordType.Scale:
                        if (transformLocation == VariableLocation.Global)
                        {
                            variable.SetVector3Value(obToRead.transform.lossyScale);
                        }
                        else if (transformLocation == VariableLocation.Local)
                        {
                            variable.SetVector3Value(obToRead.transform.localScale);
                        }
                        break;
                    }
                }
            }

            return(0f);
        }
        override public float Run()
        {
            if (runtimeObToRead != null)
            {
                if (runtimeVariable != null)
                {
                    switch (transformRecordType)
                    {
                    case TransformRecordType.Position:
                        if (transformLocation == GlobalLocal.Global)
                        {
                            runtimeVariable.SetVector3Value(runtimeObToRead.transform.position);
                        }
                        else if (transformLocation == GlobalLocal.Local)
                        {
                            runtimeVariable.SetVector3Value(runtimeObToRead.transform.localPosition);
                        }
                        break;

                    case TransformRecordType.Rotation:
                        if (transformLocation == GlobalLocal.Global)
                        {
                            runtimeVariable.SetVector3Value(runtimeObToRead.transform.eulerAngles);
                        }
                        else if (transformLocation == GlobalLocal.Local)
                        {
                            runtimeVariable.SetVector3Value(runtimeObToRead.transform.localEulerAngles);
                        }
                        break;

                    case TransformRecordType.Scale:
                        if (transformLocation == GlobalLocal.Global)
                        {
                            runtimeVariable.SetVector3Value(runtimeObToRead.transform.lossyScale);
                        }
                        else if (transformLocation == GlobalLocal.Local)
                        {
                            runtimeVariable.SetVector3Value(runtimeObToRead.transform.localScale);
                        }
                        break;
                    }

                    runtimeVariable.Upload(variableLocation, runtimeVariables);
                }
            }

            return(0f);
        }
Ejemplo n.º 4
0
        private void UnloadVariablesData(string data, LocalVariables localVariables)
        {
            if (data == null)
            {
                return;
            }

            if (data.Length > 0)
            {
                string[] varsArray = data.Split(SaveSystem.pipe[0]);

                foreach (string chunk in varsArray)
                {
                    string[] chunkData = chunk.Split(SaveSystem.colon[0]);

                    int _id = 0;
                    int.TryParse(chunkData[0], out _id);

                    GVar _var = LocalVariables.GetVariable(_id, localVariables);
                    if (_var != null)
                    {
                        if (_var.type == VariableType.String)
                        {
                            string _text = chunkData[1];
                            _var.SetStringValue(_text);
                        }
                        else if (_var.type == VariableType.Float)
                        {
                            float _value = 0f;
                            float.TryParse(chunkData[1], out _value);
                            _var.SetFloatValue(_value, SetVarMethod.SetValue);
                        }
                        else if (_var.type == VariableType.Vector3)
                        {
                            string _text = chunkData[1];
                            _text = AdvGame.PrepareStringForLoading(_text);

                            Vector3  _value      = Vector3.zero;
                            string[] valuesArray = _text.Split(","[0]);
                            if (valuesArray != null && valuesArray.Length == 3)
                            {
                                float xValue = 0f;
                                float.TryParse(valuesArray[0], out xValue);

                                float yValue = 0f;
                                float.TryParse(valuesArray[1], out yValue);

                                float zValue = 0f;
                                float.TryParse(valuesArray[2], out zValue);

                                _value = new Vector3(xValue, yValue, zValue);
                            }

                            _var.SetVector3Value(_value);
                        }
                        else
                        {
                            int _value = 0;
                            int.TryParse(chunkData[1], out _value);
                            _var.SetValue(_value, SetVarMethod.SetValue);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
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();
        }