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


C# Entity.Add方法代码示例

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


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

示例1: TestAddRemoveListenerImpl

        private void TestAddRemoveListenerImpl(Game game)
        {
            var audio = game.Audio;
            var notAddedToEntityListener = new AudioListenerComponent();
            var addedToEntityListener = new AudioListenerComponent();

            // Add a listenerComponent not present in the entity system yet and check that it is correctly added to the AudioSystem internal data structures
            Assert.DoesNotThrow(() => audio.AddListener(notAddedToEntityListener), "Adding a listener not present in the entity system failed");
            Assert.IsTrue(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem does not contains the notAddedToEntityListener.");

            // Add a listenerComponent already present in the entity system and check that it is correctly added to the AudioSystem internal data structures
            var entity = new Entity("Test");
            entity.Add(addedToEntityListener);
            throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); 
            //game.Entities.Add(entity);
            Assert.DoesNotThrow(() => audio.AddListener(addedToEntityListener), "Adding a listener present in the entity system failed");
            Assert.IsTrue(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem does not contains the addedToEntityListener.");

            // Add a listenerComponent already added to audio System and check that it does not crash
            Assert.DoesNotThrow(()=>audio.AddListener(addedToEntityListener), "Adding a listener already added to the audio system failed.");

            // Remove the listeners from the AudioSystem and check that they are removed from internal data structures.
            Assert.DoesNotThrow(() => audio.RemoveListener(notAddedToEntityListener), "Removing an listener not present in the entity system failed.");
            Assert.IsFalse(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem still contains the notAddedToEntityListener.");
            Assert.DoesNotThrow(() => audio.RemoveListener(addedToEntityListener), "Removing an listener present in the entity system fails");
            Assert.IsFalse(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem still contains the addedToEntityListener.");

            // Remove a listener not present in the AudioSystem anymore and check the thrown exception
            Assert.Throws<ArgumentException>(() => audio.RemoveListener(addedToEntityListener), "Removing the a non-existing listener did not throw ArgumentException.");
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:30,代码来源:TestAudioSystem.cs

示例2: Bind

        public override void Bind(Entity result, Main main, bool creating = false)
        {
            result.CannotSuspend = true;

            Script script = result.Get<Script>();

            Property<bool> executeOnLoad = result.GetProperty<bool>("ExecuteOnLoad");
            if (executeOnLoad && !main.EditorEnabled)
            {
                result.Add("Executor", new PostInitialization
                {
                    delegate()
                    {
                        if (executeOnLoad)
                            script.Execute.Execute();
                    }
                });
            }

            Property<bool> deleteOnExecute = result.GetOrMakeProperty<bool>("DeleteOnExecute", true, false);
            if (deleteOnExecute)
                result.Add(new CommandBinding(script.Execute, result.Delete));

            this.SetMain(result, main);
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:25,代码来源:ScriptFactory.cs

示例3: Bind

        public override void Bind(Entity result, Main main, bool creating = false)
        {
            this.SetMain(result, main);

            Transform transform = result.Get<Transform>();
            Sound sound = result.Get<Sound>("Sound");

            sound.Add(new Binding<Vector3>(sound.Position, transform.Position));

            result.CannotSuspendByDistance = !sound.Is3D;
            result.Add(new NotifyBinding(delegate()
            {
                result.CannotSuspendByDistance = !sound.Is3D;
            }, sound.Is3D));

            Property<float> min = result.GetProperty<float>("MinimumInterval");
            Property<float> max = result.GetProperty<float>("MaximumInterval");

            Random random = new Random();
            float interval = min + ((float)random.NextDouble() * (max - min));
            result.Add(new Updater
            {
                delegate(float dt)
                {
                    if (!sound.IsPlaying)
                        interval -= dt;
                    if (interval <= 0)
                    {
                        sound.Play.Execute();
                        interval = min + ((float)random.NextDouble() * (max - min));
                    }
                }
            });
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:34,代码来源:RandomAmbientSoundFactory.cs

示例4: Bind

        public override void Bind(Entity result, Main main, bool creating = false)
        {
            this.SetMain(result, main);
            result.CannotSuspendByDistance = true;

            Transform transform = result.Get<Transform>();

            ModelAlpha model = new ModelAlpha();
            model.Color.Value = new Vector3(1.2f, 1.0f, 0.8f);
            model.Editable = false;
            model.Serialize = false;
            model.Filename.Value = "Models\\electricity";
            model.DrawOrder.Value = 11;
            result.Add("Model", model);

            result.GetOrMakeProperty<bool>("IsMapEdge", true, true);

            PhysicsBlock block = result.Get<PhysicsBlock>();
            block.Box.BecomeKinematic();
            this.boundaries.Add(result);
            result.Add(new CommandBinding(result.Delete, delegate() { this.boundaries.Remove(result); }));
            block.Add(new TwoWayBinding<Matrix>(transform.Matrix, block.Transform));
            model.Add(new Binding<Matrix>(model.Transform, transform.Matrix));
            model.Add(new Binding<Vector3>(model.Scale, x => new Vector3(x.X * 0.5f, x.Y * 0.5f, 1.0f), block.Size));

            Property<Vector2> scaleParameter = model.GetVector2Parameter("Scale");
            model.Add(new Binding<Vector2, Vector3>(scaleParameter, x => new Vector2(x.Y, x.X), model.Scale));
            model.Add(new CommandBinding(main.ReloadedContent, delegate()
            {
                scaleParameter.Reset();
            }));
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:32,代码来源:MapBoundaryFactory.cs

示例5: TestComponentDoubleAddition

 public void TestComponentDoubleAddition()
 {
     Entity entity = new Entity();
     entity.Add(new ComponentA());
     entity.Add(new ComponentA());
     Assert.AreEqual(1, entity.ComponentCount);
 }
开发者ID:Djadavin,项目名称:Primal,代码行数:7,代码来源:EntityTests.cs

示例6: AttachEditorComponents

		public static void AttachEditorComponents(Entity result, ListProperty<Entity.Handle> target)
		{
			Transform transform = result.Get<Transform>();

			Property<bool> selected = result.GetOrMakeProperty<bool>("EditorSelected");

			Command<Entity> toggleEntityConnected = new Command<Entity>
			{
				Action = delegate(Entity entity)
				{
					if (target.Contains(entity))
						target.Remove(entity);
					else if (entity != result)
						target.Add(entity);
				}
			};
			result.Add("ToggleEntityConnected", toggleEntityConnected);

			LineDrawer connectionLines = new LineDrawer { Serialize = false };
			connectionLines.Add(new Binding<bool>(connectionLines.Enabled, selected));

			Color connectionLineColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
			ListBinding<LineDrawer.Line, Entity.Handle> connectionBinding = new ListBinding<LineDrawer.Line, Entity.Handle>(connectionLines.Lines, target, delegate(Entity.Handle entity)
			{
				return new LineDrawer.Line
				{
					A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
					B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(entity.Target.Get<Transform>().Position, connectionLineColor)
				};
			}, x => x.Target != null && x.Target.Active);
			result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, selected));
			result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, () => selected, transform.Position));
			connectionLines.Add(connectionBinding);
			result.Add(connectionLines);
		}
开发者ID:sparker,项目名称:Lemma,代码行数:35,代码来源:EntityConnectable.cs

示例7: AttachEditorComponents

		public static void AttachEditorComponents(Entity entity, string name, Property<Entity.Handle> target)
		{
			entity.Add(name, target);
			if (entity.EditorSelected != null)
			{
				Transform transform = entity.Get<Transform>("Transform");

				LineDrawer connectionLines = new LineDrawer { Serialize = false };
				connectionLines.Add(new Binding<bool>(connectionLines.Enabled, entity.EditorSelected));

				connectionLines.Add(new NotifyBinding(delegate()
				{
					connectionLines.Lines.Clear();
					Entity targetEntity = target.Value.Target;
					if (targetEntity != null)
					{
						Transform targetTransform = targetEntity.Get<Transform>("Transform");
						if (targetTransform != null)
						{
							connectionLines.Lines.Add
							(
								new LineDrawer.Line
								{
									A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
									B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(targetTransform.Position, connectionLineColor)
								}
							);
						}
					}
				}, transform.Position, target, entity.EditorSelected));

				entity.Add(connectionLines);
			}
		}
开发者ID:dsmo7206,项目名称:Lemma,代码行数:34,代码来源:EntityConnectable.cs

示例8: TestTwoComponentAddition

 public void TestTwoComponentAddition()
 {
     Entity entity = new Entity();
     entity.Add(new ComponentA());
     entity.Add(new ComponentB());
     Assert.AreEqual(2, entity.ComponentCount);
 }
开发者ID:Djadavin,项目名称:Primal,代码行数:7,代码来源:EntityTests.cs

示例9: Create

        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Prop");
            result.Add("Transform", new Transform());
            result.Add("Model", new Model());

            return result;
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:8,代码来源:PropFactory.cs

示例10: Create

        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "ParticleEmitter");

            result.Add("Transform", new Transform());
            result.Add("ParticleEmitter", new ParticleEmitter());

            return result;
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:9,代码来源:ParticleEmitterFactory.cs

示例11: Create

        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "AmbientSound");

            result.Add("Transform", new Transform());
            result.Add("Sound", new Sound());

            return result;
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:9,代码来源:AmbientSoundFactory.cs

示例12: Create

        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "MapBoundary");
            result.Add("Transform", new Transform());
            PhysicsBlock block = new PhysicsBlock();
            block.Size.Value = new Vector3(100.0f, 50.0f, 2.0f);
            result.Add("PhysicsBlock", block);

            return result;
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:10,代码来源:MapBoundaryFactory.cs

示例13: EditorProperties

		public static IEnumerable<string> EditorProperties(Entity script)
		{
			script.Add("LastNode", property<string>(script, "LastNode"));
			script.Add("NextNode", property<string>(script, "NextNode"));
			return new string[]
			{
				"LastNode",
				"NextNode",
			};
		}
开发者ID:dsmo7206,项目名称:Lemma,代码行数:10,代码来源:DialogueLink.cs

示例14: Create

        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "DirectionalLight");

            Transform transform = new Transform();
            result.Add("Transform", transform);
            DirectionalLight directionalLight = new DirectionalLight();
            result.Add("DirectionalLight", directionalLight);

            return result;
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:11,代码来源:DirectionalLightFactory.cs

示例15: Create

        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Water");

            Transform transform = new Transform();
            result.Add("Transform", transform);
            Water water = new Water();
            result.Add("Water", water);

            return result;
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:11,代码来源:WaterFactory.cs


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