Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use path relative to the project folder. #89

Open
ZhangHuan0407 opened this issue Dec 5, 2024 · 0 comments
Open

Use path relative to the project folder. #89

ZhangHuan0407 opened this issue Dec 5, 2024 · 0 comments

Comments

@ZhangHuan0407
Copy link

Unity Editor 2022.3.19
UnityEditor.cs

        [MenuItem("Assets/Create/DragonBones/Create Unity Data", false, 32)]
        private static void _CreateUnityDataMenuItem()
        {
            foreach (var dragonBonesSkePath in _GetDragonBonesSkePaths(true))
            {
                var dragonBonesSke = AssetDatabase.LoadMainAssetAtPath(dragonBonesSkePath) as TextAsset;
                var textureAtlasJSONs = new List<string>();
                GetTextureAtlasConfigs(textureAtlasJSONs, AssetDatabase.GetAssetPath(dragonBonesSke.GetInstanceID()));
                UnityDragonBonesData.TextureAtlas[] textureAtlas = new UnityDragonBonesData.TextureAtlas[textureAtlasJSONs.Count];

                for (int i = 0; i < textureAtlasJSONs.Count; ++i)
                {
                    string path = textureAtlasJSONs[i];
                    //load textureAtlas data
                    UnityDragonBonesData.TextureAtlas ta = new UnityDragonBonesData.TextureAtlas();

                    // 可能unity5或更早期 支持AssetDatabase完整路径,但2022已经出现问题了
                    // Invalid AssetDatabase path: D:\XXX\XXX\Assets\Resources/YYY.png.
                    // Use path relative to the project folder.
                    // 2024/10/15 强制切断为相对路径
                    // =====
                    string currentDirectoryPath = Directory.GetCurrentDirectory().ToString();
                    path = path.Substring(currentDirectoryPath.Length + 1);
                    // ====

                    //load texture
                    ta.textureAtlasJSON = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
                    path = path.Substring(0, path.LastIndexOf(".json"));
                    ta.texture = AssetDatabase.LoadAssetAtPath<Texture2D>(path + ".png");
                    //load material
                    ta.material = AssetDatabase.LoadAssetAtPath<Material>(path + "_Mat.mat");
                    ta.uiMaterial = AssetDatabase.LoadAssetAtPath<Material>(path + "_UI_Mat.mat");
                    textureAtlas[i] = ta;
                }

                //
                CreateUnityDragonBonesData(dragonBonesSke, textureAtlas);
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant