protected override void OnUpdate()
        {
            Entities.ForEach((VA_AnimationLibraryComponentAuthoring animationLib) =>
            {
                animationLib.animationLibrary.Init();

                // Blob builder to build.
                using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
                {
                    // Construct the root.
                    ref VA_AnimationLibraryData animationDataBlobAsset = ref blobBuilder.ConstructRoot <VA_AnimationLibraryData>();

                    // Set all the data.
                    BlobBuilderArray <VA_AnimationData> animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, animationLib.animationLibrary.animationData.Count);

                    for (int i = 0; i < animationDataArray.Length; i++)
                    {
                        // Copy data.
                        animationDataArray[i] = animationLib.animationLibrary.animationData[i];

                        if (animationLib.debugMode)
                        {
                            UnityEngine.Debug.Log("VA_AnimationLibrary added " + animationDataArray[i].name.ToString());
                        }
                    }

                    // Construct blob asset reference.
                    //BlobAssetReference<VA_AnimationLibraryData> animLibAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationLibraryData>(Allocator.Persistent);
                    // Static because of multi scene setup.
                    animLibAssetRef = blobBuilder.CreateBlobAssetReference <VA_AnimationLibraryData>(Allocator.Persistent);

                    // Add it to the asset store.
                    BlobAssetStore.TryAdd(new Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), animLibAssetRef);

                    if (animationLib.debugMode)
                    {
                        UnityEngine.Debug.Log("VA_AnimationLibrary has " + animLibAssetRef.Value.animations.Length.ToString() + " animations.");
                    }
                }

                // Remove the entity since we don't need it anymore.
                DstEntityManager.DestroyEntity(GetPrimaryEntity(animationLib));
            });
コード例 #2
0
        public void TestCacheAccess()
        {
            var a0 = BlobAssetReference <int> .Create(0);

            var a1 = BlobAssetReference <int> .Create(1);

            var a2 = BlobAssetReference <float> .Create(2.0f);

            var k0 = FromInt(a0.Value);
            var k1 = FromInt(a1.Value);
            var k2 = FromFloat(a2.Value);

            Assert.IsTrue(m_Store.TryAdd(k0, a0));
            Assert.IsFalse(m_Store.TryAdd(k0, a0));
            Assert.IsTrue(m_Store.TryGet <int>(k0, out var ra0));
            Assert.AreEqual(0, ra0.Value);
            Assert.AreEqual(0, m_Store.CacheMiss);
            Assert.AreEqual(1, m_Store.CacheHit);

            Assert.IsFalse(m_Store.TryGet <int>(k1, out var ra1));
            Assert.IsTrue(m_Store.TryAdd(k1, a1));
            Assert.IsTrue(m_Store.TryGet <int>(k1, out ra1));
            Assert.AreEqual(1, ra1.Value);
            Assert.AreEqual(1, m_Store.CacheMiss);
            Assert.AreEqual(2, m_Store.CacheHit);

            Assert.IsFalse(m_Store.TryGet <float>(k2, out var ra2));
            Assert.IsTrue(m_Store.TryAdd(k2, a2));
            Assert.IsTrue(m_Store.TryGet(k2, out ra2));
            Assert.AreEqual(2.0f, ra2.Value);
            Assert.AreEqual(2, m_Store.CacheMiss);
            Assert.AreEqual(3, m_Store.CacheHit);
        }