在利用json存档时想存场景中player的位置和enemy的位置。我给player和enemy分别给了不同的标签,怎么样能在场景里读取该标签的位置
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Save
{
public List livingEnermyPositions = new List();
public List livingPlayerPositions = new List();
public List sceneNums = new List();
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using LitJson;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public static GameManager _instance;
public GameObject[] enemys;
public GameObject[] player;
public GameObject[] scenes;
private void Resume()
{
_instance = this;
Pause();
}
void Update()
{
private Save CreateSaveGo()
{
Save save = new Save();
return save;
}
private void SetGame(Save save)
{
}
//Json:存档
private void SaveByJson()
{
Save save = CreateSaveGo();
string filePath = Application.dataPath + "/StreamingFile" + "/byJson.json";
//利用JsonMapper将save对象转换为Json格式的字符串
string saveJsonStr = JsonMapper.ToJson(save);
//将这个字符串写入到文件中
//创建一个StreamWriter,将字符写入到文件中
StreamWriter sw = new StreamWriter(filePath);
sw.Write(saveJsonStr);
//关闭StreamWriter
sw.Close();
if (File.Exists(Application.dataPath + "/StreamingFile" + "/byJson.json"))
{
pauseMenuUI.ShowMessage("Saved");
}
}
//Json:读档
private void LoadByJson()
{
string filePath = Application.dataPath + "/StreamingFile" + "/byJson.json";
if (File.Exists(filePath))
{
//创建一个StreamReader,用来读取流
StreamReader sr = new StreamReader(filePath);
//将读取到的流赋值给string类型的jsonstr
string jsonstr = sr.ReadToEnd();
//关闭流
sr.Close();
//将字符串jsonstr转换为save对象
Save save = JsonMapper.ToObject<Save>(jsonstr);
SetGame(save);
}
else
{
pauseMenuUI.ShowMessage("Missing");
}
}
}
public void SaveGame()
{
SaveByJson();
}
public void LoadGame()
{
LoadByJson();
}
}