コード例 #1
0
    public void Start()
    {
        var query = AssetManagerQueryPool <AssetManagerQuery> .Get();

        query.AddTagCriteria("example");

        this.assets  = AssetManager.instance.Query <AssetExample>(query);
        this.assets2 = AssetManager.instance.Query <AssetExample2>(query);

        AssetManagerQueryPool <AssetManagerQuery> .Return(query);
    }
コード例 #2
0
        public void AssetManagementTestQuery()
        {
            var a1 = CreateManagedGameObject(new string[] { "test" }, "asset1", "1");
            var a2 = CreateManagedScriptableObject <AssetExample>(new string[] { "test2" }, "asset2", "2");
            var a3 = CreateManagedScriptableObject <AssetExample>(new string[] { "test3", "test4" }, "asset3", "3");
            var a4 = CreateManagedScriptableObject <AssetExample2>(new string[] { "test5", "test6" }, "asset4", "4");

            AssetManager.instance.RegisterAsset(a1);
            AssetManager.instance.RegisterAsset(a2);
            AssetManager.instance.RegisterAsset(a3);
            AssetManager.instance.RegisterAsset(a4);

            // Tags query
            var query = AssetManagerQueryPool <AssetManagerQuery> .Get();

            query.AddTagCriteria("test");

            var qRes = AssetManager.instance.Query <Transform>(query);

            Assert.AreSame(a1.transform, qRes[0]);
            Assert.AreEqual(1, qRes.Count);

            // Exception throw test
            var aRes = AssetManager.instance.Query <AudioSource>(query);

            Assert.AreEqual(0, aRes.Count);

            try
            {
                AssetManager.instance.Query <AudioSource>(query, aRes, -1, true);
                Assert.IsTrue(false);
            }
            catch (System.InvalidCastException)
            {
            }
            Assert.AreEqual(0, aRes.Count);
            AssetManagerQueryPool <AssetManagerQuery> .Return(query);

            // Name query
            query = AssetManagerQueryPool <AssetManagerQuery> .Get();

            query.AddNameCriteria("2");

            var eRes = AssetManager.instance.Query <AssetExample>(query);

            Assert.AreSame(eRes[0], a2);
            Assert.AreEqual(1, eRes.Count);
            AssetManagerQueryPool <AssetManagerQuery> .Return(query);

            // Multitag query
            query = AssetManagerQueryPool <AssetManagerQuery> .Get();

            query.AddTagCriteria("test3");
            query.AddTagCriteria("test4");

            var oRes = AssetManager.instance.Query <UnityEngine.Object>(query);

            Assert.AreSame(oRes[0], a3);
            Assert.AreEqual(1, oRes.Count);
            AssetManagerQueryPool <AssetManagerQuery> .Return(query);

            // Type query
            query = AssetManagerQuery.GetPooledTypeQuery(typeof(AssetExample2));
            var tRes = AssetManager.instance.Query <UnityEngine.Object>(query);

            Assert.AreEqual(1, tRes.Count);
            Assert.AreSame(tRes[0], a4);

            // Deregister
            AssetManager.instance.DeregisterAsset(a1);
            AssetManager.instance.DeregisterAsset(a2);
            AssetManager.instance.DeregisterAsset(a3);

            Assert.AreSame(null, AssetManager.instance.GetObject <Transform>("asset1"));
        }