Search Unity

Create Skybox Runtime From 360 Image

Discussion in 'Scripting' started by JudahMantell, Aug 3, 2020.

  1. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Hi!
    Long story short:
    I want users to be able to import their own 360 images (pngs) at runtime (I think I got that part down), but then create a skybox with that image and apply it to the scene.

    I know I can create new materials at runtime, but how would I take a png, set it to "cube" and apply that to a new material with the skybox/cubemap shader at runtime?

    Thanks!
     
  2. GameDev_PL

    GameDev_PL

    Joined:
    Nov 14, 2016
    Posts:
    4
    Code (CSharp):
    1. var bytes=tex.EncodeToPNG();
    2. string path="Assets/Resources/... .png";
    3. File.WriteAllBytes(path,bytes);
    4. AssetDatabase.Refresh();
    5. AssetDatabase.ImportAsset(path);
    6. TextureImporter importer = AssetImporter.GetAtPath(path)as TextureImporter;
    7. importer.textureType=TextureImporterType.GUI;
    8. AssetDatabase.WriteImportSettingsIfDirty(path);
    9. Add comment ·  
    ************
    Change type.gui to wath you want
     
  3. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    I appreciate the reply... but 'm not quite sure I understand exactly what's happening in the code you wrote.
    I need this to work at runtime standalone, and I'm pretty sure the AssetDatabase class is only usable in editor.