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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| using... //角色管理器 public class CharacterManager { private static CharacterManager instance;//单例 public static CharacterManager Instance{ get{ if(instance==null) instance = new Character(); return instance; } } //玩家 public Character character = new Character();//持有的玩家属性类,如果是多个主角请改为数组 public int Money = 0;//钱 public bool canControl = true;//角色当前是否可操作 //人物属性 //增加Money的方法 #region 人物属性 //增加money public void AddMoney(int money){ Money += money; if(Money<0) Money=0; } //增加经验 public void AddExp(int exp){//多人加参数int index character.CurrentExp += exp; if(character.CurrentExp>=character.GetNextlevelExp()) {character.Level ++; character.CurrentExp = 0;} } //增加血量 public void AddHp(int hp){ character.Hp += hp; character.Hp = Mathf.Clamp(character.Hp,0,character.MaxHp); //保证血量不超过合理值 } #endregion #region 人物技能 public bool AddSkill(Skill skill){ if(character.SkillList.Contains(skill)) return false; character.SkillList..Add(skill); return true; } //是否拥有此技能 public bool HasSkill(Skill skill){ if(character.SkillList.Contains(skill)) return true; } //移除技能 public void RemoveSkill(Skill skill){ if(character.SkillList.Contains(skill)){ character.SkillList.Remove(skill); } } public Skill[] GetSkills(){ return character.SkillList.ToArray(); } #endregion #region 人物装备 //装备武器 public void EquipWeapon(int id){ //如果背包有这个武器,才允许装备 InventoryItem item = InventoryManager.instance.GetItem(id); //InventoryManager:上一篇文章 if(item!=null){ InventoryManager.instance.RemoveItem(id,1); } if(character.WeaponId > -1){//-1代表没有武器 InventoryManager.instance.AddItem(character.WeaponId,1); } character.WeaponId = id; } #endregion ... }
|