Main/Assets/Launcher/ExternalLibs/SceneDataSplit/SceneRestoreRunTimeUtils.cs
2025-01-25 04:38:09 +08:00

96 lines
2.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Thousandto.Launcher.ExternalLibs
{
public class SceneRestoreRunTimeUtils
{
#region//私有变量
private static Action<string, Action<Texture>> _textureHandle = null;
private static Action<string> _releaseTexHanle = null;
private static List<string> _cacheTexPath = new List<string>();
private static Func<Shader,Material> _newMatHandle = null;
private static Action<Material> _freeMatHandle = null;
#endregion
#region//私有变量
#endregion
public static void SetHandler(Action<string, Action<Texture>> handle, Action<string> releaseHanle, Func<Shader, Material> newMatHander, Action<Material> freeMatHander )
{
_textureHandle = handle;
_releaseTexHanle = releaseHanle;
_newMatHandle = newMatHander;
_freeMatHandle = freeMatHander;
}
public static void SetTexture(string texName, string pname, Action<Texture> action)
{
if (_textureHandle != null)
{
_textureHandle(texName, (tex) => {
if (tex != null)
{
if (action != null)
action(tex);
_cacheTexPath.Add(texName);
}
});
}
}
public static Material NewMaterial(Shader sd)
{
if (_newMatHandle != null)
{
return _newMatHandle(sd);
}
else
{
#if UNITY_EDITOR && !FUNCELL_LAUNCHER
return new Material(sd);
#endif
}
return null;
}
public static void FreeMaterial(Material mat)
{
if (_freeMatHandle != null)
{
_freeMatHandle(mat);
}
else
{
#if UNITY_EDITOR && !FUNCELL_LAUNCHER
if (mat != null)
{
GameObject.DestroyImmediate(mat);
mat = null;
}
#endif
}
}
public static void ReleaseTexture()
{
for (int i = 0; i < _cacheTexPath.Count; i++)
{
var path = _cacheTexPath[i];
_releaseTexHanle(path);
}
_cacheTexPath.Clear();
}
public static void ReleaseTexture(string name)
{
_releaseTexHanle(name);
}
}
}