[Test] public void AddRemove()
        {
            InitializableEventReceiver initTester = new InitializableEventReceiver();

            // Adding and Removing
            this.obj.AddComponent(initTester);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.AddToGameObject));
            this.obj.RemoveComponent(initTester);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.RemovingFromGameObject));
        }
        [Test] public void Serialize()
        {
            InitializableEventReceiver initTester = this.obj.AddComponent <InitializableEventReceiver>();

            using (MemoryStream stream = new MemoryStream())
            {
                this.scene.Save(stream);
                Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Saving));
                Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Saved));

                stream.Seek(0, SeekOrigin.Begin);
                this.scene = Resource.Load <Scene>(stream);
                Assert.IsTrue(this.scene.FindComponent <InitializableEventReceiver>().HasReceived(InitializableEventReceiver.EventFlag.Loaded));
            }
        }
        [Test] public void DeactivateComponentDispose()
        {
            InitializableEventReceiver initTester = this.obj.AddComponent <InitializableEventReceiver>();

            Scene.SwitchTo(this.scene, true);
            initTester.Dispose();
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate));
        }
        [Test] public void DeactivateGameObjectDispose()
        {
            InitializableEventReceiver initTester = this.obj.AddComponent <InitializableEventReceiver>();

            Scene.SwitchTo(this.scene, true);
            this.obj.Dispose();
            DualityApp.RunCleanup();             // Need to run cleanup, so disposed GameObjects will be processed.
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate));
        }
        [Test] public void ActivateDeactivate()
        {
            InitializableEventReceiver initTester = this.obj.AddComponent <InitializableEventReceiver>();

            // Activate by Scene.Current
            Scene.SwitchTo(this.scene, true);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate));
            initTester.Reset();

            // Deactivate by GameObject.Active
            this.obj.Active = false;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate));
            initTester.Reset();

            // Activate by GameObject.Active
            this.obj.Active = true;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate));
            initTester.Reset();

            // Deactivate by Component.Active
            initTester.Active = false;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate));
            initTester.Reset();

            // Activate by Component.Active
            initTester.Active = true;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate));
            initTester.Reset();

            // Deactivate by Scene.Current
            Scene.SwitchTo(null, true);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate));
            initTester.Reset();
        }
Exemple #6
0
        [Test] public void IgnoreActiveStateInNonCurrentScene()
        {
            InitializableEventReceiver initTester = this.obj.AddComponent <InitializableEventReceiver>();

            // Deactivate by GameObject.Active
            this.obj.Active = false;
            Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate));
            initTester.Reset();

            // Activate by GameObject.Active
            this.obj.Active = true;
            Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate));
            initTester.Reset();

            // Deactivate by Component.Active
            initTester.Active = false;
            Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate));
            initTester.Reset();

            // Activate by Component.Active
            initTester.Active = true;
            Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate));
            initTester.Reset();
        }
Exemple #7
0
        /// <summary>
        /// This test will determine whether a <see cref="Scene"/> that was activated in isolation / without
        /// being <see cref="Scene.Current"/> will ensure the initialization and shutdown of objects added
        /// or removed during its lifetime.
        /// </summary>
        [Test] public void IsolatedInitAndShutdown()
        {
            // Create an isolated new test scene
            Scene scene = new Scene();

            GameObject testObj = new GameObject("TestObject");
            InitializableEventReceiver testReceiver = testObj.AddComponent <InitializableEventReceiver>();

            scene.AddObject(testObj);

            // Ensure events are delivered in scene activation
            testReceiver.Reset();
            scene.Activate();
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by Scene activation");

            // Ensure events are delivered in scene deactivation
            testReceiver.Reset();
            scene.Deactivate();
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by Scene deactivation");

            // Ensure no events are delivered for removal while deactivated
            testReceiver.Reset();
            scene.RemoveObject(testObj);
            scene.Activate();
            Assert.AreEqual(InitializableEventReceiver.EventFlag.None, testReceiver.ReceivedEvents, "Removal from Scene, activation of Scene");

            // Ensure events are delivered post-activation
            testReceiver.Reset();
            scene.AddObject(testObj);
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by addition to active Scene");

            testReceiver.Reset();
            testObj.RemoveComponent(testReceiver);
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Removal from object in active Scene");
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.RemovingFromGameObject), "Removal from object in active Scene");

            testReceiver.Reset();
            testObj.AddComponent(testReceiver);
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Addition to object in active Scene");
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.AddToGameObject), "Addition to object in active Scene");

            testReceiver.Reset();
            testObj.Active = false;
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by GameObject.Active property in active Scene");

            testReceiver.Reset();
            testObj.Active = true;
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by GameObject.Active property in active Scene");

            testReceiver.Reset();
            testReceiver.Active = false;
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by Component.Active property in active Scene");

            testReceiver.Reset();
            testReceiver.Active = true;
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by Component.Active property in active Scene");

            testReceiver.Reset();
            scene.RemoveObject(testObj);
            Assert.IsTrue(testReceiver.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by removal from active Scene");

            // Ensure no de/activation events are delivered in an inactive scene
            scene.Deactivate();
            testReceiver.Reset();
            scene.AddObject(testObj);
            testObj.Active      = false;
            testObj.Active      = true;
            testReceiver.Active = false;
            testReceiver.Active = true;
            scene.RemoveObject(testObj);
            Assert.AreEqual(InitializableEventReceiver.EventFlag.None, testReceiver.ReceivedEvents, "No de/activation events in inactive Scene");
        }
Exemple #8
0
        [Test] public void ActivateDeactivate()
        {
            InitializableEventReceiver initTester = this.obj.AddComponent <InitializableEventReceiver>();

            // Activate by Scene.Current
            Scene.SwitchTo(this.scene, true);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by Scene.Current");
            initTester.Reset();

            // Deactivate by GameObject.Active
            this.obj.Active = false;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by GameObject.Active");
            initTester.Reset();

            {
                // Removing inactive object shouldn't trigger events
                this.scene.RemoveObject(this.obj);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Removing inactive object shouldn't trigger events");
                initTester.Reset();

                // Adding inactive object shouldn't trigger events
                this.scene.AddObject(this.obj);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Adding inactive object shouldn't trigger events");
                initTester.Reset();

                // Removing inactive objects Component shouldn't trigger events
                this.obj.RemoveComponent(initTester);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Removing inactive objects Component shouldn't trigger events");
                initTester.Reset();

                // Adding inactive objects Component shouldn't trigger events
                this.obj.AddComponent(initTester);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Adding inactive objects Component shouldn't trigger events");
                initTester.Reset();
            }

            // Activate by GameObject.Active
            this.obj.Active = true;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by GameObject.Active");
            initTester.Reset();

            // Deactivate by Component.Active
            initTester.Active = false;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by Component.Active");
            initTester.Reset();

            {
                // Removing inactive Components object shouldn't trigger events
                this.scene.RemoveObject(this.obj);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Removing inactive Components object shouldn't trigger events");
                initTester.Reset();

                // Adding inactive Components object shouldn't trigger events
                this.scene.AddObject(this.obj);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Adding inactive Components object shouldn't trigger events");
                initTester.Reset();

                // Removing inactive Component shouldn't trigger events
                this.obj.RemoveComponent(initTester);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Removing inactive Component shouldn't trigger events");
                initTester.Reset();

                // Adding inactive Component shouldn't trigger events
                this.obj.AddComponent(initTester);
                Assert.IsFalse(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Adding inactive Component shouldn't trigger events");
                initTester.Reset();
            }

            // Activate by Component.Active
            initTester.Active = true;
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by Component.Active");
            initTester.Reset();

            // Deactivate by removing from Scene
            this.scene.RemoveObject(this.obj);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by removing from Scene");
            initTester.Reset();

            // Activate by adding to Scene
            this.scene.AddObject(this.obj);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Activate), "Activate by adding to Scene");
            initTester.Reset();

            // Deactivate by Scene.Current
            Scene.SwitchTo(null, true);
            Assert.IsTrue(initTester.HasReceived(InitializableEventReceiver.EventFlag.Deactivate), "Deactivate by Scene.Current");
            initTester.Reset();
        }