示例#1
0
    private void OnDrawGizmos()
    {
        if (!enabled)
        {
            return;
        }
        if (waypoints != null)
        {
            if (track == null)
            {
                _track = GetComponentInParent <TrackGeometry>();
            }

            Gizmos.color = Color.red;
            for (int i = 0; i < waypoints.Count; i++)
            {
                var wp1 = Position(Waypoint(i));
                var wp2 = Position(Next(Waypoint(i)));

                Gizmos.DrawLine(
                    wp1,
                    wp2);

                Gizmos.DrawWireSphere(
                    wp1,
                    0.5f);
            }
        }
    }
示例#2
0
 private void Awake()
 {
     if (_track == null)
     {
         _track = GetComponentInParent <TrackGeometry>();
     }
     cache = new PathCache(this, 0.5f);
 }
示例#3
0
    private void FindTangent(TrackGeometry component, TrackWaypoint waypoint)
    {
        var next     = component.Next(waypoint);
        var previous = component.Previous(waypoint);

        var normal0 = next.position - waypoint.position;
        var normal1 = waypoint.position - previous.position;

        var tangent0 = Vector3.Cross(normal0, waypoint.up).normalized;
        var tangent1 = Vector3.Cross(normal1, waypoint.up).normalized;

        var tangent = Vector3.Lerp(tangent0, tangent1, 0.5f).normalized;

        waypoint.tangent = tangent;
    }
示例#4
0
    public virtual void Initialise()
    {
        _track = GetComponentInParent <TrackGeometry>();

        var numWaypoints   = Mathf.CeilToInt(track.totalLength / Resolution);
        var trueResolution = track.totalLength / numWaypoints;

        waypoints.Clear();
        for (int i = 0; i < numWaypoints; i++)
        {
            waypoints.Add(new DerivedWaypoint()
            {
                x = i * trueResolution,
                w = 0f
            });
        }

        Recompute();
    }
示例#5
0
    private void FindWidth(TrackGeometry component, TrackWaypoint waypoint)
    {
        RaycastHit raycast;

        if (Physics.Raycast(new Ray(waypoint.position + waypoint.up * 0.001f, -waypoint.tangent), out raycast))
        {
            if (raycast.distance < 100f)
            {
                waypoint.left = raycast.point;
            }
        }
        if (Physics.Raycast(new Ray(waypoint.position + waypoint.up * 0.001f, waypoint.tangent), out raycast))
        {
            if (raycast.distance < 100f)
            {
                waypoint.right = raycast.point;
            }
        }
    }
示例#6
0
    private void FindHeight(TrackGeometry component, TrackWaypoint waypoint)
    {
        RaycastHit raycast;

        if (Physics.Raycast(new Ray(waypoint.position, Vector3.down), out raycast))
        {
            if (raycast.distance < 100f)
            {
                waypoint.left = raycast.point;
            }
        }
        if (Physics.Raycast(new Ray(waypoint.position, Vector3.down), out raycast))
        {
            if (raycast.distance < 100f)
            {
                waypoint.right = raycast.point;
            }
        }
    }
示例#7
0
    public static void SetStartWaypoint(TrackGeometry geometry, TrackWaypoint waypoint)
    {
        var index = geometry.waypoints.IndexOf(waypoint);

        // get distance through which we are moving the start

        var offset = geometry.totalLength - geometry.waypoints[index].Distance;

        // first cycle the waypoints. distances are defined by position, so we don't need to change the distances, just the order,
        // then recompute

        Undo.RecordObject(geometry, "Set Starting Line");

        {
            var toMove = geometry.waypoints.GetRange(0, index);
            geometry.waypoints.RemoveRange(0, index);
            geometry.waypoints.AddRange(toMove);
            geometry.Recompute();
        }

        foreach (var item in geometry.gameObject.GetComponentsInChildren <DerivedPath>())
        {
            Undo.RecordObject(item, "Set Starting Line");
            foreach (var wp in item.waypoints)
            {
                wp.x = Mathf.Repeat(wp.x + offset, geometry.totalLength);
            }

            int smallest = 0;
            for (int i = 0; i < item.waypoints.Count; i++)
            {
                if (item.waypoints[i].x < item.waypoints[smallest].x)
                {
                    smallest = i;
                }
            }
            var toMove = item.waypoints.GetRange(0, smallest);
            item.waypoints.RemoveRange(0, smallest);
            item.waypoints.AddRange(toMove);
            item.Recompute();
        }
    }
示例#8
0
    static void DrawGizmoForWaypointsEditor(TrackGeometry component, GizmoType gizmoType)
    {
        Profiler.BeginSample("Draw Waypoints Editor");

        foreach (var waypoint in component.waypoints)
        {
            var size = 1f;
            if (waypoint.index == 0)
            {
                size = 2f;
            }

            Gizmos.color = Color.green;

            if (waypoint.nospawn)
            {
                Gizmos.color = new Color(1f, 0.8f, 1f, 1);
            }
            if (waypoint.jump)
            {
                Gizmos.color = new Color(0.5f, 0.5f, 1f, 1);
            }

            Gizmos.DrawWireSphere(waypoint.position, size);
        }

        Gizmos.color = Color.yellow;
        foreach (var waypoint in component.highlighted)
        {
            Gizmos.DrawWireSphere(waypoint.position, 1f);
        }

        Gizmos.color = Color.red;
        foreach (var waypoint in component.selected)
        {
            Gizmos.DrawWireSphere(waypoint.position, 1f);
        }

        Gizmos.color = Color.green;
        for (int i = 0; i < component.waypoints.Count; i++)
        {
            var waypoint = component.waypoints[i];
            var next     = component.Next(waypoint);

            Gizmos.DrawLine(waypoint.position, next.position);
            Gizmos.DrawLine(waypoint.left, waypoint.right);

            Gizmos.DrawLine(waypoint.left, next.left);
            Gizmos.DrawLine(waypoint.right, next.right);
        }

        if (createWaypoints)
        {
            Gizmos.color = Color.yellow;
            if (component.highlightedPoint != null && component.lastSelected != null)
            {
                Gizmos.DrawLine(component.lastSelected.position, component.highlightedPoint.Value);
                Gizmos.DrawLine(component.lastSelected.position, component.Next(component.lastSelected).position);
            }
        }

        Profiler.EndSample();

        if (component.broadphase1d == null)
        {
            component.InitialiseBroadphase();
        }
        //component.broadphase.OnDrawGizmos();
    }