Ejemplo n.º 1
0
        public static void BuildStandalonePlayer()
        {
            var outputPath = EditorUtility.SaveFolderPanel("Choose Location of the Built Game", "", "");

            if (outputPath.Length == 0)
            {
                return;
            }

            string[] levels = GetLevelsFromBuildSettings();
            if (levels.Length == 0)
            {
                Debug.Log("Nothing to build.");
                return;
            }

            string targetName = GetBuildTargetName(EditorUserBuildSettings.activeBuildTarget);

            if (targetName == null)
            {
                return;
            }
            GameUtility.SafeDeleteFile(outputPath + targetName);

            // Build and copy AssetBundles.
            BuildAssetBundles();
            AssetBundleUtility.CopyPlatformAssetBundlesToStreamingAssets();
            // makesure the local server URL is up-to-dat
            AssetBundleUtility.WriteAssetBundleServerURL();
            AssetDatabase.Refresh();

            BuildOptions option = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None;

            BuildPipeline.BuildPlayer(levels, outputPath + targetName, EditorUserBuildSettings.activeBuildTarget, option);
        }
Ejemplo n.º 2
0
        // unity editor启动和运行时调用
        static AssetBundleMenuItems()
        {
            // 1、模拟模式下在电脑上模拟手机资源更新过程,如果需要更新最新ab,需要手动构建;如果根本没有ab,则构建一次
            // 2、模拟模式下需要用到streamingAsset,没有资源则拷贝一次,之后总是从本地服务器下载ab到persistentDataPath
            var platformName   = AssetBundleUtility.GetCurPlatformName();
            var outputManifest = Path.Combine(AssetBundleConfig.AssetBundlesBuildOutputPath, platformName);

            outputManifest = Path.Combine(outputManifest, platformName);
            if (!File.Exists(outputManifest))
            {
                AssetBundleBuildScript.BuildAssetBundles();
            }
            var streamingManifest = Path.Combine(Application.streamingAssetsPath, AssetBundleConfig.AssetBundlesFolderName);

            streamingManifest = Path.Combine(streamingManifest, platformName);
            streamingManifest = Path.Combine(streamingManifest, platformName);
            if (!File.Exists(streamingManifest))
            {
                AssetBundleUtility.CopyPlatformAssetBundlesToStreamingAssets();
                AssetDatabase.Refresh();
            }
            LaunchAssetBundleServer.CheckAndDoRunning();
        }