private static void OnInitialize()
        {
            Assets.basePath     = BuildScript.outputPath + Path.DirectorySeparatorChar;
            Assets.loadDelegate = AssetDatabase.LoadAssetAtPath;

            var assets = new List <string>();
            var rules  = BuildScript.GetBuildRules();

            foreach (var asset in rules.scenesInBuild)
            {
                var path = AssetDatabase.GetAssetPath(asset);
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }
                assets.Add(path);
            }
            foreach (var rule in rules.rules)
            {
                if (rule.searchPattern.Contains("*.unity"))
                {
                    assets.AddRange(rule.GetAssets());
                }
            }
            var scenes = new EditorBuildSettingsScene[assets.Count + 1];

            scenes[0] = new EditorBuildSettingsScene("Assets/Init.unity", true);
            for (var index = 1; index < assets.Count + 1; index++)
            {
                var asset = assets[index - 1];
                scenes[index] = new EditorBuildSettingsScene(asset, true);
            }
            EditorBuildSettings.scenes = scenes;
        }
Example #2
0
 private static void OnEditorInitialize()
 {
     EditorUtility.ClearProgressBar();
     BuildScript.GetManifest();
     BuildScript.GetSettings();
     BuildScript.GetBuildRules();
 }
Example #3
0
        private static void OnInitialize()
        {
            Assets.basePath     = BuildScript.outputPath + Path.DirectorySeparatorChar;
            Assets.loadDelegate = AssetDatabase.LoadAssetAtPath;

            var assets = new List <string>();
            var rules  = BuildScript.GetBuildRules();

            foreach (var asset in rules.scenesInBuild)
            {
                var path = AssetDatabase.GetAssetPath(asset);
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }
                assets.Add(path);
            }
            foreach (var rule in rules.rules)
            {
                if (rule.searchPattern.Contains("*.unity"))
                {
                    assets.AddRange(rule.GetAssets());
                }
            }

            List <EditorBuildSettingsScene> _scenes = new List <EditorBuildSettingsScene>(0);

            foreach (var scene in EditorBuildSettings.scenes)
            {
                if (scene.path.Contains("Init.unity") || assets.Contains(scene.path))
                {
                    continue;
                }

                _scenes.Add(scene);
                Log.Print(scene.path);
            }

            EditorBuildSettingsScene[] scenes = new EditorBuildSettingsScene[assets.Count + _scenes.Count + 1];

            scenes[0] = new EditorBuildSettingsScene("Assets/Init.unity", true);//添加启动场景
            int _index = 1;

            for (var index = 0; index < _scenes.Count; index++)//添加其他场景(用户自己加的)
            {
                scenes[index + 1] = new EditorBuildSettingsScene(_scenes[index].path, true);
                _index++;
            }
            for (var index = _index; index < scenes.Length; index++)//添加热更场景(用于编译测试)
            {
                var asset = assets[index - _index];
                scenes[index] = new EditorBuildSettingsScene(asset, true);
            }

            EditorBuildSettings.scenes = scenes;
        }
Example #4
0
        private static void OnInitialize()
        {
            Assets.basePath     = BuildScript.outputPath + Path.DirectorySeparatorChar;
            Assets.loadDelegate = AssetDatabase.LoadAssetAtPath;

            var assets = new List <string>();
            var rules  = BuildScript.GetBuildRules();

            foreach (var asset in rules.scenesInBuild)
            {
                var path = AssetDatabase.GetAssetPath(asset);
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }
                assets.Add(path);
            }
            foreach (var rule in rules.rules)
            {
                if (rule.searchPattern.Contains("*.unity"))
                {
                    assets.AddRange(rule.GetAssets());
                }
            }

            List <EditorBuildSettingsScene> _scenes = new List <EditorBuildSettingsScene>(0);

            foreach (var scene in EditorBuildSettings.scenes)
            {
                if (scene.path.Equals(JEngineSetting.StartUpScenePath) || assets.Contains(scene.path))
                {
                    continue;
                }
                _scenes.Add(scene);
            }

            List <EditorBuildSettingsScene> scenes = new List <EditorBuildSettingsScene>(0);

            scenes.Add(new EditorBuildSettingsScene(JEngineSetting.StartUpScenePath, true)); //添加启动场景
            for (var index = 0; index < _scenes.Count; index++)                              //添加其他场景(用户自己加的)
            {
                scenes.Add(new EditorBuildSettingsScene(_scenes[index].path, true));
            }
            for (var index = 0; index < assets.Count; index++)//添加热更场景(用于编译测试)
            {
                var asset = assets[index];
                if (asset == JEngineSetting.StartUpScenePath)
                {
                    continue;
                }
                scenes.Add(new EditorBuildSettingsScene(asset, true));
            }

            EditorBuildSettings.scenes = scenes.ToArray();
        }
