void OnEnable() { zoffset = EditorPrefs.GetFloat("bone2d_zoffset", 0.002f); displayType = (Bone2DSetupEditor.DisplayType)EditorPrefs.GetInt("bone2d_displayType", 0); genericAnim = EditorPrefs.GetBool("bone2d_genericAnim", true); genPrefab = EditorPrefs.GetBool("bone2d_genPrefab", false); genAnimations = EditorPrefs.GetBool("bone2d_genAnims", true); genAvatar = EditorPrefs.GetBool("bone2d_genAvatar", false); genMeshCollider = EditorPrefs.GetBool("bone2d_genMeshCollider", false); genImgCollider = EditorPrefs.GetBool("bone2d_genImgCollider", false); genCustomCollider = EditorPrefs.GetBool("bone2d_genCustomCollider", true); }
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 SpineArmatureEditor CreateSpineByDir(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, textureFilePath = null; List <string> texturePaths = new List <string>(); foreach (string path in Directory.GetFiles(dirPath)) { if (path.IndexOf(".atlas") > -1 && path.LastIndexOf(".meta") == -1) { textureFilePath = path; continue; } if (path.IndexOf(".png") > -1 && path.LastIndexOf(".meta") == -1) { texturePaths.Add(path); continue; } if (path.IndexOf(".json") > -1 && path.LastIndexOf(".meta") == -1) { animJsonPath = path; } } string texturePath = null; if (texturePaths.Count > 0) { texturePath = texturePaths[0]; } if (!string.IsNullOrEmpty(animJsonPath) && !string.IsNullOrEmpty(texturePath) && !string.IsNullOrEmpty(textureFilePath)) { SpineArmatureEditor instance = ScriptableObject.CreateInstance <SpineArmatureEditor>(); instance.displayType = displayType; instance.altasTextAsset = LoadAtlas(Application.dataPath + "/" + textureFilePath.Substring(6)); instance.altasTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePath); instance.animTextAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(animJsonPath); if (texturePaths.Count > 1) { instance.otherTextures = new Atlas[texturePaths.Count - 1]; } for (int i = 1; i < texturePaths.Count; ++i) { Atlas atlas = new Atlas(); atlas.atlasText = instance.altasTextAsset; atlas.texture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePaths[i]); instance.otherTextures[i - 1] = atlas; } if (instance.altasTexture && !string.IsNullOrEmpty(instance.altasTextAsset) && instance.animTextAsset) { return(instance); } } else if (displayType == Bone2DSetupEditor.DisplayType.SpriteRender && !string.IsNullOrEmpty(animJsonPath)) { string spritesPath = null; foreach (string path in Directory.GetDirectories(dirPath)) { if (path.LastIndexOf("texture") > -1) { spritesPath = path; break; } } if (!string.IsNullOrEmpty(spritesPath)) { Dictionary <string, Sprite> spriteKV = new Dictionary <string, Sprite>(); foreach (string path in Directory.GetFiles(spritesPath)) { if (path.LastIndexOf(".png") > -1 && path.LastIndexOf(".meta") == -1) { Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(path); spriteKV[sprite.name] = sprite; } } if (spriteKV.Count > 0) { SpineArmatureEditor instance = ScriptableObject.CreateInstance <SpineArmatureEditor>(); instance.displayType = displayType; instance.spriteKV = spriteKV; instance.animTextAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(animJsonPath); return(instance); } } } } } return(null); }