示例#1
0
    private void OnGUI()
    {
        // 初始化
        InitInternal();

        // 标题
        EditorGUILayout.LabelField("Build setup", _centerStyle);
        EditorGUILayout.Space();

        // 构建版本
        _assetBuilder.BuildVersion = EditorGUILayout.IntField("Build Version", _assetBuilder.BuildVersion, GUILayout.MaxWidth(250));

        // 输出路径
        EditorGUILayout.LabelField("Build Output Path", _assetBuilder.OutputPath);

        // 构建选项
        EditorGUILayout.Space();
        _assetBuilder.IsForceRebuild = GUILayout.Toggle(_assetBuilder.IsForceRebuild, "Froce Rebuild", GUILayout.MaxWidth(120));

        // 高级选项
        using (new EditorGUI.DisabledScope(false))
        {
            EditorGUILayout.Space();
            _showSettingFoldout = EditorGUILayout.Foldout(_showSettingFoldout, "Advanced Settings");
            if (_showSettingFoldout)
            {
                int indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel                 = 1;
                _assetBuilder.CompressOption          = (AssetBuilder.ECompressOption)EditorGUILayout.EnumPopup("Compression", _assetBuilder.CompressOption);
                _assetBuilder.IsAppendHash            = EditorGUILayout.ToggleLeft("Append Hash", _assetBuilder.IsAppendHash, GUILayout.MaxWidth(120));
                _assetBuilder.IsDisableWriteTypeTree  = EditorGUILayout.ToggleLeft("Disable Write Type Tree", _assetBuilder.IsDisableWriteTypeTree, GUILayout.MaxWidth(200));
                _assetBuilder.IsIgnoreTypeTreeChanges = EditorGUILayout.ToggleLeft("Ignore Type Tree Changes", _assetBuilder.IsIgnoreTypeTreeChanges, GUILayout.MaxWidth(200));
                EditorGUI.indentLevel                 = indent;
            }
        }

        // 构建按钮
        EditorGUILayout.Space();
        if (GUILayout.Button("Build", GUILayout.MaxHeight(40)))
        {
            string title;
            string content;
            if (_assetBuilder.IsForceRebuild)
            {
                title   = "警告";
                content = "确定开始强制构建吗,这样会删除所有已有构建的文件";
            }
            else
            {
                title   = "提示";
                content = "确定开始增量构建吗";
            }
            if (EditorUtility.DisplayDialog(title, content, "Yes", "No"))
            {
                // 清空控制台
                EditorTools.ClearUnityConsole();

                // 存储配置
                SaveSettingsToPlayerPrefs(_assetBuilder);

                EditorApplication.delayCall += ExecuteBuild;
            }
            else
            {
                Debug.LogWarning("[Build] 打包已经取消");
            }
        }

        // 绘制工具栏部分
        OnDrawGUITools();
    }