obsidian/笔记文件/2.笔记/获取物体绝对路径所在文件夹.md
2025-03-26 00:02:56 +08:00

719 B

#unity/日常积累

通过SubString()就可以获取到物体所在文件夹了

!Pasted image 20230224120953.png

如果文件夹不存在,就创建:

        public void AddResource()
        {
            currentLobbyCameraAnimationPath =
                $"Assets/BundleResources/CommonRegion/OutsideGame/Skins/Characters/{RoleIndex}/SkinParts/{NumberIndex}/RelatedResources/ani&{NumberIndex}_LobbyCameraAnimation_Height.anim";
            string path =
                currentLobbyCameraAnimationPath.Substring(0, currentLobbyCameraAnimationPath.LastIndexOf(@"/"));
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }