private void HandleDetectedUnitInfo(IMarshallable dataReceived) { //~ string selectedId = string.Empty; DetectedUnitInfo det = dataReceived as DetectedUnitInfo; GameManager.Instance.MessageManager.AddMessage(dataReceived.ToString(), GameManager.MessageTypes.Detection, det.Position); //Debug.Log(dataReceived.ToString()); if (det != null) { Enemy unit = null; GameObject go = null; try { unit = GameManager.Instance.UnitManager.FindEnemyById(det.Id); go = unit != null ? unit.gameObject : null; } catch (NullReferenceException ex) { Debug.Log(ex.Message); } if (go == null) { string UnitModelFileName = "unknownSurface"; switch (det.DetectionClassification) { case GameConstants.DetectionClassification.FixedWingAircraft: UnitModelFileName = "unknownFixedWing"; break; case GameConstants.DetectionClassification.Helicopter: UnitModelFileName = "unknownHeli"; break; case GameConstants.DetectionClassification.Mine: break; case GameConstants.DetectionClassification.Missile: break; case GameConstants.DetectionClassification.Submarine: UnitModelFileName = "unknownSubmarine"; break; case GameConstants.DetectionClassification.Surface: UnitModelFileName = "unknownSurface"; break; case GameConstants.DetectionClassification.Torpedo: break; case GameConstants.DetectionClassification.Unknown: break; default: break; } if (!string.IsNullOrEmpty(det.RefersToUnitClassId)) { UnitModelFileName = GameManager.Instance.GetUnitClass(det.RefersToUnitClassId).UnitModelFileName; } go = GetVesselByUnitClassId(UnitModelFileName, det.Position); go.name = det.RefersToUnitName; unit = go.AddComponent <Enemy>(); unit.Size = new Vector2(32, 32); Vector3 pos = new Vector3(); pos.x = ((float)det.Position.LongitudeOrthoProjected * GameManager.Instance.XMapModifier) + GameManager.Instance.XMapAddition; pos.z = ((float)det.Position.LatitudeOrthoProjected * GameManager.Instance.YMapModifier) + GameManager.Instance.YMapAddtion; pos.y = 30000; go.transform.parent = GameObject.Find("EnemyUnits").transform; if (det.DomainType != GameConstants.DomainType.Air) { go.transform.localScale = GameManager.Instance.GlobalScale; GameObject healthBar = Instantiate(HealthBar, Vector3.zero, Quaternion.identity) as GameObject; healthBar.transform.parent = go.transform; healthBar.transform.localPosition = Vector3.up * 10; } GameObject detGo = new GameObject("Detection"); DetectionMarker marker = detGo.AddComponent <DetectionMarker>(); marker.Position = pos; marker.MinSize = new Vector2(8, 8); marker.MaxSize = new Vector2(128, 128); marker.KillTime = 3; marker.FadeTime = 1.5f; marker.MessageToDisplay = new Message("Detection", GameManager.MessageTypes.Detection); } //~ MapEnemy mu = AddMapEnemy(unit, GameManager.Instance.GetTextureByUnitClassId("enemyDetection")); unit.Info = det; GameManager.Instance.UnitManager.AddEnemy(unit); } }
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); } } } }