/// <summary> /// 移除玩家 /// </summary> public void OnRemovePlayerEvent(string username) { if (playerDic.ContainsKey(username) && playerDic[username] != null) { Destroy(playerDic[username].gameObject); playerDic.Remove(username); } MessageMediator.Dispatch(MessageMediatType.RemovePlayer, username); }
/// <summary> /// 添加玩家 /// </summary> public void OnAddPlayerEvent(string username, string heroModelName, string nickName, int hp, int killCount) { GameObject go = Instantiate(Resources.Load("Prefabs/Heros/" + heroModelName) as GameObject); go.GetComponent <FSMController>().system.playerType = PlayerType.Other; PlayerController playerController = go.GetComponent <PlayerController>(); playerController.heroData.Username = username; playerController.heroData.NickName = nickName; playerController.heroData.Hp = hp; playerController.heroData.KillCount = killCount; playerDic.Add(username, playerController);//利用集合保存所有的其他客户端 if (playerController.heroData.Hp <= 0) { CoroutineUtil.Instance.WaitTime(0, false, () => { playerDic[username].fsmController.system.PerformTransition(FSMTransition.IdleToDead); }); } MessageMediator.Dispatch(MessageMediatType.AddPlayer, username); }