Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit dbe993a

Browse files
committed
Fix some casts for IL2CPP
1 parent 5a1676f commit dbe993a

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed
7.5 KB
Binary file not shown.

src/UI/Widgets/UnityObjects/MaterialWidget.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,25 @@ public override void OnBorrowed(object target, Type targetType, ReflectionInspec
4848
{
4949
base.OnBorrowed(target, targetType, inspector);
5050

51-
material = target as Material;
51+
material = target.TryCast<Material>();
5252

5353
if (material.mainTexture)
5454
SetActiveTexture(material.mainTexture);
5555

56-
string[] propNames = mi_GetTexturePropertyNames.Invoke(material, ArgumentUtility.EmptyArgs) as string[];
57-
foreach (string property in propNames)
56+
if (mi_GetTexturePropertyNames.Invoke(material, ArgumentUtility.EmptyArgs) is IEnumerable<string> propNames)
5857
{
59-
if (material.GetTexture(property) is Texture texture)
58+
foreach (string property in propNames)
6059
{
61-
if (texture.TryCast<Texture2D>() is null && texture.TryCast<Cubemap>() is null)
62-
continue;
60+
if (material.GetTexture(property) is Texture texture)
61+
{
62+
if (texture.TryCast<Texture2D>() is null && texture.TryCast<Cubemap>() is null)
63+
continue;
6364

64-
textures.Add(property, texture);
65+
textures.Add(property, texture);
6566

66-
if (!activeTexture)
67-
SetActiveTexture(texture);
67+
if (!activeTexture)
68+
SetActiveTexture(texture);
69+
}
6870
}
6971
}
7072

src/UI/Widgets/UnityObjects/Texture2DWidget.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public override void OnBorrowed(object target, Type targetType, ReflectionInspec
3232
{
3333
base.OnBorrowed(target, targetType, inspector);
3434

35-
if (target is Cubemap cubemap)
35+
if (target.TryCast<Cubemap>() is Cubemap cubemap)
3636
{
3737
texture = TextureHelper.UnwrapCubemap(cubemap);
3838
shouldDestroyTexture = true;
3939
}
40-
else if (target is Sprite sprite)
40+
else if (target.TryCast<Sprite>() is Sprite sprite)
4141
{
4242
if (sprite.packingMode == SpritePackingMode.Tight)
4343
texture = sprite.texture;
@@ -47,7 +47,7 @@ public override void OnBorrowed(object target, Type targetType, ReflectionInspec
4747
shouldDestroyTexture = true;
4848
}
4949
}
50-
else if (target is Image image)
50+
else if (target.TryCast<Image>() is Image image)
5151
{
5252
if (image.sprite.packingMode == SpritePackingMode.Tight)
5353
texture = image.sprite.texture;
@@ -58,7 +58,7 @@ public override void OnBorrowed(object target, Type targetType, ReflectionInspec
5858
}
5959
}
6060
else
61-
texture = target as Texture2D;
61+
texture = target.TryCast<Texture2D>();
6262

6363
if (textureViewerRoot)
6464
textureViewerRoot.transform.SetParent(inspector.UIRoot.transform);

0 commit comments

Comments
 (0)