栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

Addressable内存释放代码

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Addressable内存释放代码

 Unity Addressable内存管理_凌志·C的博客-CSDN博客_addressables 内存管理
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
 
public class testaa : MonoBehaviour
{
    private static List Cubelist = new List();
    private static List Spherelist = new List();
    private static List CubeTexture2Dlist = new List();
    private static List SphereTexture2Dlist = new List();

    public GameObject cube;
    public GameObject sphere;
    
    [MenuItem("testaa/CreateCube")]

    public static void CreateCube()
    {
        Addressables.InstantiateAsync("Cube").Completed += delegate(AsyncOperationHandle handle)
        {  
            Cubelist.Add(handle.Result);
        };
    }
    [MenuItem("testaa/CreateSphere")]

    public static void CreateSphere()
    {
        Addressables.InstantiateAsync("Sphere").Completed += delegate(AsyncOperationHandle handle)
        {  
            Spherelist.Add(handle.Result);
        };
    }
    [MenuItem("testaa/CreateCubeTex")]

    public static void CreateCubeTex()
    {
        GameObject cube = null;
        Addressables.InstantiateAsync("Cube").Completed += delegate(AsyncOperationHandle handle)
        {
            cube = handle.Result;
            Cubelist.Add(handle.Result);
            Addressables.LoadAssetAsync("CubeTex").Completed += delegate(AsyncOperationHandle tex)
            {
                CubeTexture2Dlist.Add(tex.Result);

                var material= cube.GetComponent();
                material.material.mainTexture = (Texture2D)tex.Result;
            };
        };

    }
    
    [MenuItem("testaa/CreateSphereex")]

    public static void CreateSphereTex()
    {
        GameObject cube = null;
        Addressables.InstantiateAsync("Sphere").Completed += delegate(AsyncOperationHandle handle)
        {
            cube = handle.Result;
            Spherelist.Add(handle.Result);
            Addressables.LoadAssetAsync("SphereTex").Completed += delegate(AsyncOperationHandle tex)
            {
                SphereTexture2Dlist.Add(tex.Result);
                var material= cube.GetComponent();
                material.material.mainTexture = (Texture2D)tex.Result;
            };
        };

    }
    [MenuItem("testaa/CreateCubeTex2SceneGo")]

    public static void CreateCubeTex1()
    {
        
        Addressables.LoadAssetAsync("CubeTex").Completed += delegate(AsyncOperationHandle tex)
        {
            CubeTexture2Dlist.Add(tex.Result);

            var material= GameObject.Find("cube").GetComponent();
            material.material.mainTexture = (Texture2D)tex.Result;
        };

    }
    
    [MenuItem("testaa/CreateSphereex2SceneGo")]

    public static void CreateSphereTex1()
    {
        Addressables.LoadAssetAsync("SphereTex").Completed += delegate(AsyncOperationHandle tex)
        {
            SphereTexture2Dlist.Add(tex.Result);
            var material=  GameObject.Find("sphere").GetComponent();
            material.material.mainTexture = (Texture2D)tex.Result;
        };
    }
    [MenuItem("testaa/ClearCube")]

    public static void ClearCube()
    {
        for (int i = 0; i < Cubelist.Count; i++)
        {
            Addressables.Release(Cubelist[i]);
        }
        Cubelist.Clear();

        if ( GameObject.Find("cube"))
        {
            GameObject.DestroyImmediate( GameObject.Find("cube"));
        }
    }
    [MenuItem("testaa/ClearSphere")]
    public static void ClearSphere()
    {
        for (int i = 0; i < Spherelist.Count; i++)
        {
            Addressables.Release(Spherelist[i]);
        }
        Spherelist.Clear();
        if ( GameObject.Find("sphere"))
        {
            GameObject.DestroyImmediate( GameObject.Find("sphere"));
        }
    }
    [MenuItem("testaa/ClearCubeTexture2D")]
    public static void ClearTexture2D()
    {
        for (int i = 0; i < CubeTexture2Dlist.Count; i++)
        {
            Addressables.Release(CubeTexture2Dlist[i]);
        }
        CubeTexture2Dlist.Clear();
    }
    
    [MenuItem("testaa/ClearSphereTexture2Dlist")]
    public static void ClearSphereTexture2Dlist()
    {
        for (int i = 0; i < SphereTexture2Dlist.Count; i++)
        {
            Addressables.Release(SphereTexture2Dlist[i]);
        }
        SphereTexture2Dlist.Clear();

    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/901604.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号