//------------------------------------------------------------ // Game Framework // Copyright © 2013-2021 loyalsoft. All rights reserved. // Homepage: http://www.game7000.com/ // Feedback: http://www.game7000.com/ //------------------------------------------------------------ using GameFramework; using System.Collections.Generic; using System.IO; using System.Xml; using UnityEditor; using UnityEngine; namespace UnityGameFramework.Editor { /// /// 构建配置相关的实用函数。 /// internal static class BuildSettings { private static readonly string s_ConfigurationPath = null; private static readonly List s_DefaultSceneNames = new List(); private static readonly List s_SearchScenePaths = new List(); static BuildSettings() { s_ConfigurationPath = Type.GetConfigurationPath() ?? Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameFramework/Configs/BuildSettings.xml")); s_DefaultSceneNames.Clear(); s_SearchScenePaths.Clear(); if (!File.Exists(s_ConfigurationPath)) { return; } try { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(s_ConfigurationPath); XmlNode xmlRoot = xmlDocument.SelectSingleNode("UnityGameFramework"); XmlNode xmlBuildSettings = xmlRoot.SelectSingleNode("BuildSettings"); XmlNode xmlDefaultScenes = xmlBuildSettings.SelectSingleNode("DefaultScenes"); XmlNode xmlSearchScenePaths = xmlBuildSettings.SelectSingleNode("SearchScenePaths"); XmlNodeList xmlNodeList = null; XmlNode xmlNode = null; xmlNodeList = xmlDefaultScenes.ChildNodes; for (int i = 0; i < xmlNodeList.Count; i++) { xmlNode = xmlNodeList.Item(i); if (xmlNode.Name != "DefaultScene") { continue; } string defaultSceneName = xmlNode.Attributes.GetNamedItem("Name").Value; s_DefaultSceneNames.Add(defaultSceneName); } xmlNodeList = xmlSearchScenePaths.ChildNodes; for (int i = 0; i < xmlNodeList.Count; i++) { xmlNode = xmlNodeList.Item(i); if (xmlNode.Name != "SearchScenePath") { continue; } string searchScenePath = xmlNode.Attributes.GetNamedItem("Path").Value; s_SearchScenePaths.Add(searchScenePath); } } catch { } } /// /// 将构建场景设置为默认。 /// [MenuItem("Game Framework/Scenes in Build Settings/Default Scenes", false, 20)] public static void DefaultScenes() { HashSet sceneNames = new HashSet(); foreach (string sceneName in s_DefaultSceneNames) { sceneNames.Add(sceneName); } List scenes = new List(); foreach (string sceneName in sceneNames) { scenes.Add(new EditorBuildSettingsScene(sceneName, true)); } EditorBuildSettings.scenes = scenes.ToArray(); Debug.Log("Set scenes of build settings to default scenes."); } /// /// 将构建场景设置为所有。 /// [MenuItem("Game Framework/Scenes in Build Settings/All Scenes", false, 21)] public static void AllScenes() { HashSet sceneNames = new HashSet(); foreach (string sceneName in s_DefaultSceneNames) { sceneNames.Add(sceneName); } string[] sceneGuids = AssetDatabase.FindAssets("t:Scene", s_SearchScenePaths.ToArray()); foreach (string sceneGuid in sceneGuids) { string sceneName = AssetDatabase.GUIDToAssetPath(sceneGuid); sceneNames.Add(sceneName); } List scenes = new List(); foreach (string sceneName in sceneNames) { scenes.Add(new EditorBuildSettingsScene(sceneName, true)); } EditorBuildSettings.scenes = scenes.ToArray(); Debug.Log("Set scenes of build settings to all scenes."); } } }