- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
- 纳金币
- 20645
- 精华
- 62
|
- using UnityEngine;
- using System.Collections;
- using System;
- /// <summary>
- /// 玩家角色生成器
- /// </summary>
- public class CharacterGenerator : MonoBehaviour {
- /// <summary>
- /// 玩家的角色类
- /// </summary>
- private PlayerCharacter _player;
- /// <summary>
- /// 开始总共的技能点
- /// </summary>
- private const int Starting_Point = 25;
- /// <summary>
- /// 没做基本属性最低为5
- /// </summary>
- private const int Min_Starting_Attribute_value = 5;
- /// <summary>
- /// 基本属性的起始值
- /// </summary>
- private const int Starting_value = 5;
- /// <summary>
- /// 可分配的属性点
- /// </summary>
- private int pointsLeft;
- void Start()
- {
- //实例化角色,并命名为Player。请务必使游戏对象的名称叫Player,因为我们后面的代码中使用到了这个名字
- GameObject obj = Resources.LoadAssetAtPath("Assets\\Prefabs\\Player\\Sample Hero\\Player_Simple.prefab", typeof(GameObject)) as GameObject;
- obj = Instantiate(obj) as GameObject;
- obj.name = "Player";
- //检查持久化文本里是否保存了历史记录
- string _PlayerName = PlayerPrefs.GetString("Player Name", "");
- Debug.LogWarning("玩家的名称" + _PlayerName);
- //如果没有保存,则开启属性面板,配置属性
- if (_PlayerName == "")
- {
- _player = obj.GetComponent<PlayerCharacter>();
- pointsLeft = Starting_Point;
- for (int i = 0; i < Enum.GetValues(typeof(AttributeName)).Length; i++)
- {
- //设置基础属性的基本值
- _player.GetPrimaryAttribute(i).BaseValue = Starting_value;
- //更新可分配的属性点
- pointsLeft -= Starting_value;
- }
- _player.Points = pointsLeft;
- //更新生命属性和技能属性
- _player.StatUpdate();
- //加载属性分配的窗体
- GameObject root = GameObject.Find("UI Root/Anchor_Center");
- GameObject panel = Resources.LoadAssetAtPath("Assets\\Prefabs\\Health\\WindowPanel.prefab", typeof(GameObject)) as GameObject;
- panel = Instantiate(panel) as GameObject;
- panel.transform.parent = root.transform;
- panel.transform.localScale = Vector3.one;
- panel.transform.localPosition = Vector3.zero;
- panel.GetComponent<PlayerAttribute>().playChacter = _player;
- }
- else
- {
- Application.LoadLevel(1);
- }
- //因为这个对象在做完以上的工作后就没有作用了。因此我们把它销毁掉
- StartCoroutine("KillMySelf");
- }
- #region 一秒后自杀
- /// <summary>
- /// 一秒后自杀
- /// </summary>
- IEnumerator KillMySelf()
- {
- yield return new WaitForSeconds(1);
- Destroy(gameObject);
- }
- #endregion
- }
复制代码 |
|