static void CreateDragbonBoneByDir_UIImage() { DragonBoneArmatureEditor editor = CreateDragonBoneByDir(Bone2DSetupEditor.DisplayType.UGUIImage); if (editor) { editor.OnWizardCreate(); DestroyImmediate(editor); } }
static void CreateDragbonBoneByDir_SpriteFrame() { DragonBoneArmatureEditor editor = CreateDragonBoneByDir(Bone2DSetupEditor.DisplayType.Default); if (editor) { editor.OnWizardCreate(); DestroyImmediate(editor); } }
static void CreateDragbonBoneByDir_UnitySprite() { DragonBoneArmatureEditor editor = CreateDragonBoneByDir(Bone2DSetupEditor.DisplayType.SpriteRender); if (editor) { editor.OnWizardCreate(); DestroyImmediate(editor); } }
static DragonBoneArmatureEditor CreateDragonBoneByDir(Bone2DSetupEditor.DisplayType displayType) { if (Selection.activeObject != null) { string dirPath = AssetDatabase.GetAssetOrScenePath(Selection.activeObject); if (File.Exists(dirPath)) { dirPath = dirPath.Substring(0, dirPath.LastIndexOf("/")); } if (Directory.Exists(dirPath)) { string animJsonPath = null; Dictionary <string, string> texturePathKV = new Dictionary <string, string>(); Dictionary <string, string> textureJsonPathKV = new Dictionary <string, string>(); foreach (string path in Directory.GetFiles(dirPath)) { if (path.LastIndexOf(".meta") == -1) { if (System.IO.Path.GetExtension(path) == ".json" && (path.IndexOf("_tex") > -1 || path.IndexOf("texture") > -1)) { int start = path.LastIndexOf("/") + 1; int end = path.LastIndexOf(".json"); textureJsonPathKV[path.Substring(start, end - start)] = path; continue; } if (System.IO.Path.GetExtension(path) == ".png" && (path.IndexOf("_tex") > -1 || path.IndexOf("texture") > -1)) { int start = path.LastIndexOf("/") + 1; int end = path.LastIndexOf(".png"); texturePathKV[path.Substring(start, end - start)] = path; continue; } if (System.IO.Path.GetExtension(path) == ".json" && (path.IndexOf("_ske") > -1 || path.IndexOf("texture.json") == -1)) { animJsonPath = path; } } } if (!string.IsNullOrEmpty(animJsonPath) && texturePathKV.Count > 0 && textureJsonPathKV.Count > 0) { DragonBoneArmatureEditor instance = ScriptableObject.CreateInstance <DragonBoneArmatureEditor>(); instance.displayType = displayType; List <Atlas> atlasList = new List <Atlas>(); foreach (string name in texturePathKV.Keys) { if (textureJsonPathKV.ContainsKey(name)) { if (instance.altasTexture == null) { instance.altasTextAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(textureJsonPathKV[name]); instance.altasTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePathKV[name]); } else { Atlas atlas = new Atlas(); atlas.atlasText = AssetDatabase.LoadAssetAtPath <TextAsset>(textureJsonPathKV[name]); atlas.texture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePathKV[name]); atlasList.Add(atlas); } } } instance.otherTextures = atlasList.ToArray(); instance.animTextAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(animJsonPath); if (instance.altasTexture && instance.altasTextAsset && instance.animTextAsset) { return(instance); } } } } return(null); }
static void CreateWizard() { DragonBoneArmatureEditor editor = ScriptableWizard.DisplayWizard <DragonBoneArmatureEditor>("Create DragonBone", "Create"); editor.minSize = new Vector2(200, 500); if (Selection.activeObject != null) { string dirPath = AssetDatabase.GetAssetOrScenePath(Selection.activeObject); if (File.Exists(dirPath)) { dirPath = dirPath.Substring(0, dirPath.LastIndexOf("/")); } if (Directory.Exists(dirPath)) { string animJsonPath = null; Dictionary <string, string> texturePathKV = new Dictionary <string, string>(); Dictionary <string, string> textureJsonPathKV = new Dictionary <string, string>(); foreach (string path in Directory.GetFiles(dirPath)) { if (path.LastIndexOf(".meta") == -1) { if (System.IO.Path.GetExtension(path) == ".json" && (path.IndexOf("_tex") > -1 || path.IndexOf("texture") > -1)) { int start = path.LastIndexOf("/") + 1; int end = path.LastIndexOf(".json"); textureJsonPathKV[path.Substring(start, end - start)] = path; continue; } if (System.IO.Path.GetExtension(path) == ".png" && (path.IndexOf("_tex") > -1 || path.IndexOf("texture") > -1)) { int start = path.LastIndexOf("/") + 1; int end = path.LastIndexOf(".png"); texturePathKV[path.Substring(start, end - start)] = path; continue; } if (System.IO.Path.GetExtension(path) == ".json" && (path.IndexOf("_ske") > -1 || path.IndexOf("texture.json") == -1)) { animJsonPath = path; } } } if (!string.IsNullOrEmpty(animJsonPath)) { editor.animTextAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(animJsonPath); } if (texturePathKV.Count > 0 && textureJsonPathKV.Count > 0) { List <Atlas> atlasList = new List <Atlas>(); foreach (string name in texturePathKV.Keys) { if (textureJsonPathKV.ContainsKey(name)) { if (editor.altasTexture == null) { editor.altasTextAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(textureJsonPathKV[name]); editor.altasTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePathKV[name]); } else { Atlas atlas = new Atlas(); atlas.atlasText = AssetDatabase.LoadAssetAtPath <TextAsset>(textureJsonPathKV[name]); atlas.texture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePathKV[name]); atlasList.Add(atlas); } } } editor.otherTextures = atlasList.ToArray(); } } } }