You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
260 lines
7.8 KiB
260 lines
7.8 KiB
using AX.MessageSystem; |
|
using AX.NetworkSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UniRx; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class EquipManager : Singleton<EquipManager> |
|
{ |
|
// 当前客户端的所有消防员 |
|
public List<Bags> ClientFireManBags = new List<Bags>(); |
|
public Dictionary<string, Equip> Equips = new Dictionary<string, Equip>(); |
|
public Dictionary<string, List<string>> Groups = new Dictionary<string, List<string>>(); |
|
// 当前客户端移动水炮数量 |
|
public IntReactiveProperty MovingWaterGun = new IntReactiveProperty(); |
|
// 当前客户端暴风雪炮数量 |
|
public IntReactiveProperty SnowstormGun = new IntReactiveProperty(); |
|
// 当前客户端灭火机器人数量 |
|
public IntReactiveProperty FireFightingRobot = new IntReactiveProperty(); |
|
// 当前客户端水幕水带数量 |
|
public IntReactiveProperty WaterBag = new IntReactiveProperty(); |
|
// 水幕水带长度 |
|
public float WaterHoseLenght = 0; |
|
// 当前选中的背包 |
|
public Bags CurrentSelectedBag = null; |
|
/// <summary> |
|
/// 移动水炮绑定数据UGUI |
|
/// </summary> |
|
/// <param name="text">UGUI文本控件Text</param> |
|
public void MovingWaterGunBindText(Text text) |
|
{ |
|
MovingWaterGun.SubscribeToText(text).AddTo(this); |
|
} |
|
public void ResetEquipmanage() |
|
{ |
|
foreach (var item in ClientFireManBags) |
|
{ |
|
item.EquipData = null; |
|
item.OnAddEquip = null; |
|
} |
|
ClientFireManBags.Clear(); |
|
MovingWaterGun = new IntReactiveProperty(); |
|
SnowstormGun = new IntReactiveProperty(); |
|
FireFightingRobot = new IntReactiveProperty(); |
|
WaterBag = new IntReactiveProperty(); |
|
CurrentSelectedBag = null; |
|
} |
|
/// <summary> |
|
/// 暴风雪炮绑定数据UGUI |
|
/// </summary> |
|
/// <param name="text">UGUI文本控件Text</param> |
|
public void SnowstormGunBindText(Text text) |
|
{ |
|
SnowstormGun.SubscribeToText(text).AddTo(this); |
|
} |
|
/// <summary> |
|
/// 灭火机器人绑定数据UGUI |
|
/// </summary> |
|
/// <param name="text">UGUI文本控件Text</param> |
|
public void FireFightingRobotBindText(Text text) |
|
{ |
|
FireFightingRobot.SubscribeToText(text).AddTo(this); |
|
} |
|
/// <summary> |
|
/// 水幕水带绑定数据UGUI |
|
/// </summary> |
|
/// <param name="text">UGUI文本控件Text</param> |
|
public void WaterBagBindText(Text text) |
|
{ |
|
WaterBag.SubscribeToText(text).AddTo(this); |
|
} |
|
private void Awake() |
|
{ |
|
HAND_OVER_SYNC.OnHandOverPower += RemoveClientFireMans; |
|
HAND_OVER_SYNC.OnReceivePower += AddClientFireMans; |
|
InitData(); |
|
InitGroups(); |
|
} |
|
|
|
//初始化数据 |
|
public void InitData() |
|
{ |
|
Equips.Clear(); |
|
List<Equip> tempData = ResourceManager.LoadJson<List<Equip>>("Equip.json"); |
|
foreach (var item in tempData) |
|
{ |
|
Equips.Add(item.ID, item); |
|
} |
|
} |
|
public void InitGroups() |
|
{ |
|
List<EquipGroup> tempData = ResourceManager.LoadJson<List<EquipGroup>>("EquipGroup.json"); |
|
foreach (var item in tempData) |
|
{ |
|
Groups.Add(item.Name, item.Types); |
|
} |
|
} |
|
// 根据装备名称获取当前客户端某装备数量 |
|
private int GetClientEquipCount(string name) |
|
{ |
|
int count = 0; |
|
// 获取本客户端的所有背包 |
|
foreach (var item in ClientFireManBags) |
|
{ |
|
Equip temp = item.GetEquip(name); |
|
if (temp!=null) |
|
{ |
|
count += temp.Number; |
|
} |
|
} |
|
return count; |
|
} |
|
// 使用当前客户端某件装备数量一 |
|
public void UseClientEquip(string name) |
|
{ |
|
foreach (var item in ClientFireManBags) |
|
{ |
|
if (item.HasEquip(name)) |
|
{ |
|
item.UseEquip(name); |
|
return; |
|
} |
|
} |
|
} |
|
/// <summary> |
|
/// 使用客户端水幕水带 |
|
/// </summary> |
|
/// <param name="length">需要累加的长度</param> |
|
public void UseClientWaterHose(float length) |
|
{ |
|
WaterHoseLenght += length; |
|
foreach (var item in ClientFireManBags) |
|
{ |
|
if (item.HasEquip("水幕水带")) |
|
{ |
|
if (WaterHoseLenght>=25) |
|
{ |
|
WaterHoseLenght -= 25; |
|
item.UseEquip("水幕水带"); |
|
} |
|
return; |
|
} |
|
} |
|
} |
|
//查询指定装备ID |
|
public List<string> Serch(string typeName, string groupName) |
|
{ |
|
List<string> ids = new List<string>(); |
|
foreach (var item in Equips.Values) |
|
{ |
|
if (item.Type.Equals(typeName) && item.Group.Contains(groupName)) |
|
{ |
|
ids.Add(item.ID); |
|
} |
|
} |
|
return ids; |
|
} |
|
//根据装备ID获取指定装备 |
|
public Equip GetEquipByID(string id) |
|
{ |
|
if (Equips.ContainsKey(id)) |
|
{ |
|
return Equips[id]; |
|
} |
|
return null; |
|
} |
|
|
|
public void CheckSelectGroup(Equip equip) |
|
{ |
|
foreach (var item in Equips.Values) |
|
{ |
|
if (item.SelectGroup == equip.SelectGroup && item != equip) |
|
{ |
|
if (item.IsSelected == true) |
|
{ |
|
item.IsSelected = false; |
|
//取消选中数量要归0 |
|
item.Number = 0; |
|
//需要刷新UI |
|
MessageDispatcher.SendMessage("REFRESH_UIVIEW_EQUIPLIB"); |
|
} |
|
} |
|
} |
|
} |
|
// 添加选择物体到当前背包 |
|
internal void AddSelectedEquipToBag() |
|
{ |
|
if (CurrentSelectedBag != null) |
|
{ |
|
foreach (var item in Equips.Values) |
|
{ |
|
if (item.IsSelected) |
|
{ |
|
item.IsSelected = false; |
|
CurrentSelectedBag.AddEquip(item); |
|
} |
|
} |
|
} |
|
MessageDispatcher.SendMessage("REFRESH_UIVIEW_BAG"); |
|
//同步背包数据到其他客户端 |
|
BagDataSync(CurrentSelectedBag); |
|
} |
|
// 强制刷新背包方法 |
|
public void RefreshUIViewBag() |
|
{ |
|
MessageDispatcher.SendMessage("REFRESH_UIVIEW_BAG"); |
|
} |
|
public void BagDataSync(Bags bag) |
|
{ |
|
long gameObjectID = bag.GetGameObjectID(); |
|
BagDataSync data = new BagDataSync() |
|
{ |
|
GameObjectID = gameObjectID, |
|
BagData = bag.EquipData |
|
}; |
|
// 防止异常 |
|
if (NetworkManager.Default != null) |
|
{ |
|
NetworkManager.Default.SendAsync("BAG_DATA_SYNC", data); |
|
} |
|
} |
|
public void AddClientFireMans(GameObject go) |
|
{ |
|
CloneGameObjInfo info = go.GetComponent<CloneGameObjInfo>(); |
|
if (info.UserID.Equals(CurrentUserInfo.mySelf.Id) && |
|
info.gameObjType == CloneObjType.fireman) |
|
{ |
|
Bags bag = go.GetComponent<Bags>(); |
|
ClientFireManBags.Add(bag); |
|
// 更新装备数量 |
|
UpdateClientEquipCount(); |
|
} |
|
} |
|
public void RemoveClientFireMans(GameObject go) |
|
{ |
|
Bags bag = go.GetComponent<Bags>(); |
|
if (ClientFireManBags.Contains(bag)) |
|
{ |
|
ClientFireManBags.Remove(bag); |
|
// 更新装备数量 |
|
UpdateClientEquipCount(); |
|
} |
|
} |
|
public void UpdateClientEquipCount() |
|
{ |
|
MovingWaterGun.Value = GetClientEquipCount("移动水炮"); |
|
SnowstormGun.Value = GetClientEquipCount("暴风雪炮"); |
|
FireFightingRobot.Value = GetClientEquipCount("灭火机器人"); |
|
WaterBag.Value = GetClientEquipCount("水幕水带"); |
|
} |
|
|
|
private new void OnDestroy() |
|
{ |
|
base.OnDestroy(); |
|
HAND_OVER_SYNC.OnHandOverPower -= RemoveClientFireMans; |
|
HAND_OVER_SYNC.OnReceivePower -= AddClientFireMans; |
|
} |
|
}
|
|
|