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); base.OnBorrowed(target, targetType, inspector);
material = target as Material; material = target.TryCast<Material>();
if (material.mainTexture) if (material.mainTexture)
SetActiveTexture(material.mainTexture); SetActiveTexture(material.mainTexture);
string[] propNames = mi_GetTexturePropertyNames.Invoke(material, ArgumentUtility.EmptyArgs) as string[]; if (mi_GetTexturePropertyNames.Invoke(material, ArgumentUtility.EmptyArgs) is IEnumerable<string> propNames)
foreach (string property in propNames)
{ {
if (material.GetTexture(property) is Texture texture) foreach (string property in propNames)
{ {
if (texture.TryCast<Texture2D>() is null && texture.TryCast<Cubemap>() is null) if (material.GetTexture(property) is Texture texture)
continue; {
if (texture.TryCast<Texture2D>() is null && texture.TryCast<Cubemap>() is null)
continue;
textures.Add(property, texture); textures.Add(property, texture);
if (!activeTexture) if (!activeTexture)
SetActiveTexture(texture); SetActiveTexture(texture);
}
} }
} }

View File

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