mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-06 01:23:31 +08:00
Some cleanups
This commit is contained in:
parent
a6bf91b7af
commit
a9faec8cf9
@ -71,6 +71,9 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
while (e.InnerException != null)
|
||||
e = e.InnerException;
|
||||
|
||||
ExplorerCore.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}");
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
}
|
||||
|
@ -3,7 +3,11 @@ using System.Collections.Generic;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
#if CPP
|
||||
using UnhollowerBaseLib;
|
||||
using UnityExplorer.Helpers;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Tests
|
||||
@ -19,7 +23,6 @@ namespace UnityExplorer.Tests
|
||||
"three",
|
||||
};
|
||||
public static void StaticMethod() { }
|
||||
|
||||
}
|
||||
|
||||
public class TestClass
|
||||
@ -140,7 +143,8 @@ namespace UnityExplorer.Tests
|
||||
}
|
||||
|
||||
#if CPP
|
||||
TestTexture = UIManager.MakeSolidTexture(Color.white, 1000, 600);
|
||||
//TestTexture = UIManager.MakeSolidTexture(Color.white, 1000, 600);
|
||||
TestTexture = new Texture();
|
||||
TestTexture.name = "TestTexture";
|
||||
|
||||
var r = new Rect(0, 0, TestTexture.width, TestTexture.height);
|
||||
|
@ -149,37 +149,5 @@ namespace UnityExplorer.UI
|
||||
|
||||
return rootObj;
|
||||
}
|
||||
|
||||
public static Sprite CreateSprite(Texture2D tex, Rect size = default)
|
||||
{
|
||||
#if CPP
|
||||
Vector2 pivot = Vector2.zero;
|
||||
Vector4 border = Vector4.zero;
|
||||
|
||||
if (size == default)
|
||||
{
|
||||
size = new Rect(0, 0, tex.width, tex.height);
|
||||
}
|
||||
|
||||
return Sprite.CreateSprite_Injected(tex, ref size, ref pivot, 100f, 0u, SpriteMeshType.Tight, ref border, false);
|
||||
#else
|
||||
return Sprite.Create(tex, size, Vector2.zero);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static Texture2D MakeSolidTexture(Color color, int width, int height)
|
||||
{
|
||||
Color[] pixels = new Color[width * height];
|
||||
for (int i = 0; i < pixels.Length; i++)
|
||||
{
|
||||
pixels[i] = color;
|
||||
}
|
||||
|
||||
Texture2D tex = new Texture2D(width, height);
|
||||
tex.SetPixels(pixels);
|
||||
tex.Apply();
|
||||
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,16 @@ namespace UnityExplorer.Unstrip
|
||||
{
|
||||
public static class ImageConversionUnstrip
|
||||
{
|
||||
// LoadImage helper from a filepath
|
||||
|
||||
public static bool LoadImage(Texture2D tex, string filePath, bool markNonReadable)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
return tex.LoadImage(File.ReadAllBytes(filePath), markNonReadable);
|
||||
}
|
||||
|
||||
#if CPP
|
||||
// byte[] ImageConversion.EncodeToPNG(this Texture2D image);
|
||||
|
||||
@ -17,8 +27,12 @@ namespace UnityExplorer.Unstrip
|
||||
|
||||
public static byte[] EncodeToPNG(this Texture2D tex)
|
||||
{
|
||||
IntPtr ptr = ICallHelper.GetICall<d_EncodeToPNG>("UnityEngine.ImageConversion::EncodeToPNG")
|
||||
.Invoke(tex.Pointer);
|
||||
var iCall = ICallHelper.GetICall<d_EncodeToPNG>("UnityEngine.ImageConversion::EncodeToPNG");
|
||||
|
||||
IntPtr ptr = iCall.Invoke(tex.Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return new Il2CppStructArray<byte>(ptr);
|
||||
}
|
||||
@ -38,19 +52,23 @@ namespace UnityExplorer.Unstrip
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Helper for LoadImage from filepath
|
||||
// Sprite Sprite.Create
|
||||
|
||||
public static bool LoadImage(Texture2D tex, string filePath, bool markNonReadable)
|
||||
internal delegate IntPtr d_CreateSprite(IntPtr texture, ref Rect rect, ref Vector2 pivot, float pixelsPerUnit,
|
||||
uint extrude, int meshType, ref Vector4 border, bool generateFallbackPhysicsShape);
|
||||
|
||||
public static Sprite CreateSprite(Texture texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, Vector4 border)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var iCall = ICallHelper.GetICall<d_CreateSprite>("UnityEngine.Sprite::CreateSprite_Injected");
|
||||
|
||||
byte[] data = File.ReadAllBytes(filePath);
|
||||
return tex.LoadImage(data, markNonReadable);
|
||||
var ptr = iCall.Invoke(texture.Pointer, ref rect, ref pivot, pixelsPerUnit, extrude, 1, ref border, false);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
else
|
||||
return new Sprite(ptr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user