Exemple #1
0
    //~~~~~~~~~~~~~~~~~~~~~~~显示~~~~~~~~~~~~~~~~~~~~~~~~//
    /// <summary>
    /// 显示入口
    /// </summary>
    public GameObject Show(int id)
    {
        //从缓存中查找
        GameObject obj;

        if (m_DicUIView.TryGetValue(id, out obj))
        {
            if (obj != null)
            {
                obj.SetActive(true);
                return(obj);
            }
            else
            {
                m_DicUIView.Remove(id);
            }
        }

        //获取数据
        SUILoaderInfo info;

        if (m_DicLoaderInfo.TryGetValue(id, out info) == false)
        {
            Log.Error("UIManager::Show - not find id:" + info.mID.ToString());
            return(null);
        }

        //加载
        Object res = LoaderResByName(info.mPathName);

        if (res == null)
        {
            Log.Error("UIManager::Show - res loader error:" + info.mPathName);
            return(null);
        }

        //layer
        Transform layer = UILayerUtils.GetLayer(info.mLayer);

        if (layer == null)
        {
            Log.Warning("UIManager::Show - not find layer:" + info.mLayer.ToString());
            layer = UILayerUtils.RootLayer;
        }
        if (layer == null)
        {
            Log.Error("UIManager::Show - not set layer");
            return(null);
        }

        //构建
        obj = GameObject.Instantiate(res) as GameObject;
        obj.transform.SetParent(layer.transform, false);
        m_DicUIView.Add(id, obj);

        //设置层级
        ResetSortingOrder((int)id);

        return(obj);
    }
Exemple #2
0
    public void ShowConfirm(int id, string content, string ok_name, string cancel_name, System.Action <eAlertBtnType> fun)
    {
        //layer
        Transform layer = UILayerUtils.GetLayer((int)eUILayer.TOP);

        if (layer == null)
        {
            Log.Warning("AlertManager::Show - not find layer:" + eUILayer.TOP);
            layer = UILayerUtils.RootLayer;
        }

        //构建
        GameObject obj = UIManager.Instance.Show(id);

        if (obj == null)
        {
            return;
        }

        GameObjectUtils.SetLayer(obj, LayerMask.NameToLayer(SceneLayerID.UI));
        m_AlertView = obj.GetComponent <AlertView>() as AlertView;
        if (m_AlertView == null)
        {
            m_AlertView = obj.AddComponent <AlertView>() as AlertView;
        }

        //更新数据
        m_AlertView         = obj.GetComponent <AlertView>();
        m_AlertView.Content = content;
        m_AlertView.DicBtn.Add(eAlertBtnType.OK, ok_name);
        m_AlertView.DicBtn.Add(eAlertBtnType.CANCEL, cancel_name);
        m_AlertView.Fun = fun;
        m_AlertView.Show();
    }
Exemple #3
0
    //~~~~~~~~~~~~~~~~~~~~~~~渲染层级~~~~~~~~~~~~~~~~~~~~~~~~//
    /// <summary>
    /// 重设UI渲染层级
    /// </summary>
    /// <param name="id"></param>
    public void ResetSortingOrder(int id)
    {
        GameObject obj = UIManager.Instance.Find(id);

        if (obj == null)
        {
            return;
        }
        UIPanelBase currView = obj.GetComponent <UIPanelBase>();

        if (currView == null)
        {
            return;
        }

        currView.MaxSortingOrder = 0;
        int        UILayerID             = UIManager.Instance.GetUILayerID(id);
        GameObject layer                 = UILayerUtils.GetLayer(UILayerID).gameObject;
        int        maxCanvasSortingOrder = GetMaxCanvasSortingOrder(layer);
        Canvas     currCanvas            = obj.GetComponent <Canvas>();

        if (currCanvas == null)
        {
            currCanvas = obj.AddComponent <Canvas>();
        }
        if (maxCanvasSortingOrder != -1)
        {
            currCanvas.overrideSorting = true;
            if (maxCanvasSortingOrder == 0)
            {
                currCanvas.sortingOrder  = UILayerID * UIID.OrderLyaerInterval;
                currView.MaxSortingOrder = UILayerID * UIID.OrderLyaerInterval;
            }
            else
            {
                currCanvas.sortingOrder  = maxCanvasSortingOrder + 1;
                currView.MaxSortingOrder = maxCanvasSortingOrder + 1;
            }
        }

        // 加射线
        GraphicRaycaster cast = obj.GetComponent <GraphicRaycaster>();

        if (cast == null)
        {
            cast = obj.AddComponent <GraphicRaycaster>();
        }

        CanvasGroup canvasGroup = obj.GetComponent <CanvasGroup>();

        if (canvasGroup == null)
        {
            canvasGroup = obj.AddComponent <CanvasGroup>();
        }
    }