mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-18 17:17:52 +08:00
2.0.2
* Added support for viewing Texture2D (and Sprite) from the Inspector, and exporting them to PNG * Fixed an issue with generic methods not showing their return value type * Fixed an issue where destroyed UnityEngine.Objects would cause issues in the inspector * Fixed an issue when caching a ValueCollection of a Dictionary (the generic argument for the Entry Type is the last arg, not the first as with other Enumerables)
This commit is contained in:
51
src/Unstrip/ImageConversion/ImageConversionUnstrip.cs
Normal file
51
src/Unstrip/ImageConversion/ImageConversionUnstrip.cs
Normal file
@ -0,0 +1,51 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
|
||||
namespace Explorer.Unstrip.ImageConversion
|
||||
{
|
||||
public static class ImageConversionUnstrip
|
||||
{
|
||||
// byte[] ImageConversion.EncodeToPNG(this Texture2D image);
|
||||
|
||||
public static byte[] EncodeToPNG(this Texture2D tex)
|
||||
{
|
||||
return EncodeToPNG_iCall(tex.Pointer);
|
||||
}
|
||||
|
||||
internal delegate byte[] EncodeToPNG_delegate(IntPtr tex);
|
||||
internal static EncodeToPNG_delegate EncodeToPNG_iCall =
|
||||
IL2CPP.ResolveICall<EncodeToPNG_delegate>("UnityEngine.ImageConversion::EncodeToPNG");
|
||||
|
||||
// bool ImageConversion.LoadImage(this Texture2D tex, byte[] data, bool markNonReadable);
|
||||
|
||||
public static bool LoadImage(this Texture2D tex, byte[] data, bool markNonReadable)
|
||||
{
|
||||
return LoadImage_iCall(tex.Pointer, data, markNonReadable);
|
||||
}
|
||||
|
||||
internal delegate bool LoadImage_delegate(IntPtr tex, byte[] data, bool markNonReadable);
|
||||
internal static LoadImage_delegate LoadImage_iCall =
|
||||
IL2CPP.ResolveICall<LoadImage_delegate>("UnityEngine.ImageConversion::LoadImage");
|
||||
|
||||
// Helper for LoadImage
|
||||
|
||||
public static bool LoadImage(this Texture2D tex, string filePath, bool markNonReadable)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = File.ReadAllBytes(filePath);
|
||||
return tex.LoadImage(data, markNonReadable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user