using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using System; using AX.TrackRecord; using AX.MessageSystem; public class ShowEquipSelecteWin : MonoBehaviour { GameObject canvas; public Dictionary costSelectedEquips = new Dictionary();//选择的有消耗的装备 public Dictionary unCostSelectedEquips = new Dictionary();//选择的无消耗的装备 GameObject BagEquipImg; public Dictionary test = new Dictionary(); public static ShowEquipSelecteWin Instance; void Awake() { if (Instance == null) { Instance = this; } } void OnEnable() { MessageDispatcher.AddListener("P", P); } void OnDisable() { MessageDispatcher.RemoveListener("P", P); } private void P(IMessage msg) { if (InputManager.Instance_.GetSelectedCharacters().Count > 0) { bool isExistXFy = false; foreach (var item in InputManager.Instance_.GetSelectedCharacters()) { if (item.GetComponent()) { isExistXFy = true; break; } } if (isExistXFy) { CopyTo(InputManager.Instance_.GetSelectedCharacters(), EquipSubmit.selectEquipPlayers); ShowSelectEquipUI(); //记录打开装备库事件 if (RecordManager.Instance.IsRecording) { TrackRecordHelpClass.RecordOpenEquipUIEvent(canvas.transform.Find("StorageWin").gameObject, InputManager.Instance_.GetSelectedCharacters()); } } } } // Use this for initialization void Start () { canvas = GameObject.Find("Canvas"); BagEquipImg = Resources.Load("UIPrefab/Equipment/BagEquipImg"); //testD(); } void testD() { test.Add("A", 1); test.Add("B", 3); var test2 = new Dictionary(test); test2.Add("C", 4); Debug.Log("testtttttttttt"); foreach (var kv in test) { Debug.Log(kv.Key + ":" + kv.Value); } Debug.Log("test22222222"); foreach (var kv in test2) { Debug.Log(kv.Key + ":" + kv.Value); } test.Add("D", 5); Debug.Log("testtttttttttt"); foreach (var kv in test) { Debug.Log(kv.Key + ":" + kv.Value); } Debug.Log("test22222222"); foreach (var kv in test2) { Debug.Log(kv.Key + ":" + kv.Value); } } // Update is called once per frame // void Update () { // if (Input.GetKeyDown(KeyCode.P)) // { // } //} private void ShowSelectEquipUI() { canvas.transform.Find("StorageWin").gameObject.SetActive(true); canvas.transform.Find("BagWin").gameObject.SetActive(true); DrawEquipsInBag(); OnNotifyAgainSelectEqp(); } private void CopyTo(List arry1, List arry2) { arry2.Clear(); foreach (GameObject obj in arry1) { arry2.Add(obj); } } private void DrawEquipsInBag() { RemoveAllChild(canvas.transform.Find("BagWin").Find("BagImage")); costSelectedEquips = InputManager.Instance_.GetSelectedCharacters()[0].GetComponent().costSelectedEquips; unCostSelectedEquips = InputManager.Instance_.GetSelectedCharacters()[0].GetComponent().unCostSelectedEquips; //存在消耗的装备 foreach (string key in costSelectedEquips.Keys) { string[] str = key.Split('/'); string equipSpriteNameX = str[2] + "X"; var equipSpriteX = Resources.Load("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().localScale = new Vector3(1f, 1f, 1f); equipmentSelectedImg.GetComponent().sprite = equipSpriteX.GetComponent().sprite; equipmentSelectedImg.transform.Find("Text").GetComponent().text = (costSelectedEquips[key].selectedEquipNum - costSelectedEquips[key].useNum).ToString(); equipmentSelectedImg.AddComponent(); } //不存在消耗的装备 foreach (string key in unCostSelectedEquips.Keys) { string[] str = key.Split('/'); string equipSpriteNameX = str[2] + "X"; var equipSpriteX = Resources.Load("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().localScale = new Vector3(1f, 1f, 1f); equipmentSelectedImg.GetComponent().sprite = equipSpriteX.GetComponent().sprite; equipmentSelectedImg.AddComponent(); } } public void RemoveAllChild(Transform tsf) { foreach (Transform t in tsf) { Destroy(t.gameObject); } } public static event Action NotifyAgainSelectEqp; private static void OnNotifyAgainSelectEqp() { if (NotifyAgainSelectEqp != null) NotifyAgainSelectEqp(); EquipSubmit.costSelectedEquips.Clear(); EquipSubmit.unCostSelectedEquips.Clear(); } }