public void WritePuzzleLoadData(string path, PuzzleLoadData data) { if (File.Exists(path)) { File.Delete(path); } FileStream file = File.Create(path); StreamWriter sw = new StreamWriter(file); string jsonData = JsonMapper.ToJson(data); sw.WriteLine(jsonData); sw.Close(); }
//加载旧关卡 public void LoadData(string path, string levelID) { levelId.text = levelID; loadData = ReadPuzzleData(path); row = loadData.wordInfo.Count; col = loadData.wordInfo[0].Count; SetWordGrid(); //tipsRow.text = loadData.tipsRow; //tipsCol.text = loadData.tipsCol; for (int i = 0; i < loadData.tipsRow.Count; i++) { rowInput[i].text = loadData.tipsRow[i]; } for (int j = 0; j < loadData.tipsCol.Count; j++) { colInput[j].text = loadData.tipsCol[j]; } }
//保存操作 public void Save() { if (string.IsNullOrEmpty(levelId.text)) { HintShow("请输入关卡ID ! ", true); return; } data = new PuzzleData(); loadData = null; loadData = new PuzzleLoadData(); for (int i = 0; i < rowInput.Count; i++) { if (!string.IsNullOrEmpty(rowInput[i].text)) { data.tipsRow.Add(rowInput[i].text); } } loadData.tipsRow = data.tipsRow; for (int i = 0; i < colInput.Count; i++) { if (!string.IsNullOrEmpty(colInput[i].text)) { data.tipsCol.Add(colInput[i].text); } } loadData.tipsCol = data.tipsCol; CalculateWord(); CalculateBlock(); CalculateCenter(); string path = Application.streamingAssetsPath + "/DailyData/PuzzleData/puzzle_" + levelId.text + ".json"; string loadPath = Application.dataPath + "/WordChef/PuzzlePos/puzzlePos_" + levelId.text + ".json"; WritePuzzleData(path, data); WritePuzzleLoadData(loadPath, loadData); HintShow("保存成功"); saveBtn.gameObject.SetActive(false); wordPosDic.Clear(); blockPosDic.Clear(); }
// Called 1st // Inititialization private void Start() { // Test to make sure there is a puzzle loader PuzzleLoader puzzleLoader = PuzzleLoader.Instance; if (puzzleLoader == null) { return; } // Test to see if we have a puzzle we are trying to load into PuzzleLoadData data = puzzleLoader.GetPuzzleData(); if (data == null) { return; } // Move the player Vector3 pos = data.StartPosition; if (pos != Vector3.negativeInfinity) { PlayerMovement.Instance.GetComponent <GridMover>().SetPosition(pos); } // Unlock their shape states int[] shapeUnlockStates = data.ShapeUnlockStates; foreach (int state in shapeUnlockStates) { SkillController.Instance.UnlockSkillState(SkillController.SkillEnum.Shape, state); } // Unlock their color states int[] colorUnlockStates = data.ColorUnlockStates; foreach (int state in colorUnlockStates) { SkillController.Instance.UnlockSkillState(SkillController.SkillEnum.Color, state); } }
/// <summary>Sets the puzzle data to the given data.</summary> /// <param name="data">Data for the puzzle to load.</param> public void SetPuzzleData(PuzzleLoadData data) { puzzleData = data; }
/// <summary>Reset the variables to be passed to the player.</summary> public void ResetPuzzleLoader() { puzzleData = null; }
/// <summary>Sets the puzzle data to the given data.</summary> /// <param name="data">Data for the puzzle to load.</param> public void SetPuzzleData(PuzzleLoadData data) { PuzzleLoader.Instance.SetPuzzleData(data); }