private static void CreateConfigAsset(GiftAtlasConfig so) { if (so == null) { Debug.Log("该对象无效,无法将对象实例化"); return; } //自定义配置资源路径 string path = Application.dataPath + "/Editor/AtlasTools/Resources"; //判断该路径是否存在,不存在的话创建一个 if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } //配置文件以.asset结尾 //将对象名配置成与类名相同 path = string.Format("Assets/Editor/AtlasTools/Resources/{0}.asset", "AtlasConfig"); if (File.Exists(path)) { File.Delete(path); } //按指定路径生成配置文件 AssetDatabase.CreateAsset(so, path); AssetDatabase.Refresh(); }
private static bool CheckConfig() { if (!GiftAtlasConfigWindow.HasConfig()) { GiftAtlasConfigWindow.ConfigAtlas(); return(false); } else { GiftAtlasConfig config = GiftAtlasConfigWindow.GetConfig(); sptDesDir = Application.dataPath + config.AtlasRootPath; sptSrcDir = Application.dataPath + config.ResourcesRootPath; atlasRelativePath = config.AtlasPathInResources; if (!string.IsNullOrEmpty(config.IgnoreResourcesFolders)) { string[] ignores = config.IgnoreResourcesFolders.Split(new string[] { "," }, System.StringSplitOptions.None); if (ignores != null) { ignoreFolders = ignores; } } return(true); } }
public static void ConfigAtlas() { GiftAtlasConfig originConfig = GetConfig(); if (originConfig != null) { resourcesRootPath = originConfig.ResourcesRootPath; atlasRootPath = originConfig.AtlasRootPath; atlasRelativeResourcesPath = originConfig.AtlasPathInResources; ignoreResourcesFolders = originConfig.IgnoreResourcesFolders; } EditorWindow.GetWindow(typeof(GiftAtlasConfigWindow)).Show(); }
void OnGUI() { GUILayout.Label("原图根目录", EditorStyles.boldLabel); if (GUILayout.Button(resourcesButton)) { resourcesRootPath = EditorUtility.OpenFolderPanel("", Application.dataPath + resourcesRootPath, "").Replace(Application.dataPath, ""); } resourcesRootPath = EditorGUILayout.TextField("点击按钮选取路径", resourcesRootPath); GUILayout.Space(8); GUILayout.Label("图集根目录", EditorStyles.boldLabel); if (GUILayout.Button(atlasButton)) { atlasRootPath = EditorUtility.OpenFolderPanel("", Application.dataPath + atlasRootPath, "").Replace(Application.dataPath, ""); } atlasRootPath = EditorGUILayout.TextField("点击按钮选取路径", atlasRootPath); GUILayout.Space(8); GUILayout.Label("忽略目录列表", EditorStyles.boldLabel); ignoreResourcesFolders = EditorGUILayout.TextField("填写名称,以”,“分隔", ignoreResourcesFolders); GUILayout.Space(8); GUILayout.Label("图集相对Resources路径", EditorStyles.boldLabel); atlasRelativeResourcesPath = EditorGUILayout.TextField("填写路径", atlasRelativeResourcesPath); if (GUILayout.Button("保存设置")) { GiftAtlasConfig config = HasConfig() ? GetConfig() : ScriptableObject.CreateInstance <GiftAtlasConfig>(); config.ResourcesRootPath = resourcesRootPath; config.AtlasRootPath = atlasRootPath; config.AtlasPathInResources = string.IsNullOrEmpty(atlasRelativeResourcesPath) ? "" : atlasRelativeResourcesPath; config.IgnoreResourcesFolders = string.IsNullOrEmpty(ignoreResourcesFolders) ? "" : ignoreResourcesFolders; if (!HasConfig()) { CreateConfigAsset(config); } EditorWindow.GetWindow(typeof(GiftAtlasConfigWindow)).Close(); } }
public static GiftAtlasConfig GetConfig() { GiftAtlasConfig config = Resources.Load <GiftAtlasConfig>("AtlasConfig"); return(config); }
public static bool HasConfig() { GiftAtlasConfig config = GetConfig(); return(config != null && !string.IsNullOrEmpty(config.ResourcesRootPath) && !string.IsNullOrEmpty(config.AtlasRootPath)); }