示例#1
0
    private void OnGUIHigh()
    {
        if (GUILayout.Button("清理资源名"))
        {
            AssetBundleTool.ClearAssetBundleName();
        }

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        NeedGenVersion = EditorGUILayout.ToggleLeft("生成版本号", NeedGenVersion);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        NeedRename = EditorGUILayout.ToggleLeft("生成资源包名", NeedRename);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        NeedBuild = EditorGUILayout.ToggleLeft("生成资源包", NeedBuild);
        EditorGUILayout.EndHorizontal();

        if (NeedBuild)
        {
            EditorGUILayout.BeginHorizontal("PopupBackground");
            IsRebuild = EditorGUILayout.ToggleLeft("是否重新完整打包", IsRebuild);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal("PopupBackground");

            BundleOptions = (BuildAssetBundleOptions)EditorGUILayout.EnumMaskField("资源打包设置", BundleOptions, GUILayout.Width(500));
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();
        NeedGenAssetsList = EditorGUILayout.ToggleLeft("生成资源列表", NeedGenAssetsList);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        IsCopyToStreamPath = EditorGUILayout.ToggleLeft("拷贝AssetBundle到StreamPath", IsCopyToStreamPath);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        NeedGenApp = EditorGUILayout.ToggleLeft("生成APP", NeedGenApp);
        EditorGUILayout.EndHorizontal();

        if (NeedGenApp)
        {
            EditorGUILayout.BeginHorizontal("PopupBackground");
            Options = (BuildOptions)EditorGUILayout.EnumMaskField("生成APP设置", Options, GUILayout.Width(500));
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();
    }
示例#2
0
    private void Gen()
    {
        bool needRename        = NeedRename || !IsHighMode;
        bool needBuild         = NeedBuild || !IsHighMode;
        bool needGenAssetsList = NeedGenAssetsList || !IsHighMode;
        bool needGenVersion    = NeedGenVersion || !IsHighMode;
        bool needGenApp        = NeedGenApp || !IsHighMode;

        bool isRebuild          = IsRebuild || !IsHighMode;
        bool isCopyToStreamPath = IsCopyToStreamPath || !IsHighMode;

        BuildOptions            buildOptions  = BuildOptions.None;
        BuildAssetBundleOptions bundleOptions = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.StrictMode | BuildAssetBundleOptions.DeterministicAssetBundle;

        if (IsHighMode)
        {
            buildOptions  = Options;
            bundleOptions = BundleOptions;
        }

        if (needGenApp && string.IsNullOrEmpty(AppOutPath))
        {
            AppOutPath = EditorUtility.OpenFolderPanel("请选择目录", AppOutPath, AppOutPath);
            if (string.IsNullOrEmpty(AppOutPath))
            {
                return;
            }
        }

        if (needGenVersion)
        {
            if (EditorUtility.DisplayCancelableProgressBar("生成新版本号", "不着急", 0))
            {
                EditorUtility.ClearProgressBar();
                return;
            }

            AssetBundleTool.GenVersion(Target, currentVersion, "develop");

            if (EditorUtility.DisplayCancelableProgressBar("生成新版本号", "不着急", 1))
            {
                EditorUtility.ClearProgressBar();
                return;
            }
        }

        if (needRename)
        {
            if (EditorUtility.DisplayCancelableProgressBar("命名资源文件", "不着急", 0))
            {
                EditorUtility.ClearProgressBar();
                return;
            }

            AssetBundleTool.ClearAssetBundleName();
            AssetBundleTool.GenAssetBundleName();
            if (EditorUtility.DisplayCancelableProgressBar("命名资源文件", "不着急", 1))
            {
                EditorUtility.ClearProgressBar();
                return;
            }
        }

        if (needBuild)
        {
            if (EditorUtility.DisplayCancelableProgressBar("生成AB包", "不着急", 0))
            {
                EditorUtility.ClearProgressBar();
                return;
            }

            AssetBundleTool.BuildBundle(isRebuild, Target, bundleOptions);
            AssetBundleTool.ClearAssetBundleName();

            if (EditorUtility.DisplayCancelableProgressBar("生成AB包", "不着急", 1))
            {
                EditorUtility.ClearProgressBar();
                return;
            }
        }

        if (needGenAssetsList)
        {
            if (EditorUtility.DisplayCancelableProgressBar("生成资源列表", "不着急", 0))
            {
                EditorUtility.ClearProgressBar();
                return;
            }

            AssetBundleTool.GenAssetsList(Target);

            if (EditorUtility.DisplayCancelableProgressBar("生成资源列表", "不着急", 1))
            {
                EditorUtility.ClearProgressBar();
                return;
            }
        }

        if (isCopyToStreamPath)
        {
            if (EditorUtility.DisplayCancelableProgressBar("拷贝AssetBundle", "不着急", 0))
            {
                EditorUtility.ClearProgressBar();
                return;
            }
            AssetBundleTool.CopyAssetBundleToStream(Target);
            if (EditorUtility.DisplayCancelableProgressBar("拷贝AssetBundle", "不着急", 1))
            {
                EditorUtility.ClearProgressBar();
                return;
            }
        }

        if (needGenApp)
        {
            if (EditorUtility.DisplayCancelableProgressBar("生成APP", "不着急", 0))
            {
                EditorUtility.ClearProgressBar();
                return;
            }

            string appFilePath = null;
            if (UseVersionSuffix)
            {
                switch (Target)
                {
                case BuildTarget.StandaloneWindows:
                case BuildTarget.StandaloneWindows64:
                    appFilePath = string.Format("{0}/football_{1}.exe", AppOutPath, currentVersion);
                    break;

                case BuildTarget.iOS:
                    appFilePath = string.Format("{0}/football_{1}.ipa", AppOutPath, currentVersion);
                    break;

                case BuildTarget.Android:
                    appFilePath = string.Format("{0}/football_{1}.apk", AppOutPath, currentVersion);
                    break;

                default:
                {
                    EditorUtility.ClearProgressBar();
                    return;
                }
                }
            }
            else
            {
                switch (Target)
                {
                case BuildTarget.StandaloneWindows:
                    appFilePath = string.Format("{0}/football.exe", AppOutPath);
                    break;

                case BuildTarget.iOS:
                    appFilePath = string.Format("{0}/football.ipa", AppOutPath);
                    break;

                case BuildTarget.Android:
                    appFilePath = string.Format("{0}/football.apk", AppOutPath);
                    break;

                default:
                {
                    EditorUtility.ClearProgressBar();
                    return;
                }
                }
            }

            if (appFilePath != null)
            {
#if UNITY_ANDROID
                PlayerSettings.Android.keystoreName = Application.dataPath + "/../football.keystore";
                PlayerSettings.Android.keystorePass = "******";
                PlayerSettings.Android.keyaliasName = "斗球学园";
                PlayerSettings.Android.keyaliasPass = "******";
#endif

                BuildPipeline.BuildPlayer(AssetBundleTool.GetBuildScenes(), appFilePath, Target, buildOptions);
            }
        }

        EditorUtility.ClearProgressBar();
    }