- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
- 纳金币
- 20645
- 精华
- 62
|
- using UnityEngine;
- using System.Collections;
- using System;
- /// <summary>
- /// 游戏配置类
- /// </summary>
- public class GameSetting : MonoBehaviour {
- /// <summary>
- /// 玩家的复活点游戏对象的名称
- /// </summary>
- public const string PLAYER_SPWAN_POINT = "Player Spwan Point";
- void Awake()
- {
- //载入时不删除
- DontDestroyOnLoad(this);
- }
- #region 持久化保存角色的数据
- /// <summary>
- /// 持久化保存角色的数据
- /// </summary>
- public void SaveCharacterData()
- {
- PlayerCharacter playerCharacter = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerCharacter>();
- if (playerCharacter != null)
- {
- PlayerPrefs.SetString("Player Name", playerCharacter.Name);
- //保存基础属性
- for (int i = 0; i < Enum.GetValues(typeof(AttributeName)).Length; i++)
- {
- PlayerPrefs.SetInt(((AttributeName)i).ToString() + "-Base Value", playerCharacter.GetPrimaryAttribute(i).BaseValue);
- PlayerPrefs.SetInt(((AttributeName)i).ToString() + "-Exp To Level", playerCharacter.GetPrimaryAttribute(i).ExpToLevel);
- }
- //保存生命属性
- for (int i = 0; i < Enum.GetValues(typeof(VitalName)).Length; i++)
- {
- PlayerPrefs.SetInt(((VitalName)i).ToString() + "-Base Value", playerCharacter.GetVital(i).BaseValue);
- PlayerPrefs.SetInt(((VitalName)i).ToString() + "-Exp To Level", playerCharacter.GetVital(i).ExpToLevel);
- PlayerPrefs.SetInt(((VitalName)i).ToString() + "-Cur Value", playerCharacter.GetVital(i).CurrentValue);
- }
- //保存技能属性
- for (int i = 0; i < Enum.GetValues(typeof(SkillName)).Length; i++)
- {
- PlayerPrefs.SetInt(((SkillName)i).ToString() + "-Base Value", playerCharacter.Getskill(i).BaseValue);
- PlayerPrefs.SetInt(((SkillName)i).ToString() + "-Exp To Level", playerCharacter.Getskill(i).ExpToLevel);
- }
- }
- else
- Debug.LogWarning("不好意思,没有找到Player游戏对象");
- }
- #endregion
- #region 加载角色的数据
- /// <summary>
- /// 加载角色的数据
- /// </summary>
- public void LoadCharacterData()
- {
- PlayerCharacter playerCharacter = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerCharacter>();
- //如果找到了该游戏对象
- if (playerCharacter != null)
- {
- //获取角色的名称
- playerCharacter.name = PlayerPrefs.GetString("Player Name", "凌天");
- //获取角色的基础属性
- for (int i = 0; i < System.Enum.GetValues(typeof(AttributeName)).Length; i++)
- {
- playerCharacter.GetPrimaryAttribute(i).BaseValue = PlayerPrefs.GetInt(((AttributeName)i).ToString() + "-Base Value", 0);
- playerCharacter.GetPrimaryAttribute(i).ExpToLevel = PlayerPrefs.GetInt(((AttributeName)i).ToString() + "-Exp To Level", 0);
- }
- //获取角色的生命属性
- for (int i = 0; i < System.Enum.GetValues(typeof(VitalName)).Length; i++)
- {
- playerCharacter.GetVital(i).BaseValue = PlayerPrefs.GetInt(((VitalName)i).ToString() + "-Base Value", 0);
- playerCharacter.GetVital(i).ExpToLevel = PlayerPrefs.GetInt(((VitalName)i).ToString() + "-Exp To Level", 0);
- playerCharacter.GetVital(i).Update();
- playerCharacter.GetVital(i).CurrentValue = PlayerPrefs.GetInt(((VitalName)i).ToString() + "- Cur Value", 1);
- }
- //获取角色的技能属性
- for (int i = 0; i < System.Enum.GetValues(typeof(SkillName)).Length; i++)
- {
- playerCharacter.Getskill(i).BaseValue = PlayerPrefs.GetInt(((SkillName)i).ToString() + "-Base Value", 0);
- playerCharacter.Getskill(i).ExpToLevel = PlayerPrefs.GetInt(((SkillName)i).ToString() + "-Exp To Level", 0);
- playerCharacter.Getskill(i).Update();
- }
- }
- else
- Debug.LogWarning("真的不好意思哎,我没有找到名叫Player的游戏对象哎");
- }
- #endregion
- }
复制代码 |
|