/// <summary>
    /// 打开UI
    /// </summary>
    /// <param name="UIName">UI名</param>
    /// <param name="callback">动画播放完毕回调</param>
    /// <param name="objs">回调传参</param>`
    /// <returns>返回打开的UI</returns>
    public static UIWindowBase OpenUIWindow(string UIName, UICallBack callback = null, params object[] objs)
    {
        UIWindowBase UIbase = GetHideUI(UIName);

        if (UIbase == null)
        {
            UIbase = CreateUIWindow(UIName);
        }

        RemoveHideUI(UIbase);
        AddUI(UIbase);

        UIStackManager.OnUIOpen(UIbase);
        UILayerManager.SetLayer(UIbase);      //设置层级

        UIbase.windowStatus = UIWindowBase.WindowStatus.OpenAnim;

        UISystemEvent.Dispatch(UIbase, UIEvent.OnOpen);  //派发OnOpen事件
        try
        {
            UIbase.OnOpen();
        }
        catch (Exception e)
        {
            Debug.LogError(UIName + " OnOpen Exception: " + e.ToString());
        }


        UIAnimManager.StartEnterAnim(UIbase, callback, objs); //播放动画
        return(UIbase);
    }
Beispiel #2
0
    public static UIWindowBase CreateUIWindow(string UIName)
    {
        Debug.Log("CreateUIWindow " + UIName);

        GameObject   UItmp        = GameObjectManager.CreateGameObjectByPool(UIName, UIManagerGo);
        UIWindowBase UIWIndowBase = UItmp.GetComponent <UIWindowBase>();

        UISystemEvent.Dispatch(UIWIndowBase, UIEvent.OnInit);  //派发OnInit事件

        UIWIndowBase.windowStatus = UIWindowBase.WindowStatus.Create;

        try
        {
            UIWIndowBase.InitWindow(GetUIID(UIName));
        }
        catch (Exception e)
        {
            Debug.LogError(UIName + "OnInit Exception: " + e.ToString());
        }

        AddHideUI(UIWIndowBase);

        UILayerManager.SetLayer(UIWIndowBase);      //设置层级

        return(UIWIndowBase);
    }
    public static void CreatUI(string l_UIWindowName, UIType l_UIType, UILayerManager l_UILayerManager, bool l_isAutoCreatePrefab)
    {
        GameObject l_uiGo = new GameObject(l_UIWindowName);

        Type         type        = EditorTool.GetType(l_UIWindowName);
        UIWindowBase l_uiBaseTmp = l_uiGo.AddComponent(type) as UIWindowBase;

        l_uiGo.layer = LayerMask.NameToLayer("UI");

        l_uiBaseTmp.m_UIType = l_UIType;

        l_uiGo.AddComponent <Canvas>();
        l_uiGo.AddComponent <GraphicRaycaster>();

        RectTransform l_ui = l_uiGo.GetComponent <RectTransform>();

        l_ui.sizeDelta = Vector2.zero;
        l_ui.anchorMin = Vector2.zero;
        l_ui.anchorMax = Vector2.one;

        GameObject l_BgGo = new GameObject("BG");

        l_BgGo.layer = LayerMask.NameToLayer("UI");
        RectTransform l_Bg = l_BgGo.AddComponent <RectTransform>();

        l_Bg.SetParent(l_ui);
        l_Bg.sizeDelta = Vector2.zero;
        l_Bg.anchorMin = Vector2.zero;
        l_Bg.anchorMax = Vector2.one;

        GameObject l_rootGo = new GameObject("root");

        l_rootGo.layer = LayerMask.NameToLayer("UI");
        RectTransform l_root = l_rootGo.AddComponent <RectTransform>();

        l_root.SetParent(l_ui);
        l_root.sizeDelta = Vector2.zero;
        l_root.anchorMin = Vector2.zero;
        l_root.anchorMax = Vector2.one;

        l_uiBaseTmp.m_bgMask = l_BgGo;
        l_uiBaseTmp.m_uiRoot = l_rootGo;

        if (l_UILayerManager)
        {
            l_UILayerManager.SetLayer(l_uiBaseTmp);
        }

        if (l_isAutoCreatePrefab)
        {
            string Path = "Resources/UI/" + l_UIWindowName + "/" + l_UIWindowName + ".prefab";
            FileTool.CreatFilePath(Application.dataPath + "/" + Path);
            PrefabUtility.CreatePrefab("Assets/" + Path, l_uiGo, ReplacePrefabOptions.ConnectToPrefab);
        }

        ProjectWindowUtil.ShowCreatedAsset(l_uiGo);
    }
Beispiel #4
0
    public static void CreatUIbyLua(string UIWindowName, UIType UIType, UILayerManager UILayerManager, bool isAutoCreatePrefab)
    {
        GameObject uiGo = new GameObject(UIWindowName);

        UIWindowLuaHelper uiBaseTmp = uiGo.AddComponent <UIWindowLuaHelper>();

        uiGo.layer = LayerMask.NameToLayer("UI");

        uiBaseTmp.m_UIType = UIType;

        uiGo.AddComponent <Canvas>();
        uiGo.AddComponent <GraphicRaycaster>();

        RectTransform ui = uiGo.GetComponent <RectTransform>();

        ui.sizeDelta = Vector2.zero;
        ui.anchorMin = Vector2.zero;
        ui.anchorMax = Vector2.one;

        GameObject BgGo = new GameObject("BG");

        BgGo.layer = LayerMask.NameToLayer("UI");
        RectTransform Bg = BgGo.AddComponent <RectTransform>();

        Bg.SetParent(ui);
        Bg.sizeDelta = Vector2.zero;
        Bg.anchorMin = Vector2.zero;
        Bg.anchorMax = Vector2.one;

        GameObject rootGo = new GameObject("root");

        rootGo.layer = LayerMask.NameToLayer("UI");
        RectTransform root = rootGo.AddComponent <RectTransform>();

        root.SetParent(ui);
        root.sizeDelta = Vector2.zero;
        root.anchorMin = Vector2.zero;
        root.anchorMax = Vector2.one;

        uiBaseTmp.m_bgMask = BgGo;
        uiBaseTmp.m_uiRoot = rootGo;

        if (UILayerManager)
        {
            UILayerManager.SetLayer(uiBaseTmp);
        }

        if (isAutoCreatePrefab)
        {
            string Path = "Resources/UI/" + UIWindowName + "/" + UIWindowName + ".prefab";
            FileTool.CreatFilePath(Application.dataPath + "/" + Path);
            PrefabUtility.CreatePrefab("Assets/" + Path, uiGo, ReplacePrefabOptions.ConnectToPrefab);
        }

        ProjectWindowUtil.ShowCreatedAsset(uiGo);
    }
