using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Thousandto.Launcher.ExternalLibs { public class SceneRestoreRunTimeUtils { #region//私有变量 private static Action> _textureHandle = null; private static Action _releaseTexHanle = null; private static List _cacheTexPath = new List(); private static Func _newMatHandle = null; private static Action _freeMatHandle = null; #endregion #region//私有变量 #endregion public static void SetHandler(Action> handle, Action releaseHanle, Func newMatHander, Action freeMatHander ) { _textureHandle = handle; _releaseTexHanle = releaseHanle; _newMatHandle = newMatHander; _freeMatHandle = freeMatHander; } public static void SetTexture(string texName, string pname, Action 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); } } }