public IEnumerator DisableObject()
        {
            float minScale = 0.5f;
            float maxScale = 2f;

            var bbox         = InstantiateSceneAndDefaultBbox();
            var scaleHandler = bbox.EnsureComponent <MinMaxScaleConstraint>();

            scaleHandler.ScaleMinimum = minScale;
            scaleHandler.ScaleMaximum = maxScale;
            yield return(null);

            Vector3 initialScale = bbox.transform.localScale;

            const int numHandSteps = 1;

            Vector3  initialHandPosition = new Vector3(0, 0, 0.5f);
            var      frontRightCornerPos = bbox.ScaleCorners[3].transform.position; // front right corner is corner 3
            TestHand hand = new TestHand(Handedness.Right);

            // Hands grab object at initial position
            yield return(hand.Show(initialHandPosition));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.OpenSteadyGrabPoint));

            yield return(hand.MoveTo(frontRightCornerPos, numHandSteps));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            // Verify that scale works before deactivating
            yield return(hand.Move(Vector3.right * 0.2f, numHandSteps));

            Vector3 afterTransformScale = bbox.transform.localScale;

            Assert.AreNotEqual(initialScale, afterTransformScale);

            // Deactivate object and ensure that we don't scale
            bbox.gameObject.SetActive(false);
            yield return(null);

            bbox.gameObject.SetActive(true);
            yield return(hand.Move(Vector3.right * 0.2f, numHandSteps));

            Assert.AreEqual(afterTransformScale, bbox.transform.localScale);
        }
예제 #2
0
        public void SubscriveTimingTest()
        {
            string result  = "";
            var    subject = new Subject <string>();

            {
                // OnNextの内容をスペース区切りで連結し、最後の一つだけを出力するObservable
                var appendStringObservable = subject
                                             .Scan((prev, current) => prev + " " + current)
                                             .Last();

                appendStringObservable.Subscribe(x => result = x);

                subject.OnNext("I");
                subject.OnNext("have");
                subject.OnNext("a");
                subject.OnNext("pen.");
                subject.OnCompleted();
                subject.Dispose();

                Assert.AreEqual("I have a pen.", result, "文字列が連結されている");
            }
            {
                subject = new Subject <string>();

                var appendStringObservable = subject
                                             .Scan((prev, current) => prev + " " + current)
                                             .Last();

                // Subscribeされる前に値を発行する
                subject.OnNext("I");
                subject.OnNext("have");

                // 途中でSubscribeする
                appendStringObservable.Subscribe(x => result = x);

                subject.OnNext("a");
                subject.OnNext("pen.");
                subject.OnCompleted();
                subject.Dispose();

                Assert.AreNotEqual("I have a pen.", result, "Subscribeより前に発行してもメッセージを受信できない");
            }
        }
예제 #3
0
        public void WhenDispatchRestartGameSignal_RestartKeyboard()
        {
            SignalDelegate callback = null;

            _eventDispatcherService
            .When(service => service.Subscribe <RestartGameSignal>(Arg.Any <SignalDelegate>()))
            .Do(info => callback = info.Arg <SignalDelegate>());
            var inGamePresenter = new InGamePresenter(_inGameViewModel, _eventDispatcherService);

            _keyButtonViewModel.Color.Value     = "";
            _keyButtonViewModel.IsEnabled.Value = false;
            _colorObserver.ClearReceivedCalls();
            _isKetEnabledObserver.ClearReceivedCalls();

            Assert.AreNotEqual(InGameViewModel.DefaultColor, _keyButtonViewModel.Color.Value);
            Assert.AreNotEqual(true, _keyButtonViewModel.IsEnabled.Value);
            callback(new RestartGameSignal());

            _colorObserver.Received().OnNext(InGameViewModel.DefaultColor);
            _isKetEnabledObserver.Received().OnNext(true);
        }
예제 #4
0
        public void ErrorTest()
        {
            int  counter = 0;
            bool error   = false;
            var  subject = new Subject <string>();

            subject
            .Select(str => int.Parse(str))
            .Subscribe(
                x => { Debug.Log(x); counter++; },
                ex => { Debug.LogWarning("例外が発生しました:" + ex.Message); error = true; },
                () => Debug.Log("OnCOmpleted"));

            subject.OnNext("1");
            subject.OnNext("2");

            // int.Parseに失敗して例外が発生する
            subject.OnNext("Three");

            Assert.IsTrue(error, "エラーが発行されたのでカウンタが1");

            // OnErrorメッセージ発生により購読は終了済み
            subject.OnNext("4");

            Assert.AreNotEqual(counter, 3, "終了しているのでカウントされない");

            // ただしSubject自体が例外出したわけじゃないのでSubjectは正常稼働中
            // そのため再購読すれば利用ができる
            counter = 0;

            subject.Subscribe(
                x => { Debug.Log(x); counter = 1; },
                () => Debug.Log("Completed"));

            subject.OnNext("Hellor");
            subject.OnCompleted();
            subject.Dispose();

            Assert.AreEqual(1, counter, "再購読したらカウントが 1 になった");
        }
