public GeoGroupInfo Clone() { GeoGroupInfo ggi = new GeoGroupInfo(); ggi.GeoInfos = new List <GeoInfo>(); foreach (GeoInfo gi in GeoInfos) { ggi.GeoInfos.Add(gi.Clone()); } ggi.Name = Name; ggi.FertilityRate = FertilityRate; ggi.OffspringSizePercent = OffspringSizePercent; ggi.MatureSizePercent = MatureSizePercent; ggi.MinSizePercent = MinSizePercent; ggi.MaxSizePercent = MaxSizePercent; ggi.StartNumber = StartNumber; ggi.MaxNumber = MaxNumber; ggi.GrowUpRate = GrowUpRate; foreach (string s in Diets) { ggi.Diets.Add(s); } foreach (string s in Predators) { ggi.Predators.Add(s); } ggi.ResetCenterAndSortingOrder(); ggi.RefreshInfo(); return(ggi); }
public void RefreshLeftPanelInfo(GeoGroupInfo ci) { LifeBar.value = ci.Life; LifeText.text = Mathf.RoundToInt(ci.Life).ToString(); SpeedBar.value = ci.Speed; SpeedText.text = Mathf.RoundToInt(ci.Speed).ToString(); DamageBar.value = ci.Damage; DamageText.text = Mathf.RoundToInt(ci.Damage).ToString(); VisionBar.value = ci.Vision; VisionText.text = Mathf.RoundToInt(ci.Vision).ToString(); GeneralSize.text = Mathf.Round(ci.GeneralSize / 10) + "cm"; Mass.text = Mathf.Round(ci.Mass) + "kg"; DietButton.onClick.RemoveAllListeners(); DietButton.onClick.AddListener(delegate { if (string.IsNullOrEmpty(NameInputField.text)) { ConfirmPanel cp = UIManager.Instance.ShowUIForms <ConfirmPanel>(); cp.Initialize("Please set the name first", "Confirm", null, delegate { cp.CloseUIForm(); }, delegate { }); return; } else { DietPanel.gameObject.SetActive(true); DietPanel.Refresh(ci); } }); }
private void LogResponseText(DF2Response response) { string text = response.queryResult.fulfillmentText; string talkingSpeciesName = ""; if (text.Contains("{TalkingSpecies_")) { foreach (KeyValuePair <string, GeoGroupInfo> kv in NatureController.Instance.AllGeoGroupInfo) { if (text.Contains("{TalkingSpecies_" + kv.Key + "}")) { talkingSpeciesName = kv.Key; text = text.Replace("{TalkingSpecies_" + kv.Key + "}", ""); } } } if (!string.IsNullOrWhiteSpace(talkingSpeciesName)) { GeoGroupInfo species = NatureController.Instance.AllGeoGroupInfo[talkingSpeciesName]; text = text.Replace("@life", Mathf.RoundToInt(species.Life).ToString()); text = text.Replace("@speed", Mathf.RoundToInt(species.Speed).ToString()); text = text.Replace("@damage", Mathf.RoundToInt(species.Damage).ToString()); text = text.Replace("@vision", Mathf.RoundToInt(species.Vision).ToString()); text = text.Replace("@fertilityRate", Mathf.RoundToInt(species.FertilityRate) + "%"); text = text.Replace("@matureSizePercent", Mathf.RoundToInt(species.MatureSizePercent) + "%"); text = text.Replace("@diets", GetDescFromList(species.Diets.ToList())); text = text.Replace("@predators", GetDescFromList(species.Predators.ToList())); } QAPanel.GenerateText(text, TextBubble.Alignment.Left); }
public void LoadAllSpeciesFromXML() { AllGeoGroupInfo.Clear(); AllSelectedGeoGroupInfoNames.Clear(); UIManager.Instance.GetBaseUIForm <NaturalPanel>().Initialize(); string text; using (StreamReader sr = new StreamReader(XMLPath)) { text = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(text); XmlElement allCreaturesEle = doc.DocumentElement; for (int i = 0; i < allCreaturesEle.ChildNodes.Count; i++) { XmlNode creature_ele = allCreaturesEle.ChildNodes[i]; GeoGroupInfo ggi = GeoGroupInfo.GenerateGeoGroupInfoFromXML(creature_ele); AllGeoGroupInfo.Add(ggi.Name, ggi); ggi.RefreshInfo(); } RecreateAllSpecies(); }
public void LoadGeoGroupInfo(GeoGroupInfo ggi) { Cur_GGI = ggi.Clone(); foreach (GeoElement geo in GeoElements) { geo.PoolRecycle(); } GeoElements.Clear(); MyState = States.None; StartDragMove = false; IsMouseIn = false; MouseLeftDown = false; SortingOrder = 2; foreach (GeoInfo gi in ggi.GeoInfos) { GeoElement ge = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.GeoElement].AllocateGameObject <GeoElement>(transform); ge.transform.localPosition = gi.Position; ge.transform.rotation = gi.Rotation; ge.Initialize(gi.GeoType, gi.Size * GameManager.Instance.ScaleFactor * GameManager.Instance.ScaleFactor, gi.Color, gi.SortingOrder); SortingOrder = Mathf.Max(SortingOrder, gi.SortingOrder + 1); GeoElements.Add(ge); } }
public void Init(Species species, GeoGroupInfo ci, float _size, bool randomSize = false) { MyGeoGroupInfo = ci; Rigidbody2D.mass = MyGeoGroupInfo.Mass; if (randomSize) { Size = Random.Range(MyGeoGroupInfo.MinSize, MyGeoGroupInfo.MaxSize); } else { Size = _size; } Life = ci.Life * Size / ci.MaxSize; Damage = ci.Damage * Size / ci.MaxSize; GeoGroup?.PoolRecycle(); GeoGroup = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.GeoGroup].AllocateGameObject <GeoGroup>(transform); My_Species = species; M_SpeciesName = species.MyGeoGroupInfo.Name; foreach (GeoInfo gi in species.MyGeoGroupInfo.GeoInfos) { GeoElement ge = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.GeoElement].AllocateGameObject <GeoElement>(GeoGroup.transform); ge.Collider.enabled = false; GeoGroup.AllGeos.Add(ge); GeoGroup.GeoGroupInfo = species.MyGeoGroupInfo; ge.transform.localPosition = (gi.Position - ci.Center) / GameManager.Instance.ScaleFactor / GameManager.Instance.ScaleFactor; ge.transform.rotation = gi.Rotation; ge.Initialize(gi.GeoType, gi.Size, gi.Color, gi.SortingOrder); } MyCollider.radius = MyGeoGroupInfo.ColliderRadius; }
public void Initialize(GeoGroupInfo ggi, bool readOnlyName = false) { NameInputField.readOnly = readOnlyName; LoadInfoForLeftPanel(ggi); EditArea.LoadGeoGroupInfo(ggi); UIManager.Instance.ShowUIForms <ConfirmPanel>().InputField1.text = ggi.Name; UIManager.Instance.CloseUIForm <ConfirmPanel>(); StartCoroutine(ClientUtils.UpdateLayout((RectTransform)EditMenuScrollRect.transform)); EditMenuScrollRect.ScrollToTop(); }
public void LoadInfoForLeftPanel(GeoGroupInfo ci) { RefreshLeftPanelInfo(ci); NameInputField.text = ci.Name; FertilityRateInputField.text = ci.FertilityRate.ToString(); OffspringSize.text = ci.OffspringSizePercent.ToString(); MatureSize.text = ci.MatureSizePercent.ToString(); MinSize.text = ci.MinSizePercent.ToString(); MaxSize.text = ci.MaxSizePercent.ToString(); GrowthRate.text = Mathf.RoundToInt(ci.GrowUpRate * 1000f).ToString(); StartNumber.text = ci.StartNumber.ToString(); MaxNumber.text = ci.MaxNumber.ToString(); }
public void Initialize(GeoGroupInfo ggi) { Button.image.color = new Color(Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f)); GGI = ggi; Text.text = ggi.Name; Button.onClick.RemoveAllListeners(); Button.onClick.AddListener(delegate { NatureController.Instance.ClearAll(); CreatureEditorPanel cep = UIManager.Instance.ShowUIForms <CreatureEditorPanel>(); cep.Initialize(GGI, true); UIManager.Instance.CloseUIForm <NaturalPanel>(); UIManager.Instance.GetBaseUIForm <NaturalPanel>().isSimulationStart = false; }); }
public static GeoGroupInfo GenerateGeoGroupInfoFromXML(XmlNode creatureElement) { GeoGroupInfo ggi = new GeoGroupInfo(); ggi.Name = creatureElement.Attributes["name"].Value; XmlNode creatureInfo = creatureElement.ChildNodes[0]; ggi.FertilityRate = int.Parse(creatureInfo.Attributes["FertilityRate"].Value); ggi.OffspringSizePercent = int.Parse(creatureInfo.Attributes["OffspringSizePercent"].Value); ggi.MatureSizePercent = int.Parse(creatureInfo.Attributes["MatureSizePercent"].Value); ggi.MinSizePercent = int.Parse(creatureInfo.Attributes["MinSizePercent"].Value); ggi.MaxSizePercent = int.Parse(creatureInfo.Attributes["MaxSizePercent"].Value); ggi.GrowUpRate = float.Parse(creatureInfo.Attributes["GrowUpRate"].Value); ggi.StartNumber = int.Parse(creatureInfo.Attributes["StartNumber"].Value); ggi.MaxNumber = int.Parse(creatureInfo.Attributes["MaxNumber"].Value); List <string> diets = creatureInfo.Attributes["Diets"].Value.Split(',').ToList(); List <string> predators = creatureInfo.Attributes["Predators"].Value.Split(',').ToList(); foreach (string diet in diets) { if (!string.IsNullOrWhiteSpace(diet)) { ggi.Diets.Add(diet); } } foreach (string p in predators) { if (!string.IsNullOrWhiteSpace(p)) { ggi.Predators.Add(p); } } XmlNode geoInfos_element = creatureElement.ChildNodes[1]; for (int i = 0; i < geoInfos_element.ChildNodes.Count; i++) { XmlNode geoInfo_element = geoInfos_element.ChildNodes[i]; GeoInfo gi = GeoInfo.GenerateGeoInfoFromXML(geoInfo_element); ggi.GeoInfos.Add(gi); } return(ggi); }
public void RecreateAllSpecies() { ClearAll(); NaturalPanel np = UIManager.Instance.GetBaseUIForm <NaturalPanel>(); np.RefreshButtonSelected(); foreach (string ggiName in AllSelectedGeoGroupInfoNames) { GeoGroupInfo ggi = AllGeoGroupInfo[ggiName]; Species species = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.Species].AllocateGameObject <Species>(transform); species.name = ggi.Name + "_Species"; species.MyGeoGroupInfo = ggi; AllSpecies.Add(ggi.Name, species); } np.Initialize(); }
public void RefreshInfo() { if (Cur_GGI == null) { Cur_GGI = new GeoGroupInfo(); } Cur_GGI.GeoInfos.Clear(); foreach (GeoElement geo in GeoElements) { GeoInfo gi = geo.ExportGeoInfo(); Cur_GGI.GeoInfos.Add(gi); } Cur_GGI.RefreshInfo(); UIManager.Instance.GetBaseUIForm <CreatureEditorPanel>().RefreshLeftPanelInfo(Cur_GGI); UIManager.Instance.GetBaseUIForm <CreatureEditorPanel>().GetLeftPanelManualInfo(Cur_GGI); }
public void Initialize(GeoGroupInfo hostGGI, GeoGroupInfo targetGGI, Types type) { SpeciesName.text = targetGGI.Name; Toggle.onValueChanged.RemoveAllListeners(); if (type == Types.TargetIsPrey) { Toggle.isOn = hostGGI.Diets.Contains(targetGGI.Name); } else if (type == Types.TargetIsPredator) { Toggle.isOn = hostGGI.Predators.Contains(targetGGI.Name); } Toggle.onValueChanged.AddListener(delegate(bool toggleBool) { if (type == Types.TargetIsPrey) { if (toggleBool) { hostGGI.Diets.Add(targetGGI.Name); targetGGI.Predators.Add(hostGGI.Name); } else { hostGGI.Diets.Remove(targetGGI.Name); targetGGI.Predators.Remove(hostGGI.Name); } } else if (type == Types.TargetIsPredator) { if (toggleBool) { hostGGI.Predators.Add(targetGGI.Name); targetGGI.Diets.Add(hostGGI.Name); } else { hostGGI.Predators.Remove(targetGGI.Name); targetGGI.Diets.Remove(hostGGI.Name); } } }); }
public void Refresh(GeoGroupInfo hostGGI) { foreach (KeyValuePair <string, DietToggle> kv in DietToggles) { kv.Value.PoolRecycle(); } DietToggles.Clear(); foreach (KeyValuePair <string, DietToggle> kv in PredatorToggles) { kv.Value.PoolRecycle(); } PredatorToggles.Clear(); foreach (string dietName in NatureController.Instance.AllGeoGroupInfo.Keys) { if (dietName == hostGGI.Name) { continue; } DietToggle dt = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.DietToggle].AllocateGameObject <DietToggle>(DietContainer); DietToggles.Add(dietName, dt); dt.Initialize(hostGGI, NatureController.Instance.AllGeoGroupInfo[dietName], DietToggle.Types.TargetIsPrey); } foreach (string predatorName in NatureController.Instance.AllGeoGroupInfo.Keys) { if (predatorName == hostGGI.Name) { continue; } DietToggle dt = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.DietToggle].AllocateGameObject <DietToggle>(PredatorContainer); PredatorToggles.Add(predatorName, dt); dt.Initialize(hostGGI, NatureController.Instance.AllGeoGroupInfo[predatorName], DietToggle.Types.TargetIsPredator); } }
public void GetLeftPanelManualInfo(GeoGroupInfo ci) { if (int.TryParse(FertilityRateInputField.text, out int fr)) { ci.FertilityRate = fr; } else { ci.FertilityRate = 100; FertilityRateInputField.text = "100"; } if (int.TryParse(OffspringSize.text, out int os)) { ci.OffspringSizePercent = os; } else { ci.OffspringSizePercent = 30; OffspringSize.text = "30"; } if (int.TryParse(MatureSize.text, out int ms)) { ci.MatureSizePercent = ms; } else { ci.MatureSizePercent = 70; MatureSize.text = "70"; } if (int.TryParse(MinSize.text, out int mins)) { ci.MinSizePercent = mins; } else { ci.MinSizePercent = 20; MinSize.text = "20"; } if (int.TryParse(MaxSize.text, out int maxs)) { ci.MaxSizePercent = maxs; } else { ci.MaxSizePercent = 130; MaxSize.text = "130"; } if (int.TryParse(MaxNumber.text, out int mn)) { ci.MaxNumber = mn; } else { ci.MaxNumber = 100; MaxNumber.text = "100"; } if (int.TryParse(StartNumber.text, out int sn)) { ci.StartNumber = sn; } else { ci.StartNumber = 10; StartNumber.text = "10"; } if (int.TryParse(GrowthRate.text, out int gr)) { ci.GrowUpRate = gr / 1000f; } else { ci.GrowUpRate = 0.001f; GrowthRate.text = "1"; } if (!string.IsNullOrWhiteSpace(NameInputField.text)) { ci.Name = NameInputField.text; } else { ci.Name = null; } }