Example #5
0
 private static void EditorApplicationOnplayModeStateChanged(PlayModeStateChange obj)
 {
     if (obj == PlayModeStateChange.ExitingPlayMode)
     {
         Assets.onAssetLoaded   = null;
         Assets.onAssetUnloaded = null;
         var rules = BuildScript.GetBuildRules();
         rules.EndSample();
         EditorUtility.SetDirty(rules);
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
     }
 }
Example #6
0
        private static void PatchAssets(PatchId patch)
        {
            var selection = Selection.GetFiltered <Object>(SelectionMode.DeepAssets);
            var rules     = BuildScript.GetBuildRules();

            foreach (var o in selection)
            {
                var path = AssetDatabase.GetAssetPath(o);
                if (string.IsNullOrEmpty(path) || Directory.Exists(path))
                {
                    continue;
                }
                rules.PatchAsset(path, patch);
            }

            EditorUtility.SetDirty(rules);
            AssetDatabase.SaveAssets();
        }
        private static void OnInitialize()
        {
            Assets.basePath     = BuildScript.outputPath + Path.DirectorySeparatorChar;
            Assets.EditorLoader = AssetDatabase.LoadAssetAtPath;
            var assets = new List <string>();
            var rules  = BuildScript.GetBuildRules();

            foreach (var asset in rules.scenesInBuild)
            {
                var path = AssetDatabase.GetAssetPath(asset);
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }
                assets.Add(path);
            }
            _searchPaths.Clear();
            foreach (var asset in rules.assets)
            {
                if (asset.path.EndsWith(".unity"))
                {
                    assets.Add(asset.path);
                }

                var dir = Path.GetDirectoryName(asset.path);
                if (!_searchPaths.Contains(dir))
                {
                    _searchPaths.Add(dir);
                }
            }
            var scenes = new EditorBuildSettingsScene[assets.Count];

            for (var index = 0; index < assets.Count; index++)
            {
                var asset = assets[index];
                scenes[index] = new EditorBuildSettingsScene(asset, true);
            }
            Assets.EditorSearcher      = EditorSearcher;
            EditorBuildSettings.scenes = scenes;
        }
Example #8
0
        private static void ApplyRuleScene()
        {
            var rules = BuildScript.GetBuildRules();

            AddRulesForSelection(rules, rules.searchPatternScene);
        }
Example #9
0
        private static void ApplyRuleController()
        {
            var rules = BuildScript.GetBuildRules();

            AddRulesForSelection(rules, rules.searchPatternController);
        }