예제 #5
0
        public IEnumerator DisableObject()
        {
            var boundsControl = InstantiateSceneAndDefaultBoundsControl();

            yield return(VerifyInitialBoundsCorrect(boundsControl));

            Vector3 initialScale = boundsControl.transform.localScale;

            const int numHandSteps = 1;

            Vector3  initialHandPosition = new Vector3(0, 0, 0.5f);
            var      frontRightCornerPos = boundsControl.gameObject.transform.Find("rigRoot/corner_3").position; // front right corner is corner 3
            TestHand hand = new TestHand(Handedness.Right);

            // Hands grab object at initial position
            yield return(hand.Show(initialHandPosition));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.OpenSteadyGrabPoint));

            yield return(hand.MoveTo(frontRightCornerPos, numHandSteps));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            // Verify that scale works before deactivating
            yield return(hand.Move(Vector3.right * 0.2f, numHandSteps));

            Vector3 afterTransformScale = boundsControl.transform.localScale;

            Assert.AreNotEqual(initialScale, afterTransformScale);

            // Deactivate object and ensure that we don't scale
            boundsControl.gameObject.SetActive(false);
            yield return(null);

            boundsControl.gameObject.SetActive(true);
            yield return(hand.Move(Vector3.right * 0.2f, numHandSteps));

            Assert.AreEqual(afterTransformScale, boundsControl.transform.localScale);
        }
예제 #6
0
        public void TestDuplicatedExposedReferenceAreNotLinked()
        {
            SimpleExposedPropertyTable propTable = CreatePropertyTableGameObject();
            DummyScriptableObject      obj0      = ScriptableObject.CreateInstance <DummyScriptableObject>();

            GameObject fooGameObject = new GameObject("Foo");

            ExposedReferenceUtility.SetReferenceValueInEditor(ref obj0.exposedGameObject, propTable, fooGameObject);

            //Duplicate
            DummyScriptableObject obj1          = Object.Instantiate(obj0);
            GameObject            barGameObject = new GameObject("Bar");

            ExposedReferenceUtility.RecreateReferenceInEditor(ref obj1.exposedGameObject, propTable);
            Assert.AreEqual(obj0.exposedGameObject.Resolve(propTable), obj1.exposedGameObject.Resolve(propTable));

            //Change value
            ExposedReferenceUtility.SetReferenceValueInEditor(ref obj1.exposedGameObject, propTable, barGameObject);
            Assert.AreNotEqual(obj0.exposedGameObject.Resolve(propTable), obj1.exposedGameObject.Resolve(propTable));

            Object.DestroyImmediate(obj1);
            Object.DestroyImmediate(obj0);
        }
