From d3d84d13807734f77214ee3098877671ad9e86d4 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Thu, 9 Jan 2025 12:07:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Editor/SetReadWrite.cs | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Assets/Scripts/Editor/SetReadWrite.cs diff --git a/Assets/Scripts/Editor/SetReadWrite.cs b/Assets/Scripts/Editor/SetReadWrite.cs new file mode 100644 index 00000000..cb45e4f0 --- /dev/null +++ b/Assets/Scripts/Editor/SetReadWrite.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; + +public class SetReadWrite : Editor +{ + [MenuItem("Assets/FBX ReadWrite Enable %&r")] + public static void EnableFBXReadWrite() + { + Object[] selectedObjects = Selection.GetFiltered(SelectionMode.DeepAssets); + foreach (Object obj in selectedObjects) + { + if (obj != null) + { + string path = AssetDatabase.GetAssetPath(obj); + if (Directory.Exists(path)) + { + EnableFBXReadWriteInFolder(path); + } + else if (path.EndsWith(".fbx", System.StringComparison.OrdinalIgnoreCase)) + { + EnableFBXReadWriteForFile(path); + } + } + } + } + + public static void EnableFBXReadWriteInFolder(string folderPath) + { + string[] files = Directory.GetFiles(folderPath, "*.fbx", SearchOption.AllDirectories); + foreach (string file in files) + { + EnableFBXReadWriteForFile(file); + } + } + + public static void EnableFBXReadWriteForFile(string filePath) + { + string relativePath = filePath; + ModelImporter importer = AssetImporter.GetAtPath(relativePath) as ModelImporter; + if (importer != null) + { + importer.isReadable = true; + AssetDatabase.ImportAsset(relativePath, ImportAssetOptions.ForceUpdate); + Debug.Log("Enabled Read/Write for: " + relativePath); + } + } +}