我必須找到一種方法來使用c#腳本和php保存並加載數據庫中的遊戲狀態。到目前爲止,我可以將播放器位置存儲到本地註冊表中,但是將其遠程保存是問題所在。有誰知道我需要實施這個步驟的列表?如何將遊戲狀態存儲到數據庫並使用php和c#腳本加載它
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class SaveSystem : MonoBehaviour {
// Use this for initialization
public void SaveState() {
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create (Application.persistentDataPath + "/PlayerData.dat");
PlayerData data = new PlayerData();
data.posX = transform.position.x;
data.posY = transform.position.y;
data.posZ = transform.position.z;
data.rotX = transform.eulerAngles.x;
data.rotY = transform.eulerAngles.y;
data.rotZ = transform.eulerAngles.z;
bf.Serialize (file, data);
file.Close();
}
// Update is called once per frame
public void LoadState() {
if(File.Exists(Application.persistentDataPath + "/PlayerData.dat")){
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/PlayerData.dat", FileMode.Open);
PlayerData data = (PlayerData) bf.Deserialize(file);
file.Close();
transform.position = new Vector3(data.posX, data.posY, data.posZ);
transform.rotation = Quaternion.Euler(data.rotX, data.rotY, data.rotZ);
}
[Serializable]
class PlayerData{
public float posX;
public float posY;
public float posZ;
public float rotX;
public float rotY;
public float rotZ;
}