Exemplo n.º 1
0
    /// <summary>
    /// 设置指定UI的遮罩状态
    /// </summary>
    /// <param name="displayUIForms">需要为其服务的UIGameObject,比如UIMain所挂载的对象</param>
    /// <param name="transparent">透明度级别</param>
    public void SetMaskWindow(GameObject displayUIForms, UITransparentEnum transparent = UITransparentEnum.NoPenetratingTotal)
    {
        //顶层窗体下移
        _topPanel.transform.SetAsLastSibling();
        //开启并设定遮罩级别
        SetMaskEnable(transparent);
        //推送消息
        MaskEnableEventHandler?.Invoke(_maskImage.enabled);

        //遮罩窗体下移
        _maskPanel.transform.SetAsLastSibling();
        //显示窗体的下移
        displayUIForms.transform.SetAsLastSibling();
        ////增加当前UI摄像机的层深,保证当前摄像机为最前显示
        //if ( _uiCamera != null )
        //    _uiCamera.depth += 100;
    }
Exemplo n.º 2
0
    /// <summary>
    /// 根据传入枚举类型,激活蒙版并完成对应显示状态
    /// </summary>
    /// <param name="transparent">透明度级别</param>
    public void SetMaskEnable(UITransparentEnum transparent = UITransparentEnum.NoPenetratingTotal)
    {
        switch (transparent)
        {
        case UITransparentEnum.NoPenetratingLow:
            //_maskPanel.SetActive( true );
            _maskImage.enabled       = true;
            _color.a                 = 255F / 255F;
            _maskImage.color         = _color;
            _maskImage.raycastTarget = true;
            break;

        //半透明
        case UITransparentEnum.NoPenetratingMiddle:
            //_maskPanel.SetActive( true );
            _maskImage.enabled       = true;
            _color.a                 = 175F / 255F;
            _maskImage.color         = _color;
            _maskImage.raycastTarget = true;
            break;

        //完全透明
        case UITransparentEnum.NoPenetratingTotal:
            //_maskPanel.SetActive( true );
            _maskImage.enabled       = true;
            _color.a                 = 0F / 255F;
            _maskImage.color         = _color;
            _maskImage.raycastTarget = true;
            break;

        //可以穿透
        case UITransparentEnum.Penetrating:
            if (_maskImage.enabled /*_maskPanel.activeInHierarchy*/)
            {
                _maskImage.enabled = false;
            }                                                                                        /* _maskPanel.SetActive( false )*/
            ;
            _maskImage.raycastTarget = false;
            break;
        }
    }
