- Home /
How to change texture type to Cubemap in script?
My app will download stereoscopic images(.jpg) from server, and convert them into cubemap, applied to material and used as skybox.
How do I achieve in script?
AssetImporter can only be reached from UnityEditor.
Answer by FortisVenaliter · May 21, 2015 at 04:51 PM
You'll need to find a way to read in the JPG into a Color[] and then use SetPixels() on a new cubemap.
It seems like the "Cubemap" that you mentioned is not the one I'm looking for.
For example, when we import image and convert to texture, we can select what is the 'Texture Type' of the texture in the inspector of the Unity Editor: e.g Normal $$anonymous$$ap, Lightmap, Sprite...
and then we can change the settings based on the Texture Type that we choose..
The only way to do it by script is using AssetImporter, which can only be executed in Unity Editor but not in app.
Seems like the only solution is to use AssetBundles.
Answer by Bunny83 · May 22, 2015 at 03:03 AM
A cubemap is simply a collection of 6 textures. To create a cubemap at runtime you simply use the Cubemap-class like FortisVenaliter mentioned.
The "import type" you're referring to is an editor-only feature. At runtime none of the asset importers are available. So all those "settings" you see in the inspector belong to the AssetImporter and don't exist at all at runtime.
If you import an image in the editor, Unity actually splits / extracts those 6 images from the incomming texture data. Take a look at this.
Answer by Yum1ng · Jul 28, 2016 at 01:20 PM
Hi, I am having the same problem. How did you resolve this? @felixwcf
Your answer