Fix some casts for IL2CPP

This commit is contained in:
Sinai 2022-05-05 22:18:19 +10:00
parent 5a1676fb84
commit dbe993a7c7
3 changed files with 15 additions and 13 deletions

View File

@ -48,23 +48,25 @@ namespace UnityExplorer.UI.Widgets
{
base.OnBorrowed(target, targetType, inspector);
material = target as Material;
material = target.TryCast<Material>();
if (material.mainTexture)
SetActiveTexture(material.mainTexture);
string[] propNames = mi_GetTexturePropertyNames.Invoke(material, ArgumentUtility.EmptyArgs) as string[];
foreach (string property in propNames)
if (mi_GetTexturePropertyNames.Invoke(material, ArgumentUtility.EmptyArgs) is IEnumerable<string> propNames)
{
if (material.GetTexture(property) is Texture texture)
foreach (string property in propNames)
{
if (texture.TryCast<Texture2D>() is null && texture.TryCast<Cubemap>() is null)
continue;
if (material.GetTexture(property) is Texture texture)
{
if (texture.TryCast<Texture2D>() is null && texture.TryCast<Cubemap>() is null)
continue;
textures.Add(property, texture);
textures.Add(property, texture);
if (!activeTexture)
SetActiveTexture(texture);
if (!activeTexture)
SetActiveTexture(texture);
}
}
}

View File

@ -32,12 +32,12 @@ namespace UnityExplorer.UI.Widgets
{
base.OnBorrowed(target, targetType, inspector);
if (target is Cubemap cubemap)
if (target.TryCast<Cubemap>() is Cubemap cubemap)
{
texture = TextureHelper.UnwrapCubemap(cubemap);
shouldDestroyTexture = true;
}
else if (target is Sprite sprite)
else if (target.TryCast<Sprite>() is Sprite sprite)
{
if (sprite.packingMode == SpritePackingMode.Tight)
texture = sprite.texture;
@ -47,7 +47,7 @@ namespace UnityExplorer.UI.Widgets
shouldDestroyTexture = true;
}
}
else if (target is Image image)
else if (target.TryCast<Image>() is Image image)
{
if (image.sprite.packingMode == SpritePackingMode.Tight)
texture = image.sprite.texture;
@ -58,7 +58,7 @@ namespace UnityExplorer.UI.Widgets
}
}
else
texture = target as Texture2D;
texture = target.TryCast<Texture2D>();
if (textureViewerRoot)
textureViewerRoot.transform.SetParent(inspector.UIRoot.transform);