当前位置: 首页>>代码示例>>C#>>正文


C# Scene.AddObject方法代码示例

本文整理汇总了C#中Scene.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# Scene.AddObject方法的具体用法?C# Scene.AddObject怎么用?C# Scene.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scene的用法示例。


在下文中一共展示了Scene.AddObject方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddRemoveGameObjectsMultiScene

        public void AddRemoveGameObjectsMultiScene()
        {
            // Set up some objects
            Scene scene = new Scene();
            Scene scene2 = new Scene();
            GameObject obj = new GameObject("TestObject");
            GameObject obj2 = new GameObject("TestObject2");
            GameObject objChildA = new GameObject("TestObjectChildA", obj);
            GameObject objChildB = new GameObject("TestObjectChildB", obj);
            scene.AddObject(obj);
            scene2.AddObject(obj2);

            // Let object switch Scenes implicitly by parent-child relationship
            objChildA.Parent = obj2;
            Assert.AreEqual(scene2, objChildA.ParentScene);
            CollectionAssert.AreEquivalent(new[] { obj, objChildB }, scene.AllObjects);
            CollectionAssert.AreEquivalent(new[] { obj2, objChildA }, scene2.AllObjects);
            CollectionAssert.Contains(obj2.Children, objChildA);
            Assert.AreEqual(obj2, objChildA.Parent);

            // Remove object from a Scene it doesn't belong to
            scene.RemoveObject(obj2);
            CollectionAssert.AreEquivalent(new[] { obj, objChildB }, scene.AllObjects);
            CollectionAssert.AreEquivalent(new[] { obj2, objChildA }, scene2.AllObjects);

            // Add object to Scene, despite belonging to a different Scene
            scene.AddObject(obj2);
            CollectionAssert.AreEquivalent(new[] { obj, obj2, objChildA, objChildB }, scene.AllObjects);
            CollectionAssert.IsEmpty(scene2.AllObjects);

            // Clean up
            scene.Dispose();
            scene2.Dispose();
        }
开发者ID:BraveSirAndrew,项目名称:duality,代码行数:34,代码来源:SceneTest.cs