Beispiel #5
0
    public static UIWindowBase CreateUIWindow(string UIName)
    {
        GameObject   UItmp  = GameObjectManager.CreateGameObject(UIName, s_UIManagerGo);
        UIWindowBase UIbase = UItmp.GetComponent <UIWindowBase>();

        UISystemEvent.Dispatch(UIbase, UIEvent.OnInit);  //派发OnInit事件
        try{
            UIbase.Init(GetUIID(UIName));
        }
        catch (Exception e)
        {
            Debug.LogError("OnInit Exception: " + e.ToString());
        }

        AddHideUI(UIbase);

        s_UILayerManager.SetLayer(UIbase);      //设置层级

        return(UIbase);
    }
Beispiel #6
0
    /// <summary>
    /// 创建UI,存放在Hide列表中
    /// </summary>
    /// <param name="UIName"></param>
    /// <returns></returns>
    public static UIWindowBase CreateUIWindow(string UIName)
    {
        var uiTmp  = GameObjectManager.Instance.CreatePoolObject(UIName, m_instance);
        var uiBase = uiTmp.GetComponent <UIWindowBase>();

        //派发OnInit事件
        UISystemEvent.Dispatch(uiBase, UIEvent.OnInit);

        try
        {
            uiBase.Init(GetUIID(UIName));
        }
        catch (Exception e)
        {
            Debug.LogError("OnInit Exception: " + e.ToString());
        }

        AddHideUI(uiBase);

        m_uiLayerManager.SetLayer(uiBase);      //设置层级

        return(uiBase);
    }
 /// <summary>
 /// 将一个UI重新放回它原本的UICamera下
 /// </summary>
 /// <param name="ui"></param>
 /// <param name="cameraKey"></param>
 public static void ResetUICamera(UIWindowBase ui)
 {
     UILayerManager.SetLayer(ui, ui.cameraKey);
 }
 /// <summary>
 /// 将一个UI移动到另一个UICamera下
 /// </summary>
 /// <param name="ui"></param>
 /// <param name="cameraKey"></param>
 public static void ChangeUICamera(UIWindowBase ui, string cameraKey)
 {
     UILayerManager.SetLayer(ui, cameraKey);
 }
Beispiel #9
0
    public static void CreatUI(string UIWindowName, string UIcameraKey, UIType UIType, UILayerManager UILayerManager, bool isAutoCreatePrefab)
    {
        GameObject uiGo = new GameObject(UIWindowName);

        Type         type      = EditorTool.GetType(UIWindowName);
        UIWindowBase uiBaseTmp = uiGo.AddComponent(type) as UIWindowBase;

        uiGo.layer = LayerMask.NameToLayer("UI");

        uiBaseTmp.m_UIType = UIType;

        Canvas canvas = uiGo.AddComponent <Canvas>();

        if (EditorExpand.isExistShortLayer(UIType.ToString()))
        {
            canvas.overrideSorting  = true;
            canvas.sortingLayerName = UIType.ToString();
        }

        uiGo.AddComponent <GraphicRaycaster>();

        RectTransform ui = uiGo.GetComponent <RectTransform>();

        ui.sizeDelta = Vector2.zero;
        ui.anchorMin = Vector2.zero;
        ui.anchorMax = Vector2.one;

        GameObject BgGo = new GameObject("BG");

        BgGo.layer = LayerMask.NameToLayer("UI");
        RectTransform Bg = BgGo.AddComponent <RectTransform>();

        Bg.SetParent(ui);
        Bg.sizeDelta = Vector2.zero;
        Bg.anchorMin = Vector2.zero;
        Bg.anchorMax = Vector2.one;

        GameObject rootGo = new GameObject("root");

        rootGo.layer = LayerMask.NameToLayer("UI");
        RectTransform root = rootGo.AddComponent <RectTransform>();

        root.SetParent(ui);
        root.sizeDelta = Vector2.zero;
        root.anchorMin = Vector2.zero;
        root.anchorMax = Vector2.one;

        uiBaseTmp.m_bgMask = BgGo;
        uiBaseTmp.m_uiRoot = rootGo;

        if (UILayerManager)
        {
            UILayerManager.SetLayer(uiBaseTmp);
        }

        if (isAutoCreatePrefab)
        {
            string Path = "Resources/UI/" + UIWindowName + "/" + UIWindowName + ".prefab";
            FileTool.CreatFilePath(Application.dataPath + "/" + Path);
            PrefabUtility.CreatePrefab("Assets/" + Path, uiGo, ReplacePrefabOptions.ConnectToPrefab);
        }

        ProjectWindowUtil.ShowCreatedAsset(uiGo);
    }