private void OnEnable() { m_transportApi = Api.Instance.TransportApi; m_spacesApi = Api.Instance.SpacesApi; m_currentInputSampleIndex = 0; m_time = 0.0; m_prevSampleTime = 0.0; m_currentSampleTime = 0.0; m_nextSampleTime = SamplePeriod; m_needCurrentMatched = false; m_needPathfind = false; m_capsule = CreateCapsule(Color.yellow, 4.0f); m_capsule.SetActive(false); m_prevPointOnGraph = TransportPositionerPointOnGraph.MakeEmpty(); m_currentPointOnGraph = TransportPositionerPointOnGraph.MakeEmpty(); m_pathfindResult = null; m_transportPositioner = m_transportApi.CreatePositioner(new TransportPositionerOptionsBuilder() .SetInputCoordinates(m_inputSamples[0].LatitudeDegrees, m_inputSamples[0].LongitudeDegrees) .Build()); m_transportPositioner.OnPointOnGraphChanged += OnPointOnGraphChanged; SetInputSample(); }
private void OnPointOnGraphChanged() { if (m_needCurrentMatched && m_transportPositioner.IsMatched()) { m_prevSampleTime = m_currentSampleTime; m_currentSampleTime = m_nextSampleTime; m_prevPointOnGraph = new TransportPositionerPointOnGraph(m_currentPointOnGraph); m_currentPointOnGraph = m_transportPositioner.GetPointOnGraph(); m_needCurrentMatched = false; } if (m_needPathfind && m_currentPointOnGraph.IsMatched && m_prevPointOnGraph.IsMatched) { var pathfindResult = m_transportApi.FindShortestPath(new TransportPathfindOptionsBuilder() .SetPointOnGraphA(m_prevPointOnGraph) .SetPointOnGraphB(m_currentPointOnGraph) .Build()); if (pathfindResult.IsPathFound) { m_needPathfind = false; m_pathfindResult = pathfindResult; } } }
private void OnDisable() { GameObject.Destroy(m_capsule); m_transportPositioner.OnPointOnGraphChanged -= OnPointOnGraphChanged; m_transportPositioner.Discard(); m_transportPositioner = null; m_prevPointOnGraph = null; m_currentPointOnGraph = null; m_pathfindResult = null; }
/// <summary> /// Set the goal point from the given TransportPositionerPointOnGraph object. /// </summary> /// <param name="pointOnGraph">A TransportPositionerPointOnGraph object, for example as supplied by TransportPositioner.GetPointOnGraph()</param> /// <returns>This object, with the goal point set.</returns> public TransportPathfindOptionsBuilder SetPointOnGraphB(TransportPositionerPointOnGraph pointOnGraph) { if (pointOnGraph.IsMatched) { m_directedEdgeIdB = pointOnGraph.DirectedEdgeId; m_parameterizedPointOnEdgeB = pointOnGraph.GetParameterOnDirectedEdge(); m_isPointBSet = true; } else { m_directedEdgeIdB = new TransportDirectedEdgeId(); m_parameterizedPointOnEdgeB = 0.0; m_isPointBSet = false; } return(this); }