示例2: SwitchToDuringUpdate

		[Test] public void SwitchToDuringUpdate()
		{
			// Set up some objects
			Scene scene = new Scene();
			Scene scene2 = new Scene();
			
			// Switch to the first Scene regularly
			{
				Scene.SwitchTo(scene);
				Assert.AreEqual(Scene.Current, scene);
			}

			// Switch to the second during update
			{
				GameObject obj = new GameObject("SwitchObject");
				var switchComponent = new UpdateSwitchToSceneComponent { Target = scene2 };
				obj.AddComponent(switchComponent);
				scene.AddObject(obj);

				DualityApp.Update();
				Assert.False(switchComponent.Switched);
				Assert.AreEqual(Scene.Current, scene2);

				Scene.SwitchTo(scene);
				Assert.AreEqual(Scene.Current, scene);
			}

			// Clean up
			scene.Dispose();
			scene2.Dispose();
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:31,代码来源:SceneTest.cs

示例3: Render_test_scene

        public void Render_test_scene()
        {
            var s = new Scene();

            var m1 = new Material { Diffuse = new RealColor(Color.Yellow), ReflectionCoefficient = 0.5 };
            var m2 = new Material { Diffuse = new RealColor(Color.Cyan), ReflectionCoefficient = 0.5 };
            var m3 = new Material { Diffuse = new RealColor(Color.Magenta), ReflectionCoefficient = 0.5 };

            s.AddObject(new Sphere(100, 233, 290, 0, m1));
            s.AddObject(new Sphere(100, 407, 290, 0, m2));
            s.AddObject(new Sphere(100, 320, 140, 0, m3));
            s.AddObject(new Sphere(30, 160, 240, -50, m3));

            s.AddLightSource(new PointLight(new RealColor(1, 1, 1), 0, 240, -100));
            s.AddLightSource(new PointLight(new RealColor(0.6f, 0.6f, 0.6f), 640, 240, -10000));

            RenderSceneToFile(s);
        }
开发者ID:jmfryan,项目名称:csharp-raytracer,代码行数:18,代码来源:Class1.cs

示例4: Render_Ball_on_plane

        public void Render_Ball_on_plane()
        {
            var s = new Scene();

            var mirror = new Material { Diffuse = new RealColor(Color.White), ReflectionCoefficient = 1.0 };
            var matt = new Material { Diffuse = new RealColor(Color.Red), ReflectionCoefficient = 0 };

            s.AddObject(new Sphere(100, 320, 300, 0, matt));

            s.AddLightSource(new PointLight(new RealColor(1, 1, 1), 0, 240, -100));
            s.AddLightSource(new PointLight(new RealColor(0.6f, 0.6f, 0.6f), 640, 240, -10000));

            RenderSceneToFile(s);
        }
开发者ID:jmfryan,项目名称:csharp-raytracer,代码行数:14,代码来源:Class1.cs

示例5: AddRemoveGameObjects

        public void AddRemoveGameObjects()
        {
            // Set up some objects
            Scene scene = new Scene();
            GameObject obj = new GameObject("TestObject");
            GameObject objChildA = new GameObject("TestObjectChildA", obj);
            GameObject objChildB = new GameObject("TestObjectChildB", obj);
            scene.AddObject(obj);

            // Basic setup check (Added properly?)
            Assert.AreEqual(scene, obj.ParentScene);
            CollectionAssert.AreEquivalent(new[] { obj, objChildA, objChildB }, scene.AllObjects);

            // Removing root object
            scene.RemoveObject(obj);
            Assert.AreEqual(null, obj.ParentScene);
            CollectionAssert.IsEmpty(scene.AllObjects);

            // Adding removed root object again
            scene.AddObject(obj);
            Assert.AreEqual(scene, obj.ParentScene);
            CollectionAssert.AreEquivalent(new[] { obj, objChildA, objChildB }, scene.AllObjects);

            // Remove non-root object
            scene.RemoveObject(objChildA);
            CollectionAssert.AreEquivalent(new[] { obj, objChildB }, scene.AllObjects);
            CollectionAssert.DoesNotContain(obj.Children, objChildA);
            Assert.IsNull(objChildA.ParentScene);
            Assert.IsNull(objChildA.Parent);

            // Clear Scene
            scene.Clear();
            CollectionAssert.IsEmpty(scene.AllObjects);

            // Clean up
            scene.Dispose();
        }
开发者ID:BraveSirAndrew,项目名称:duality,代码行数:37,代码来源:SceneTest.cs

示例6: GameObjectParentLoop

		[Test] public void GameObjectParentLoop()
		{
			// Set up some objects
			Scene scene = new Scene();
			GameObject obj = new GameObject("TestObject");
			GameObject objChild = new GameObject("TestObjectChild", obj);
			GameObject objChildChild = new GameObject("TestObjectChildChild", objChild);
			scene.AddObject(obj);

			// Attempt to create a closed parent loop. Expect the operation to be rejected.
			Assert.Throws<ArgumentException>(() => obj.Parent = objChildChild);
			Assert.AreEqual(null, obj.Parent);
			Assert.AreEqual(obj, objChild.Parent);
			Assert.AreEqual(objChild, objChildChild.Parent);

			// Attempt to create a direct self-reference loop. Expect the operation to be rejected.
			Assert.Throws<ArgumentException>(() => obj.Parent = obj);
			Assert.AreEqual(null, obj.Parent);
			Assert.AreEqual(obj, objChild.Parent);
			Assert.AreEqual(objChild, objChildChild.Parent);

			// Clean up
			scene.Dispose();
		}
开发者ID:arajar,项目名称:duality,代码行数:24,代码来源:SceneTest.cs

示例7: GameObjectActiveLists

		[Test] public void GameObjectActiveLists()
		{
			// Set up some objects
			Scene scene = new Scene();
			GameObject obj = new GameObject("TestObject");
			GameObject obj2 = new GameObject("TestObject2");
			GameObject objChildA = new GameObject("TestObjectChildA", obj);
			GameObject objChildB = new GameObject("TestObjectChildB", obj);
			scene.AddObject(obj);
			scene.AddObject(obj2);

			// Inactive objects shouldn't show up in active lists
			objChildB.Active = false;
			obj2.Active = false;
			CollectionAssert.AreEquivalent(new[] { obj, obj2, objChildA, objChildB }, scene.AllObjects);
			CollectionAssert.AreEquivalent(new[] { obj, objChildA }, scene.ActiveObjects);
			CollectionAssert.AreEquivalent(new[] { obj, obj2 }, scene.RootObjects);
			CollectionAssert.AreEquivalent(new[] { obj }, scene.ActiveRootObjects);
			
			// Activating them again should make them show up again
			objChildB.Active = true;
			obj2.Active = true;
			CollectionAssert.AreEquivalent(scene.AllObjects, scene.ActiveObjects);
			CollectionAssert.AreEquivalent(scene.RootObjects, scene.ActiveRootObjects);

			// Clean up
			scene.Dispose();
		}
开发者ID:arajar,项目名称:duality,代码行数:28,代码来源:SceneTest.cs

示例8: GameObjectHierarchy

		[Test] public void GameObjectHierarchy()
		{
			// Set up some objects
			Scene scene = new Scene();
			Scene scene2 = new Scene();
			GameObject obj = new GameObject("TestObject");
			GameObject obj2 = new GameObject("TestObject2");
			GameObject objChildA = new GameObject("TestObjectChildA", obj);
			GameObject objChildB = new GameObject("TestObjectChildB", obj);
			scene.AddObject(obj);
			scene2.AddObject(obj2);

			// Remove non-root object
			scene.RemoveObject(objChildA);
			CollectionAssert.AreEquivalent(new[] { obj, objChildB }, scene.AllObjects);
			CollectionAssert.DoesNotContain(obj.Children, objChildA);
			Assert.IsNull(objChildA.ParentScene);
			Assert.IsNull(objChildA.Parent);

			// Add object implicitly by parent-child relationship
			objChildA.Parent = obj;
			CollectionAssert.AreEquivalent(new[] { obj, objChildA, objChildB }, scene.AllObjects);
			CollectionAssert.Contains(obj.Children, objChildA);
			Assert.AreEqual(scene, objChildA.ParentScene);
			Assert.AreEqual(obj, objChildA.Parent);

			// Change object parent
			objChildA.Parent = objChildB;
			CollectionAssert.AreEquivalent(new[] { obj, objChildA, objChildB }, scene.AllObjects);
			CollectionAssert.Contains(objChildB.Children, objChildA);
			Assert.AreEqual(scene, objChildA.ParentScene);
			Assert.AreEqual(objChildB, objChildA.Parent);

			// Clean up
			scene.Dispose();
			scene2.Dispose();
		}
开发者ID:arajar,项目名称:duality,代码行数:37,代码来源:SceneTest.cs

示例9: CloneScene

		[Test] public void CloneScene()
		{
			Random rnd = new Random();
			Scene source = new Scene();
			{
				// Create a basic object hierarchy
				GameObject objA = new GameObject("ObjectA");
				GameObject objB = new GameObject("ObjectB");
				GameObject objC = new GameObject("ObjectC", objA);

				// Create some Components containing data
				objA.AddComponent(new TestComponent(rnd));
				objB.AddComponent(new TestComponent(rnd));
				objC.AddComponent(new TestComponent(rnd));

				// Introduce some cross-object references
				objA.GetComponent<TestComponent>().GameObjectReference = objC;
				objA.GetComponent<TestComponent>().ComponentReference = objB.GetComponent<TestComponent>();
				objB.GetComponent<TestComponent>().GameObjectReference = objA;
				objB.GetComponent<TestComponent>().ComponentReference = objC.GetComponent<TestComponent>();
				objC.GetComponent<TestComponent>().GameObjectReference = objB;
				objC.GetComponent<TestComponent>().ComponentReference = objA.GetComponent<TestComponent>();

				// Add it all to the Scene
				source.AddObject(objA);
				source.AddObject(objB);
				source.AddObject(objC);
			}
			Scene target = source.DeepClone();

			Assert.AreNotSame(source, target);
			Assert.AreEqual(source.AllObjects.Count(), target.AllObjects.Count());
			foreach (GameObject sourceObj in source.AllObjects)
			{
				GameObject targetObj = target.FindGameObject(sourceObj.FullName);

				Assert.AreNotSame(sourceObj, targetObj);
				Assert.AreEqual(sourceObj.FullName, targetObj.FullName);

				TestComponent sourceCmp = sourceObj.GetComponent<TestComponent>();
				TestComponent targetCmp = targetObj.GetComponent<TestComponent>();

				// See if the data Components are cloned and intact
				Assert.AreEqual(sourceCmp, targetCmp);
				Assert.AreNotSame(sourceCmp, targetCmp);
				Assert.AreNotSame(sourceCmp.TestReferenceList, targetCmp.TestReferenceList);

				// Check cross-object references
				Assert.AreNotSame(sourceCmp.GameObjectReference, targetCmp.GameObjectReference);
				Assert.AreEqual(sourceCmp.GameObjectReference.FullName, targetCmp.GameObjectReference.FullName);
				Assert.AreNotSame(sourceCmp.ComponentReference, targetCmp.ComponentReference);
				Assert.AreEqual(sourceCmp.ComponentReference.GameObj.FullName, targetCmp.ComponentReference.GameObj.FullName);
			}
		}
开发者ID:undue,项目名称:duality,代码行数:54,代码来源:SpecificCloningTest.cs

示例10: CopyToGameObjectAddGameObjectEvent

		[Test] public void CopyToGameObjectAddGameObjectEvent()
		{
			Random rnd = new Random();
			bool gameObjectAddedEventReceived = false;

			// Prepare a test Scene
			Scene testScene = new Scene();
			GameObject source = new GameObject("ObjectA");
			GameObject sourceChild = new GameObject("Child", source);
			testScene.AddObject(source);
			GameObject target = new GameObject("ObjectB");
			testScene.AddObject(target);
			
			// Listen to object added events
			EventHandler<GameObjectEventArgs> sceneHandler = delegate (object sender, GameObjectEventArgs e)
			{
				gameObjectAddedEventReceived = true;
			};
			Scene.GameObjectAdded += sceneHandler;

			// Enter the test Scene, so global Scene events will be fired
			Scene.SwitchTo(testScene);
			try
			{
				// Copy source object to target object
				source.DeepCopyTo(target);
			
				// Make sure that events are fired properly when adding completely new Components
				Assert.IsTrue(gameObjectAddedEventReceived);

				gameObjectAddedEventReceived = false;
				source.DeepCopyTo(target);

				// Don't fire the event when the Component was already there
				Assert.IsFalse(gameObjectAddedEventReceived);
			}
			finally
			{
				Scene.GameObjectAdded -= sceneHandler;
				Scene.SwitchTo(null);
			}
		}
开发者ID:undue,项目名称:duality,代码行数:42,代码来源:SpecificCloningTest.cs

示例11: CopyToGameObjectParentScene

		[Test] public void CopyToGameObjectParentScene()
		{
			Random rnd = new Random();
			GameObject source = new GameObject("ObjectA");
			source.AddComponent(new TestComponent(rnd));
			GameObject target = new GameObject("ObjectB");
			Scene scene = new Scene();
			scene.AddObject(target);

			source.DeepCopyTo(target);
			
			Assert.AreSame(scene, target.ParentScene);
		}
开发者ID:undue,项目名称:duality,代码行数:13,代码来源:SpecificCloningTest.cs


注:本文中的Scene.AddObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。