using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; public class CraftSelectionPanel : PopUpPanel { public GameObject craftItemPrefab; public RectTransform containerTrans; public GameObject closeBtn; public Text titleTxt; public bool useSwap; public Player myPlayer; void Start() { myPlayer = Session.GetInstance().GetBattleSession().myPlayer; List list = CraftManager.GetInstance().GetDataList(); for(int i=0; i(craftItemPrefab); craftObj.transform.SetParent(containerTrans); craftObj.transform.localPosition = Vector3.zero; craftObj.transform.localScale = new Vector3(1f, 1f, 1f); CraftSelectionItem craftSelectionItem = craftObj.GetComponent(); craftSelectionItem.craftSelectionPanel = this; craftSelectionItem.index = i; craftSelectionItem.SetCraftData(craftData); } if(useSwap) titleTxt.text = Language.GetStr("GameInfo", "swapCraft"); else titleTxt.text = Language.GetStr("GameInfo", "selectCraft"); Session.GetInstance().GetBattleSession().GetBattleController().battleUI.powerIconContainer.Hide(); } public static void SelectCraft(Player player, int craftId) { BattleSession battleSession = Session.GetInstance().GetBattleSession(); if(currentPanel != null && currentPanel.useSwap) { if (player != null) { Player.Hero hero = player.GetHero(); if(hero.GetCraft() != null) battleSession.GetMessageManager ().PrepareSwap (hero.GetCraft().id, craftId); } } else { Vector3 pos = battleSession.GetBattleController().GetMap().GetStartPosition(player); battleSession.GetMessageManager().SelectCraft(player, craftId, Map.XToColumn(pos.x), Map.ZToRow(pos.z)); } } void FixedUpdate() { if(useSwap) { Player.Hero hero = myPlayer.GetHero(); if(hero.GetCraft() == null || !hero.GetCraft().IsLeaveDamage()) Close(); } } void OnDestroy() { BattleController battleController = Session.GetInstance ().GetBattleSession ().GetBattleController (); if(battleController.GetCtrlCraft() != null) Session.GetInstance().GetBattleSession().GetBattleController().battleUI.powerIconContainer.Show(); if(BattleController.battleType == BattleController.BattleType.Menu) Session.GetInstance ().GetBattleSession ().GetBattleController ().menuUI.startBtnContainer.Show(); currentPanel = null; } public static bool IsShown() { return currentPanel != null; } private static CraftSelectionPanel currentPanel; public static CraftSelectionPanel Show(bool useSwap=false) { if(currentPanel == null) { GameObject panelObj = Instantiate(Resources.Load("Prefabs/UI/Battle/CraftSelectionPanel")); currentPanel = panelObj.GetComponent(); PopUpManager.AddToMainCanvas(panelObj); } currentPanel.useSwap = useSwap; currentPanel.closeBtn.SetActive(useSwap); if (useSwap) { Session.GetInstance ().GetBattleSession ().GetBattleController ().battleUI.powerIconContainer.Hide (); if(BattleController.battleType == BattleController.BattleType.Menu) Session.GetInstance ().GetBattleSession ().GetBattleController ().menuUI.startBtnContainer.Hide(); } return currentPanel; } public static void Hide() { if(currentPanel != null) Destroy(currentPanel.gameObject); } }