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


C# Entity.GetProperty方法代码示例

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


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

示例1: 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

示例2: Bind

 public override void Bind(Entity result, Main main, bool creating = false)
 {
     this.SetMain(result, main);
     Transform transform = result.Get<Transform>();
     AnimatedModel model = result.Get<AnimatedModel>("Model");
     model.Add(new Binding<Matrix>(model.Transform, transform.Matrix));
     Property<string> animation = result.GetProperty<string>("Animation");
     Property<bool> loop = result.GetProperty<bool>("Loop");
     model.Add(new NotifyBinding(delegate()
     {
         model.Stop();
         if (animation != null)
             model.StartClip(animation, 0, loop);
     }, animation, loop));
 }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:15,代码来源:AnimatedPropFactory.cs

示例3: 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

示例4: Validate

        protected override void Validate(Entity entity, RuleArgs e)
        {
            var value = Convert.ToDouble(entity.GetProperty(e.Property));

            var min = this.Min;
            if (value < min)
            {
                if (this.MessageBuilder != null)
                {
                    e.BrokenDescription = this.MessageBuilder(entity);
                }
                else
                {
                    e.BrokenDescription = string.Format("{0} 不能低于 {1}。".Translate(), e.DisplayProperty(), min);
                }
            }
            else
            {
                var max = this.Max;
                if (value > max)
                {
                    if (this.MessageBuilder != null)
                    {
                        e.BrokenDescription = this.MessageBuilder(entity);
                    }
                    else
                    {
                        e.BrokenDescription = string.Format("{0} 不能超过 {1}。".Translate(), e.DisplayProperty(), max);
                    }
                }
            }
        }
开发者ID:569550384,项目名称:Rafy,代码行数:32,代码来源:NumberRangeRule.cs

示例5: Validate

        protected override void Validate(Entity entity, RuleArgs e)
        {
            var value = Convert.ToDouble(entity.GetProperty(e.Property));

            if (value <= 0)
            {
                if (this.MessageBuilder != null)
                {
                    e.BrokenDescription = this.MessageBuilder(entity);
                }
                else
                {
                    e.BrokenDescription = string.Format("{0} 需要是正数。".Translate(), e.DisplayProperty());
                }
            }
        }
开发者ID:569550384,项目名称:Rafy,代码行数:16,代码来源:PositiveNumberRule.cs

