當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。