Exemple #1
0
        //打包资源
        private static void BuildAsset(BuildTarget buildTarget, bool autoUpload = false, string remotePath = "oss://unity-res-mini-games")
        {
            string buildPath = AssetBundleBuildEditor.BuildAssetBundles(buildTarget);

            if (autoUpload)
            {
                //获取完整的路径
                buildPath = Path.GetFullPath(buildPath);

                string directoryPath = Path.GetFullPath(Path.GetDirectoryName(Application.dataPath));
                if (!buildPath.Contains(directoryPath))
                {
                    buildPath = Path.Combine(directoryPath, buildPath);
                }
                //上传服务器
                remotePath = $"{remotePath}/{AssetBundleBuildEditor.BuildTargetToString(buildTarget)}";
                OssFolderUpload(buildPath, remotePath);

                //string targetName = AssetBundleBuildEditor.BuildTargetToString(buildTarget).ToLower();
                ////开始协程
                //FileUpload fileUpload = new FileUpload();
                //EditorCoroutines.StartCoroutine(fileUpload.FilesUpload(buildPath, targetName, "http://127.0.0.1:19321/"), fileUpload) ;
            }
        }
Exemple #2
0
        private static void BuildPlayer(BuildTarget buildTarget)
        {
            CSObjectWrapEditor.Generator.ClearAll();
            AssetDatabase.Refresh();
            //gen xlua
            CSObjectWrapEditor.Generator.GenAll();
            AssetDatabase.Refresh();

            //设置场景的场景的参数
            string launchScenePath = "Assets/Game/Scenes/main.unity";

            UnityEngine.SceneManagement.Scene activeScene = EditorSceneManager.OpenScene(launchScenePath);
            if (activeScene != null)
            {
                EditorSceneManager.SetActiveScene(activeScene);
                foreach (var item in activeScene.GetRootGameObjects())
                {
                    if (item.name.Equals("GameMode"))
                    {
                        GameMode gameMode = item.GetComponent <GameMode>();
                        gameMode.ConfigJsonData["ResourceUpdateType"] = (int)ResourceUpdateType.Update;
                        string configPath = AssetDatabase.GetAssetPath(gameMode.ConfigAsset);
                        File.WriteAllText(configPath, gameMode.ConfigJsonData.ToJson());
                        AssetDatabase.Refresh();
                        EditorUtility.SetDirty(gameMode);
                        EditorSceneManager.SaveOpenScenes();
                        AssetDatabase.Refresh();
                        break;
                    }
                }
            }

            if (buildTarget == BuildTarget.Android)
            {
                //android keystore
                string path         = Path.GetDirectoryName(Application.dataPath);
                string keyStorePath = Path.Combine(path, "tools/user.keystore");
                PlayerSettings.Android.keystoreName = keyStorePath;
                PlayerSettings.Android.keystorePass = "******";
                PlayerSettings.Android.keyaliasName = "********";
                PlayerSettings.Android.keyaliasPass = "******";
            }

            //build
            BuildPlayerOptions playerOptions = new BuildPlayerOptions();

            playerOptions.scenes = EditorBuildSettingsScene.GetActiveSceneList(EditorBuildSettings.scenes);
            // playerOptions.scenes = new string[] { "Assets/Core/Scenes/SampleScene.unity" };
            playerOptions.target = buildTarget;
            var buildTargetPath = $"build/{AssetBundleBuildEditor.BuildTargetToString(buildTarget)}";

            if (!Directory.Exists(buildTargetPath))
            {
                Directory.CreateDirectory(buildTargetPath);
            }

            if (buildTarget == BuildTarget.Android)
            {
                buildTargetPath = $"{buildTargetPath}/{Application.productName}.apk";
            }
            else if (buildTarget == BuildTarget.StandaloneWindows)
            {
                buildTargetPath = $"{buildTargetPath}/{Application.productName}.exe";
            }
            else if (buildTarget == BuildTarget.StandaloneLinux64)
            {
                buildTargetPath = $"{buildTargetPath}/{Application.productName}.x86_64";
            }
            else if (buildTarget == BuildTarget.StandaloneOSX)
            {
                buildTargetPath = $"{buildTargetPath}/{Application.productName}";
            }
            playerOptions.locationPathName = buildTargetPath;

            BuildPipeline.BuildPlayer(playerOptions);
            Debug.Log("build sccuess!");
        }