示例6: AttachEditorComponents

        public override void AttachEditorComponents(Entity result, Main main)
        {
            Model model = new Model();
            model.Filename.Value = "Models\\light";
            model.Color.Value = this.Color;
            model.Editable = false;
            model.Serialize = false;

            result.Add("EditorModel", model);

            Transform transform = result.Get<Transform>();
            Property<Direction> dir = result.GetProperty<Direction>("Direction");

            model.Add(new Binding<Matrix>(model.Transform, delegate()
            {
                Vector3 pos = transform.Position;
                return PlatformFactory.rotationMatrices[(int)dir.Value] * Matrix.CreateTranslation(pos);
            }, transform.Position, dir));
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:19,代码来源:PlatformFactory.cs

示例7: Validate

 protected override void Validate(Entity entity, RuleArgs e)
 {
     var value = entity.GetProperty(e.Property) as string;
     if (!string.IsNullOrEmpty(value))
     {
         var min = this.Min;
         if (value.Length < min)
         {
             if (this.MessageBuilder != null)
             {
                 e.BrokenDescription = this.MessageBuilder(entity);
             }
             else
             {
                 e.BrokenDescription = string.Format(
                     "{0} 不能低于 {1} 个字符。".Translate(),
                     e.DisplayProperty(), min
                     );
             }
         }
         else
         {
             var max = this.Max;
             if (value.Length > max)
             {
                 if (this.MessageBuilder != null)
                 {
                     e.BrokenDescription = this.MessageBuilder(entity);
                 }
                 else
                 {
                     e.BrokenDescription = string.Format(
                         "{0} 不能超过 {1} 个字符。".Translate(),
                         e.DisplayProperty(), max
                         );
                 }
             }
         }
     }
 }
开发者ID:569550384,项目名称:Rafy,代码行数:40,代码来源:StringLengthRangeRule.cs

示例8: Bind

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

            Transform transform = result.Get<Transform>();
            PhysicsBlock physics = result.Get<PhysicsBlock>();
            ModelInstance model = result.Get<ModelInstance>();

            physics.Add(new TwoWayBinding<Matrix>(transform.Matrix, physics.Transform));

            Property<string> soundCue = result.GetProperty<string>("CollisionSoundCue");

            Property<Vector3> scale = new Property<Vector3> { Value = Vector3.One };

            model.Add(new Binding<Matrix>(model.Transform, () => Matrix.CreateScale(scale) * transform.Matrix, scale, transform.Matrix));

            const float volumeMultiplier = 0.003f;

            physics.Add(new CommandBinding<Collidable, ContactCollection>(physics.Collided, delegate(Collidable collidable, ContactCollection contacts)
            {
                float volume = contacts[contacts.Count - 1].NormalImpulse * volumeMultiplier;
                if (volume > 0.2f && soundCue.Value != null)
                {
                    Sound sound = Sound.PlayCue(main, soundCue, transform.Position, volume, 0.05f);
                    if (sound != null)
                        sound.GetProperty("Pitch").Value = 1.0f;
                }
            }));

            result.Add("Fade", new Animation
            (
                new Animation.Delay(5.0f),
                new Animation.Vector3MoveTo(scale, Vector3.Zero, 1.0f),
                new Animation.Execute(delegate() { result.Delete.Execute(); })
            ));

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

示例9: Validate

        protected override void Validate(Entity entity, RuleArgs e)
        {
            var value = (string)entity.GetProperty(e.Property) ?? string.Empty;

            if (!string.IsNullOrEmpty(value))
            {
                if (!this.Regex.IsMatch(value))
                {
                    if (this.MessageBuilder != null)
                    {
                        e.BrokenDescription = this.MessageBuilder(entity);
                    }
                    else
                    {
                        e.BrokenDescription = string.Format(
                            "{0} 必须是 {1}。".Translate(),
                            e.DisplayProperty(),
                            this.RegexLabel.Translate()
                            );
                    }
                }
            }
        }
开发者ID:569550384,项目名称:Rafy,代码行数:23,代码来源:RegexMatchRule.cs

示例10: Validate

        protected override void Validate(Entity entity, RuleArgs e)
        {
            var property = e.Property;

            bool isNull = false;

            if (property is IRefProperty)
            {
                var id = entity.GetRefNullableId((property as IRefProperty).RefIdProperty);
                isNull = id == null;
            }
            else
            {
                var value = entity.GetProperty(property);
                if (property.PropertyType == typeof(string))
                {
                    isNull = string.IsNullOrEmpty(value as string);
                }
                else
                {
                    isNull = value == null;
                }
            }

            if (isNull)
            {
                if (this.MessageBuilder != null)
                {
                    e.BrokenDescription = this.MessageBuilder(entity);
                }
                else
                {
                    e.BrokenDescription = string.Format("{0} 里没有输入值。".Translate(), e.DisplayProperty());
                }
            }
        }
开发者ID:569550384,项目名称:Rafy,代码行数:36,代码来源:RequiredRule.cs

示例11: Bind

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

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

            Direction initialDirection = result.GetProperty<Direction>("Direction");
            Direction dir = initialDirection;

            Entity.Handle limit1 = result.GetProperty<Entity.Handle>("Limit 1");
            Entity.Handle limit2 = result.GetProperty<Entity.Handle>("Limit 2");

            Property<bool> isAtStart = new Property<bool> { Editable = false, Serialize = false };
            Property<bool> isAtEnd = new Property<bool> { Editable = false, Serialize = false };
            result.Add("IsAtStart", isAtStart);
            result.Add("IsAtEnd", isAtEnd);

            EntityMover mover = null;
            EntityRotator rotator = null;
            if (!main.EditorEnabled)
            {
                mover = new EntityMover(map.PhysicsEntity);
                mover.TargetPosition = transform.Position;
                main.Space.Add(mover);
                rotator = new EntityRotator(map.PhysicsEntity);
                rotator.TargetOrientation = transform.Quaternion;
                main.Space.Add(rotator);
            }

            Vector3 targetPosition = transform.Position;

            Property<float> speed = result.GetProperty<float>("Speed");
            Property<bool> stopOnEnd = result.GetProperty<bool>("StopOnEnd");

            Updater update = null;
            update = new Updater
            {
                delegate(float dt)
                {
                    if (!result.Active || limit1.Target == null || limit2.Target == null)
                        return;

                    float currentLocation = targetPosition.GetComponent(dir);

                    targetPosition = targetPosition.SetComponent(dir, currentLocation + dt * speed);

                    mover.TargetPosition = targetPosition;

                    float limit1Location = limit1.Target.Get<Transform>().Position.Value.GetComponent(dir);
                    float limit2Location = limit2.Target.Get<Transform>().Position.Value.GetComponent(dir);
                    float limitLocation = Math.Max(limit1Location, limit2Location);
                    if (currentLocation > limitLocation)
                    {
                        dir = dir.GetReverse();
                        if (limitLocation == limit1Location)
                        {
                            isAtStart.Value = true;
                            isAtEnd.Value = false;
                        }
                        else
                        {
                            isAtStart.Value = false;
                            isAtEnd.Value = true;
                        }
                        if (stopOnEnd)
                            update.Enabled.Value = false;
                    }
                }
            };
            update.Add(new TwoWayBinding<bool>(result.GetProperty<bool>("Enabled"), update.Enabled));

            result.Add(update);
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:74,代码来源:PlatformFactory.cs

示例12: attachEditorComponents

		private static void attachEditorComponents(Entity result, Main main)
		{
			Transform transform = result.Get<Transform>();

			Property<Entity.Handle> parentMap = result.GetOrMakeProperty<Entity.Handle>("Parent");

			EntityConnectable.AttachEditorComponents(result, parentMap);
			Model model = new Model();
			model.Filename.Value = "Models\\cone";
			model.Editable = false;
			model.Serialize = false;
			result.Add("DirectionModel", model);

			Property<Direction> dir = result.GetProperty<Direction>("Direction");
			Transform mapTransform = result.Get<Transform>("MapTransform");
			model.Add(new Binding<Matrix>(model.Transform, delegate()
			{
				Matrix m = Matrix.Identity;
				m.Translation = transform.Position;

				if (dir == Direction.None)
					m.Forward = m.Right = m.Up = Vector3.Zero;
				else
				{
					Vector3 normal = Vector3.TransformNormal(dir.Value.GetVector(), mapTransform.Matrix);

					m.Forward = -normal;
					if (normal.Equals(Vector3.Up))
						m.Right = Vector3.Left;
					else if (normal.Equals(Vector3.Down))
						m.Right = Vector3.Right;
					else
						m.Right = Vector3.Normalize(Vector3.Cross(normal, Vector3.Down));
					m.Up = Vector3.Cross(normal, m.Left);
				}
				return m;
			}, transform.Matrix, mapTransform.Matrix));
		}
开发者ID:sparker,项目名称:Lemma,代码行数:38,代码来源:JointFactory.cs

示例13: Bind

        public override void Bind(Entity result, Main main, bool creating = false)
        {
            Transform transform = result.Get<Transform>();
            EnemyBase enemy = result.GetOrCreate<EnemyBase>("Base");
            PlayerCylinderTrigger trigger = result.Get<PlayerCylinderTrigger>();

            PointLight light = result.GetOrCreate<PointLight>();
            light.Color.Value = new Vector3(1.3f, 0.5f, 0.5f);
            light.Attenuation.Value = 15.0f;
            light.Shadowed.Value = false;
            light.Serialize = false;

            ListProperty<Entity.Handle> dynamicMaps = result.GetListProperty<Entity.Handle>("DynamicMaps");
            Property<float> timeUntilRebuild = result.GetProperty<float>("TimeUntilRebuild");
            Property<float> timeUntilRebuildComplete = result.GetProperty<float>("TimeUntilRebuildComplete");
            Property<float> rebuildDelay = result.GetProperty<float>("RebuildDelay");
            Property<float> rebuildTime = result.GetProperty<float>("RebuildTime");

            const float rebuildTimeMultiplier = 0.03f;

            enemy.Add(new CommandBinding(enemy.Delete, result.Delete));
            enemy.Add(new Binding<Matrix>(enemy.Transform, transform.Matrix));
            light.Add(new Binding<Vector3>(light.Position, enemy.Position));

            trigger.Add(new Binding<Matrix>(trigger.Transform, () => Matrix.CreateTranslation(0.0f, 0.0f, enemy.Offset) * transform.Matrix, transform.Matrix, enemy.Offset));

            Action<Entity> fall = delegate(Entity player)
            {
                if (timeUntilRebuild.Value > 0 || timeUntilRebuildComplete.Value > 0)
                    return;

                if (!enemy.IsValid)
                {
                    result.Delete.Execute();
                    return;
                }

                // Disable the cell-emptied notification.
                // This way, we won't think that the base has been destroyed by the player.
                // We are not in fact dying, we're just destroying the base so we can fall over.
                enemy.EnableCellEmptyBinding = false;

                Map m = enemy.Map.Value.Target.Get<Map>();

                m.Empty(enemy.BaseBoxes.SelectMany(x => x.GetCoords()));

                m.Regenerate(delegate(List<DynamicMap> spawnedMaps)
                {
                    Vector3 playerPos = player.Get<Transform>().Position;
                    playerPos += player.Get<Player>().LinearVelocity.Value * 0.65f;
                    foreach (DynamicMap newMap in spawnedMaps)
                    {
                        Vector3 toPlayer = playerPos - newMap.PhysicsEntity.Position;
                        toPlayer.Normalize();
                        if (Math.Abs(toPlayer.Y) < 0.9f)
                        {
                            toPlayer *= 25.0f * newMap.PhysicsEntity.Mass;

                            Vector3 positionAtPlayerHeight = newMap.PhysicsEntity.Position;
                            Vector3 impulseAtBase = toPlayer * -0.75f;
                            impulseAtBase.Y = 0.0f;
                            positionAtPlayerHeight.Y = playerPos.Y;
                            newMap.PhysicsEntity.ApplyImpulse(ref positionAtPlayerHeight, ref impulseAtBase);

                            newMap.PhysicsEntity.ApplyLinearImpulse(ref toPlayer);
                        }
                        newMap.PhysicsEntity.Material.KineticFriction = 1.0f;
                        newMap.PhysicsEntity.Material.StaticFriction = 1.0f;
                        dynamicMaps.Add(newMap.Entity);
                    }
                });

                timeUntilRebuild.Value = rebuildDelay;
            };

            result.Add(new PostInitialization
            {
                delegate()
                {
                    foreach (Entity.Handle map in dynamicMaps)
                    {
                        if (map.Target != null)
                        {
                            BEPUphysics.Entities.MorphableEntity e = map.Target.Get<DynamicMap>().PhysicsEntity;
                            e.Material.KineticFriction = 1.0f;
                            e.Material.StaticFriction = 1.0f;
                        }
                    }
                }
            });

            result.Add(new CommandBinding<Entity>(trigger.PlayerEntered, fall));

            result.Add(new Updater
            {
                delegate(float dt)
                {
                    if (timeUntilRebuild > 0)
                    {
                        if (enemy.Map.Value.Target == null || !enemy.Map.Value.Target.Active)
//.........这里部分代码省略.........
开发者ID:kernelbitch,项目名称:Lemma,代码行数:101,代码来源:FallingTowerFactory.cs

示例14: Bind

        public override void Bind(Entity result, Main main, bool creating = false)
        {
            this.SetMain(result, main);
            Transform transform = result.Get<Transform>();
            PlayerTrigger trigger = result.Get<PlayerTrigger>();
            Property<string> nextMap = result.GetProperty<string>("NextMap");
            Property<string> startSpawnPoint = result.GetProperty<string>("SpawnPoint");

            trigger.Add(new TwoWayBinding<Vector3>(transform.Position, trigger.Position));
            trigger.Add(new CommandBinding<Entity>(trigger.PlayerEntered, delegate(Entity player)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<Entity>));

                Container notification = new Container();
                notification.Tint.Value = Microsoft.Xna.Framework.Color.Black;
                notification.Opacity.Value = 0.5f;
                TextElement notificationText = new TextElement();
                notificationText.Name.Value = "Text";
                notificationText.FontFile.Value = "Font";
                notificationText.Text.Value = "Loading...";
                notification.Children.Add(notificationText);
                ((GameMain)main).UI.Root.GetChildByName("Notifications").Children.Add(notification);

                Stream stream = new MemoryStream();
                main.AddComponent(new Animation
                (
                    new Animation.Delay(0.01f),
                    new Animation.Execute(delegate()
                    {
                        // We are exiting the map; just save the state of the map without the player.
                        ListProperty<PlayerFactory.RespawnLocation> respawnLocations = Factory.Get<PlayerDataFactory>().Instance(main).GetOrMakeListProperty<PlayerFactory.RespawnLocation>("RespawnLocations");
                        respawnLocations.Clear();

                        List<Entity> persistentEntities = main.Entities.Where((Func<Entity, bool>)MapExitFactory.isPersistent).ToList();

                        serializer.Serialize(stream, persistentEntities);

                        foreach (Entity e in persistentEntities)
                            e.Delete.Execute();

                        ((GameMain)main).StartSpawnPoint = startSpawnPoint;
                    }),
                    new Animation.Execute(((GameMain)main).SaveCurrentMap),
                    new Animation.Set<string>(main.MapFile, nextMap),
                    new Animation.Execute(delegate()
                    {
                        notification.Visible.Value = false;
                        stream.Seek(0, SeekOrigin.Begin);
                        List<Entity> entities = (List<Entity>)serializer.Deserialize(stream);
                        foreach (Entity entity in entities)
                        {
                            Factory factory = Factory.Get(entity.Type);
                            factory.Bind(entity, main);
                            main.Add(entity);
                        }
                        stream.Dispose();
                    }),
                    new Animation.Delay(1.5f),
                    new Animation.Set<string>(notificationText.Text, "Saving..."),
                    new Animation.Set<bool>(notification.Visible, true),
                    new Animation.Delay(0.01f),
                    new Animation.Execute(((GameMain)main).Save),
                    new Animation.Set<string>(notificationText.Text, "Saved"),
                    new Animation.Parallel
                    (
                        new Animation.FloatMoveTo(notification.Opacity, 0.0f, 1.0f),
                        new Animation.FloatMoveTo(notificationText.Opacity, 0.0f, 1.0f)
                    ),
                    new Animation.Execute(notification.Delete)
                ));
            }));
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:72,代码来源:MapExitFactory.cs

示例15: isPersistent

        private static bool isPersistent(Entity entity)
        {
            if (MapExitFactory.persistentTypes.Contains(entity.Type))
                return true;

            if (MapExitFactory.attachedTypes.Contains(entity.Type))
            {
                Property<bool> attached = entity.GetProperty<bool>("Attached");
                if (attached != null && attached)
                    return true;
            }
            return false;
        }
开发者ID:kernelbitch,项目名称:Lemma,代码行数:13,代码来源:MapExitFactory.cs


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