Add support for Cubemaps in Texture2DWidget

This commit is contained in:
Sinai
2022-05-05 02:45:24 +10:00
parent ef4bc75d5e
commit 104288a912
3 changed files with 8 additions and 16 deletions

View File

@ -33,7 +33,10 @@ namespace UnityExplorer.UI.Widgets
{
base.OnBorrowed(target, targetType, inspector);
TextureRef = target.TryCast<Texture2D>();
if (target.TryCast<Cubemap>() is Cubemap cubemap)
TextureRef = TextureHelper.UnwrapCubemap(cubemap);
else
TextureRef = target.TryCast<Texture2D>();
realWidth = TextureRef.width;
realHeight = TextureRef.height;
@ -175,18 +178,7 @@ namespace UnityExplorer.UI.Widgets
if (File.Exists(path))
File.Delete(path);
Texture2D tex = TextureRef;
if (!TextureHelper.IsReadable(tex))
tex = TextureHelper.ForceReadTexture(tex);
byte[] data = TextureHelper.EncodeToPNG(tex);
File.WriteAllBytes(path, data);
if (tex != TextureRef)
{
// cleanup temp texture if we had to force-read it.
GameObject.Destroy(tex);
}
TextureHelper.SaveTextureAsPNG(TextureRef, path);
}
public override GameObject CreateContent(GameObject uiRoot)

View File

@ -30,7 +30,7 @@ namespace UnityExplorer.UI.Widgets
UnityObjectWidget widget = target switch
{
Texture2D => Pool<Texture2DWidget>.Borrow(),
Texture2D or Cubemap => Pool<Texture2DWidget>.Borrow(),
AudioClip => Pool<AudioClipWidget>.Borrow(),
_ => Pool<UnityObjectWidget>.Borrow()
};