コード例 #1
0
        protected override void OnMarsUpdate()
        {
            var frameCount = MarsTime.FrameCount - m_StartFrame;

            switch (frameCount)
            {
            case 2:
                m_ProxyObject  = InstantiateReferenceObject(TestPrefab);
                m_Proxy        = m_ProxyObject.GetComponent <Proxy>();
                m_ProxyContent = m_ProxyObject.transform.GetChild(0).gameObject;
                break;

            case 4:
                Assert.False(m_ProxyContent.activeInHierarchy);
                break;

            case 5:
                Assert.Throws <ArgumentException>(() =>
                {
                    var result1 = this.AssignQueryMatch(m_Proxy.queryID, k_DataId);
                    Assert.False(result1);
                });

                Assert.False(m_ProxyContent.activeInHierarchy);
                Assert.Null(m_Proxy.currentData);
                break;

            case 6:
                // this data has all traits required by the proxy, but doesn't match the conditions
                this.AddOrUpdateTrait(k_DataId, TraitNames.Bounds2D, new Vector2(0.01f, 0.01f));
                this.AddOrUpdateTrait(k_DataId, TraitNames.Pose, new Pose());
                this.AddOrUpdateTrait(k_DataId, TraitNames.Plane, true);
                break;

            case 7:
                Assert.Throws <ArgumentException>(() =>
                {
                    var result2 = this.AssignQueryMatch(m_Proxy.queryID, k_DataId);
                    Assert.False(result2);
                });

                Assert.False(m_ProxyContent.activeInHierarchy);
                Assert.Null(m_Proxy.currentData);
                break;

            case 8:
                // this should make the data match the conditions
                this.AddOrUpdateTrait(k_DataId, TraitNames.Bounds2D, k_DataId1Bounds);

                // now that conditions match, assignment should succeed
                var result3 = this.AssignQueryMatch(m_Proxy.queryID, k_DataId);
                Assert.True(result3);

                // make sure the data match made it into the query result
                Assert.AreEqual(k_DataId, m_Proxy.currentData.DataID);
                Assert.True(m_Proxy.currentData.TryGetTrait(TraitNames.Bounds2D, out Vector2 boundsValue1));
                Assert.AreEqual(k_DataId1Bounds, boundsValue1);
                break;

            case 9:
                // verify the content was activated after acquire
                Assert.True(m_ProxyContent.activeInHierarchy);
                break;

            case 10:
                // this data has all traits required by the proxy, but doesn't match the conditions
                this.AddOrUpdateTrait(k_DataId2, TraitNames.Bounds2D, k_DataId2Bounds);
                this.AddOrUpdateTrait(k_DataId2, TraitNames.Pose, new Pose());
                this.AddOrUpdateTrait(k_DataId2, TraitNames.Plane, true);
                break;

            case 11:
                // Assignment should fail because the query is already using the data
                Assert.Throws <ArgumentException>(() =>
                {
                    var result4 = this.AssignQueryMatch(m_Proxy.queryID, k_DataId);
                    Assert.False(result4);
                });
                break;

            case 12:
                // Assignment should succeed, even though conditions aren't met
                var result5 = m_Proxy.AssignMatch(k_DataId2, false);
                Assert.True(result5);
                Assert.True(m_ProxyContent.activeInHierarchy);

                // make sure the new data made it into the query result
                Assert.AreEqual(k_DataId2, m_Proxy.currentData.DataID);
                Assert.True(m_Proxy.currentData.TryGetTrait(TraitNames.Bounds2D, out Vector2 boundsValue2));
                Assert.AreEqual(k_DataId2Bounds, boundsValue2);
                break;

            case 13:
                this.UnregisterQuery(m_Proxy.queryID);
                Assert.AreEqual(0, m_QueryBackend.UnsetStandaloneMatchIndices.Count);
                break;
            }
        }