예제 #7
0
        public void WhenDispatchRestartGameSignal_RestartGallow()
        {
            SignalDelegate callback = null;

            _eventDispatcherService
            .When(service => service.Subscribe <RestartGameSignal>(Arg.Any <SignalDelegate>()))
            .Do(info => callback = info.Arg <SignalDelegate>());
            var isEnabledObserver = Substitute.For <IObserver <bool> >();

            _inGameViewModel.IsGallowPartVisible.Clear();
            var gallowImageProperty = _inGameViewModel.SubscribeGallowImage();
            var inGamePresenter     = new InGamePresenter(_inGameViewModel, _eventDispatcherService);

            gallowImageProperty.Subscribe(isEnabledObserver);
            gallowImageProperty.Value             = true;
            _inGameViewModel.NextGallowPartToShow = 2;

            Assert.AreNotEqual(0, _inGameViewModel.NextGallowPartToShow);
            Assert.IsTrue(gallowImageProperty.Value);
            callback(new RestartGameSignal());

            Assert.AreEqual(0, _inGameViewModel.NextGallowPartToShow);
            isEnabledObserver.Received().OnNext(false);
        }
            internal unsafe static void ExecuteInternal(
                ref JobEntityBatchWrapper <T> jobWrapper,
                IntPtr bufferRangePatchData,
                ref JobRanges ranges,
                int jobIndex)
            {
                var chunks          = jobWrapper.CachedChunks;
                var prebuiltBatches = (ArchetypeChunk *)jobWrapper.PrebuiltBatchList.Ptr;

                bool isParallel  = jobWrapper.IsParallel == 1;
                bool isFiltering = jobWrapper.Filter.RequiresMatchesFilter;

                while (true)
                {
                    int beginBatchIndex = 0;
                    int endBatchIndex   = jobWrapper.UsePrebuiltBatchList == 1 ? jobWrapper.PrebuiltBatchList.Length : chunks.Length;

                    // If we are running the job in parallel, steal some work.
                    if (isParallel)
                    {
                        // If we have no range to steal, exit the loop.
                        if (!JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out beginBatchIndex, out endBatchIndex))
                        {
                            break;
                        }

                        JobsUtility.PatchBufferMinMaxRanges(bufferRangePatchData, UnsafeUtility.AddressOf(ref jobWrapper), 0, 0);
                    }

                    // Do the actual user work.
                    if (jobWrapper.UsePrebuiltBatchList == 1)
                    {
                        for (int batchIndex = beginBatchIndex; batchIndex < endBatchIndex; ++batchIndex)
                        {
                            var batch = prebuiltBatches[batchIndex];

                            if (isFiltering && !batch.m_Chunk->MatchesFilter(jobWrapper.MatchingArchetypes.Ptr[jobWrapper.PrebuiltBatchListMatchingArchetypeIndices.Ptr[batchIndex]], ref jobWrapper.Filter))
                            {
                                continue;
                            }

                            Assert.AreNotEqual(0, batch.Count);
                            jobWrapper.JobData.Execute(batch, batchIndex);
                        }
                    }
                    else
                    {
                        if (jobWrapper.JobsPerChunk == 1)
                        {
                            // 1 batch per chunk, with/without filtering
                            for (int batchIndex = beginBatchIndex; batchIndex < endBatchIndex; ++batchIndex)
                            {
                                var chunkIndex = batchIndex;
                                var chunk      = chunks.Ptr[chunkIndex];

                                if (isFiltering && !chunk->MatchesFilter(jobWrapper.MatchingArchetypes.Ptr[chunks.PerChunkMatchingArchetypeIndex.Ptr[chunkIndex]], ref jobWrapper.Filter))
                                {
                                    continue;
                                }

                                var batch = new ArchetypeChunk(chunk, chunks.EntityComponentStore);
                                Assert.AreNotEqual(0, batch.Count);
                                jobWrapper.JobData.Execute(batch, batchIndex);
                            }
                        }
                        else
                        {
                            // 2+ batches per chunk, with/without filtering
                            // This is the most general case; if only one code path survives, it should be this one.
                            for (int batchIndex = beginBatchIndex; batchIndex < endBatchIndex; ++batchIndex)
                            {
                                var chunkIndex        = batchIndex / jobWrapper.JobsPerChunk;
                                var batchIndexInChunk = batchIndex % jobWrapper.JobsPerChunk;
                                var chunk             = chunks.Ptr[chunkIndex];

                                if (isFiltering && !chunk->MatchesFilter(
                                        jobWrapper.MatchingArchetypes.Ptr[
                                            chunks.PerChunkMatchingArchetypeIndex.Ptr[chunkIndex]],
                                        ref jobWrapper.Filter))
                                {
                                    continue;
                                }

                                if (ArchetypeChunk.EntityBatchFromChunk(chunk, chunk->Count, jobWrapper.JobsPerChunk,
                                                                        batchIndexInChunk, chunks.EntityComponentStore, out var batch))
                                {
                                    jobWrapper.JobData.Execute(batch, batchIndex);
                                }
                            }
                        }
                    }

                    // If we are not running in parallel, our job is done.
                    if (!isParallel)
                    {
                        break;
                    }
                }
            }
예제 #9
0
 public static void AreNotEqual(short expected, short actual) => UnityAssert.AreNotEqual(expected, actual);
예제 #10
0
 public static void AreNotEqual <T>(T expected, T actual, string message, IEqualityComparer <T> comparer) => UnityAssert.AreNotEqual(expected, actual, message, comparer);
