public void LoadData(string dataString) { if (parameterType == ParameterType.Float) { floatValue = 0f; float.TryParse(dataString, out floatValue); } else if (parameterType == ParameterType.String) { stringValue = AdvGame.PrepareStringForLoading(dataString); } else if (parameterType == ParameterType.GameObject) { gameObject = null; int constantID = 0; if (int.TryParse(dataString, out constantID)) { ConstantID _constantID = Serializer.returnComponent <ConstantID> (constantID); if (_constantID != null) { gameObject = _constantID.gameObject; } } } else if (parameterType == ParameterType.UnityObject) { if (dataString == "") { objectValue = null; } else { Object[] objects = (Object[])Resources.LoadAll(""); foreach (Object _object in objects) { if (_object.name == dataString) { objectValue = _object; return; } } } } else { intValue = 0; int.TryParse(dataString, out intValue); } }
protected string[] StringToStringArray(string _string) { if (_string == null || _string == "" || _string.Length == 0) { return(null); } string[] stringArray = _string.Split(SaveSystem.pipe[0]); for (int i = 0; i < stringArray.Length; i++) { stringArray[i] = AdvGame.PrepareStringForLoading(stringArray[i]); } return(stringArray); }
/** * <summary>Re-assigns the CustomToken variables from a saved string.</summary> * <param name = "savedString">The string that contains the CustomToken variables data</param> */ public void AssignCustomTokensFromString(string tokenData) { if (!string.IsNullOrEmpty(tokenData)) { customTokens.Clear(); string[] countArray = tokenData.Split(SaveSystem.pipe[0]); foreach (string chunk in countArray) { string[] chunkData = chunk.Split(SaveSystem.colon[0]); int _id = 0; int.TryParse(chunkData[0], out _id); string _replacementText = chunkData[1]; customTokens.Add(new CustomToken(_id, AdvGame.PrepareStringForLoading(_replacementText))); } } }
/** * <summary>Restores the class's data from a saved string.</summary> * <param name = "data">The saved string to restore from</param> * <param name = "subScene">If set, only data for a given subscene will be loaded. If null, only data for the active scene will be loaded</param> * <returns>True if the data was successfully restored</returns> */ public bool LoadData(string dataString, SubScene subScene = null) { if (string.IsNullOrEmpty(dataString)) { return(false); } string[] dataArray = dataString.Split(SaveSystem.colon[0]); // ID string listName = AdvGame.PrepareStringForLoading(dataArray[0]); resumeIndices = new int[0]; // Resume string[] resumeData = dataArray[1].Split("]"[0]); if (resumeData.Length > 0) { List <int> resumeIndexList = new List <int>(); for (int i = 0; i < resumeData.Length; i++) { int resumeIndex = -1; if (int.TryParse(resumeData[i], out resumeIndex) && resumeIndex >= 0) { resumeIndexList.Add(resumeIndex); } } resumeIndices = resumeIndexList.ToArray(); } // StartIndex int.TryParse(dataArray[2], out startIndex); // Skip queue int j = 0; int.TryParse(dataArray[3], out j); inSkipQueue = (j == 1) ? true : false; // IsRunning j = 0; int.TryParse(dataArray[4], out j); isRunning = (j == 1) ? true : false; // Conversation on end int convID = 0; int.TryParse(dataArray[5], out convID); if (convID != 0) { if (subScene != null) { conversationOnEnd = ConstantID.GetComponent <Conversation> (convID, subScene.gameObject.scene); } else { conversationOnEnd = ConstantID.GetComponent <Conversation> (convID); } } // Parameter data parameterData = dataArray[6]; // ActionList int ID = 0; if (int.TryParse(listName, out ID)) { // Scene ConstantID constantID = null; if (subScene != null) { constantID = ConstantID.GetComponent(ID, subScene.gameObject.scene); } else { constantID = ConstantID.GetComponent(ID); } if (constantID && constantID.GetComponent <ActionList>() != null) { actionList = constantID.GetComponent <ActionList>(); return(true); } } else { // Asset file ActionListAsset tempAsset = ScriptableObject.CreateInstance <ActionListAsset> (); actionListAsset = AssetLoader.RetrieveAsset <ActionListAsset> (tempAsset, listName); if (actionListAsset && actionListAsset != tempAsset) { return(true); } ACDebug.LogWarning("Could not restore data related to the ActionList asset '" + listName + "' - to restore it correctly, the asset must be placed in a folder named Resources."); } return(false); }
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); } } } } }
public void LoadData(string dataString) { if (parameterType == ParameterType.Float) { floatValue = 0f; float.TryParse(dataString, out floatValue); } else if (parameterType == ParameterType.String) { stringValue = AdvGame.PrepareStringForLoading(dataString); } else if (parameterType == ParameterType.GameObject) { gameObject = null; int constantID = 0; if (int.TryParse(dataString, out constantID)) { ConstantID _constantID = Serializer.returnComponent <ConstantID> (constantID); if (_constantID != null) { gameObject = _constantID.gameObject; } } } else if (parameterType == ParameterType.UnityObject) { if (dataString == "") { objectValue = null; } else { Object[] objects = (Object[])Resources.LoadAll(""); foreach (Object _object in objects) { if (_object.name == dataString) { objectValue = _object; return; } } } } else if (parameterType == ParameterType.Vector3) { if (!string.IsNullOrEmpty(dataString)) { dataString = AdvGame.PrepareStringForLoading(dataString); Vector3 _value = Vector3.zero; string[] valuesArray = dataString.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); } vector3Value = _value; } } else { intValue = 0; int.TryParse(dataString, out intValue); } }
/** * <summary>Sets the save file's label in a safe format. Pipe's and colons are converted so that they can be stored.</summary> * <param name = "_label">The new label for the file.</param> */ public void SetLabel(string _label) { label = AdvGame.PrepareStringForLoading(_label); }
/** * <summary>Assigns the replacementText from a safe-to-store string that was stored in save data.</summary> * <param name = "safeText">The safe-to-store variant of replacementText that was stored in save data</param> */ public void SetSafeReplacementText(string safeText) { replacementText = AdvGame.PrepareStringForLoading(safeText); }