1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| using System.IO; using UnityEngine;
public class SerializeDataTest : MonoBehaviour { private string filePath; private void Start() => filePath = Path.Combine(Application.streamingAssetsPath, "Data.txt"); private void Update() { if (Input.GetKeyDown(KeyCode.S)) { Player player = new Player() { playerName = "June", attack = 20, armor = 50 }; SerializeDataManager.SaveData(filePath, player); } if (Input.GetKeyDown(KeyCode.L)) { Player player = SerializeDataManager.LoadData(filePath); Debug.Log($"玩家名字:{player.playerName} 攻击力:{player.attack} 护甲:{player.armor}"); } } }
|