Exemplo n.º 3
0
    void OnGUI()
    {
        //必选项:类名
        GUILayout.Label("脚本类名(UI+类名) 例如:UIMain");
        uiScriptsName = EditorGUILayout.TextField(uiScriptsName);

        //选填
        GUILayout.Label("类说明,建议写UI界面类型,例如:主界面");
        uiSummary = EditorGUILayout.TextField(uiSummary);

        uiNodeType    = ( UINodeTypeEnum )EditorGUILayout.EnumPopup("挂载节点", uiNodeType);
        uiShowMode    = ( UIShowModeEnum )EditorGUILayout.EnumPopup("窗体显示方式", uiShowMode);
        uiTransparent = ( UITransparentEnum )EditorGUILayout.EnumPopup("窗体背后的遮罩透明度", uiTransparent);

        EditorGUILayout.Space();

        //勾选项
        useOnEnable_OnDisable = EditorGUILayout.Toggle("OnEnable/OnDisable", useOnEnable_OnDisable);
        useDefaultExitBtn     = EditorGUILayout.Toggle("退出按钮", useDefaultExitBtn);
        if (useDefaultExitBtn)
        {
            useOnEnable_OnDisable = useDefaultExitBtn ? true : EditorGUILayout.Toggle("启用OnEnable/OnDisable", useOnEnable_OnDisable);
        }
        useAnimRoot = EditorGUILayout.Toggle("动画控制器", useAnimRoot);
        if (useAnimRoot)
        {
            animStartID = EditorGUILayout.TextField("    弹出动画ID", animStartID);
            animCloseID = EditorGUILayout.TextField("    关闭动画ID", animCloseID);
        }

        EditorGUILayout.Space();

        using (new BackgroundColorScope(Color.green))
        {
            if (GUILayout.Button("创建脚本+UI预制件+注册绑定", GUILayout.Height(40)))
            {
                _saveLocalFileInfo = new FileInfo(Application.dataPath + "/Editor/" + GlobalEditorSetting.JSON_FILE_NAME);

                if (CheckClassNameValid())
                {
                    isDirty = true;

                    EditorUtility.DisplayProgressBar("生成UI模块", "", 1f);

                    //CS 脚本
                    UICreateParse cs        = new UICreateParse();
                    string        csOutPath = Application.dataPath + "/Scripts/UI";
                    if (!FrameworkConfig.Instance.UseHotFixMode)
                    {
                        csOutPath = Application.dataPath + "/Scripts/UI";
                    }
                    else
                    {
                        csOutPath = Application.dataPath + "/Scripts/ILRuntime/HotFixLogic/UI";
                    }
                    EditorMenuExtention.CreateCSFile(csOutPath, uiScriptsName + ".cs", cs.CreateCS(this));
                    AssetDatabase.Refresh();

                    //预制件
                    newCanvas            = new GameObject("Canvas_" + uiScriptsName.Substring(2), typeof(Canvas)).GetComponent <Canvas>();
                    newCanvas.renderMode = RenderMode.ScreenSpaceOverlay;

                    var canvasScaler = newCanvas.gameObject.AddComponent <CanvasScaler>();
                    canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize;

                    var graphics = newCanvas.gameObject.AddComponent <GraphicRaycaster>();
                    graphics.ignoreReversedGraphics = true;
                    graphics.blockingObjects        = GraphicRaycaster.BlockingObjects.None;

                    GameObject animTrans = new GameObject("Container_Anim", typeof(RectTransform));
                    animTrans.transform.SetParent(newCanvas.transform);
                    var recTrans = animTrans.GetComponent <RectTransform>();
                    recTrans.sizeDelta                = Vector2.zero;
                    recTrans.anchorMin                = Vector2.zero;
                    recTrans.anchorMax                = Vector2.one;
                    recTrans.anchoredPosition         = Vector2.zero;
                    animTrans.transform.localPosition = Vector3.zero;
                    animTrans.transform.localScale    = Vector3.one;

                    if (useAnimRoot)
                    {
                        //DOTEEN插件未集成在编辑器库中,引出到库外部使用
                        CreateAnimationComponentEvent?.Invoke(animTrans, animStartID, animCloseID);
                    }

                    if (useDefaultExitBtn)
                    {
                        GameObject btnExit = new GameObject("Btn_Exit", typeof(RectTransform));
                        btnExit.AddComponent <CanvasRenderer>();
                        btnExit.AddComponent <Image>().maskable = false;
                        btnExit.AddComponent <Button>();
                        btnExit.transform.SetParent(animTrans.transform);
                        btnExit.transform.localPosition = Vector3.zero;
                        btnExit.transform.localScale    = Vector3.one;
                    }

                    //Layer设定
                    ChangeUILayer(newCanvas.transform, "UI");

                    //预制件自注册
                    RigisterUIPath(uiScriptsName);

                    AssetDatabase.Refresh();
                }
                else
                {
                    EditorUtility.DisplayDialog("类名错误", "类名应该不为空、空格,并且以UI开头", "哦");
                }
            }
        }

        EditorGUILayout.Space();

        using (new BackgroundColorScope(Color.green))
        {
            if (GUILayout.Button("仅创建脚本", GUILayout.Height(40)))
            {
                _saveLocalFileInfo = new FileInfo(Application.dataPath + "/Editor/" + GlobalEditorSetting.JSON_FILE_NAME);

                if (CheckClassNameValid())
                {
                    //CS 脚本
                    UICreateParse cs        = new UICreateParse();
                    string        csOutPath = Application.dataPath + "/Scripts/UI";

                    if (!FrameworkConfig.Instance.UseHotFixMode)
                    {
                        csOutPath = Application.dataPath + "/Scripts/UI";
                    }
                    else
                    {
                        csOutPath = Application.dataPath + "/Scripts/ILRuntime/HotFixLogic/UI";
                    }


                    EditorMenuExtention.CreateCSFile(csOutPath, uiScriptsName + ".cs", cs.CreateCS(this));
                    AssetDatabase.Refresh();
                }
                else
                {
                    EditorUtility.DisplayDialog("类名错误", "类名应该不为空、空格,并且以UI开头", "哦");
                }
            }
        }

        EditorGUILayout.Space();

        using (new BackgroundColorScope(Color.yellow))
        {
            if (GUILayout.Button("更新UI配置", GUILayout.Height(40)))
            {
                _saveLocalFileInfo = new FileInfo(Application.dataPath + "/Editor/" + GlobalEditorSetting.JSON_FILE_NAME);

                //============JSON文件取出============//
                ResPathTemplate rpt = null;
                //如果文件存在,则读取解析为存储类,写入相关数据条后写入JSON并保存
                if (DocumentAccessor.IsExists(Application.dataPath + "/Editor/" + GlobalEditorSetting.JSON_FILE_NAME))
                {
                    var content = DocumentAccessor.ReadFile(Application.dataPath + "/Editor/" + GlobalEditorSetting.JSON_FILE_NAME);

                    rpt = JsonMapper.ToObject <ResPathTemplate>(content);
                }
                //如果文件不存在,则新建存储类,并保存相关的数据,然后写入JSON并保存
                else
                {
                    rpt = new ResPathTemplate();
                }
                //=================================//

                //每次都重新写入ResPath
                Dictionary <string, string> resPathSumList = new Dictionary <string, string>();
                foreach (var item in rpt.UI)
                {
                    var sum = item.Value.Split('|');
                    if (sum.Length > 1 && !string.IsNullOrEmpty(sum[1]))
                    {
                        resPathSumList.Add(item.Key.ToUpper(), sum[1]);
                    }
                }
                rpt.UI.Clear();

                //============存入UI配置============//

                List <string> allResourcesPath = new List <string>();
                RecursionAction("Assets", allResourcesPath);

                foreach (var childPath in allResourcesPath)
                {
                    DirectoryInfo folder = new DirectoryInfo("Assets" + childPath + "/" + GlobalEditorSetting.UI_PREFAB_PATH);

                    if (!folder.Exists)
                    {
                        continue;
                    }

                    foreach (FileInfo file in folder.GetFiles())
                    {
                        string ss = file.Extension.ToUpper();
                        if (ss.Contains(".PREFAB") && file.FullName.Contains("Canvas"))
                        {
                            var result = file.Name.Split('.')[0];
                            var key    = "UI" + result.Split('_')[1].ToUpper();
                            rpt.UI.Add(key, GlobalEditorSetting.UI_PREFAB_PATH + result);

                            if (resPathSumList.ContainsKey(key))
                            {
                                rpt.UI[key] += "|" + resPathSumList[key];
                            }
                        }
                    }
                }

                //=================================//

                //============JSON文件存入============//
                using (StreamWriter sw = _saveLocalFileInfo.CreateText())
                {
                    var result = JsonMapper.ToJson(rpt);
                    sw.Write(result);
                }
                //=================================//

                //============更新并保存CS============//
                //更新并保存CS
                ResPathParse rpp = new ResPathParse();

                if (!FrameworkConfig.Instance.UseHotFixMode)
                {
                    EditorMenuExtention.CreateCSFile(Application.dataPath + "/Scripts", GlobalEditorSetting.OUTPUT_RESPATH, rpp.CreateCS(rpt));
                }
                else
                {
                    EditorMenuExtention.CreateCSFile(Application.dataPath + "/Scripts/ILRuntime/HotFixLogic", GlobalEditorSetting.OUTPUT_RESPATH, rpp.CreateCS(rpt));
                }

                AssetDatabase.Refresh();
            }
        }

        //汇总编译
        while (isDirty && !EditorApplication.isCompiling)
        {
            isDirty = false;

            EditorUtility.ClearProgressBar();
            LDebug.Log(" 成功生成UI预制件! ");

            if (!FrameworkConfig.Instance.UseHotFixMode)
            {
                //反射生成脚本组件
                var asmb = System.Reflection.Assembly.Load("Assembly-CSharp");
                var t    = asmb.GetType("Assets.Scripts.UI." + uiScriptsName);
                if (null != t)
                {
                    newCanvas.gameObject.AddComponent(t);
                }
                else
                {
                    LDebug.LogError("UI脚本绑定失败");
                }
            }

            string localPath = "Assets/Resources/" + GlobalEditorSetting.UI_PREFAB_PATH + newCanvas.gameObject.name + ".prefab";
            //预防重名
            localPath = AssetDatabase.GenerateUniqueAssetPath(localPath);
            PrefabUtility.SaveAsPrefabAssetAndConnect(newCanvas.gameObject, localPath, InteractionMode.UserAction);

            AssetDatabase.Refresh();
        }
    }