void Update() { time += Time.deltaTime; timeSinceLastPositionUpdate += Time.deltaTime; if (time > blinkingTime) { time = time - Mathf.Floor(time / blinkingTime) * blinkingTime; } if (timeSinceLastPositionUpdate > timeToFlush) { if (!geochar) { geochar = FindObjectOfType <GeoPositionedCharacter>(); } if (IsStarted() || geochar) { var latlon = IsStarted() ? Input.location.lastData.LatLon() : geochar.LatLon.ToVector2(); TrackerExtension.Movement.Geoposition("player", latlon); TrackerAsset.Instance.Flush(); timeSinceLastPositionUpdate = 0; Debug.Log(latlon); } } }
/// <summary> /// Finds the closest step based on the element position. Only returns not completed steps. /// </summary> /// <param name="steps">All the steps</param> /// <returns>Closest not completed step</returns> private NavigationStep FindClosestStep(List <NavigationStep> steps) { if (!character) { character = FindObjectOfType <GeoPositionedCharacter>(); } var latLon = new Vector2d(double.NegativeInfinity, double.NegativeInfinity); // Minus infinite, as the elements will be positioned at inifine if (character) // If there is a character { latLon = character.LatLon; // use the position of the character to calculate distance } else if (GeoExtension.Instance.IsLocationValid()) // If We have a location source we use it { latLon = Input.location.lastData.LatLonD(); } var notCompleted = steps .FindAll(e => !stepCompleted[e] && !double.IsNaN(GetElementPosition(e.Reference).x)); // Filter the completed if (notCompleted.Count > 0) { return(notCompleted.FindMin(s => GM.SeparationInMeters(GetElementPosition(s.Reference), latLon))); // Order the rest to distance } else { return(null); } }
private bool IsReached(NavigationStep currentStep) { if (!character) { character = FindObjectOfType <GeoPositionedCharacter>(); } var mb = GetReference(currentStep.Reference); if (mb == null) { return(false); // If the element is not there, just try to skip it } return(IsReached(mb)); }
private bool IsReached(NavigationStep currentStep) { if (!character) { character = FindObjectOfType <GeoPositionedCharacter>(); } var mb = GetReference(currentStep.Reference); if (mb == null) { return(false); // If the element is not there, just try to skip it } else if (mb is GeoWrapper) { var wrap = mb as GeoWrapper; var position = (Vector2d)wrap.Reference.TransformManagerParameters["Position"]; var interactionRange = (float)wrap.Reference.TransformManagerParameters["InteractionRange"]; var distance = GM.SeparationInMeters(position, character.LatLon); var realDistance = GM.SeparationInMeters(position, Input.location.lastData.LatLonD()); // Is inside if the character is in range but also the real coords are saying so // Otherwise, if there is no character or gps, only one of the checks is valid return((!character || distance < interactionRange) && (!GPSController.Instance.IsStarted() || realDistance < interactionRange) && (GPSController.Instance.IsStarted() || character)); } else if (mb is GeoElementMB) { var geomb = mb as GeoElementMB; // Is inside if the character is inside the influence but also the real coords are saying so // Otherwise, if there is no character or gps, only one of the checks is valid // TODO check if the line element is reached return((!character || geomb.Element.Geometry.InsideInfluence(character.LatLon)) && (!GPSController.Instance.IsStarted() || geomb.Element.Geometry.InsideInfluence(Input.location.lastData.LatLonD())) && (GPSController.Instance.IsStarted() || character)); } else { return(false); } }
void Update() { if (!gameIsReady) { return; } if (!Application.isEditor && !IsStarted()) { StartCoroutine(StartLocation()); } time += Time.deltaTime; timeSinceLastPositionUpdate += Time.deltaTime; if (time > blinkingTime) { time -= Mathf.Floor(time / blinkingTime) * blinkingTime; } if (Game.Instance.CurrentTargetRunner.Data is MapScene && !geochar) { geochar = FindObjectOfType <GeoPositionedCharacter>(); } if (timeSinceLastPositionUpdate > timeToFlush) { timeSinceLastPositionUpdate = 0; if (IsStarted() || UsingDebugLocation || geochar) { var mapScene = Game.Instance.CurrentTargetRunner.Data as MapScene; if (mapScene != null) { TrackerExtension.Movement.Moved(mapScene.Id, Location); } else { TrackerExtension.Movement.Moved("World", Location); } TrackerAsset.Instance.Flush(); } } }
void Update() { time += Time.deltaTime; timeSinceLastPositionUpdate += Time.deltaTime; if (time > blinkingTime) { time = time - Mathf.Floor(time / blinkingTime) * blinkingTime; } if (Game.Instance.CurrentTargetRunner.Data is MapScene && !geochar) { geochar = FindObjectOfType <GeoPositionedCharacter>(); } if (timeSinceLastPositionUpdate > timeToFlush) { timeSinceLastPositionUpdate = 0; if (IsStarted() || UsingDebugLocation || geochar) { var mapScene = Game.Instance.CurrentTargetRunner.Data as MapScene; Debug.Log(Location); if (mapScene != null) { TrackerExtension.Movement.Moved(mapScene.Id, Location); } else { TrackerExtension.Movement.Moved("World", Location); } TrackerAsset.Instance.Flush(); } } }
// Use this for initialization void Start() { UpdateConditions(); player = FindObjectOfType <GeoPositionedCharacter>(); geoActionManagers = new List <IGeoActionManager>(); foreach (var action in Element.Actions) { var newManager = GeoActionManagerFactory.Instance.CreateFor(action); newManager.Element = Element; newManager.Holder = this; geoActionManagers.Add(newManager); } var mesh = GetComponent <MeshFilter>().mesh; var selectedGeometry = Geometry; if (selectedGeometry != null && selectedGeometry.Points != null && selectedGeometry.Points.Length > 0) { switch (selectedGeometry.Type) { case GMLGeometry.GeometryType.Point: { var poi = GameObject.CreatePrimitive(PrimitiveType.Sphere); GetComponent <MeshFilter>().mesh = poi.GetComponent <MeshFilter>().mesh; GetComponent <MeshRenderer>().material = poiMat; DestroyImmediate(poi); var dotMerc = GM.LatLonToMeters(selectedGeometry.Points[0].x, selectedGeometry.Points[0].y); var localMercPos = dotMerc - Tile.Rect.Center; transform.localPosition = new Vector3((float)localMercPos.x, 1f, (float)localMercPos.y); transform.localScale = new Vector3(10, 10, 10); } break; case GMLGeometry.GeometryType.LineString: { // First we extend the line for it to have some width using clipper Path polygon = selectedGeometry.Points.ToList() .ConvertAll(p => GM.LatLonToMeters(p.x, p.y)) // To meters .ConvertAll(p => new IntPoint(p.x, p.y)); // To IntPoint type usable by clipper Paths solution = new Paths(); ClipperOffset c = new ClipperOffset(); c.AddPath(polygon, JoinType.jtSquare, EndType.etOpenSquare); c.Execute(ref solution, 5); // 5 meters var r = solution[0].ConvertAll(p => new Vector2d(p.X, p.Y)).ToArray(); // ConvertBack to Vector2d all the points (meters) // Then create the polygon that represents the path CreatePolygonMesh(r, ref mesh); GetComponent <MeshRenderer>().material = pathMat; } break; case GMLGeometry.GeometryType.Polygon: CreatePolygonMesh(selectedGeometry.Points.ToList().ConvertAll(p => GM.LatLonToMeters(p.x, p.y)).ToArray(), ref mesh); GetComponent <MeshRenderer>().material = polyMat; break; default: break; } inside = selectedGeometry.InsideInfluence(player.LatLon); } if (!string.IsNullOrEmpty(Element.getName())) { var tooltip = GameObject.Instantiate(Tooltip); tooltip.transform.SetParent(this.transform); tooltip.transform.localRotation = Quaternion.Euler(90, 0, 0); tooltip.transform.localScale = new Vector3(1 / transform.localScale.x, 1 / transform.localScale.y, 1 / transform.localScale.z); tooltip.transform.localPosition = Tooltip.transform.localPosition * (tooltip.transform.localScale.x / Tooltip.transform.localScale.x); tooltip.GetComponentInChildren <UnityEngine.UI.Text>().text = Element.getName(); } }
private bool IsReached(NavigationStep currentStep) { if (!character) { character = FindObjectOfType <GeoPositionedCharacter>(); } var mb = GetReference(currentStep.Reference); if (mb == null) { return(false); // If the element is not there, just try to skip it } else if (mb is GeoPositioner) { var wrap = mb as GeoPositioner; var position = (Vector2d)wrap.Context.TransformManagerParameters["Position"]; var interactionRange = (float)wrap.Context.TransformManagerParameters["InteractionRange"]; var distance = GM.SeparationInMeters(position, character.LatLon); var realDistance = GM.SeparationInMeters(position, GeoExtension.Instance.Location); // Is inside if the character is in range but also the real coords are saying so // Otherwise, if there is no character or gps, only one of the checks is valid return((!character || distance < interactionRange) && (!GeoExtension.Instance.IsStarted() || realDistance < interactionRange) && (GeoExtension.Instance.IsStarted() || character)); } else if (mb is GeoElementMB) { var geomb = mb as GeoElementMB; // Is inside if the character is inside the influence but also the real coords are saying so // Otherwise, if there is no character or gps, only one of the checks is valid var location = character ? character.LatLon : GeoExtension.Instance.Location; if (geomb.Geometry.InsideInfluence(location)) { if (geomb.Geometry.Type == GMLGeometry.GeometryType.LineString) { var step = 0; completedElementsForStep.TryGetValue(currentStep, out step); var position = geomb.Geometry.Points[step]; var distance = GM.SeparationInMeters(position, location); return(distance < geomb.Geometry.Influence); } else { return(true); } } else { return(false); } } else { return(false); } }