ToBytes
How do I use To Bytes
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
52 | byte[] bytes = ImportUtils.Base64ToBytes(data); | 1 |
105 | public static byte[] Base64ToBytes(string base64) | 2 |
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: ImportUtils.cs
Copy
105 public static byte[] Base64ToBytes(string base64)
106 {
107 return Convert.FromBase64String(base64);
108 }
ToBytes 106 lượt xem
Gõ tìm kiếm nhanh...