public override void XmlDeserialize(XElement element) { Fixture sensorTemplate = null; if (element != null) { base.XmlDeserialize(element.Element("Trigger")); var attachedEle = element.Attribute("attachedTarget"); if (attachedEle != null) { Actor target = this.Map.NamedObjects[attachedEle.Value] as Actor; if (target != null) { this.sensorBody = target.Body; } } var bodyInfoEle = element.Element("FixtureTemplate"); if (bodyInfoEle == null) { Vector2 position = ExtensionMethods.XmlDeserializeVector2(element.Element("Position")); var tempBody = BodyFactory.CreateCircle( this.World, float.Parse(element.Attribute("radius").Value, CultureInfo.CurrentCulture), 1f, new Vector2(position.X, this.Map.Height - position.Y).ToSimUnits()); // tempBody.IsSensor = true; tempBody.FixtureList.ForEach(fx => fx.UserData = "Sensor"); if (this.sensorBody == null) { this.sensorBody = tempBody; this.sensorBody.BodyType = BodyType.Static; } sensorTemplate = tempBody.FixtureList[0]; } else { var bodyData = XmlBodyFactory.DeserializeBody(this.World, this.Map.Height, bodyInfoEle.Elements().ElementAt(0)); this.World.RemoveBody(bodyData.Item1); this.bodyInfo = bodyData.Item2; sensorTemplate = bodyData.Item1.FixtureList[0]; } this.CreateSensors(sensorTemplate); this.IsContinuous = element.GetAttribute("isContinuous", true); this.IsSensor = element.GetAttribute("isSensor", false); } }
public override void XmlDeserialize(XElement element) { if (element != null) { // Create GameSprites out of the Deserialze functions in GameSprite var spriteElements = element.Element("Sprites"); if (spriteElements != null) { foreach (XElement gameSpriteEle in spriteElements.Elements("GameSprite")) { GameSprite gameSprite = new GameSprite(); gameSprite.XmlDeserialize(gameSpriteEle); this.sprites.Add(gameSprite.SpriteName, gameSprite); } } // ---------------------- // Find the Body element XElement bodyElement = element.Element("BodyInfo"); if (bodyElement != null) { var bodyData = XmlBodyFactory.DeserializeBody(this.World, this.Map.Height, bodyElement.Elements().ElementAt(0)); this.Body = bodyData.Item1; this.bodyInfo = bodyData.Item2; } this.PathManager = new PathManager(this); this.PathManager.Screen = this.Screen; XElement pathManagerEle = element.Element("PathManager"); if (pathManagerEle != null) { this.PathManager.XmlDeserialize(pathManagerEle); } // -------------------------------------------------------- // Assign the new values to the Actor after body is created this.Name = element.GetAttribute("name", string.Empty); this.MovementSpeed = ExtensionMethods.XmlDeserializeVector2(element.Element("MovementSpeed")); this.Health = element.GetAttribute("health", 1); this.Rotation = element.GetAttribute("rotation", 0f); this.IsEnabled = element.GetAttribute("isEnabled", true); this.VisibleState = element.GetAttribute("visibleState", Visibility.Visible); this.RotatesWithWorld = element.GetAttribute("rotatesWithWorld", false); this.CanBeDamaged = element.GetAttribute("canBeDamaged", true); } }
public override void XmlDeserialize(XElement element) { if (element != null) { var bodyData = XmlBodyFactory.DeserializeBody(this.World, this.Map.Height, element); this.Body = bodyData.Item1; this.MapBodyInfo = bodyData.Item2; this.TextureReference = element.GetAttribute("textureRef", string.Empty); this.fill = element.GetAttribute("fill", false); if (this.fill) { if (this.MapBodyInfo.BodyCategory != Enums.BodyCategory.LoopShape) { foreach (var fixture in this.Body.FixtureList) { Tuple <Texture2D, Vector2> textureInfo = new Tuple <Texture2D, Vector2>( AssetCreator.Instance.TextureFromShape(fixture.Shape, this.TextureReference, Color.White, 1f), fixture.FixtureOffset(this.MapBodyInfo.BodyCategory, this.MapBodyInfo.Position, this.MapBodyInfo.ShapeOffset)); this.textures.Add(textureInfo); } } else { System.Console.WriteLine("Error! Loop Shape is not supported for fill"); } } else { this.textures.Add(new Tuple <Texture2D, Vector2>(ContentController.Instance.GetContent <Texture2D>(this.TextureReference), Vector2.Zero)); } if (this.Body != null) { this.Body.CollisionCategories = PhysicistCategory.Map1; } } }