ImportAssetOptions









How do I use Import Asset Options
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonConverter.cs Copy
160     static void ConvertScripts(List scriptPathList)
161     {
162         bool ignoreWarningIsLogged = false;
163
164         foreach (string script in scriptPathList)
165         {
166             if (script.Contains("PhotonNetwork")) //Don't convert this file (and others)
167             {
168                 if (!ignoreWarningIsLogged)
169                 {
170                     ignoreWarningIsLogged = true;
171                     Debug.LogWarning("Conversion to PUN ignores all files with \"PhotonNetwork\" in their file-path.\nCheck: " + script);
172                 }
173                 continue;
174             }
175             if (script.Contains("Image Effects"))
176             {
177                 continue;
178             }
179
180             ConvertToPhotonAPI(script);
181         }
182
183         foreach (string script in scriptPathList)
184         {
185             AssetDatabase.ImportAsset(script, ImportAssetOptions.ForceUpdate);
186         }
187     }
File name: PhotonConverter.cs Copy
341     static void EnsureFolder(string path)
342     {
343         if (!Directory.Exists(path))
344         {
345             Directory.CreateDirectory(path);
346             AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
347             AssetDatabase.Refresh();
348         }
349     }
File name: ImportTiled2Unity.Xml.cs Copy
42         private void ImportTexturesFromXml(XDocument xml)
43         {
44             var texData = xml.Root.Elements("ImportTexture");
45             foreach (var tex in texData)
46             {
47                 string name = tex.Attribute("filename").Value;
48                 string data = tex.Value;
49
50                 // The data is gzip compressed base64 string. We need the raw bytes.
51                 //byte[] bytes = ImportUtils.GzipBase64ToBytes(data);
52                 byte[] bytes = ImportUtils.Base64ToBytes(data);
53
54                 // Save and import the texture asset
55                 {
56                     string pathToSave = ImportUtils.GetTexturePath(name);
57                     ImportUtils.ReadyToWrite(pathToSave);
58                     File.WriteAllBytes(pathToSave, bytes);
59                     AssetDatabase.ImportAsset(pathToSave, ImportAssetOptions.ForceSynchronousImport);
60                 }
61
62                 // Create a material if needed in prepartion for the texture being successfully imported
63                 {
64                     string materialPath = ImportUtils.GetMaterialPath(name);
65                     Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
66                     if (material == null)
67                     {
68                         // We need to create the material afterall
69                         // Use our custom shader
70                         material = new Material(Shader.Find("Tiled/TextureTintSnap"));
71                         ImportUtils.ReadyToWrite(materialPath);
72                         AssetDatabase.CreateAsset(material, materialPath);
73                     }
74                 }
75             }
76         }
File name: ImportTiled2Unity.Xml.cs Copy
103         private void ImportMeshesFromXml(XDocument xml)
104         {
105             var meshData = xml.Root.Elements("ImportMesh");
106             foreach (var mesh in meshData)
107             {
108                 // We're going to create/write a file that contains our mesh data as a Wavefront Obj file
109                 // The actual mesh will be imported from this Obj file
110
111                 string name = mesh.Attribute("filename").Value;
112                 string data = mesh.Value;
113
114                 // The data is in base64 format. We need it as a raw string.
115                 string raw = ImportUtils.Base64ToString(data);
116
117                 // Save and import the asset
118                 string pathToMesh = "Assets/Tiled2Unity/Meshes/" + name;
119                 ImportUtils.ReadyToWrite(pathToMesh);
120                 File.WriteAllText(pathToMesh, raw, Encoding.UTF8);
121                 AssetDatabase.ImportAsset(pathToMesh, ImportAssetOptions.ForceSynchronousImport);
122             }
123         }

ImportAssetOptions 132 lượt xem

Gõ tìm kiếm nhanh...