public Coordinate GetCoordinateFromScreenPoint(Vector3 screenPoint) { RaycastHit hit; if (Physics.Raycast(GameManager.Instance.CameraManager.SateliteCamera.ScreenPointToRay(screenPoint), out hit)) { Vector3 worldPoint = Map.transform.InverseTransformPoint(hit.point); //~ Debug.Log(map.transform.InverseTransformPoint(hit.point))); Vector3 point = new Vector3(worldPoint.x * Map.transform.localScale.x, worldPoint.y * Map.transform.localScale.y, worldPoint.z * Map.transform.localScale.z); //~ Debug.Log(GameManager.Instance.xToLong(point.x)); //Vector3 pos = new Vector3(((worldPoint.x - 5.0f) * map.transform.localScale.x) * -1, worldPoint.y, ((worldPoint.z + 5.0f) * map.transform.localScale.z)); float a = GameManager.Instance.XMapModifier; float b = GameManager.Instance.YMapModifier; Vector3 pos2 = new Vector3(); //y = -225a-1 + a-1x //pos2.x = -1347.305389f + 5.988023952f * hit.point.x; pos2.x = -GameManager.Instance.XMapAddition * Mathf.Pow(a, -1) + Mathf.Pow(a, -1) * hit.point.x; pos2.z = -GameManager.Instance.YMapAddtion * Mathf.Pow(b, -1) + Mathf.Pow(b, -1) * hit.point.z; pos2.y = Map.transform.position.y; Coordinate coordPoint = CoordinateHelper.FromOrthoProjectedCoordinate(pos2.z, pos2.x); return(coordPoint); } return(null); }
public void MoveToPoint(Vector3 screenPoint) { RaycastHit hit; if (Physics.Raycast(GameManager.Instance.CameraManager.SateliteCamera.ScreenPointToRay(screenPoint), out hit)) { if (Map) { Vector3 worldPoint = Map.transform.InverseTransformPoint(hit.point); //~ Debug.Log(map.transform.InverseTransformPoint(hit.point))); Vector3 point = new Vector3(worldPoint.x * Map.transform.localScale.x, worldPoint.y * Map.transform.localScale.y, worldPoint.z * Map.transform.localScale.z); //~ Debug.Log(GameManager.Instance.xToLong(point.x)); //Vector3 pos = new Vector3(((worldPoint.x - 5.0f) * map.transform.localScale.x) * -1, worldPoint.y, ((worldPoint.z + 5.0f) * map.transform.localScale.z)); float a = GameManager.Instance.XMapModifier; float b = GameManager.Instance.YMapModifier; Vector3 pos2 = new Vector3(); //y = -225a-1 + a-1x //pos2.x = -1347.305389f + 5.988023952f * hit.point.x; pos2.x = -GameManager.Instance.XMapAddition * Mathf.Pow(a, -1) + Mathf.Pow(a, -1) * hit.point.x; pos2.z = -GameManager.Instance.YMapAddtion * Mathf.Pow(b, -1) + Mathf.Pow(b, -1) * hit.point.z; pos2.y = Map.transform.position.y; Coordinate coordPoint = CoordinateHelper.FromOrthoProjectedCoordinate(pos2.z, pos2.x); GameObject go = new GameObject("PositionMarker"); DetectionMarker marker = go.AddComponent <DetectionMarker>(); //marker.Position = new Vector3(pos2.z, 0, pos2.x); marker.Position = hit.point; marker.MinSize = new Vector2(8, 8); marker.MaxSize = new Vector2(128, 128); marker.KillTime = 1; marker.FadeTime = 0.5f; marker.MessageToDisplay = new Message("Movement", GameManager.MessageTypes.Game); //Debug.Log(pos2); //Vector3 pos = new Vector3(); //pos.x = ((float)_Info.Position.LongitudeOrthoProjected * 0.1671117f) + 225.0f; //pos.z = ((float)_Info.Position.LatitudeOrthoProjected * -0.1675854f) + 360.0f; //pos.y = 30002; //Debug.Log(hit.point); //Gizmos.DrawCube(hit.point, new Vector3(10, 10, 10)); //double lat = CoordinateHelper.YToLat(point.z); //double lng = CoordinateHelper.XToLong(point.x); //Debug.Log(string.Format("Lat:{0} , Long: {1}", lat, lng)); bool removeWaypoints = true; if (Input.GetKey(KeyCode.LeftShift)) { removeWaypoints = false; } GameObject gui = GameObject.Find("GUI"); InteractionWindow iw = gui.GetComponent <InteractionWindow>(); if (iw.AwaitingOrder) { iw.Move(coordPoint); } else { GameManager.Instance.OrderManager.Move(coordPoint.Latitude, coordPoint.Longitude, GameManager.Instance.UnitManager.SelectedGroupMainUnit.Info, removeWaypoints); } } } }