Beispiel #1
0
    void OnGUI()
    {
        GUILayout.Label(" 指定当前版本号, 与服务器保持一致", EditorStyles.boldLabel);
        myVersion = GUILayout.TextField(myVersion);
        GUILayout.Space(20);

        // =========================== 3. 标记AB资源   ===========================
        if (GUILayout.Button("刷新版本", GUILayout.Height(30)))
        {
            string[] szAssetBundleNames = AssetDatabase.GetAllAssetBundleNames();
            for (int i = 0; i < szAssetBundleNames.Length; i++)
            {
                AssetDatabase.RemoveAssetBundleName(szAssetBundleNames[i], true);
            }

            VersionEditorManager.Instance().curVersion = myVersion;
            PlayerSettings.Android.bundleVersionCode = VersionEditorManager.Instance().getVersionNum();
            PlayerSettings.bundleVersion             = myVersion;
        }

        GUILayout.Space(30);

        //=========================== 1.选择平台 ================================
        GUILayout.Label(" 选择发布平台  ", EditorStyles.boldLabel);
        GUILayout.Space(20);

        TargetPlatform select = (TargetPlatform)EditorGUILayout.EnumPopup(Packager.curTarget);

        if (select != Packager.curTarget)
        {
            // 重新判断当前版本设定
            Packager.curTarget = select;
        }

        GUILayout.Space(20);

        // =========================== 3. 标记AB资源   ===========================
        if (GUILayout.Button("标记AB", GUILayout.Height(30)))
        {
            Packager.BuildAssetMarks();
            Packager.WritePreloadFile();
            BuildUtil.createVersion();
        }

        GUILayout.Space(20);

        if (GUILayout.Button("生成AB", GUILayout.Height(30)))
        {
            Packager.ClearABFolder();
            Packager.GenerateAB();
        }

        // =========================== 4. 是否读取AB包  ===========================
        bool cur = GUILayout.Toggle(Packager.bLoadAB, "读取AB包");

        if (Packager.bLoadAB != cur)
        {
            Packager.bLoadAB = cur;
            AssetBundleManager.SimulateAssetBundleInEditor = !Packager.bLoadAB;
        }

        GUILayout.Space(20);
        GUIContent content = new GUIContent(" 请确认完成了 AB包 的制做过程 !!!");
        GUIStyle   style   = new GUIStyle();

        style.fontStyle = FontStyle.Normal;
        style.fontSize  = 13;

        GUILayout.Label(content);
        GUILayout.Space(20);
        GUILayout.Label(" 选择发布版本类型:");
        GUILayout.Space(20);
        BuildTargetGroup curGroup  = transPlatform(Packager.curTarget);
        string           curSymbol = null;

        if (curSelect == -1)
        {
            curSymbol = PlayerSettings.GetScriptingDefineSymbolsForGroup(curGroup);
            if (curSymbol.IndexOf("RELEASE_VER", 0, curSymbol.Length) == -1)
            {
                curSelect = 0;
            }
            else
            {
                if (curSymbol.IndexOf("STORE_VERSION", 0, curSymbol.Length) == -1)
                {
                    curSelect = 1;
                }
                else
                {
                    curSelect = 2;
                }
            }
        }

        int newSelect = GUILayout.SelectionGrid(curSelect, verList, 6);

        //处理不同版本的一些 PlayerSetting 设置
        if (newSelect != curSelect)
        {
            curSelect = newSelect;
            curSymbol = PlayerSettings.GetScriptingDefineSymbolsForGroup(curGroup);
            switch (curSelect)
            {
            case 0:
            {
                curSymbol = curSymbol.Replace("RELEASE_VER", "DEVELOP_VERSION");
                curSymbol = curSymbol.Replace("STORE_VERSION", "DEVELOP_VERSION");
                if (curSymbol.IndexOf("DEVELOP_VERSION", 0, curSymbol.Length) == -1)
                {
                    if (!string.IsNullOrEmpty(curSymbol))
                    {
                        curSymbol += ";";
                    }
                    curSymbol += "DEVELOP_VERSION";
                }
            }
            break;

            case 1:
            {
                curSymbol = curSymbol.Replace("DEVELOP_VERSION", "RELEASE_VER");
                curSymbol = curSymbol.Replace("STORE_VERSION", "RELEASE_VER");
                if (curSymbol.IndexOf("RELEASE_VER", 0, curSymbol.Length) == -1)
                {
                    if (!string.IsNullOrEmpty(curSymbol))
                    {
                        curSymbol += ";";
                    }
                    curSymbol += "RELEASE_VER";
                }
            }
            break;

            case 2:
            {
                curSymbol = curSymbol.Replace("DEVELOP_VERSION", "STORE_VERSION");
                curSymbol = curSymbol.Replace("RELEASE_VER", "STORE_VERSION");
                if (curSymbol.IndexOf("STORE_VERSION", 0, curSymbol.Length) == -1)
                {
                    if (!string.IsNullOrEmpty(curSymbol))
                    {
                        curSymbol += ";";
                    }
                    curSymbol += "STORE_VERSION";
                }
            }
            break;
            }

            PlayerSettings.SetScriptingDefineSymbolsForGroup(curGroup, curSymbol);
            Debug.Log(curSymbol);
        }
        GUILayout.Space(20);
        // =========================== 4. 拷贝资源    ===========================
        if (GUILayout.Button("拷贝资源 ", GUILayout.Height(30)))
        {
            switch (Packager.curTarget)
            {
            case TargetPlatform.IOS:
                BuildUtil.copyPlatformRes(BuildTarget.iOS);
                break;

            case TargetPlatform.Windows:
                BuildUtil.copyPlatformRes(BuildTarget.StandaloneWindows);
                break;

            case TargetPlatform.Android:
                BuildUtil.copyPlatformRes(BuildTarget.Android);
                break;

            case TargetPlatform.WebGL:
                BuildUtil.copyPlatformRes(BuildTarget.WebGL);
                break;
            }
            AssetDatabase.Refresh();
        }
        GUILayout.Space(20);
        // =========================== 5. 生成安装包    ===========================
        if (GUILayout.Button("生成安装包 ", GUILayout.Height(30)))
        {
            if (myVersion.Length == 0 || myVersion.Equals("0.0.0"))
            {
                EditorUtility.DisplayDialog(" Error !!", " 请修改版本为有效数字", "确定");
            }
            else
            {
                switch (Packager.curTarget)
                {
                case TargetPlatform.IOS:
                    BuildUtil.buildIOS();
                    break;

                case TargetPlatform.Windows:
                    BuildUtil.buildWindows();
                    break;

                case TargetPlatform.Android:
                    BuildUtil.buildAndroid();
                    break;

                case TargetPlatform.WebGL:
                    BuildUtil.buildWebGL();
                    break;
                }
            }
        }
        ;
        GUILayout.Space(20);

        if (Packager.curTarget == TargetPlatform.IOS)
        {
            if (GUILayout.Button("生成IPA", GUILayout.Height(30)))
            {
                IPABuilder.buildIPA();
            }
            GUILayout.Space(20);
        }

        if (GUILayout.Button("生成版本更新包 ", GUILayout.Height(30)))
        {
            BuildUtil.PatchAll();
        }
    }