override public ActionEnd End(List <Action> actions) { if (numSockets <= 0) { ACDebug.LogWarning("Could not compute Random check because no values were possible!"); return(GenerateStopActionEnd()); } GVar linkedVariable = null; if (saveToVariable) { if (location == VariableLocation.Local && !isAssetFile) { linkedVariable = LocalVariables.GetVariable(variableID); } else { linkedVariable = GlobalVariables.GetVariable(variableID); } } int randomResult = Random.Range(0, numSockets); if (numSockets > 1 && disallowSuccessive) { if (saveToVariable) { if (linkedVariable != null && linkedVariable.type == VariableType.Integer) { ownVarValue = linkedVariable.val; } else { ACDebug.LogWarning("'Variable: Check random number' Action is referencing a Variable that does not exist or is not an Integer!"); } } while (ownVarValue == randomResult) { randomResult = Random.Range(0, numSockets); } ownVarValue = randomResult; if (saveToVariable && linkedVariable != null && linkedVariable.type == VariableType.Integer) { linkedVariable.SetValue(ownVarValue); } } return(ProcessResult(randomResult, actions)); }
private void UnloadVariablesData(string data) { if (data == null) { return; } if (data.Length > 0) { string[] varsArray = data.Split("|"[0]); foreach (string chunk in varsArray) { string[] chunkData = chunk.Split(":"[0]); int _id = 0; int.TryParse(chunkData[0], out _id); GVar var = LocalVariables.GetVariable(_id); if (var.type == VariableType.String) { string _text = chunkData[1]; var.SetValue(_text); } else if (var.type == VariableType.Float) { float _value = 0f; float.TryParse(chunkData[1], out _value); var.SetValue(_value, SetVarMethod.SetValue); } else { int _value = 0; int.TryParse(chunkData[1], out _value); var.SetValue(_value, SetVarMethod.SetValue); } } } }
private void CopyVariable(GVar newVar, GVar oldVar) { if (newVar == null || oldVar == null) { ACDebug.LogWarning("Cannot copy variable since it cannot be found!"); return; } if (oldLocation == VariableLocation.Global) { oldVar.Download(); } if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean || newVar.type == VariableType.PopUp) { int oldValue = oldVar.val; if (oldVar.type == VariableType.Float) { oldValue = (int)oldVar.floatVal; } else if (oldVar.type == VariableType.String) { float oldValueAsFloat = 0f; float.TryParse(oldVar.textVal, out oldValueAsFloat); oldValue = (int)oldValueAsFloat; } newVar.SetValue(oldValue, SetVarMethod.SetValue); } else if (newVar.type == VariableType.Float) { float oldValue = oldVar.floatVal; if (oldVar.type == VariableType.Integer || oldVar.type == VariableType.Boolean || oldVar.type == VariableType.PopUp) { oldValue = (float)oldVar.val; } else if (oldVar.type == VariableType.String) { float.TryParse(oldVar.textVal, out oldValue); } newVar.SetFloatValue(oldValue, AC.SetVarMethod.SetValue); } else if (newVar.type == VariableType.String) { string oldValue = oldVar.GetValue(); newVar.SetStringValue(oldValue); } }
/** * <summary>Sets the value of a global Boolean variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new bool 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 SetBooleanValue(int _id, bool _value, bool synchronise = true) { GVar var = GetVariable(_id); if (var != null) { var.SetValue((_value) ? 1 : 0); if (synchronise) { var.Upload(VariableLocation.Global); } } }
/** * <summary>Sets the value of a global Integer variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new integer 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 SetIntegerValue(int _id, int _value, bool synchronise = true) { GVar var = GetVariable(_id); if (var != null) { var.SetValue(_value); if (synchronise) { var.Upload(VariableLocation.Global); } } }
private void SetVariable(GVar newVar, VariableLocation _newLocation, GVar oldVar) { if (newVar == null || oldVar == null) { Debug.LogWarning("Cannot copy variable since it cannot be found!"); return; } if (oldLocation == VariableLocation.Global) { oldVar.Download(); } if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean) { int oldValue = oldVar.val; newVar.SetValue(oldValue, SetVarMethod.SetValue); } else if (newVar.type == VariableType.Float) { float oldValue = oldVar.floatVal; newVar.SetValue(oldValue, AC.SetVarMethod.SetValue); } else if (newVar.type == VariableType.String) { string oldValue = oldVar.textVal; newVar.SetValue(oldValue); } if (_newLocation == VariableLocation.Global) { newVar.Upload(); } KickStarter.actionListManager.VariableChanged(); }
public override ActionEnd End(List <Action> actions) { if (numSockets <= 0) { LogWarning("Could not compute Random check because no values were possible!"); return(GenerateStopActionEnd()); } int randomResult = Random.Range(0, numSockets); if (numSockets > 1 && disallowSuccessive) { if (saveToVariable) { if (runtimeVariable != null && runtimeVariable.type == VariableType.Integer) { ownVarValue = runtimeVariable.val; } else { LogWarning("No Integer variable found!"); } } while (ownVarValue == randomResult) { randomResult = Random.Range(0, numSockets); } ownVarValue = randomResult; if (saveToVariable && runtimeVariable != null && runtimeVariable.type == VariableType.Integer) { runtimeVariable.SetValue(ownVarValue); } } return(ProcessResult(randomResult, actions)); }
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(); }
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); } } } } }
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.SetFloatValue (_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.SetStringValue (_value); } if (location == VariableLocation.Global) { var.Upload (); } KickStarter.actionListManager.VariableChanged (); }
private void SetVariable(GVar newVar, VariableLocation _newLocation, GVar oldVar) { if (newVar == null || oldVar == null) { ACDebug.LogWarning ("Cannot copy variable since it cannot be found!"); return; } if (oldLocation == VariableLocation.Global) { oldVar.Download (); } if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean) { int oldValue = oldVar.val; newVar.SetValue (oldValue, SetVarMethod.SetValue); } else if (newVar.type == VariableType.Float) { float oldValue = oldVar.floatVal; newVar.SetFloatValue (oldValue, AC.SetVarMethod.SetValue); } else if (newVar.type == VariableType.String) { string oldValue = oldVar.textVal; newVar.SetStringValue (oldValue); } if (_newLocation == VariableLocation.Global) { newVar.Upload (); } KickStarter.actionListManager.VariableChanged (); }
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(); }
private void SetVariable (GVar var, VariableLocation location) { 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; } } var.SetValue (_value, setVarMethod); } 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; } } var.SetValue (_value, setVarMethod); } 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.SetAsMenuInputLabel) { if (PlayerMenus.GetElementWithName (menuName, elementName) != null) { MenuInput menuInput = (MenuInput) PlayerMenus.GetElementWithName (menuName, elementName); _value = menuInput.label; 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 { Debug.LogWarning ("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'"); } } var.SetValue (_value); } if (location == VariableLocation.Global) { var.Upload (); } GameObject.FindWithTag (Tags.gameEngine).GetComponent <ActionListManager>().VariableChanged (); }
private void SetVariable (GVar newVar, VariableLocation _newLocation, GVar oldVar) { if (newVar == null || oldVar == null) { return; } if (oldLocation == VariableLocation.Global) { oldVar.Download (); } if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean) { int oldValue = oldVar.val; newVar.SetValue (oldValue, SetVarMethod.SetValue); } else if (newVar.type == VariableType.Float) { float oldValue = oldVar.floatVal; newVar.SetValue (oldValue, AC.SetVarMethod.SetValue); } else if (newVar.type == VariableType.String) { string oldValue = oldVar.textVal; newVar.SetValue (oldValue); } if (_newLocation == VariableLocation.Global) { newVar.Upload (); } GameObject.FindWithTag (Tags.gameEngine).GetComponent <ActionListManager>().VariableChanged (); }