Ejemplo n.º 1
0
    public void ResLoadTest()
    {
        // 注册自定义类型的 Res
        ResFactory.RegisterCustomRes((address) =>
        {
            if (address.StartsWith("test://"))
            {
                return(new TestRes()
                {
                    Name = address
                });
            }

            return(null);
        });

        // 测试
        var resLoader = new ResLoader();

        var iconTextureRes = resLoader.LoadRes("test://icon_texture");

        Assert.IsTrue(iconTextureRes is TestRes);
        Assert.AreEqual(1, iconTextureRes.RefCount);
        Assert.AreEqual(ResState.Loaded, iconTextureRes.State);

        resLoader.UnloadAllAsset();

        Assert.AreEqual(0, iconTextureRes.RefCount);
        Assert.AreEqual(ResState.NotLoad, iconTextureRes.State);


        resLoader = null;
    }
        public void ResLoaderTest()
        {
            ResFactory.RegisterCustomRes((resSearchKeys) =>
            {
                if (resSearchKeys.Address.StartsWith("test://"))
                {
                    return(new TestRes()
                    {
                        Name = resSearchKeys.Address,
                        ResType = resSearchKeys.ResType
                    });
                }

                return(null);
            });
            // 测试
            var resLoader = new ResLoader();

            var iconTextureRes = resLoader.LoadRes(new ResSearchKeys("test://icon_texture", typeof(Texture2D)));

            Assert.IsTrue(iconTextureRes is TestRes);
            Assert.AreEqual(1, iconTextureRes.RefCount);
            Assert.AreEqual(ResState.Loaded, iconTextureRes.State);

            resLoader.UnloadAllAssets();

            Assert.AreEqual(0, iconTextureRes.RefCount);
            Assert.AreEqual(ResState.NotLoad, iconTextureRes.State);
        }