public void AddBirthEvent(BirthEvent birthEvent) { Debug.Log("EVENT: "); m_events.Add(birthEvent); string name = "事件" + m_events.Count; m_eventNames.Add(name); m_dpdEventList.ClearOptions(); m_dpdEventList.AddOptions(m_eventNames); m_dpdEventList.value = m_events.Count; }
public FemaleImpl(ILoggerFactory loggerFactory, GettingPregnantEvent gettingPregnantEvent, PregnancyProgressionEvent pregnancyProgressionEvent, BirthEvent birthEvent, GameObjectsCreationEvent gameObjectsCreationEvent, IEventRecorder eventRecorder) { _gettingPregnantEvent = gettingPregnantEvent; _pregnancyProgressionEvent = pregnancyProgressionEvent; _birthEvent = birthEvent; _gameObjectsCreationEvent = gameObjectsCreationEvent; _eventRecorder = eventRecorder; _logger = loggerFactory.CreateLogger <FemaleImpl>(); _stringBuilder = new StringBuilder(); }
public GEDCOM(string filePath) { try { StreamReader sr = new StreamReader(filePath); //Put together our list of individuals and families List<Individual> individuals = new List<Individual>(); List<Family> families = new List<Family>(); //create individual blocks string[] zeroLines = sr.ReadToEnd().Replace("0 @", "\u0646").Split('\u0646'); foreach(string block in zeroLines) { //cut these pieces into lines for parsing string[] lines = block.Replace("\r\n", "\r").Split('\r'); if(lines[0].Contains("INDI")) { //create a new individual Individual indi = new Individual(); //Find, replace junk characters, and save data. indi.Id = lines[0].Replace("@", "").Replace(" INDI", "").Trim(); indi.Name = lines[FindIndexinArray(lines, "NAME")].Replace("1 NAME", "").Replace("/", "").Trim(); indi.Sex = lines[FindIndexinArray(lines, "SEX")].Replace("1 SEX ", "").Trim(); //special conditional data #region Birth Event if (FindIndexinArray(lines, "1 BIRT ") != -1) { BirthEvent be = new BirthEvent(); // add birthday event int i = 1; while (lines[FindIndexinArray(lines, "1 BIRT ") + i].StartsWith("2")) { switch (lines[FindIndexinArray(lines, "1 BIRT ") + i].Substring(0,5)) { case "2 Date": be.Date = lines[FindIndexinArray(lines, "1 BIRT ") + 1].Replace("2 DATE ", "").Trim(); break; case "2 Plac": be.Place = lines[FindIndexinArray(lines, "1 BIRT ") + 2].Replace("2 PLAC ", "").Trim(); break; } } } #endregion #region Death Event if (FindIndexinArray(lines, "1 DEAT ") != -1) { BirthEvent be = new BirthEvent(); // add birthday event int i = 1; while (lines[FindIndexinArray(lines, "1 DEAT ") + i].StartsWith("2")) { switch (lines[FindIndexinArray(lines, "1 DEAT ") + i].Substring(0, 5)) { case "2 Date": be.Date = lines[FindIndexinArray(lines, "1 DEAT ") + 1].Replace("2 DATE ", "").Trim(); break; case "2 Plac": be.Place = lines[FindIndexinArray(lines, "1 DEAT ") + 2].Replace("2 PLAC ", "").Trim(); break; } } } #endregion // Throw the Individual into the List individuals.Add(indi); } else if (lines[0].Contains("FAM")) { //Create the new family and marriage Family fam = new Family(); MarriageEvent mar = new MarriageEvent(); //grab Fam id from node early on to keep from doing it over and over fam.Id = lines[0].Replace("@ FAM", ""); //Look for Marriage Event, deal with alternate events. foreach (string line in lines) { } // Look at each line of node foreach (string line in lines) { /* So as an explanation, Gedcom uses Husband/Wife nomenclature. Gedcom explains that this is because the Marriage Event is a record of a union that produced a child and is strictly a matter of bloodline. This will inevitably change when the LDS changes their own family record keeping My own software will allow for adoption events and be gender neutral regarding spouses (but will likely still only allow two participants until marriage law changes) */ // If node is HUSB if (line.Contains("1 HUSB ")) { string indId = line.Replace("1 HUSB ", "").Replace("@", "").Trim(); Individual temp = (Individual)individuals.Where(indi => indi.Id.ToString().Equals(indId)); if (temp != null) { fam.Husband = temp; } } //If node for Wife else if (line.Contains("1 WIFE ")) { string indId = line.Replace("1 WIFE ", "").Replace("@", "").Trim(); Individual temp = (Individual)individuals.Where(indi => indi.Id.ToString().Equals(indId)); if (temp != null) { fam.Wife = temp; } } //if node for multi children else if (line.Contains("1 CHIL ")) { string indId = line.Replace("1 CHIL ", "").Replace("@", "").Trim(); Individual temp = (Individual)individuals.Where(indi => indi.Id.ToString().Equals(indId)); if (temp != null) { fam.Children.Add(temp); } } } } } } catch(Exception e) { throw new NotImplementedException(e.Message); } }
public void Update(uint tick, float _gameSpeed) { Random r = new Random(); for (int i = 0; i < Compatible.Count; i++) { var parentEntity = Compatible[i]; var reproduction = parentEntity.GetComponent <ReproductionComponent>(); if (reproduction.Reproduce > reproduction.ReproductionThreshold) { var energy = parentEntity.GetComponent <EnergyComponent>(); // check if we have the energy if (!energy.CanAfford(reproduction.ReproductionEnergyCost)) { continue; } if (energy.Energy - reproduction.ReproductionEnergyCost < reproduction.RequiredRemainingEnergy) { continue; } // charge teh parent energy. Each critter has an efficency rating, so some energy gets wasted an the rest gets sent to the child. float charged = energy.ChargeEnergy(reproduction.ReproductionEnergyCost); float toChild = reproduction.Efficency * charged; float wasted = charged - toChild; // Let the energy manager know about the wasted energy. _energyManager.DepositEnergy(wasted); // Some set up for the new child, setting positions/giving energy. var babyEntity = Pool.AddEntityFromDefinition(reproduction.ChildDefinitionId, _simulation.JsonSettings, parentEntity.Tag); babyEntity.GetComponent <EnergyComponent>().Energy = toChild; var parentPosition = parentEntity.GetComponent <TransformComponent>().LocalPosition; babyEntity.GetComponent <TransformComponent>().LocalPosition = parentPosition; // The new child will need a mutated brain var originalBrainComponent = parentEntity.GetComponent <BrainComponent>(); var originalBrain = originalBrainComponent.Brain; AbstractBrainGenotype parentGenotype = ((NeatBrainPhenotype)originalBrain).Genotype; NeatBrainGenotype childGenotype = (NeatBrainGenotype)parentGenotype.Clone(); _muationManager.Mutate(childGenotype, _innovationIdManager); var newBrain = babyEntity.GetComponent <BrainComponent>(); newBrain.SetGenotype(childGenotype); // Do not need to pass it type as we have already set the brain, therefore it does not need initializing. newBrain.SetUpLinks(null, _simulation.Settings); newBrain.ParentSpecies = originalBrainComponent.Species; BirthEventInfo e = new BirthEventInfo(parentPosition, tick * _gameSpeed, parentEntity.Id, parentEntity.Tag, babyEntity.Id, babyEntity.Tag, childGenotype, originalBrainComponent.Species.Id); BirthEvent?.Invoke(e); } } }
/// <summary> /// Reads from file and attempts to fill Individuals /// </summary> /// <returns> /// A Collection of /// </returns> public GedcomCollection ReadFromFile(string filePath) { GedcomCollection gcc = new GedcomCollection(); string[] zeroLines; if (!filePath.EndsWith(".ged")) { throw new Exception("File is not a GedCom File"); } using (StreamReader sr = new StreamReader(filePath)) { if (sr != null) { //create individual blocks zeroLines = sr.ReadToEnd().Replace("0 @", "\u0646").Split('\u0646'); } else { throw new NullReferenceException("StreamReader failed to create a stream from path: " + filePath); } } foreach (string block in zeroLines) { //cut these pieces into lines for parsing string[] lines = block.Replace("\r\n", "\r").Split('\r'); if (lines[0].Contains("INDI")) { //create a new individual Individual indi = new Individual(); //Find, replace junk characters, and save data. indi.Id = lines[0].Replace("@", "").Replace(" INDI", "").Trim(); indi.Name = lines[FindIndexinArray(lines, "NAME")].Replace("1 NAME", "").Replace("/", "").Trim(); indi.Sex = lines[FindIndexinArray(lines, "SEX")].Replace("1 SEX ", "").Trim(); //special conditional data #region Birth Event if (FindIndexinArray(lines, "1 BIRT ") != -1) { BirthEvent be = new BirthEvent(); be = GetEventData <BirthEvent>(lines); indi.BirthEvent = be; } #endregion #region Death Event if (FindIndexinArray(lines, "1 DEAT ") != -1) { DeathEvent de = new DeathEvent(); de = GetEventData <DeathEvent>(lines); indi.DeathEvent = de; } #endregion // Throw the Individual into the List gcc.individuals.Add(indi); } else if (lines[0].Contains("FAM")) { //Create the new family and marriage Family fam = new Family(); //grab Fam id from node early on to keep from doing it over and over fam.Id = lines[0].Replace("@ FAM", ""); // Look at each line of node foreach (string line in lines) { //Look for a Marriage Event if (line.Contains("1 MARR ")) { MarriageEvent mar = new MarriageEvent(); mar = GetEventData <MarriageEvent>(lines); fam.MarriageEvent = mar; } /* So as an explanation, Gedcom uses Husband/Wife nomenclature. Gedcom explains that this is because the Marriage Event is * a record of a union that produced a child and is strictly a matter of bloodline. This will inevitably change when the LDS * changes their own family record keeping * * My own software will allow for adoption events and be gender neutral regarding spouses (but will likely still only allow two * participants until marriage law changes) */ // If node is HUSB if (line.Contains("1 HUSB ")) { string indId = line.Replace("1 HUSB ", "").Replace("@", "").Trim(); Individual temp = (Individual)gcc.individuals.Where(indi => indi.Id.ToString().Equals(indId)); if (temp != null) { fam.Husband = temp; } else { throw new IndividualNotFound("Husband: " + indId + " Not found in record for " + fam.Id); } } //If node for Wife else if (line.Contains("1 WIFE ")) { string indId = line.Replace("1 WIFE ", "").Replace("@", "").Trim(); Individual temp = (Individual)gcc.individuals.Where(indi => indi.Id.ToString().Equals(indId)); if (temp != null) { fam.Wife = temp; } else { throw new IndividualNotFound("Wife: " + indId + " Not found in record for " + fam.Id); } } //if node for multi children else if (line.Contains("1 CHIL ")) { string indId = line.Replace("1 CHIL ", "").Replace("@", "").Trim(); Individual temp = (Individual)gcc.individuals.Where(indi => indi.Id.ToString().Equals(indId)); if (temp != null) { fam.Children.Add(temp); } else { throw new IndividualNotFound("Child: " + indId + " Not found in record for " + fam.Id); } } } } } return(gcc); }
private bool ParseXml(string filePath) { try { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(filePath); XmlElement eRoot = (XmlElement)xmlDocument.SelectSingleNode("MapData"); foreach (XmlElement element in eRoot.ChildNodes) { //处理地图信息 if (element.Name == "Map") { int len = int.Parse(DecryptAttribute(element, "len")); int wid = int.Parse(DecryptAttribute(element, "wid")); string textureName = (DecryptAttribute(element, "TexturePath")); //int len = int.Parse(element.GetAttribute("len")); //int wid = int.Parse(element.GetAttribute("wid")); //string textureName = element.GetAttribute("TexturePath"); MapManager.Instance.CreateMap(len, wid, textureName); } else if (element.Name == "EntitiesList") { List <Entity> entities = new List <Entity>(); foreach (XmlElement eEntity in element.ChildNodes) { //实体属性 XmlElement eEntityAtr = (XmlElement)eEntity.SelectSingleNode("EntityAtr"); //位置 float x = float.Parse(DecryptAttribute(eEntityAtr, "posX")); float y = float.Parse(DecryptAttribute(eEntityAtr, "posY")); float z = float.Parse(DecryptAttribute(eEntityAtr, "posZ")); //float x = float.Parse(eEntityAtr.GetAttribute("posX")); //float y = float.Parse(eEntityAtr.GetAttribute("posY")); //float z = float.Parse(eEntityAtr.GetAttribute("posZ")); Vector3 pos = new Vector3(x, y, z); //旋转 x = float.Parse(DecryptAttribute(eEntityAtr, "quaX")); y = float.Parse(DecryptAttribute(eEntityAtr, "quaY")); z = float.Parse(DecryptAttribute(eEntityAtr, "quaZ")); float w = float.Parse(DecryptAttribute(eEntityAtr, "quaW")); //x = float.Parse(eEntityAtr.GetAttribute("quaX")); //y = float.Parse(eEntityAtr.GetAttribute("quaY")); //z = float.Parse(eEntityAtr.GetAttribute("quaZ")); //float w = float.Parse(eEntityAtr.GetAttribute("quaW")); Quaternion qua = new Quaternion(x, y, z, w); //模型 string modelName = DecryptAttribute(eEntityAtr, "Model"); //string modelName = eEntityAtr.GetAttribute("Model"); //类型 string temp = DecryptAttribute(eEntityAtr, "Type"); //string temp = eEntityAtr.GetAttribute("Type"); EntityType entityType = EntityType.Zero; if (temp == "NPC") { entityType = EntityType.NPC; } else if (temp == "Monster") { entityType = EntityType.Monster; } else if (temp == "Building") { entityType = EntityType.Building; } //地图块索引 int mapCubeIndex = int.Parse(DecryptAttribute(eEntityAtr, "MapCubeIndex")); //int mapCubeIndex = int.Parse(eEntityAtr.GetAttribute("MapCubeIndex")); //路径索引 int pathIndex = int.Parse(DecryptAttribute(eEntityAtr, "PathIndex")); //int pathIndex = int.Parse(eEntityAtr.GetAttribute("PathIndex")); int eventIndex = int.Parse(DecryptAttribute(eEntityAtr, "EventIndex")); //游戏属性 XmlElement eGameAtr = (XmlElement)eEntity.SelectSingleNode("GameAtr"); float HP = int.Parse(DecryptAttribute(eGameAtr, "HP")); float AtkValue = float.Parse(DecryptAttribute(eGameAtr, "AtkValue")); float DefValue = float.Parse(DecryptAttribute(eGameAtr, "DefValue")); float AtkSpeed = float.Parse(DecryptAttribute(eGameAtr, "AtkSpeed")); float AtkRange = float.Parse(DecryptAttribute(eGameAtr, "AtkRange")); float MoveSpeed = float.Parse(DecryptAttribute(eGameAtr, "MoveSpeed")); bool IsMove = bool.Parse(DecryptAttribute(eGameAtr, "IsMove")); bool IsAtk = bool.Parse(DecryptAttribute(eGameAtr, "IsAtk")); //float HP = int.Parse(eGameAtr.GetAttribute("HP")); //float AtkValue = float.Parse(eGameAtr.GetAttribute("AtkValue")); //float DefValue = float.Parse(eGameAtr.GetAttribute("DefValue")); //float AtkSpeed = float.Parse(eGameAtr.GetAttribute("AtkSpeed")); //float AtkRange = float.Parse(eGameAtr.GetAttribute("AtkRange")); //float MoveSpeed = float.Parse(eGameAtr.GetAttribute("MoveSpeed")); //bool IsMove = bool.Parse(eGameAtr.GetAttribute("IsMove")); //bool IsAtk = bool.Parse(eGameAtr.GetAttribute("IsAtk")); //添加到当前实体管理类 EntityManager.Instance.AddEntity(pos, qua, entityType, modelName, mapCubeIndex, pathIndex, eventIndex, HP, AtkValue, DefValue, AtkSpeed, AtkRange, MoveSpeed, IsMove, IsAtk); //更新地图块的状态 MapManager.Instance.GetMapCube(mapCubeIndex).m_isEmpty = false; } } else if (element.Name == "PathList") { //根据当前地图信息生成寻路数据 PathManager.Instance.GeneratePointMsg(); //读取并加载存档中的路径信息 foreach (XmlElement ePath in element.ChildNodes) { //状态信息 int index = int.Parse(DecryptAttribute(ePath, "Index")); bool isEmpty = bool.Parse(DecryptAttribute(ePath, "IsEmpty")); //int index = int.Parse(ePath.GetAttribute("Index")); //bool isEmpty = bool.Parse(ePath.GetAttribute("IsEmpty")); //关键点信息 XmlElement eKeyPointList = (XmlElement)ePath.SelectSingleNode("KeyPointList"); List <Vector2> tempKeyPointList = new List <Vector2>(); foreach (XmlElement eKeyPoint in eKeyPointList.ChildNodes) { Vector2 tempKeyPoint = new Vector2 { x = int.Parse(DecryptAttribute(eKeyPoint, "x")), y = int.Parse(DecryptAttribute(eKeyPoint, "y")) //x = int.Parse(eKeyPoint.GetAttribute("x")), //y = int.Parse(eKeyPoint.GetAttribute("y")) }; tempKeyPointList.Add(tempKeyPoint); } //点信息 XmlElement ePointList = (XmlElement)ePath.SelectSingleNode("PointList"); List <Vector2> tempPointList = new List <Vector2>(); foreach (XmlElement ePoint in ePointList.ChildNodes) { Vector2 tempPoint = new Vector2 { x = int.Parse(DecryptAttribute(ePoint, "x")), y = int.Parse(DecryptAttribute(ePoint, "y")) //x = int.Parse(ePoint.GetAttribute("x")), //y = int.Parse(ePoint.GetAttribute("y")) }; tempPointList.Add(tempPoint); } //添加到当前路径管理类 PathManager.Instance.AddPath(index, isEmpty, tempKeyPointList, tempPointList); } } else if (element.Name == "EventList") { foreach (XmlElement eEvent in element.ChildNodes) { int index = int.Parse(DecryptAttribute(eEvent, "Index")); string type = DecryptAttribute(eEvent, "Type"); if (type.CompareTo("Birth") == 0) { Debug.Log("BIRTHEVENT: " + type); float cd = float.Parse(DecryptAttribute(eEvent, "CD")); float time = float.Parse(DecryptAttribute(eEvent, "Time")); bool isInfinite = bool.Parse(DecryptAttribute(eEvent, "IsInfinite")); BirthEvent birthEvent = new BirthEvent(cd, time, isInfinite); EventManager.Instance.AddBirthEvent(birthEvent); } else if (type.CompareTo("Bomb") == 0) { float delay = float.Parse(DecryptAttribute(eEvent, "Delay")); float hurt = float.Parse(DecryptAttribute(eEvent, "Hurt")); bool isDetroy = bool.Parse(DecryptAttribute(eEvent, "IsDestroy")); BombEvent bombEvent = new BombEvent(delay, hurt, isDetroy); EventManager.Instance.AddBombEvent(bombEvent); } else if (type.CompareTo("Speed") == 0) { float speed = float.Parse(DecryptAttribute(eEvent, "Speed")); float time = float.Parse(DecryptAttribute(eEvent, "Time")); bool isInfinite = bool.Parse(DecryptAttribute(eEvent, "IsInfinite")); SpeedEvent speedEvent = new SpeedEvent(speed, time, isInfinite); EventManager.Instance.AddSpeedEvent(speedEvent); } else if (type.CompareTo("Telepo") == 0) { int teleportID = int.Parse(DecryptAttribute(eEvent, "TeleportID")); float cd = float.Parse(DecryptAttribute(eEvent, "CD")); float time = float.Parse(DecryptAttribute(eEvent, "Time")); bool isInfinite = bool.Parse(DecryptAttribute(eEvent, "IsInfinite")); TeleportEvent teleportEvent = new TeleportEvent(teleportID, cd, time, isInfinite); EventManager.Instance.AddTeleportEvent(teleportEvent); } } } else if (element.Name == "Music") { if (element.HasAttributes) { string name = DecryptAttribute(element, "Name"); float volume = float.Parse(DecryptAttribute(element, "Volume")); //string name = element.GetAttribute("Name"); //float volume = float.Parse(element.GetAttribute("Volume")); MusicManager.Instance.SetMusic(name, volume); } } } return(true); } catch { LogManager.Instance.Log("加载地图失败!"); return(false); } }
private bool CreateXml(string filePath) { try { XmlDocument xmlDocument = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null); xmlDocument.AppendChild(xmlDeclaration); XmlElement eRoot = xmlDocument.CreateElement("MapData"); xmlDocument.AppendChild(eRoot); //保存地图信息 XmlElement eMap = xmlDocument.CreateElement("Map"); Map map = MapManager.Instance.m_map; EncryptAttribute(eMap, "TexturePath", map.m_textureName.ToString()); EncryptAttribute(eMap, "wid", map.m_width.ToString()); EncryptAttribute(eMap, "len", map.m_length.ToString()); //eMap.SetAttribute("TexturePath", map.m_textureName.ToString()); //eMap.SetAttribute("wid", map.m_width.ToString()); //eMap.SetAttribute("len", map.m_length.ToString()); eRoot.AppendChild(eMap); //保存实体信息 XmlElement eEntitiesList = xmlDocument.CreateElement("EntitiesList"); foreach (Entity entity in EntityManager.Instance.GetEntities()) { XmlElement eEntity = xmlDocument.CreateElement("Entity"); eEntitiesList.AppendChild(eEntity); //实体属性(逆序设置,顺序输出) XmlElement eEntityAtr = xmlDocument.CreateElement("EntityAtr"); EncryptAttribute(eEntityAtr, "EventIndex", entity.m_eventIndex.ToString()); EncryptAttribute(eEntityAtr, "PathIndex", entity.m_pathIndex.ToString()); EncryptAttribute(eEntityAtr, "MapCubeIndex", entity.m_mapCubeIndex.ToString()); EncryptAttribute(eEntityAtr, "Type", entity.m_type.ToString()); EncryptAttribute(eEntityAtr, "Model", entity.m_modelName); EncryptAttribute(eEntityAtr, "quaW", entity.m_quaternion.w.ToString()); EncryptAttribute(eEntityAtr, "quaZ", entity.m_quaternion.z.ToString()); EncryptAttribute(eEntityAtr, "quaY", entity.m_quaternion.y.ToString()); EncryptAttribute(eEntityAtr, "quaX", entity.m_quaternion.x.ToString()); EncryptAttribute(eEntityAtr, "posZ", entity.m_position.z.ToString()); EncryptAttribute(eEntityAtr, "posY", entity.m_position.y.ToString()); EncryptAttribute(eEntityAtr, "posX", entity.m_position.x.ToString()); //eEntityAtr.SetAttribute("PathIndex", entity.m_pathIndex.ToString()); //eEntityAtr.SetAttribute("MapCubeIndex", entity.m_mapCubeIndex.ToString()); //eEntityAtr.SetAttribute("Type", entity.m_type.ToString()); //eEntityAtr.SetAttribute("Model", entity.m_modelName); //eEntityAtr.SetAttribute("quaW", entity.m_quaternion.w.ToString()); //eEntityAtr.SetAttribute("quaZ", entity.m_quaternion.z.ToString()); //eEntityAtr.SetAttribute("quaY", entity.m_quaternion.y.ToString()); //eEntityAtr.SetAttribute("quaX", entity.m_quaternion.x.ToString()); //eEntityAtr.SetAttribute("posZ", entity.m_position.z.ToString()); //eEntityAtr.SetAttribute("posY", entity.m_position.y.ToString()); //eEntityAtr.SetAttribute("posX", entity.m_position.x.ToString()); //游戏属性 XmlElement eGameAtr = xmlDocument.CreateElement("GameAtr"); EncryptAttribute(eGameAtr, "IsAtk", entity.IsAtk.ToString()); EncryptAttribute(eGameAtr, "IsMove", entity.IsMove.ToString()); EncryptAttribute(eGameAtr, "MoveSpeed", entity.MoveSpeed.ToString()); EncryptAttribute(eGameAtr, "AtkRange", entity.AtkRange.ToString()); EncryptAttribute(eGameAtr, "AtkSpeed", entity.AtkSpeed.ToString()); EncryptAttribute(eGameAtr, "DefValue", entity.DefValue.ToString()); EncryptAttribute(eGameAtr, "AtkValue", entity.HP.ToString()); EncryptAttribute(eGameAtr, "HP", entity.HP.ToString()); //eGameAtr.SetAttribute("IsAtk", entity.IsAtk.ToString()); //eGameAtr.SetAttribute("IsMove", entity.IsMove.ToString()); //eGameAtr.SetAttribute("MoveSpeed", entity.MoveSpeed.ToString()); //eGameAtr.SetAttribute("AtkRange", entity.AtkRange.ToString()); //eGameAtr.SetAttribute("AtkSpeed", entity.AtkSpeed.ToString()); //eGameAtr.SetAttribute("DefValue", entity.DefValue.ToString()); //eGameAtr.SetAttribute("AtkValue", entity.HP.ToString()); //eGameAtr.SetAttribute("HP", entity.HP.ToString()); eEntity.AppendChild(eEntityAtr); eEntity.AppendChild(eGameAtr); } eRoot.AppendChild(eEntitiesList); //保存路径信息 XmlElement ePathList = xmlDocument.CreateElement("PathList"); foreach (Path path in PathManager.Instance.GetPaths()) { //单个路径节点 XmlElement ePath = xmlDocument.CreateElement("Path"); //路径的状态信息 EncryptAttribute(ePath, "IsEmpty", path.m_isEmpty.ToString()); EncryptAttribute(ePath, "Index", path.m_index.ToString()); //ePath.SetAttribute("IsEmpty", path.m_isEmpty.ToString()); //ePath.SetAttribute("Index", path.m_index.ToString()); //路径的关键点信息 XmlElement eKeyPointList = xmlDocument.CreateElement("KeyPointList"); foreach (Point keyPoint in path.m_keyPoints) { XmlElement eKeyPoint = xmlDocument.CreateElement("KeyPoint"); EncryptAttribute(eKeyPoint, "y", keyPoint.m_y.ToString()); EncryptAttribute(eKeyPoint, "x", keyPoint.m_x.ToString()); //eKeyPoint.SetAttribute("y", keyPoint.m_y.ToString()); //eKeyPoint.SetAttribute("x", keyPoint.m_x.ToString()); eKeyPointList.AppendChild(eKeyPoint); } ePath.AppendChild(eKeyPointList); //路径的点信息 XmlElement ePointList = xmlDocument.CreateElement("PointList"); foreach (Point point in path.m_points) { XmlElement ePoint = xmlDocument.CreateElement("Point"); EncryptAttribute(ePoint, "y", point.m_y.ToString()); EncryptAttribute(ePoint, "x", point.m_x.ToString()); //ePoint.SetAttribute("y", point.m_y.ToString()); //ePoint.SetAttribute("x", point.m_x.ToString()); ePointList.AppendChild(ePoint); } ePath.AppendChild(ePointList); ePathList.AppendChild(ePath); } eRoot.AppendChild(ePathList); //保存事件信息 XmlElement eEventList = xmlDocument.CreateElement("EventList"); foreach (Event @event in EventManager.Instance.GetEvents()) { XmlElement eEvent = xmlDocument.CreateElement("Event"); EncryptAttribute(eEvent, "Index", @event.m_index.ToString()); string type = @event.Type; //Debug.Log("事件的类型是: " + type); EncryptAttribute(eEvent, "Type", type); if (type == "Birth") { BirthEvent birthEvent = (BirthEvent)@event; EncryptAttribute(eEvent, "CD", birthEvent.m_cd.ToString()); EncryptAttribute(eEvent, "Time", birthEvent.m_time.ToString()); EncryptAttribute(eEvent, "IsInfinite", birthEvent.m_isInfinite.ToString()); } else if (type == "Bomb") { BombEvent bombEvent = (BombEvent)@event; EncryptAttribute(eEvent, "Delay", bombEvent.m_delay.ToString()); EncryptAttribute(eEvent, "Hurt", bombEvent.m_hurt.ToString()); EncryptAttribute(eEvent, "IsDestroy", bombEvent.m_isDestory.ToString()); } else if (type == "Speed") { SpeedEvent speedEvent = (SpeedEvent)@event; EncryptAttribute(eEvent, "Speed", speedEvent.m_speed.ToString()); EncryptAttribute(eEvent, "Time", speedEvent.m_time.ToString()); EncryptAttribute(eEvent, "IsInfinite", speedEvent.m_isInfinite.ToString()); } else if (type == "Teleport") { TeleportEvent teleportEvent = (TeleportEvent)@event; EncryptAttribute(eEvent, "TeleportID", teleportEvent.m_teleportID.ToString()); EncryptAttribute(eEvent, "CD", teleportEvent.m_cd.ToString()); EncryptAttribute(eEvent, "Time", teleportEvent.m_time.ToString()); EncryptAttribute(eEvent, "IsInfinite", teleportEvent.m_isInfinite.ToString()); } eEventList.AppendChild(eEvent); } eRoot.AppendChild(eEventList); //保存音乐信息 XmlElement eMusic = xmlDocument.CreateElement("Music"); Music music = MusicManager.Instance.m_music; if (music != null) { EncryptAttribute(eMusic, "Volume", music.m_volume.ToString()); EncryptAttribute(eMusic, "Name", music.m_name); //eMusic.SetAttribute("Volume", music.m_volume.ToString()); //eMusic.SetAttribute("Name", music.m_name); } eRoot.AppendChild(eMusic); //保存XML文件 xmlDocument.Save(filePath); return(true); } catch { LogManager.Instance.Log("保存地图失败!"); return(false); } }
//显示事件属性 private void DisplayEvent() { m_objBirthEvent.SetActive(false); m_objBombEvent.SetActive(false); m_objSpeedEvent.SetActive(false); m_objTeleportEvent.SetActive(false); string eventType = m_currEvent.Type; Transform tempTransform; if (eventType == "Birth") { m_objBirthEvent.SetActive(true); BirthEvent birthEvent = (BirthEvent)m_currEvent; tempTransform = m_objBirthEvent.transform.Find("Index"); tempTransform.Find("Text").GetComponent <Text>().text = birthEvent.m_index.ToString(); tempTransform = m_objBirthEvent.transform.Find("CD"); tempTransform.GetComponentInChildren <InputField>().text = birthEvent.m_cd.ToString(); tempTransform = m_objBirthEvent.transform.Find("Time"); tempTransform.GetComponentInChildren <InputField>().text = birthEvent.m_time.ToString(); tempTransform = m_objBirthEvent.transform.Find("IsInfinite"); tempTransform.GetComponentInChildren <Toggle>().isOn = birthEvent.m_isInfinite; } else if (eventType == "Bomb") { m_objBombEvent.SetActive(true); BombEvent bombEvent = (BombEvent)m_currEvent; tempTransform = m_objBombEvent.transform.Find("Index"); tempTransform.Find("Text").GetComponent <Text>().text = bombEvent.m_index.ToString(); tempTransform = m_objBombEvent.transform.Find("Delay"); tempTransform.GetComponentInChildren <InputField>().text = bombEvent.m_delay.ToString(); tempTransform = m_objBombEvent.transform.Find("Hurt"); tempTransform.GetComponentInChildren <InputField>().text = bombEvent.m_hurt.ToString(); tempTransform = m_objBombEvent.transform.Find("IsDestroy"); tempTransform.GetComponentInChildren <Toggle>().isOn = bombEvent.m_isDestory; } else if (eventType == "Speed") { m_objSpeedEvent.SetActive(true); SpeedEvent speedEvent = (SpeedEvent)m_currEvent; tempTransform = m_objSpeedEvent.transform.Find("Index"); tempTransform.Find("Text").GetComponent <Text>().text = speedEvent.m_index.ToString(); tempTransform = m_objSpeedEvent.transform.Find("Speed"); tempTransform.GetComponentInChildren <InputField>().text = speedEvent.m_speed.ToString(); tempTransform = m_objSpeedEvent.transform.Find("Time"); tempTransform.GetComponentInChildren <InputField>().text = speedEvent.m_time.ToString(); tempTransform = m_objSpeedEvent.transform.Find("IsInfinite"); tempTransform.GetComponentInChildren <Toggle>().isOn = speedEvent.m_isInfinite; } else if (eventType == "Teleport") { m_objTeleportEvent.SetActive(true); TeleportEvent teleportEvent = (TeleportEvent)m_currEvent; tempTransform = m_objTeleportEvent.transform.Find("Index"); tempTransform.Find("Text").GetComponent <Text>().text = teleportEvent.m_index.ToString(); tempTransform = m_objTeleportEvent.transform.Find("TeleportID"); tempTransform.GetComponentInChildren <InputField>().text = teleportEvent.m_teleportID.ToString(); tempTransform = m_objTeleportEvent.transform.Find("CD"); tempTransform.GetComponentInChildren <InputField>().text = teleportEvent.m_cd.ToString(); tempTransform = m_objTeleportEvent.transform.Find("Time"); tempTransform.GetComponentInChildren <InputField>().text = teleportEvent.m_time.ToString(); tempTransform = m_objTeleportEvent.transform.Find("IsInfinite"); tempTransform.GetComponentInChildren <Toggle>().isOn = teleportEvent.m_isInfinite; } else { LogManager.Instance.Log("事件类型不存在!"); return; } }