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.
184 lines
6.0 KiB
184 lines
6.0 KiB
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<string, CostEquip> costSelectedEquips = new Dictionary<string, CostEquip>();//选择的有消耗的装备 |
|
public Dictionary<string, UnCostEquip> unCostSelectedEquips = new Dictionary<string, UnCostEquip>();//选择的无消耗的装备 |
|
GameObject BagEquipImg; |
|
|
|
public Dictionary<string, int> test = new Dictionary<string, int>(); |
|
|
|
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<Bag>()) |
|
{ |
|
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<GameObject>("UIPrefab/Equipment/BagEquipImg"); |
|
//testD(); |
|
} |
|
void testD() |
|
{ |
|
test.Add("A", 1); |
|
test.Add("B", 3); |
|
|
|
|
|
var test2 = new Dictionary<string, int>(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<GameObject> arry1, List<GameObject> 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<Bag>().costSelectedEquips; |
|
unCostSelectedEquips = InputManager.Instance_.GetSelectedCharacters()[0].GetComponent<Bag>().unCostSelectedEquips; |
|
|
|
//存在消耗的装备 |
|
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>(); |
|
} |
|
|
|
//不存在消耗的装备 |
|
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>(); |
|
} |
|
} |
|
|
|
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(); |
|
} |
|
}
|
|
|