private void touchedPos(Vector3 pos) { Vector3 mouseGeoLocation = OnlineMapsControlBase.instance.GetCoords(pos); // Get the geographical coordinates of the cursor. //Vector2 cursorCoords = map.control.GetCoords(); // Create a new marker at the specified coordinates. OnlineMapsControlBase3D control2 = GetComponent <OnlineMapsControlBase3D> (); if (m_bPin1Set == false) { OnlineMapsMarker3D marker = control2.AddMarker3D(mouseGeoLocation.x, mouseGeoLocation.y, m_PinPlane); //m_PinPlaneRed); // OnlineMapsMarker3D marker = control2.AddMarker3D (mouseGeoLocation, m_PinPlane); marker.scale = 18.0f; //30.0f;//18.0f; m_Pin1 = marker; m_Pin1Position = mouseGeoLocation; m_bPin1Set = true; } else if (m_bPin2Set == false) { OnlineMapsMarker3D marker = control2.AddMarker3D(mouseGeoLocation.x, mouseGeoLocation.y, m_PinPlane); //m_PinPlaneRed); // OnlineMapsMarker3D marker = control2.AddMarker3D (mouseGeoLocation, m_PinPlane); marker.scale = 18.0f; //30.0f;//18.0f; m_Pin2 = marker; m_Pin2Position = mouseGeoLocation; m_bPin2Set = true; } // OnlineMapsMarker marker = map.AddMarker(cursorCoords, m_PinPlane, "Marker " + (map.markers.Length + 1)); // Save marker and coordinates. // markerPositions.Add(mouseGeoLocation); // markers.Add(marker); // Mark that markers changed. changed = true; m_ButtonReset.SetActive(true); addLineToPin(); Debug.Log("Added marker at pos: " + mouseGeoLocation.x + " y: " + mouseGeoLocation.y); if (m_bPin1Set && m_bPin2Set) { m_ButtonNext.SetActive(true); } else { m_ButtonNext.SetActive(false); } m_ExplanationText.SetActive(false); m_ExplanationBack.SetActive(false); }
private void OnPinClick(GameObject go) { OnlineMapsControlBase3D control2 = GetComponent <OnlineMapsControlBase3D> (); if (m_bPin1Set) { if (m_Pin1.instance == go) { m_bPin1Set = false; } } if (m_bPin2Set) { if (m_Pin2.instance == go) { m_bPin2Set = false; } } api.RemoveAllMarkers(); api.RemoveAllDrawingElements(); if (control2 != null) { control2.RemoveAllMarker3D(); } if (m_bPin1Set) { OnlineMapsMarker3D marker = control2.AddMarker3D(m_Pin1Position.x, m_Pin1Position.y, m_PinPlane); //m_PinPlaneRed); //OnlineMapsMarker3D marker = control2.AddMarker3D (m_Pin1Position, m_PinPlane); marker.scale = 18.0f; //30.0f;//18.0f; m_Pin1 = marker; } if (m_bPin2Set) { OnlineMapsMarker3D marker = control2.AddMarker3D(m_Pin2Position.x, m_Pin2Position.y, m_PinPlane); //m_PinPlaneRed); //OnlineMapsMarker3D marker = control2.AddMarker3D (m_Pin2Position, m_PinPlane); marker.scale = 18.0f; //30.0f;//18.0f; m_Pin2 = marker; } addLineToPin(); if (m_bPin1Set == false && m_bPin2Set == false) { m_ButtonReset.SetActive(false); } if (m_bPin1Set && m_bPin2Set) { m_ButtonNext.SetActive(true); } else { m_ButtonNext.SetActive(false); } }
private void UpdateMarker() { if (_marker == null) { if (markerType == OnlineMapsLocationServiceMarkerType.twoD) { _marker = OnlineMaps.instance.AddMarker(position, marker2DTexture, markerTooltip); (_marker as OnlineMapsMarker).align = marker2DAlign; if (useCompassForMarker) { (_marker as OnlineMapsMarker).rotation = trueHeading / 360; } } else { OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance; if (control == null) { Debug.LogError("You must use the 3D control (Texture or Tileset)."); createMarkerInUserPosition = false; return; } _marker = control.AddMarker3D(position, marker3DPrefab); _marker.label = markerTooltip; if (useCompassForMarker) { (_marker as OnlineMapsMarker3D).rotationY = trueHeading; } } } else { _marker.position = position; } }
private void Start() { // Gets the current 3D control. OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance; if (control == null) { Debug.LogError("You must use the 3D control (Texture or Tileset)."); return; } //Create a marker to show the current GPS coordinates. //Instead of "null", you can specify the texture desired marker. locationMarker = control.AddMarker3D(Vector2.zero, prefab); //Hide handle until the coordinates are not received. locationMarker.enabled = false; // Gets Location Service Component. OnlineMapsLocationService ls = OnlineMapsLocationService.instance; if (ls == null) { Debug.LogError( "Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service)."); return; } //Subscribe to the GPS coordinates change ls.OnLocationChanged += OnLocationChanged; ls.OnCompassChanged += OnCompassChanged; //Subscribe to zoom change OnlineMaps.instance.OnChangeZoom += OnChangeZoom; }
/// <summary> /// The event, which is called when the user clicked on the map. /// </summary> private void OnMapClick() { OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance; // Create new marker OnlineMapsMarker3D marker = control.AddMarker3D(control.GetCoords(), markerPrefab); marker.scale = markerScale; }
private void Start() { // Get instance of OnlineMapsControlBase3D (Texture or Tileset) OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance; if (control == null) { Debug.LogError("You must use the 3D control (Texture or Tileset)."); return; } // Marker position. Geographic coordinates. Vector2 markerPosition = new Vector2(0, 0); // Create 3D marker marker3D = control.AddMarker3D(markerPosition, markerPrefab); // Specifies that marker should be shown only when zoom from 1 to 10. marker3D.range = new OnlineMapsRange(1, 10); }
protected void DrawMarkersGUI(ref bool dirty) { if (control.markers3D == null) { control.markers3D = new OnlineMapsMarker3D[0]; dirty = true; } EditorGUILayout.BeginVertical(GUI.skin.box); showMarkers = OnlineMapsEditor.Foldout(showMarkers, "3D markers"); if (showMarkers) { EditorGUI.BeginChangeCheck(); control.marker3DScale = EditorGUILayout.FloatField("Marker3D Scale: ", control.marker3DScale); control.allowDefaultMarkerEvents = EditorGUILayout.Toggle("Allow Default Marker Events: ", control.allowDefaultMarkerEvents); if (EditorGUI.EndChangeCheck()) { dirty = true; } int index = 1; bool hasDeleted = false; OnlineMaps map = control.GetComponent <OnlineMaps>(); for (int i = 0; i < control.markers3D.Length; i++) { DrawMarkerGUI(i, ref index, ref hasDeleted, map, ref dirty); } if (hasDeleted) { List <OnlineMapsMarker3D> markers = control.markers3D.ToList(); markers.RemoveAll(m => m == null); control.markers3D = markers.ToArray(); if (Application.isPlaying) { OnlineMaps.instance.Redraw(); } dirty = true; } EditorGUILayout.Space(); if (GUILayout.Button("Add marker")) { if (!Application.isPlaying) { OnlineMapsMarker3D marker = new OnlineMapsMarker3D { position = control.GetComponent <OnlineMaps>().position, scale = control.marker3DScale }; List <OnlineMapsMarker3D> markers = new List <OnlineMapsMarker3D>(control.markers3D) { marker }; control.markers3D = markers.ToArray(); } else { GameObject prefab = GameObject.CreatePrimitive(PrimitiveType.Cube); control.AddMarker3D(OnlineMaps.instance.position, prefab); DestroyImmediate(prefab); } EditorUtility.SetDirty(control); } } EditorGUILayout.EndVertical(); }
protected void DrawMarkersGUI(ref bool dirty) { EditorGUILayout.BeginVertical(GUI.skin.box); showMarkers = OnlineMapsEditor.Foldout(showMarkers, string.Format("3D markers (Count: {0})", pMarkers3D.arraySize)); if (showMarkers) { EditorGUILayout.PropertyField(pDefault3DMarker); EditorGUILayout.PropertyField(pMarker3DScale); EditorGUILayout.PropertyField(pAllowDefaultMarkerEvents); int removedIndex = -1; EditorGUI.BeginChangeCheck(); for (int i = 0; i < pMarkers3D.arraySize; i++) { EditorGUILayout.BeginVertical(GUI.skin.box); OnlineMapsMarker3DPropertyDrawer.isRemoved = false; OnlineMapsMarker3DPropertyDrawer.isEnabledChanged = null; EditorGUILayout.PropertyField(pMarkers3D.GetArrayElementAtIndex(i), new GUIContent("Marker " + (i + 1))); if (OnlineMapsMarker3DPropertyDrawer.isRemoved) { removedIndex = i; } if (OnlineMapsMarker3DPropertyDrawer.isEnabledChanged.HasValue) { control.markers3D[i].enabled = OnlineMapsMarker3DPropertyDrawer.isEnabledChanged.Value; } EditorGUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { dirty = true; } if (removedIndex != -1) { ArrayUtility.RemoveAt(ref control.markers3D, removedIndex); dirty = true; } EditorGUILayout.Space(); if (GUILayout.Button("Add Marker")) { if (!Application.isPlaying) { OnlineMapsMarker3D marker = new OnlineMapsMarker3D { position = control.GetComponent <OnlineMaps>().position, scale = pMarker3DScale.floatValue }; ArrayUtility.Add(ref control.markers3D, marker); } else { GameObject prefab = GameObject.CreatePrimitive(PrimitiveType.Cube); control.AddMarker3D(OnlineMaps.instance.position, prefab); OnlineMapsUtils.DestroyImmediate(prefab); } dirty = true; } } EditorGUILayout.EndVertical(); }
private void Update() { try { if (update) { //UnityEngine.Debug.Log("Test"); loc = locService.lastData; latitude = loc.latitude; longtitude = loc.longitude; BitConverter.GetBytes(latitude).CopyTo(coords, 0); BitConverter.GetBytes(longtitude).CopyTo(coords, 4); client.Send(coords); if (responseTime.IsRunning) { responseTime.Reset(); } else { responseTime.Start(); } update = false; } if (!waitUpdate.WaitOne(0)) { UnityEngine.Debug.Log(SceneManager.GetActiveScene().name); //place objects on screen or update position if guid already present, store respective guid with object for later use //objects stored in list nearbyObjects which is a list of NearbyObjects that contain lat, long, object type, and id //note: should check which scene is active before drawing, should be able to do that with scenemanager.getactivescene if (SceneManager.GetActiveScene().name.Equals("Overworld")) { //UnityEngine.Debug.Log("there are: " + nearbyObjects.Count); landmarks = new List <OnlineMapsMarker3D>(); colosseums = new List <OnlineMapsMarker3D>(); enemyList = new Dictionary <string, NearbyObject>(); enemyRadar.options.Clear(); enemyRadar.options.Add(new Dropdown.OptionData("(Select)")); //enemyRadar.options.Add(new Dropdown.OptionData("Test")); foreach (NearbyObject nearbyObject in nearbyObjects) { OnlineMapsMarker3D newMarker = new OnlineMapsMarker3D(); Console.WriteLine(nearbyObject.Name); newMarker.id = nearbyObject.Id; newMarker.lat = nearbyObject.Latitude; newMarker.lon = nearbyObject.Longtitude; //UnityEngine.Debug.Log("???????????" + nearbyObject.Type); switch (nearbyObject.Type) { case 0: //UnityEngine.Debug.Log("found someone at least"); //newMarker.prefab = (GameObject)Instantiate(Resources.Load("EnemyPlayer")); if (nearbyObject.Id != Player.playerID) { //UnityEngine.Debug.Log("enemy id found"); enemyList.Add(nearbyObject.Name, nearbyObject); } break; case 1: newMarker.prefab = coloPrefab; newMarker.prefab.GetComponent <ColosseumFaction>().coloseumID = newMarker.id; newMarker.prefab.GetComponent <ColosseumFaction>().UpdateFaction(); colosseums.Add(newMarker); landmarks.Add(newMarker); break; case 2: newMarker.prefab = landPrefab; landmarks.Add(newMarker); break; default: break; } } } // Add the enemies to the dropdown menu foreach (KeyValuePair <string, NearbyObject> enemy in enemyList) { UnityEngine.Debug.Log("should be adding enemy id"); enemyRadar.options.Add(new Dropdown.OptionData(enemy.Value.Name.ToString())); } foreach (OnlineMapsMarker3D marker in landmarks) { locationMarker = marker; Vector2 locale = new Vector2((float)marker.lat, (float)marker.lon); locationMarker = control.AddMarker3D(locale, locationMarker.prefab); } waitUpdate.Set(); } } catch (Exception e) { UnityEngine.Debug.Log(e.ToString()); waitUpdate.Set(); } if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); //Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider.CompareTag("Landmark")) { Land.enabled = true; GenComManager.setUpdate(4, Player.playerID); } else if (hit.collider.CompareTag("Colosseum")) { Colosseum.enabled = true; } } } }
// Use this for initialization void Start() { if (!started) { started = true; UnityEngine.Debug.Log(Player.playerID); try { locService = Input.location; if (locService.status == LocationServiceStatus.Stopped) { if (!locService.isEnabledByUser) { //display some sort of error message telling user location services must be enabled } locService.Start(); //isnt working so remove location startup stuff so dont have to wait //MAKE SURE YOU CHANGE BACK LATER (SHOULD BE 30) int timeout = 30; //potentially display some sort of loading screen while waiting for location services, etc. while (Input.location.status == LocationServiceStatus.Initializing && timeout > 0) { Thread.Sleep(1000); timeout--; } if (timeout < 1 || Input.location.status == LocationServiceStatus.Failed) { //display some sort of error message, failed to start location services } } //DontDestroyOnLoad(gameObject); coords = new byte[UPDATE_SIZE]; size = new byte[4]; //remote endpoint of the server IPEndPoint remoteEP = new IPEndPoint(IP, OVERWORLD_PORT); //create TCP socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //connect to remote endpoint client.Connect(remoteEP); UnityEngine.Debug.Log("Connect Overworld Successful"); //send the players id to the server client.Send(Player.playerID.ToByteArray()); //upNearbyObj = false; waitUpdate = new ManualResetEvent(false); rand = new System.Random(); UnityEngine.Debug.Log("Connect Successful"); t = new Timer(setUpdate, null, 0, 12000); //start receiving updates from server client.BeginReceive(size, 0, 4, 0, new AsyncCallback(updateDriver), null); // Gets the current 3D control. control = OnlineMapsControlBase3D.instance; if (control == null) { UnityEngine.Debug.LogError("You must use the 3D control (Texture or Tileset)."); return; } //Create a marker to show the current GPS coordinates. //Instead of "null", you can specify the texture desired marker. locationMarker = control.AddMarker3D(Vector2.zero, prefab); //Hide handle until the coordinates are not received. locationMarker.enabled = true; // Gets Location Service Component. OnlineMapsLocationService ls = OnlineMapsLocationService.instance; if (ls == null) { UnityEngine.Debug.LogError( "Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service)."); return; } //Subscribe to the GPS coordinates change ls.OnLocationChanged += OnLocationChanged; ls.OnCompassChanged += OnCompassChanged; } //catch exception if fail to connect catch (Exception e) { UnityEngine.Debug.Log(e.ToString()); UnityEngine.Debug.Log("Connection Failure"); } } }