예제 #11
0
        private static unsafe Entity CopyEntity(Entity srcEntity, World srcWorld, World dstWorld)
        {
            Assert.AreNotEqual(Entity.Null, srcEntity);

            using (var entityReferences = new NativeList <EntityReferenceRemap>(8, Allocator.Temp))
                using (var componentTypes = srcWorld.EntityManager.GetComponentTypes(srcEntity))
                {
                    var archetype = dstWorld.EntityManager.CreateArchetype(componentTypes.ToArray());
                    var dstEntity = dstWorld.EntityManager.CreateEntity(archetype);

                    if (componentTypes.Any(x => x.HasEntityReferences) && !dstWorld.EntityManager.HasComponent <EntityReferenceRemap>(dstEntity))
                    {
                        dstWorld.EntityManager.AddBuffer <EntityReferenceRemap>(dstEntity);
                    }

                    foreach (var componentType in componentTypes)
                    {
                        var typeInfo = TypeManager.GetTypeInfo(componentType.TypeIndex);

                        if (typeInfo.SizeInChunk == 0)
                        {
                            continue;
                        }

                        if (componentType.IsSharedComponent)
                        {
                            // @TODO For now we assume that all shared component data is blittable
                            var srcComponent = srcWorld.EntityManager.GetSharedComponentData(srcEntity, componentType.TypeIndex);

                            var ptr = Unsafe.AsPointer(ref srcComponent);

                            // Pull out all references into the `entityReferences` list
                            ExtractEntityReferences(entityReferences, typeInfo, srcWorld.EntityManager, ptr);

                            // Zero out entity references
                            ClearEntityReferences(typeInfo, ptr);

                            dstWorld.EntityManager.SetSharedComponentDataBoxed(dstEntity, componentType.TypeIndex, srcComponent);
                            continue;
                        }

                        if (componentType.IsBuffer)
                        {
                            var srcBuffer = (BufferHeader *)srcWorld.EntityManager.GetComponentDataRawRW(srcEntity, componentType.TypeIndex);
                            var dstBuffer = (BufferHeader *)dstWorld.EntityManager.GetComponentDataRawRW(dstEntity, componentType.TypeIndex);

                            dstBuffer->Length = srcBuffer->Length;
                            BufferHeader.EnsureCapacity(dstBuffer, srcBuffer->Length, typeInfo.ElementSize, 4, BufferHeader.TrashMode.RetainOldData);

                            // Copy all blittable data
                            UnsafeUtility.MemCpy(BufferHeader.GetElementPointer(dstBuffer), BufferHeader.GetElementPointer(srcBuffer), typeInfo.ElementSize * srcBuffer->Length);

                            for (var i = 0; i < srcBuffer->Length; i++)
                            {
                                var baseOffset = i * typeInfo.ElementSize;

                                // Pull out all references into the `entityReferences` list
                                ExtractEntityReferences(entityReferences, typeInfo, srcWorld.EntityManager, BufferHeader.GetElementPointer(dstBuffer), baseOffset);

                                // Zero out entity references
                                ClearEntityReferences(typeInfo, BufferHeader.GetElementPointer(dstBuffer), baseOffset);
                            }

                            continue;
                        }

                        var componentData = srcWorld.EntityManager.GetComponentDataRawRW(srcEntity, componentType.TypeIndex);

                        // Copy all blittable data
                        dstWorld.EntityManager.SetComponentDataRaw(dstEntity, componentType.TypeIndex, componentData, typeInfo.SizeInChunk);

                        // Pull out all references into the `entityReferences` list
                        ExtractEntityReferences(entityReferences, typeInfo, srcWorld.EntityManager, componentData);

                        // Zero out entity references
                        ClearEntityReferences(typeInfo, dstWorld.EntityManager.GetComponentDataRawRW(dstEntity, componentType.TypeIndex));
                    }

                    if (entityReferences.Length > 0)
                    {
                        dstWorld.EntityManager.GetBuffer <EntityReferenceRemap>(dstEntity).AddRange(entityReferences);
                    }

                    return(dstEntity);
                }
        }
예제 #12
0
 public static void AreNotEqual <T>(T expected, T actual) => UnityAssert.AreNotEqual(expected, actual);
예제 #13
0
 public static void AreNotEqual <T>(T expected, T actual, string message) => UnityAssert.AreNotEqual(expected, actual, message);
예제 #14
0
 public static void AreNotEqual(long expected, long actual) => UnityAssert.AreNotEqual(expected, actual);
예제 #15
0
 public static void AreNotEqual(ulong expected, ulong actual, string message) => UnityAssert.AreNotEqual(expected, actual);
예제 #16
0
 public static void AreNotEqual(int expected, int actual, string message) => UnityAssert.AreNotEqual(expected, actual);
예제 #17
0
 public static void AreNotEqual(uint expected, uint actual) => UnityAssert.AreNotEqual(expected, actual);
예제 #18
0
 public static void AreNotEqual(Object expected, Object actual, string message) => UnityAssert.AreNotEqual(expected, actual, message);
예제 #19
0
 public static void AreNotEqual(char expected, char actual, string message) => UnityAssert.AreNotEqual(expected, actual);
예제 #20
0
 public static void AreNotEqual(char expected, char actual) => UnityAssert.AreNotEqual(expected, actual);
예제 #21
0
 public static void AreNotEqual(byte expected, byte actual, string message) => UnityAssert.AreNotEqual(expected, actual);
예제 #22
0
 public static void AreNotEqual(byte expected, byte actual) => UnityAssert.AreNotEqual(expected, actual);