Example #10
0
        private static void OnInitialize()
        {
            var sceneAssets = new List <string>();
            var rules       = BuildScript.GetBuildRules();

            foreach (var guid in AssetDatabase.FindAssets("t:Scene", new[] { "Assets" }))
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(guid);
                sceneAssets.Add(assetPath);
            }

            var patches     = new List <Patch>();
            var assets      = new List <AssetRef>();
            var searchPaths = new List <string>();
            var dirs        = new Dictionary <string, int>();

            foreach (var asset in rules.assets)
            {
                if (!File.Exists(asset.name))
                {
                    continue;
                }
                var dir = Path.GetDirectoryName(asset.name);
                if (!string.IsNullOrEmpty(dir))
                {
                    if (!searchPaths.Contains(dir))
                    {
                        dirs[dir] = searchPaths.Count;
                        searchPaths.Add(dir);
                    }
                }
                var ar = new AssetRef {
                    name = Path.GetFileName(asset.name), bundle = -1, dir = dirs[dir]
                };
                assets.Add(ar);
            }

            var scenes = new EditorBuildSettingsScene[sceneAssets.Count];

            for (var index = 0; index < sceneAssets.Count; index++)
            {
                var asset = sceneAssets[index];
                scenes[index] = new EditorBuildSettingsScene(asset, true);
                var dir = Path.GetDirectoryName(asset);
                if (!searchPaths.Contains(dir))
                {
                    searchPaths.Add(dir);
                }
            }

            for (var i = 0; i < rules.patches.Count; i++)
            {
                var item  = rules.patches[i];
                var patch = new Patch();
                patch.name = item.name;
                patches.Add(patch);
            }

            var developVersions = new Versions();

            developVersions.dirs    = searchPaths.ToArray();
            developVersions.assets  = assets;
            developVersions.patches = patches;

            Assets.basePath         = Environment.CurrentDirectory.Replace("\\", "/") + "/" + BuildScript.outputPath + "/";
            Assets.assetLoader      = AssetDatabase.LoadAssetAtPath;
            Assets.versionsLoader  += () => developVersions;
            Assets.onAssetLoaded   += rules.OnLoadAsset;
            Assets.onAssetUnloaded += rules.OnUnloadAsset;
            rules.BeginSample();
            EditorBuildSettings.scenes              = scenes;
            EditorApplication.playModeStateChanged += EditorApplicationOnplayModeStateChanged;
        }
Example #11
0
        private static void ApplyRuleMaterail()
        {
            var rules = BuildScript.GetBuildRules();

            AddRulesForSelection(rules, rules.searchPatternMaterial);
        }
Example #12
0
        public static void BuildStandalonePlayer()
        {
            var outputPath = $"{c_RelativeDirPrefix}{GetPlatformName()}_EXE";            //EditorUtility.SaveFolderPanel("Choose Location of the Built Game", "", "");

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

            var levels = GetLevelsFromBuildSettings();

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

            #region 根据XAsset BuildInScene配置复原Unity的BuildInScene 因为我们为了支持在编辑器模式下的测试而必须将所有Scene放到Unity的BuildInSetting里

            var assets = new List <string>();
            var rules  = BuildScript.GetBuildRules();
            foreach (var asset in rules.scenesInBuild)
            {
                var path = AssetDatabase.GetAssetPath(asset);
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }
                assets.Add(path);
            }
            foreach (var rule in rules.rules)
            {
                if (rule.searchPattern.Contains("*.unity"))
                {
                    assets.AddRange(rule.GetAssets());
                }
            }
            var scenes = new EditorBuildSettingsScene[assets.Count];
            for (var index = 0; index < assets.Count; index++)
            {
                var asset = assets[index];
                scenes[index] = new EditorBuildSettingsScene(asset, true);
            }
            EditorBuildSettings.scenes = scenes;

            #endregion

            // 如果执行打包,就强行替换为非本地调试模式,进行AB加载与云端服务器连接
            Updater updater       = Object.FindObjectOfType <Updater>();
            bool    isDevelopMode = updater.DevelopmentMode;
            updater.DevelopmentMode = false;

            var targetName = GetBuildTargetName(EditorUserBuildSettings.activeBuildTarget);
            if (targetName == null)
            {
                return;
            }
#if UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0
            BuildOptions option = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None;
            BuildPipeline.BuildPlayer(levels, path + targetName, EditorUserBuildSettings.activeBuildTarget, option);
#else
            var buildPlayerOptions = new BuildPlayerOptions {
                scenes                  = levels,
                locationPathName        = outputPath + targetName,
                assetBundleManifestPath = GetAssetBundleManifestFilePath(),
                target                  = EditorUserBuildSettings.activeBuildTarget,
                options                 = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None
            };
            BuildPipeline.BuildPlayer(buildPlayerOptions);
#endif
            updater.DevelopmentMode = isDevelopMode;
        }
 private static void OnEditorInitialize()
 {
     BuildScript.GetManifest();
     BuildScript.GetSettings();
     BuildScript.GetBuildRules();
 }