/// <summary> /// 关闭单个面板 /// </summary> /// <param name="panelID">面板ID</param> private void HidePanelGameObject(EUIPanelID panelID) { for (int i = 0; i < m_panelsList_DynamicLoading.Count; ++i) { if (m_panelsList_DynamicLoading[i].panelID == panelID && m_panelsList_DynamicLoading[i].panelObj != null && m_panelsList_DynamicLoading[i].panelObj.activeSelf) { m_panelsList_DynamicLoading[i].panelObj.SendMessage("DestroyUIData"); m_panelsList_DynamicLoading[i].panelObj.SetActive(false); for (int index = 0; i < m_nShownPanelCount; ++index) { if (m_shownPanelIDArr[index] == panelID) { m_shownPanelIDArr[index] = m_shownPanelIDArr[m_nShownPanelCount - 1]; m_shownPanelIDArr[m_nShownPanelCount - 1] = EUIPanelID.CommonPanelsEnd; } } --m_nShownPanelCount; if (m_nShownPanelCount < 0) { CorrectShowPanelCount(); } if (OnClosePanel != null) { OnClosePanel((int)panelID); } } } }
/// <summary> /// 显示面板 /// </summary> /// <param name="panelID">面板ID</param> /// <param name="bHideOther">是否隐藏其他的面板</param> /// <param name="param"></param> public void ShowPanel(EUIPanelID panelID, bool bHideOther, object param = null) { int nIndex = (int)panelID; if (bHideOther) { if (m_nShownPanelCount > 0) { for (int i = 0; i < m_nShownPanelCount; ++i) { if (panelID != m_shownPanelIDArr[i]) { HidePanelGameObject(m_shownPanelIDArr[i]); } } } } ShowPanelGameObject(panelID, param); CheckBottomFrame(); m_priorPanelID = panelID; m_priorPanelParam = param; m_morePriorPanelID = m_priorPanelID; m_morePriorPanelParam = m_priorPanelParam; }
/// <summary> /// 检查底板是否关闭 /// </summary> private void CheckBottomFrame() { if (m_nShownPanelCount > 0) { bool bActive = false; for (int i = 0; i < m_nShownPanelCount; ++i) { if (true == m_bUseMainPanelArr[(int)m_shownPanelIDArr[i]]) { bActive = true; break; } } if (m_mainPanelGameObj.activeSelf != bActive) { m_mainPanelGameObj.SetActive(bActive); } } else { m_priorPanelID = EUIPanelID.Null; m_priorPanelParam = null; m_morePriorPanelID = EUIPanelID.Null; m_morePriorPanelParam = null; m_mainPanelGameObj.SetActive(false); } }
/// <summary> /// 各种初始化 /// </summary> void Awake() { m_instance = this; m_panelsList_DynamicLoading = new List <StruUncommonPrefab>(); //时间间隔,用来判断动态加载的面板是否可以销毁 m_nTimeInterval = 0; //倒计时总数,600秒 m_nSeconds = 600; m_nShownPanelCount = 0; m_priorPanelID = EUIPanelID.Null; m_priorPanelParam = null; m_morePriorPanelID = EUIPanelID.Null; m_morePriorPanelParam = null; m_shownPanelIDArr = new EUIPanelID[10]; m_bUseMainPanelArr = new bool[(int)EUIPanelID.AllPanelsEnd]; m_eventMgrScript = new EventMgr(); InitCommonPanels(); for (int i = 0; i < m_bUseMainPanelArr.Length; ++i) { m_bUseMainPanelArr[i] = true; } m_hintObj = Resources.Load("Prefabs/Tooltip") as GameObject; }
/// <summary> /// 设置动态加载的面板 /// [外部调用] /// </summary> /// <param name="panelID">面板ID</param> private void SetPanel_DynamicLoading(EUIPanelID panelID) { //初始化一个结构体 StruUncommonPrefab tmpUncommonObj = new StruUncommonPrefab(); //将结构体存放到列表中 m_panelsList_DynamicLoading.Add(tmpUncommonObj); //主要就是加个ID,GameObject和一个倒计时时间 //并且对GameObject进行一些设置 m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelID = panelID; //给需要长时间保持的面板,或者不通过UIMgr显示的面板一个足够长的时间 if (panelID == EUIPanelID.HelpDesPanel || panelID == EUIPanelID.HelpLeaguePanel) { m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].countDownTimer = 999999; } else { //否则就十分钟一次~ m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].countDownTimer = m_nSeconds; } m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj = GameObject.Instantiate(Resources.Load("Panels/" + panelID + "/Panel")) as GameObject; m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.name = panelID.ToString(); m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.parent = m_targetTopNode.transform; m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.localScale = Vector3.one; m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.localPosition = new Vector3(0, 0, m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.localPosition.z); //简单的初始化 PanelScript tmpScript = m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.GetComponent <PanelScript>(); tmpScript.AppInit(); m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.SetActive(true); //注册这个面板的事件 m_eventMgrScript.RegisterEvent(panelID); }
public static void UnitTest_Out() { EUIPanelID id = EUIPanelID.INT1; Color32 c = new Color32(2, 2, 3, 5); byte b = 0; c.GetA(out b); Logger.Log("a=" + b); c.GetB(ref b); Logger.Log("b=" + b); }
/// <summary> /// 判断面板是否已经打开 /// </summary> /// <param name="panelID"></param> /// <returns></returns> public bool IsPanelsShown(EUIPanelID panelID) { for (int i = 0; i < m_panelsList_DynamicLoading.Count; ++i) { if (m_panelsList_DynamicLoading[i].panelID == panelID && m_panelsList_DynamicLoading[i].panelObj.activeSelf) { return(true); } } return(false); }
/// <summary> /// 隐藏面板 /// </summary> /// <param name="panelID">面板ID</param> public void HidePanel(EUIPanelID panelID, int nType = 0) { if (nType == 0) { HidePanelGameObject(panelID); } else if (nType == 1) { HidePanelGameObject(panelID); ShowPanelGameObject(m_priorPanelID, m_priorPanelParam); } CheckBottomFrame(); m_morePriorPanelID = EUIPanelID.Null; m_morePriorPanelParam = null; m_priorPanelID = m_morePriorPanelID; m_priorPanelParam = m_morePriorPanelParam; }
/// <summary> /// 设置面板 /// </summary> /// <param name="nIndex">该面板在列表中的索引</param> /// <param name="panelID">面板ID</param> /// <param name="param"></param> private void SetPanel(int nIndex, EUIPanelID panelID, object param) { //重置时间,主要是针对普通面板 if (m_panelsList_DynamicLoading[nIndex].countDownTimer < m_nSeconds) { m_panelsList_DynamicLoading[nIndex].countDownTimer = m_nSeconds; } if (m_panelsList_DynamicLoading[nIndex].panelObj != null) { Debug.Log("Panel : " + panelID); if (!m_panelsList_DynamicLoading[nIndex].panelObj.activeSelf) { ++m_nShownPanelCount; } m_panelsList_DynamicLoading[nIndex].panelObj.SetActive(true); m_shownPanelIDArr[m_nShownPanelCount - 1] = panelID; PanelScript tmpScript = m_panelsList_DynamicLoading[nIndex].panelObj.GetComponent <PanelScript>(); tmpScript.UIParam = param; tmpScript.InitUIData(); if (panelID == EUIPanelID.GameSet) { if ((int)param == 1) { tmpScript.transform.localPosition = Vector3.forward * -1000; } else { tmpScript.transform.localPosition = Vector3.forward * -1600; } } } if (m_nShownPanelCount > m_panelsList_DynamicLoading.Count) { CorrectShowPanelCount(); } if (OnOpenPanel != null) { OnOpenPanel((int)panelID); } }
/// <summary> /// 显示面板的GameObject /// </summary> /// <param name="panelID"></param> /// <param name="param"></param> private void ShowPanelGameObject(EUIPanelID panelID, object param) { //开始设置面板 //遍历动态面板的字典~ //找到panelID,然后再把时间重置一下~ for (int i = 0; i < m_panelsList_DynamicLoading.Count; ++i) { if (m_panelsList_DynamicLoading[i].panelID == panelID) { SetPanel(i, panelID, param); return; } } //如果在动态面板列表中没有找到这个面板,就动态加载一个 SetPanel_DynamicLoading(panelID); //然后再设置 if (m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelID == panelID && m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj != null) { SetPanel(m_panelsList_DynamicLoading.Count - 1, panelID, param); } }
/// <summary> /// 关闭所有面板 /// </summary> /// <param name="bOnlyPanelWithMainPanel"></param> public void HideAll(bool bOnlyPanelWithMainPanel) { for (int nIndex = 0; nIndex < m_nShownPanelCount; ++nIndex) { for (int i = 0; i < m_panelsList_DynamicLoading.Count; ++i) { if (m_panelsList_DynamicLoading[i].panelID == m_shownPanelIDArr[nIndex]) { m_panelsList_DynamicLoading[i].panelObj.SendMessage("DestroyUIData"); m_panelsList_DynamicLoading[i].panelObj.SetActive(false); if (OnClosePanel != null) { OnClosePanel((int)m_shownPanelIDArr[nIndex]); } } } } m_nShownPanelCount = 0; m_priorPanelID = EUIPanelID.Null; m_priorPanelParam = null; m_morePriorPanelID = EUIPanelID.Null; m_morePriorPanelParam = null; m_mainPanelGameObj.SetActive(false); }
/// <summary> /// 设置面板 /// </summary> /// <param name="nIndex">该面板在列表中的索引</param> /// <param name="panelID">面板ID</param> /// <param name="param"></param> private void SetPanel(int nIndex, EUIPanelID panelID, object param) { //重置时间,主要是针对普通面板 if(m_panelsList_DynamicLoading[nIndex].countDownTimer < m_nSeconds) { m_panelsList_DynamicLoading[nIndex].countDownTimer = m_nSeconds; } if (m_panelsList_DynamicLoading[nIndex].panelObj != null) { Debug.Log("Panel : " + panelID); if (!m_panelsList_DynamicLoading[nIndex].panelObj.activeSelf) { ++m_nShownPanelCount; } m_panelsList_DynamicLoading[nIndex].panelObj.SetActive(true); m_shownPanelIDArr[m_nShownPanelCount - 1] = panelID; PanelScript tmpScript = m_panelsList_DynamicLoading[nIndex].panelObj.GetComponent<PanelScript>(); tmpScript.UIParam = param; tmpScript.InitUIData(); if (panelID == EUIPanelID.GameSet) { if ((int)param == 1) { tmpScript.transform.localPosition = Vector3.forward * -1000; } else { tmpScript.transform.localPosition = Vector3.forward * -1600; } } } if (m_nShownPanelCount > m_panelsList_DynamicLoading.Count) { CorrectShowPanelCount(); } if (OnOpenPanel != null) { OnOpenPanel((int)panelID); } }
/// <summary> /// 设置是否使用底板 /// 这个主要是用来设置不用底板的 /// </summary> /// <param name="panelID">面板ID</param> /// <param name="bUseMainPanel">是否使用底板</param> public void SetUseMainPanel(EUIPanelID panelID, bool bUseMainPanel) { m_bUseMainPanelArr[(int)panelID] = bUseMainPanel; }
/// <summary> /// 各种初始化 /// </summary> void Awake() { m_instance = this; m_panelsList_DynamicLoading = new List<StruUncommonPrefab>(); //时间间隔,用来判断动态加载的面板是否可以销毁 m_nTimeInterval = 0; //倒计时总数,600秒 m_nSeconds = 600; m_nShownPanelCount = 0; m_priorPanelID = EUIPanelID.Null; m_priorPanelParam = null; m_morePriorPanelID = EUIPanelID.Null; m_morePriorPanelParam = null; m_shownPanelIDArr = new EUIPanelID[10]; m_bUseMainPanelArr = new bool[(int)EUIPanelID.AllPanelsEnd]; m_eventMgrScript = new EventMgr(); InitCommonPanels(); for (int i = 0; i < m_bUseMainPanelArr.Length; ++i) { m_bUseMainPanelArr[i] = true; } m_hintObj = Resources.Load("Prefabs/Tooltip") as GameObject; }
static void Test_02(EUIPanelID id) { Logger.Log("test_enum.UnitTest_02"); }
/// <summary> /// 注销事件 /// Controller.Instance.Unregister(); /// </summary> /// <param name="panelID">面板ID</param> public void UnRegisterEvent(EUIPanelID panelID) { }
/// <summary> /// 隐藏面板 /// </summary> /// <param name="panelID">面板ID</param> public void HidePanel(EUIPanelID panelID,int nType = 0) { if (nType == 0) { HidePanelGameObject(panelID); } else if(nType == 1) { HidePanelGameObject(panelID); ShowPanelGameObject(m_priorPanelID,m_priorPanelParam); } CheckBottomFrame(); m_morePriorPanelID = EUIPanelID.Null; m_morePriorPanelParam = null; m_priorPanelID = m_morePriorPanelID; m_priorPanelParam = m_morePriorPanelParam; }
/// <summary> /// 设置动态加载的面板 /// [外部调用] /// </summary> /// <param name="panelID">面板ID</param> private void SetPanel_DynamicLoading(EUIPanelID panelID) { //初始化一个结构体 StruUncommonPrefab tmpUncommonObj = new StruUncommonPrefab(); //将结构体存放到列表中 m_panelsList_DynamicLoading.Add(tmpUncommonObj); //主要就是加个ID,GameObject和一个倒计时时间 //并且对GameObject进行一些设置 m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelID = panelID; //给需要长时间保持的面板,或者不通过UIMgr显示的面板一个足够长的时间 if (panelID == EUIPanelID.HelpDesPanel || panelID == EUIPanelID.HelpLeaguePanel) { m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].countDownTimer = 999999; } else { //否则就十分钟一次~ m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].countDownTimer = m_nSeconds; } m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj = GameObject.Instantiate(Resources.Load("Panels/" + panelID + "/Panel")) as GameObject; m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.name = panelID.ToString(); m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.parent = m_targetTopNode.transform; m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.localScale = Vector3.one; m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.localPosition = new Vector3(0, 0, m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.transform.localPosition.z); //简单的初始化 PanelScript tmpScript = m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.GetComponent<PanelScript>(); tmpScript.AppInit(); m_panelsList_DynamicLoading[m_panelsList_DynamicLoading.Count - 1].panelObj.SetActive(true); //注册这个面板的事件 m_eventMgrScript.RegisterEvent(panelID); }
/// <summary> /// 判断面板是否已经打开 /// </summary> /// <param name="panelID"></param> /// <returns></returns> public bool IsPanelsShown(EUIPanelID panelID) { for (int i = 0; i < m_panelsList_DynamicLoading.Count; ++i) { if (m_panelsList_DynamicLoading[i].panelID == panelID && m_panelsList_DynamicLoading[i].panelObj.activeSelf) { return true; } } return false; }