-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUtils.cs
42 lines (38 loc) · 1.43 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using PVZ_Hyper_Fusion.AssetStore;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace PVZ_Hyper_Fusion
{
internal class Utils
{
#if USE_TEXTURE
internal static bool TryReplaceTexture2D(Texture2D ogTexture)
{
if (ogTexture is not null)
{
if (TextureStore.textureDict.ContainsKey(ogTexture.name))
{
string textturePath = TextureStore.textureDict[ogTexture.name];
ImageConversion.LoadImage(ogTexture, File.ReadAllBytes(textturePath));
Log.LogDebug("OK! Replaced Texture " + ogTexture.name);
ogTexture.name = "replaced_" + ogTexture.name;
return true;
}
}
return false;
}
internal static Texture2D LoadImage(string path)
{
if (!File.Exists(path))
{
// Throw an exception if the file does not exist
throw new FileNotFoundException($"The image file at path '{path}' does not exist.");
}
byte[] array = File.ReadAllBytes(path);
Texture2D texture2D = new Texture2D(2, 2, GraphicsFormat.R8G8B8A8_UNorm, TextureCreationFlags.None, 1, IntPtr.Zero, null);
ImageConversion.LoadImage(texture2D, array);
return texture2D;
}
#endif
}
}