using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using System; namespace YLBattle { /// /// /// partial class FightingManager : MonoSingleton { /// /// 已加载的怪物的龙骨数据(角色排除) /// private List mLoadedMonsterDragons = new List(); /// /// 添加一个战斗者 /// /// 对象全局唯一编号(当着战斗) /// 对象全局唯一编号(ServerId,Monster没有) /// 模版ID /// 资源名称 /// 所属队伍 /// 位置 /// 友情支援 /// 玩家注册ID internal void AddOneFighter(string _id, string _strIid, string _strTid, string _strDragonBoneName, EBattleTeam _eTeam, int _seat, string _sounds, int levelmode, bool isFriend = false, string playerUID = "" ) { if (mFighterList.ContainsKey(_id) == false) { mFighterTIDs.Add(_id, _strTid); ///pvp时,敌方也存在IID,这里只有己方需要添加到iid里供UI使用 if (_eTeam == EBattleTeam.BLUETEAM) { mFighterIIDs.Add(_id, _strIid); } if (mFriendIIDs.ContainsKey(_seat) == false && isFriend) { mFriendIIDs.Add(_seat, playerUID); } GameObject obj = null; string bundleName = _eTeam == EBattleTeam.BLUETEAM ? "DragonBone_Role" : "DragonBone_Mon"; Transform part = null; if (_eTeam == EBattleTeam.REDTEAM) { part = FightingSeatManager.Instance.GetFightingMapSeat(_seat, levelmode); } else { part = BUI_FighterAniWindow.Instance.GetTransBySeat(_seat); } if (part == null) { LogHelper.LogWarning("编队信息有误!!! " + _id); } #region ResourceHelper.Instance.LoadAssetBundle(bundleName, ab => { if (ab != null) { //LogHelper.LogWarning("1 成功加载龙骨数据 " + bundleName); obj = (GameObject)Instantiate(ab.LoadAsset(bundleName)); obj.transform.SetParent(part); obj.transform.localRotation = Quaternion.identity; obj.transform.localPosition = Vector3.zero; obj.transform.localScale = new Vector3(1, 1, 1); obj.gameObject.SetActive(false); Fighter fighter = obj.AddComponent(); fighter.SetInfo(_id, _strTid, _eTeam, _seat, mBFM, _sounds, _strDragonBoneName); if (this.mLoadedMonsterDragons.Contains(_strDragonBoneName) == false && _eTeam == EBattleTeam.REDTEAM) { this.mLoadedMonsterDragons.Add(_strDragonBoneName); } BUI_DragonBonesControl.Instance.ShowHeroModel(_id, _strDragonBoneName, _eTeam == EBattleTeam.BLUETEAM ? FightingResManager.EDragonResLevel.Hero : FightingResManager.EDragonResLevel.Monster, (armatureComponent) => { RenderTexture rendertexture = null; BUI_DragonBonesControl.Instance.AttachDragonToSeat(armatureComponent.transform, _seat, _eTeam, ref rendertexture); fighter.SetDragonBone(armatureComponent.GetComponent(), rendertexture); fighter.SetHidden(); if (_eTeam == EBattleTeam.REDTEAM) { BUI_BattleInfoBar.Instance.CreatNewBar(_id); } obj.gameObject.SetActive(true); mFighterList.Add(_id, fighter); if (isFriend && playerUID.Trim().Length > 0) { this.OnUpdateSlotData(_seat, playerUID); } }); } else { LogHelper.LogError(bundleName + " bundle 丢失"); } }); #endregion } else { LogHelper.LogError("sa不sa,sa不sa,损色...." + _id + " have contain~"); } } /// /// 删除一个战斗者 /// /// 编号 public void DeleteOneFighter(string id) { //LogHelper.LogError("[" + id + "]..................delete from battle~~"); if (mFighterList.ContainsKey(id)) { BUI_DragonBonesControl.Instance.DestroyModel(id); Destroy(mFighterList[id].gameObject); mFighterList.Remove(id); } mFighterIIDs.Remove(id); mFighterTIDs.Remove(id); } /// /// 清除所有战斗者 /// public void ClearAllFighter() { List fighters = new List(mFighterList.Values); for (int i = 0; i < fighters.Count; i++) { Destroy(fighters[i].gameObject); BUI_DragonBonesControl.Instance.DestroyModel(fighters[i].mID); } mFighterList.Clear(); mFighterTIDs.Clear(); mFighterIIDs.Clear(); mFriendIIDs.Clear(); } /// /// /// /// public Dictionary GetFriendIID() { return this.mFriendIIDs; } /// /// 获取所有己方战斗者(serverId) /// /// IID列表 public Dictionary GetBlueFighterIID() { Dictionary list = new Dictionary(); foreach (KeyValuePair keyvalue in mFighterIIDs) { if (keyvalue.Value != string.Empty) { list.Add(mFighterList[keyvalue.Key].mSeat.ToString(), keyvalue.Value); } } return list; } /// /// 通过ServerIID获取战斗唯一ID /// /// /// public string GetFitherIdByIID(string iid) { string result = string.Empty; foreach (KeyValuePair keyvalue in mFighterIIDs) { if (keyvalue.Value == iid) { return keyvalue.Key; } } return result; } /// /// 获取战斗者 /// /// 玩家ID /// 战斗者实例 public Fighter GetFighter(string id) { if (mFighterList.ContainsKey(id)) { return mFighterList[id]; } return null; } } }