Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to use TextureImporter to change texture shape

Discussion in 'Scripting' started by ryanmccauley211, Sep 6, 2018.

  1. ryanmccauley211

    ryanmccauley211

    Joined:
    Jul 25, 2018
    Posts:
    6
    I want to load a 360 image and change the texture shape from the default 2D to 'cube'. I don't really understand how to use TextureImporter to achieve this and I need to be able to to it via script? What I have below does not change the texture shape / dimension.

    byte[] bytes = File.ReadAllBytes(imgPath);

    Code (CSharp):
    1.  
    2. Texture2D imgTexture = new Texture2D(0, 0);
    3. ImageConversion.LoadImage(imgTexture, bytes);
    4. TextureImporter importer = (TextureImporter) TextureImporter.GetAtPath(imgPath);
    5.  
    6. if (imgTexture.dimension != UnityEngine.Rendering.TextureDimension.Cube)
    7. {
    8.     importer.textureShape = TextureImporterShape.TextureCube;
    9.     importer.SaveAndReimport();
    10. }
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
  3. ryanmccauley211

    ryanmccauley211

    Joined:
    Jul 25, 2018
    Posts:
    6