缓存池的测试

丢人个人来补上次缓存池中没写的测试代码了c#

缓存池的测试

缓存池的测试须要一个激活物体的代码和一个移走物体的代码,具体以下:
激活物体:缓存

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if ( Input.GetMouseButtonDown(0) )
        {
            PoolManager.GetInstance().GetObj("目标路径/Obj1");
        }
        if ( Input.GetMouseButtonDown (1))
        {
            PoolManager.GetInstance().GetObj("目标路径/Obj2");
        }
    }
}

点一下鼠标左键,会出现Obj1;点一下鼠标右键,会出现Obj2。能够挂在场景的任何物体上,测试生成的结果。
移走物体:测试

public class DelayPush : MonoBehaviour
{
    // Start is called before the first frame update
    void OnEnable()
    {
        Invoke("Push", 1);
    }

    // Update is called once per frame
    void Update()
    {
        PoolManager.GetInstance().PushObj(this.gameObject.name, this.gameObject);
    }
}

与Test同样随便挂在场景中,能够使物体延迟1秒后失活,从场景中消失。
观察unity中的hierarchy,发现不管你手速有多快,建立的GameObject是有限的,这样就达到了缓存池的目的,减小内存的消耗。this

相关文章
相关标签/搜索