天津23维预案
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.
 
 
 
 
 
 

315 lines
14 KiB

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System;
using AX.TrackRecord;
using AX.MessageSystem;
public class Bag : MonoBehaviour
{
public Dictionary<string, CostEquip> costSelectedEquips = new Dictionary<string, CostEquip>();//选择的有消耗的装备
public Dictionary<string, UnCostEquip> unCostSelectedEquips = new Dictionary<string, UnCostEquip>();//选择的无消耗的装备
GameObject canvas;
GameObject BagEquipImg;
public Texture zhanDouFu;
public Texture qiangXianJYF;
// Use this for initialization
void OnEnable()
{
if (BagEquipImg == null)
{
BagEquipImg = Resources.Load<GameObject>("UIPrefab/Equipment/BagEquipImg");
}
if (canvas == null)
{
canvas = GameObject.Find("Canvas");
}
MessageDispatcher.AddListener("B", B);
}
void OnDisable()
{
MessageDispatcher.RemoveListener("B", B);
}
private void B(IMessage msg)
{
ViewBagEquips();
}
void test()
{
CostEquip a = new CostEquip();
a.selectedEquipName = "消防高压水带";
a.selectedEquipNum = 1;
a.unit = 20;
a.useNum = 0;
costSelectedEquips.Add("消防高压水带", a);
CostEquip b = new CostEquip();
b.selectedEquipName = "救生照明线";
b.selectedEquipNum = 1;
b.unit = 100;
b.useNum = 0;
costSelectedEquips.Add("救生照明线", b);
}
// Update is called once per frame
void Update()
{
//ViewBagEquips();
//ChangeEquip();
}
public void LoadViewBagEquips()
{
//存在消耗的装备
if (costSelectedEquips.Count > 0)
{
foreach (string key in costSelectedEquips.Keys)
{
string[] str = key.Split('/');
string equipSpriteNameX = str[2] + "X";
var equipSpriteX = Resources.Load<GameObject>("UIPrefab/Equipment/" + equipSpriteNameX);
var equipmentSelectedImg = Instantiate(BagEquipImg) as GameObject;
equipmentSelectedImg.name = equipSpriteNameX.Substring(0, equipSpriteNameX.Length - 1);
equipmentSelectedImg.transform.parent = canvas.transform.Find("BagWin").Find("BagImage");
equipmentSelectedImg.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 1f);
equipmentSelectedImg.GetComponent<Image>().sprite = equipSpriteX.GetComponent<SpriteRenderer>().sprite;
equipmentSelectedImg.transform.Find("Text").GetComponent<Text>().text = (costSelectedEquips[key].selectedEquipNum - costSelectedEquips[key].useNum).ToString();
equipmentSelectedImg.AddComponent<ViewBagEquip>();
}
}
//不存在消耗的装备
if (unCostSelectedEquips.Count > 0)
{
foreach (string key in unCostSelectedEquips.Keys)
{
string[] str = key.Split('/');
string equipSpriteNameX = str[2] + "X";
var equipSpriteX = Resources.Load<GameObject>("UIPrefab/Equipment/" + equipSpriteNameX);
var equipmentSelectedImg = Instantiate(BagEquipImg) as GameObject;
equipmentSelectedImg.name = equipSpriteNameX.Substring(0, equipSpriteNameX.Length - 1);
equipmentSelectedImg.transform.parent = canvas.transform.Find("BagWin").Find("BagImage");
equipmentSelectedImg.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 1f);
equipmentSelectedImg.GetComponent<Image>().sprite = equipSpriteX.GetComponent<SpriteRenderer>().sprite;
equipmentSelectedImg.AddComponent<ViewBagEquip>();
}
}
}
private void ViewBagEquips()
{
List<GameObject> selectedCharacters = InputManager.Instance_.GetSelectedCharacters();
//显示背包,并更新所选装备数据
if (selectedCharacters.Count == 1)
{
bool isExistXFy = false;
if (selectedCharacters.Count > 0)
{
foreach (var item in selectedCharacters)
{
if (item.GetComponent<Bag>())
{
isExistXFy = true;
break;
}
}
}
if (/*Input.GetKeyDown(KeyCode.B) &&*/ isExistXFy && this.gameObject.name == selectedCharacters[0].name)
{
canvas.transform.Find("BagWin").gameObject.SetActive(true);
if (RecordManager.Instance.IsRecording)
{
TrackRecordHelpClass.RecordOpenEquipUIEvent(canvas.transform.Find("BagWin").gameObject, selectedCharacters);
}
RemoveAllChild(canvas.transform.Find("BagWin").Find("BagImage"));
//存在消耗的装备
if (costSelectedEquips.Count >0)
{
foreach (string key in costSelectedEquips.Keys)
{
string[] str = key.Split('/');
string equipSpriteNameX = str[2] + "X";
var equipSpriteX = Resources.Load<GameObject>("UIPrefab/Equipment/" + equipSpriteNameX);
var equipmentSelectedImg = Instantiate(BagEquipImg) as GameObject;
equipmentSelectedImg.name = equipSpriteNameX.Substring(0, equipSpriteNameX.Length - 1);
equipmentSelectedImg.transform.parent = canvas.transform.Find("BagWin").Find("BagImage");
equipmentSelectedImg.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 1f);
equipmentSelectedImg.GetComponent<Image>().sprite = equipSpriteX.GetComponent<SpriteRenderer>().sprite;
equipmentSelectedImg.transform.Find("Text").GetComponent<Text>().text = (costSelectedEquips[key].selectedEquipNum - costSelectedEquips[key].useNum).ToString();
equipmentSelectedImg.AddComponent<ViewBagEquip>();
}
}
//不存在消耗的装备
if (unCostSelectedEquips.Count > 0)
{
foreach (string key in unCostSelectedEquips.Keys)
{
string[] str = key.Split('/');
string equipSpriteNameX = str[2] + "X";
var equipSpriteX = Resources.Load<GameObject>("UIPrefab/Equipment/" + equipSpriteNameX);
var equipmentSelectedImg = Instantiate(BagEquipImg) as GameObject;
equipmentSelectedImg.name = equipSpriteNameX.Substring(0, equipSpriteNameX.Length - 1);
equipmentSelectedImg.transform.parent = canvas.transform.Find("BagWin").Find("BagImage");
equipmentSelectedImg.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 1f);
equipmentSelectedImg.GetComponent<Image>().sprite = equipSpriteX.GetComponent<SpriteRenderer>().sprite;
equipmentSelectedImg.AddComponent<ViewBagEquip>();
}
}
}
}
}
private void SetTopName(string typeName)
{
var topName = GetComponent<ObjMessage>().TopName;
var strs = topName.Split('-');
for (int i = 0; i < strs.Length; i++)
{
if (strs[i].Contains("服"))
{
GetComponent<ObjMessage>().TopName = topName.Replace(strs[i], typeName);
break;
}
}
}
public void ChangeEquip()
{
bool NeedKongHuQi = true;
bool HasKongHuQi = false;
//换装
if (unCostSelectedEquips.Count > 0 )
{
foreach (var item in unCostSelectedEquips)
{
if (item.Key.Contains("消防避火服"))
{
NeedKongHuQi = false;
this.transform.Find("BHF_Body").gameObject.SetActive(true);
this.transform.Find("BHF_Body").gameObject.layer = 8;
this.transform.Find("GHF_Body").gameObject.SetActive(false);
this.transform.Find("FHF_Body").gameObject.SetActive(false);
this.transform.Find("zhandoufu_yellow").gameObject.SetActive(false);
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.SetActive(false);
this.transform.Find("zhandoufu_red_zhihui").gameObject.SetActive(false);
SetTopName("避火服");
//break;
}
if (item.Key.Contains("隔热防护服"))
{
NeedKongHuQi = false;
this.transform.Find("BHF_Body").gameObject.SetActive(false);
this.transform.Find("GHF_Body").gameObject.SetActive(true);
this.transform.Find("GHF_Body").gameObject.layer = 8;
this.transform.Find("FHF_Body").gameObject.SetActive(false);
this.transform.Find("zhandoufu_yellow").gameObject.SetActive(false);
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.SetActive(false);
this.transform.Find("zhandoufu_red_zhihui").gameObject.SetActive(false);
SetTopName("隔热服");
//break;
}
if (item.Key.Contains("消防防化服"))
{
NeedKongHuQi = true;
this.transform.Find("BHF_Body").gameObject.SetActive(false);
this.transform.Find("GHF_Body").gameObject.SetActive(false);
this.transform.Find("FHF_Body").gameObject.SetActive(true);
this.transform.Find("FHF_Body").gameObject.layer = 8;
this.transform.Find("zhandoufu_yellow").gameObject.SetActive(false);
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.SetActive(false);
this.transform.Find("zhandoufu_red_zhihui").gameObject.SetActive(false);
SetTopName("防化服");
//break;
}
if (item.Key.Contains("抢险救援服"))
{
NeedKongHuQi = true;
this.transform.Find("BHF_Body").gameObject.SetActive(false);
this.transform.Find("GHF_Body").gameObject.SetActive(false);
this.transform.Find("FHF_Body").gameObject.SetActive(false);
this.transform.Find("zhandoufu_yellow").gameObject.SetActive(true);
this.transform.Find("zhandoufu_yellow").gameObject.layer = 8;
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.SetActive(false);
this.transform.Find("zhandoufu_red_zhihui").gameObject.SetActive(false);
SetTopName("救援服");
//break;
}
if (item.Key.Contains("灭火防护服"))
{
NeedKongHuQi = true;
this.transform.Find("BHF_Body").gameObject.SetActive(false);
this.transform.Find("FHF_Body").gameObject.SetActive(false);
this.transform.Find("GHF_Body").gameObject.SetActive(false);
this.transform.Find("zhandoufu_yellow").gameObject.SetActive(true);
this.transform.Find("zhandoufu_yellow").gameObject.layer = 8;
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.SetActive(false);
this.transform.Find("zhandoufu_red_zhihui").gameObject.SetActive(false);
SetTopName("战斗服");
//break;
}
if (item.Key.Contains("义务消防员"))
{
NeedKongHuQi = true;
this.transform.Find("BHF_Body").gameObject.SetActive(false);
this.transform.Find("FHF_Body").gameObject.SetActive(false);
this.transform.Find("GHF_Body").gameObject.SetActive(false);
this.transform.Find("zhandoufu_yellow").gameObject.SetActive(false);
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.SetActive(true);
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.layer = 8;
this.transform.Find("zhandoufu_red_zhihui").gameObject.SetActive(false);
SetTopName("义务消防服");
//break;
}
if (item.Key.Contains("指挥员"))
{
NeedKongHuQi = true;
this.transform.Find("BHF_Body").gameObject.SetActive(false);
this.transform.Find("FHF_Body").gameObject.SetActive(false);
this.transform.Find("GHF_Body").gameObject.SetActive(false);
this.transform.Find("zhandoufu_yellow").gameObject.SetActive(false);
this.transform.Find("zhandoufu_red_zhihui").gameObject.SetActive(true);
this.transform.Find("zhandoufu_red_zhihui").gameObject.layer = 8;
this.transform.Find("zhandoufu_green_yiwuxiaofang").gameObject.SetActive(false);
SetTopName("指挥服");
//break;
}
if (item.Key.Contains("正压式空气呼吸器"))
{
HasKongHuQi = true;
}
}
}
if (NeedKongHuQi && HasKongHuQi)
{
this.transform.Find("Bip01/Bip01 Pelvis/Bip01 Spine/Bip01 Spine1/KongHuQi").gameObject.SetActive(true);
}
else
{
this.transform.Find("Bip01/Bip01 Pelvis/Bip01 Spine/Bip01 Spine1/KongHuQi").gameObject.SetActive(false);
}
}
private void RemoveAllChild(Transform tsf)
{
foreach (Transform t in tsf)
{
Destroy(t.gameObject);
}
}
}