123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using System;
- namespace YLBattle
- {
- /// <summary>
- ///
- /// </summary>
- partial class FightingManager : MonoSingleton<FightingManager>
- {
- /// <summary>
- /// 已加载的怪物的龙骨数据(角色排除)
- /// </summary>
- private List<string> mLoadedMonsterDragons = new List<string>();
- /// <summary>
- /// 添加一个战斗者
- /// </summary>
- /// <param name="_id">对象全局唯一编号(当着战斗)</param>
- /// <param name="_strIid">对象全局唯一编号(ServerId,Monster没有)</param>
- /// <param name="_strTid">模版ID</param>
- /// <param name="_strPrefebName">资源名称</param>
- /// <param name="_intTeam">所属队伍</param>
- /// <param name="_seat">位置</_seat>
- /// <param name="isFriend">友情支援</_seat>
- /// <param name="playerUID">玩家注册ID</_seat>
- 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>();
- 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<DragonBones.UnityArmatureComponent>(), 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~");
- }
- }
- /// <summary>
- /// 删除一个战斗者
- /// </summary>
- /// <param name="id">编号</param>
- 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);
- }
- /// <summary>
- /// 清除所有战斗者
- /// </summary>
- public void ClearAllFighter()
- {
- List<Fighter> fighters = new List<Fighter>(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();
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public Dictionary<int, string> GetFriendIID()
- {
- return this.mFriendIIDs;
- }
- /// <summary>
- /// 获取所有己方战斗者(serverId)
- /// </summary>
- /// <returns>IID列表</returns>
- public Dictionary<string, string> GetBlueFighterIID()
- {
- Dictionary<string, string> list = new Dictionary<string, string>();
- foreach (KeyValuePair<string, string> keyvalue in mFighterIIDs)
- {
- if (keyvalue.Value != string.Empty)
- {
- list.Add(mFighterList[keyvalue.Key].mSeat.ToString(), keyvalue.Value);
- }
- }
- return list;
- }
- /// <summary>
- /// 通过ServerIID获取战斗唯一ID
- /// </summary>
- /// <param name="iid"></param>
- /// <returns></returns>
- public string GetFitherIdByIID(string iid)
- {
- string result = string.Empty;
- foreach (KeyValuePair<string, string> keyvalue in mFighterIIDs)
- {
- if (keyvalue.Value == iid)
- {
- return keyvalue.Key;
- }
- }
- return result;
- }
- /// <summary>
- /// 获取战斗者
- /// </summary>
- /// <param name="id"> 玩家ID </param>
- /// <returns>战斗者实例</returns>
- public Fighter GetFighter(string id)
- {
- if (mFighterList.ContainsKey(id))
- {
- return mFighterList[id];
- }
- return null;
- }
- }
- }
|