示例#1
0
    void Start()
    {
        cc = new ComponentCache(gameObject , ComponentCache.LogMessageLevel.all);

        Debug.LogWarning("Test Cache");
        cc.GetComponent<AudioSource>();
        cc.GetComponent<AudioSource>();
        cc.DestroyComponent<AudioSource>();

        Debug.LogWarning("Add component test");
        asrc1 = gameObject.AddComponent<AudioSource>();
        asrc1.mute = true;
        AudioSource testAs = cc.GetComponent<AudioSource>();
        if (testAs != asrc1)
            Debug.LogError("Retrieved component not the same?");

        testAs = cc.GetComponent<AudioSource>();
        if (testAs != asrc1)
            Debug.LogError("Retrieved component not the same?");

        Debug.LogWarning("Adding second component");
        AudioSource asrc2 = gameObject.AddComponent<AudioSource>();
        Debug.LogWarning("Destroying first component");
        cc.DestroyComponent(asrc1);
        cc.GetComponent<AudioSource>();
        cc.GetComponent<AudioSource>();

        Assert.IsNull(asrc1);
        Assert.IsNotNull(asrc2);
    }