private CityObject CreateCityObjectFromProjectData(ProjectData projectData, CityObject cityObjectParent) { var prefab = FindPrefab(projectData.type); if (!prefab) { return(null); } CityObject rootCityObject = new CityObject(prefab, cityObjectParent, projectData.width, projectData.height, projectData.value); ScaleObject(rootCityObject); /* * * * If an object has one or more children, then the children should execute this method on their own. */ if (projectData.children.Count() != 0) { foreach (ProjectData data in projectData.children) { CityObject newChild = CreateGameObjectFromProjectData(data, rootCityObject); rootCityObject.AppendChild(newChild); } } return(rootCityObject); }
public void SetValue(CityObject node) { Material valMaterial; switch (node.value) { case 1: valMaterial = value1; break; case 2: valMaterial = value2; break; case 3: valMaterial = value3; break; case 4: valMaterial = value4; break; case 5: valMaterial = value5; break; case 6: valMaterial = value6; break; case 7: valMaterial = value7; break; case 8: valMaterial = value8; break; case 9: valMaterial = value9; break; default: valMaterial = valueDefault; break; } node.form.GetComponent <Renderer>().material = valMaterial; }
private GenericValidator ValidateCity(CityObject city) { var gVal = new GenericValidator(); if (city == null) { gVal.Code = -1; gVal.Error = message_Feedback.Fatal_Error; return(gVal); } if (string.IsNullOrEmpty(city.Name)) { gVal.Code = -1; gVal.Error = message_Feedback.City_Name_Error; return(gVal); } if (city.StateId < 1) { gVal.Code = -1; gVal.Error = message_Feedback.State_Selection_Error; return(gVal); } gVal.Code = 5; return(gVal); }
public long AddCity(CityObject city) { try { if (city == null) { return(-2); } var duplicates = _repository.Count(m => m.Name.Trim().ToLower().Equals(city.Name.Trim().ToLower()) && city.StateId.Equals(m.StateId)); if (duplicates > 0) { return(-3); } var cityEntity = ModelCrossMapper.Map <CityObject, City>(city); if (cityEntity == null || string.IsNullOrEmpty(cityEntity.Name)) { return(-2); } var returnStatus = _repository.Add(cityEntity); _uoWork.SaveChanges(); return(returnStatus.CityId); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateCity(CityObject city) { try { if (city == null) { return(-2); } var duplicates = _repository.Count(m => m.Name.Trim().ToLower().Equals(city.Name.Trim().ToLower()) && city.StateId.Equals(m.StateId) && (m.CityId != city.CityId)); if (duplicates > 0) { return(-3); } var cityEntity = ModelCrossMapper.Map <CityObject, City>(city); if (cityEntity == null || cityEntity.CityId < 1) { return(-2); } _repository.Update(cityEntity); _uoWork.SaveChanges(); return(5); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
/* * * * This function walks trough the whole tree and deletes the objects from the bottom to the top */ public void DestroyBuiltCity(CityObject node) { foreach (CityObject child in node.children) { DestroyBuiltCity(child); } node.DestroyCityObject(); }
public void SyncCity(City squareDictionaryCity, GameObject objectInScene){ CityObject cityInScene = objectInScene.GetComponent<CityObject> (); cityInScene.baseDefence = squareDictionaryCity.baseDefence; cityInScene.coords = squareDictionaryCity.coords; cityInScene.occupiedBy = squareDictionaryCity.occupiedBy; cityInScene.replenishRatePerTurn = squareDictionaryCity.replenishRatePerTurn; }
private void PositionObjectsRadial(CityObject node) { LayoutVar variables = new LayoutVar(); Debug.Log("Size: " + GetArraySize(node)); variables.size = GetArraySize(node); GameObject[,] layout = new GameObject[variables.size, variables.size]; distance = distance * 1.3 / node.width; foreach (CityObject child in node.children) { layout[variables.z, variables.x] = child.form; Debug.Log(variables.x + " und " + variables.z); float xPos; float zPos; if (variables.x == 0 && variables.z == 0) { xPos = 1 - child.form.transform.localScale.x - (float)distance; zPos = 1 - child.form.transform.localScale.z - (float)distance; } else if (variables.x == 0 && variables.z != 0) { xPos = 1 - child.form.transform.localScale.x - (float)distance; zPos = layout[variables.z - 1, variables.x].transform.position.z - layout[variables.z - 1, variables.x].transform.localScale.z - child.form.transform.localScale.z - (float)distance * 2f; } else if (variables.x != 0 && variables.z == 0) { xPos = layout[variables.z, variables.x - 1].transform.position.x - layout[variables.z, variables.x - 1].transform.localScale.x - child.form.transform.localScale.x - (float)distance * 2f; zPos = 1 - child.form.transform.localScale.z - (float)distance; } else { xPos = layout[variables.z - 1, variables.x].transform.position.x - (float)distance * 2f; zPos = layout[variables.z, variables.x - 1].transform.position.z - (float)distance * 2f; } float yPos = 1.025f + (0.5f * child.height / 100) + (node.form.transform.localScale.y); child.form.transform.position = new Vector3(xPos, yPos, zPos); if (IsScope(child)) { float planeHeight = plane.transform.localScale.y / 2; child.form.transform.position += new Vector3(0, planeHeight, 0); PositionChildrenRadial(child); } LayoutManager(variables); } }
/* * * * This Method adjusts the widths of the planes because they didn´t get a width of the ProjectData before. * So the Planes add up all widths of their children (cubes) for theirown. */ private double Subtree(CityObject cityObject) { foreach (CityObject child in cityObject.children) { cityObject.width += Subtree(child) + 2 * distance; Debug.Log(cityObject.width); } return(cityObject.width); }
public CityObject(GameObject prefab, CityObject cityObjectParent, double newWidth, int newHeight, int newValue) { form = Instantiate(prefab); parent = cityObjectParent; children = new List <CityObject>(); width = newWidth; height = newHeight; value = newValue; }
public ActionResult EditCity(CityObject city) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateCity(city); if (valStatus.Code < 1) { gVal.Code = 0; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_city"] == null) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldCity = Session["_city"] as CityObject; if (oldCity == null || oldCity.CityId < 1) { gVal.Code = -5; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldCity.Name = city.Name.Trim(); oldCity.StateId = city.StateId; var k = new CityServices().UpdateCity(oldCity); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; gVal.Error = message_Feedback.Update_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -5; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
/* * * * For positioning the Objects radial, a Scope needs to be split into a n*n Matrix. This Function finds the next * biggest square number n^2 and returns n for knowledge about the needed matrix size. */ private int GetArraySize(CityObject node) { int size = 0;; while ((size * size) < node.children.Count) { size++; } return(size); }
//---- Protected Methods ----/ protected override bool IsInteractable(CityObject cityObject) { if (cityObject == null) { return false; } Clickable clickable = cityObject.GetComponent<Clickable>(); if (clickable != null) { if (!clickable.enabled) { return false; } } if (cityObject is Waypoint) { return false; } if (cityObject is Cloak) { return false; } return true; }
/* * * * This function sets the material for every created GameObject */ private void SetMaterials(CityObject node) { foreach (CityObject child in node.children) { valueManager.SetValue(child); if (IsScope(child)) { SetMaterials(child); } } }
/* * * * This Method checks if a CityObject has children. If it has children, the function knows that the Object is * a Scope and returns true. Else it just returns false because only Leafs of the tree haven´t got children. */ private bool IsScope(CityObject cityObject) { if (cityObject.children.Count != 0) { return(true); } else { return(false); } }
/* * * * This function sorts all children of a cityobject in descending order */ private void SortChildren(CityObject node) { node.children = node.children.OrderByDescending(x => x.width).ToList(); foreach (CityObject child in node.children) { if (IsScope(child)) { SortChildren(child); } } }
public long AddCity(CityObject cityAccount) { try { return(_cityRepository.AddCity(cityAccount)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateCity(CityObject city) { try { return(_cityRepository.UpdateCity(city)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
public IActionResult Cities() { var obj = new CityObject() { firstCity = CityObject[new Random().Next(CityObject.Length)], secondCity = CityObject[new Random().Next(CityObject.Length)], thirdCity = CityObject[new Random().Next(CityObject.Length)], forthCity = CityObject[new Random().Next(CityObject.Length)], fifthCity = CityObject[new Random().Next(CityObject.Length)] }; return(Ok(obj)); }
internal List<CityObject> getObjects(string list) { List<CityObject> b = new List<CityObject>(); IDataReader reader = executeSelect("select name from " + list + ""); while (reader.Read()) { CityObject tmp = new CityObject(reader["name"].ToString()); b.Add(tmp); } return b; }
/* * * * Scopes and leafs need a different way to scale their heights and this function is doing it. * The size of the scopes should be all the same while the leaf objects get heights relativ to it´s height-value. */ private float ScaleHeights(CityObject node) { float height; if (IsScope(node)) { height = 1f; } else { height = (float)(1 / plane.transform.localScale.y) * node.height / 100; //40 = 1 / 0.01 (= height of the first scope) } return(height); }
public void Init(CityObject city, Player player) { playerInspecting = player; cityObject = city; nameTxt.text = player.Name; if (player == Player.LocalPlayer) { nameTxt.text += "(You)"; } climateTxt.text = playerInspecting.ClimateType.ToString(); setTradeOffersBtn.gameObject.SetActive(player == Player.LocalPlayer); gameObject.SetActive(true); pollutionPerMinuteTxt.text = string.Format("{0:0}", player.PlayerPollutionPerYear); InstantiateTradeOffers(); }
//---- Protected Methods ----/ protected override bool IsInteractable(CityObject cityObject) { if (cityObject == null) { return false; } Clickable clickable = cityObject.GetComponent<Clickable>(); if (clickable != null) { if (!clickable.enabled) { return false; } } bool isPowerStation = cityObject is PowerStation; bool isApp = cityObject is App; bool isIOBuilding = cityObject is IOBuilding; bool isConnection = cityObject is Connection; bool isOrchestrator = cityObject is Orchestrator; bool isTransporterStation = cityObject is TransporterStation; bool isLion = cityObject is CityLion; bool isTerminal = cityObject is ClientTerminal; return isPowerStation || isApp || isIOBuilding || isLion || isTerminal || isConnection || isOrchestrator || isTransporterStation; }
public IEnumerator BuildCodeCity(JsonProject JsonProjectToBuild) { Debug.Log(JsonProjectToBuild.views[0].href); WWW complexityUrl = new WWW(JsonProjectToBuild.views[0].href); yield return(complexityUrl); if (complexityUrl.error != null) { Debug.Log("ERROR: " + complexityUrl.error); } else { ProjectView projectView = ProcessProjectData(complexityUrl.text); origin = CreateGameObjectFromProjectData(projectView.data[0], origin); Algorithm(); } }
private void ScaleObject(CityObject node) { double maxWidth = node.width; foreach (CityObject child in node.children) { float scaleRatio = (float)(child.width * 1.3 / maxWidth); if (scaleRatio > 1) { scaleRatio = (float)(child.width / maxWidth); } float height = ScaleHeights(child); child.form.transform.localScale = new Vector3(scaleRatio, height, scaleRatio); if (child.children.Count() != null) { ScaleObject(child); } } }
public ActionResult AddCity(CityObject city) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateCity(city); if (valStatus.Code < 1) { gVal.Code = 0; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var k = new CityServices().AddCity(city); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = k; gVal.Error = message_Feedback.Insertion_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -1; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
/* * * * This function sets all creted objects in a line on one side of the table using its whole width. */ private void PositionObjectsLine(CityObject node) { float usedSpace = 0; float middle = node.form.transform.localScale.x / 2; //SortChildren(node); foreach (CityObject child in node.children) { float xPos = 1 - child.form.transform.localScale.x; //Debug.Log(xPos); float yPos = 1.025f + (0.5f * child.height / 100) + (node.form.transform.localScale.y); //0.025 is the top of the table float zPos = 1 - (usedSpace * 2) - child.form.transform.localScale.z; usedSpace += child.form.transform.localScale.z; child.form.transform.position = new Vector3(xPos, yPos, zPos); if (IsScope(child)) { float planeHeight = plane.transform.localScale.y / 2; child.form.transform.position += new Vector3(0, planeHeight, 0); PositionChildrenLine(child); } } }
IEnumerator RequestWeather() { /*if (System.IO.File.Exists(Application.persistentDataPath + "/request.txt")) * { * System.IO.FileInfo info = new System.IO.FileInfo(Application.persistentDataPath + "/request.txt"); * int time = int.Parse(DateTimeToStamp( info.CreationTimeUtc ))- int.Parse(DateTimeToStamp(System.DateTime.Now)); * if (time < 3600 * 6) * { * WeatherObject Weather = JsonConvert.DeserializeObject<WeatherObject>(System.IO.File.ReadAllText(Application.persistentDataPath + "/request.txt")); * OnWeatherInit(Weather.data.Today, city.data.city); * * } * }*/ UnityWebRequest ipRequest = UnityWebRequest.Get("http://pv.sohu.com/cityjson?ie=utf-8"); yield return(ipRequest.SendWebRequest()); IPObject ip = JsonConvert.DeserializeObject <IPObject>(ipRequest.downloadHandler.text.Replace("var returnCitySN = ", "").Replace(";", "")); UnityWebRequest cityRequest = UnityWebRequest.Get("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip.cip); yield return(cityRequest.SendWebRequest()); CityObject city = JsonConvert.DeserializeObject <CityObject>(cityRequest.downloadHandler.text); UnityWebRequest weatherRequest = UnityWebRequest.Get("http://wthrcdn.etouch.cn/weather_mini?citykey=" + CityCode(city.data.city)); weatherRequest.SetRequestHeader("Content-Type", "application/octet-stream"); weatherRequest.SetRequestHeader("Content-Encoding", "gzip"); yield return(weatherRequest.SendWebRequest()); System.IO.File.WriteAllBytes(Application.persistentDataPath + "/request.zip", weatherRequest.downloadHandler.data); System.IO.FileStream inStream = new System.IO.FileStream(Application.persistentDataPath + "/request.zip", System.IO.FileMode.Open); System.IO.FileStream outStream = new System.IO.FileStream(Application.persistentDataPath + "/request.txt", System.IO.FileMode.Create); GZip.Decompress(inStream, outStream, true); WeatherObject Weather = JsonConvert.DeserializeObject <WeatherObject>(System.IO.File.ReadAllText(Application.persistentDataPath + "/request.txt")); OnWeatherInit(Weather.data.Today, city.data.city); }
void BuildBuilding(GridTile tile) { // Pick a type of building randomly CityObject buildObject = buildings[rand.Next(0, buildings.Length)]; float diameter = buildObject.prefabs[0].GetComponent <SizeController>().diameter; // Rotation quaternion for the building orientation Quaternion rotation; // List of possible orientations float[] possibleOrientations = { 0, 90, 180, 270 }; // Get an angle from the possible orientation float angle = possibleOrientations[rand.Next(0, possibleOrientations.Length)]; // Make a maximum of 10 degrees offset from the cardinal direction (purely for making it more visibly appealing) //angle += (float)rand.NextDouble() * 10; // Create the rotation quaternion rotation = Quaternion.AngleAxis(angle, Vector3.up); if (world.CanBuild(tile.position, diameter, buildObject.prefabs[0], buildObject.scale, rotation, true)) { GameObject parentObj = new GameObject(); parentObj.transform.parent = transform; CityBuildingManager parentController = parentObj.AddComponent <CityBuildingManager>(); parentController.cityObject = buildObject; // Place the building GameObject cityObj = world.AddOther(buildObject.prefabs[0], tile.position + Vector3.down * 0.1f, rotation, buildObject.scale, GridTileOccupant.OccupantType.City, parentObj.transform); parentController.curObject = cityObj; curBuildings.Add(parentController); currentPlacedHouses++; } }
// Use this for initialization void Start() { string[] cityMapL = System.IO.File.ReadAllText("Assets/map2.csv").Split(new char[] { ';', '\n' }); //cityMapL. for (int i = 0; i < cityMapL.Length; i++) { Debug.Log(i + " " + cityMapL[i]); } cityMap = new CityObject[cityMapL.Length]; for (int i = 0; i < cityMapL.Length - 1; i++) { cityMap[i] = (CityObject)Enum.Parse(typeof(CityObject), cityMapL[i]); } for (int i = 0; i < mapHeight * mapWidth; i++) { CityObject cityObj = cityMap[i]; int x = i % mapWidth; int y = i / mapWidth; GameObject obj; switch (cityObj) { case CityObject.R: obj = roads[(int)getRoadType(x, y)]; break; case CityObject.N: obj = nature[UnityEngine.Random.Range(0, nature.Length)]; break; default: obj = houses[UnityEngine.Random.Range(0, houses.Length)]; break; } Instantiate(obj, new Vector3(-x * 20 - 10, 0, y * 20 + 20) + obj.transform.position, obj.transform.rotation); } }
/* * * * Due to the way unity is calculating with its scaling of the parents etc. - this function is needed to position all objects * beyond the second levelin the tree of all Objects. */ private void PositionChildrenLine(CityObject node) { float usedSpace = 0; float middle = node.form.transform.localScale.x / 2; foreach (CityObject child in node.children) { float xPos = 1 - (child.form.transform.localScale.x * node.form.transform.localScale.x); //passt float yPos = 1.035f + (0.5f * child.height / 100) + node.form.transform.lossyScale.y; //1.035 => 1.03 is the yPos of the first Plane + 0.005 for the plane //1.03 => 1.025 is the top of the table + 0.005 for the first plane float zPos = (node.form.transform.position.z + node.form.transform.localScale.z) - ((child.form.transform.localScale.z + usedSpace) * node.form.transform.localScale.z); usedSpace += (child.form.transform.localScale.z * 2); child.form.transform.position = new Vector3(xPos, yPos, zPos); if (IsScope(child)) { PositionChildrenLine(child); } } }
public void AppendChild(CityObject cityObject) { children.Add(cityObject); cityObject.form.transform.SetParent(this.form.transform); }
private void OnHoverOver(CityObject cityObject) { if (!IsInteractable(cityObject)) { cityObject.Highlight(false); return; } cityObject.Highlight(true); AudioManager.Instance.Play(AudioChannelIDX.GameSFX, "GridMove"); }
internal List<CityObject> interSects(double x, double y,string type) { List<CityObject> b = new List<CityObject>(); String sql = "SELECT c.id, c.name FROM "+ type +" c WHERE SDO_ANYINTERACT(c.shape, SDO_GEOMETRY(2001, NULL, sdo_point_type(" + x + "," + y + ",null), NULL,NULL)) = 'TRUE'"; Console.WriteLine(sql); IDataReader reader = executeSelect(sql); while (reader.Read()) { CityObject tmp = new CityObject(reader["name"].ToString()); b.Add(tmp); } return b; }
private void OnHoverOut(CityObject cityObject) { cityObject.Highlight(false); }
protected abstract bool IsInteractable(CityObject cityObject);