Пример #1
0
    /// <summary>
    /// Begin path finding to a new location.
    /// </summary>
    /// <param name="newLocation">The location to move to.</param>
    internal void MoveToNewLocation(LocationSubject newLocation)
    {
        if (newLocation == null)
        {
            Debug.Log("AnimalObjectScript::MoveToNewLocation() \n    Error: null location");
            return;
        }

        if (destination != null)
        {
            if (destination.SubjectID == newLocation.SubjectID)
            {
                return;
            }
        }
        // remove chase target if we're moving to a location
        chaseTarget = null;
        destination = newLocation;
        isCurrentLocationExplored = false;
        // queue up the waypoints for the new location

        // flip a coin on which method of area waypoints to use
        if (UnityEngine.Random.Range(0.0f, 1.0f) > 0.5f)
        {
            destinationWayPoints = newLocation.GetAreaWaypoints(npcCharacter.SightRangeNear);
            if (destinationWayPoints.Length > 1)
            {
                destinationWayPoints = ShiftToNearestFirst(destinationWayPoints);
            }
        }
        else
        {
            destinationWayPoints = newLocation.GetAreaWaypoints(npcCharacter.SightRangeNear, 1);
            if (destinationWayPoints.Length > 1)
            {
                destinationWayPoints = destinationWayPoints
                                       .OrderBy(o => Vector3.Distance(transform.position, o))
                                       .ToArray();
            }
        }
        // debugging- show generated waypoints in editor interface
        for (int i = 0; i < destinationWayPoints.Length; i++)
        {
            Color waypointColor = Color.red;
            if (subject.SubjectID == DbIds.Plinkett)
            {
                waypointColor = Color.blue;
            }
            if (subject.SubjectID == DbIds.Gobber)
            {
                waypointColor = Color.yellow;
            }
            Vector3 wayPtTop =
                new Vector3(destinationWayPoints[i].x,
                            0.25f + ((float)i / destinationWayPoints.Length) * 0.5f,
                            destinationWayPoints[i].z);
            Debug.DrawLine(destinationWayPoints[i], wayPtTop, waypointColor, 10.0f);
        }
        currentWaypointIndex = 0;
    }
    public void TestSet2()
    {
        // testing location waypoint generation
        float                testLocationRadius = 6.0f;
        float                testSightRadius    = 2.0f;
        Vector3              loc1Offset         = new Vector3(-testLocationRadius - (2 * testSightRadius), 0, 0);
        Vector3              loc2Offset         = new Vector3(0, 0, -testLocationRadius - (2 * testSightRadius));
        GameObject           loc1      = T_PlaceLocation(loc1Offset, testLocationRadius);
        LocationObjectScript locScript = loc1.GetComponent <LocationObjectScript>();
        LocationSubject      locSub    = locScript.Subject as LocationSubject;

        Vector3[] locs = locSub.GetAreaWaypoints(testSightRadius, 1);
        if (locs.Length > 0)
        {
            for (int i = 0; i <= locs.Length - 1; i++)
            {
                //Debug.Log(i + " : " + locs[i].x + "," + locs[i].y + "," + locs[i].z + "\n");
                T_PlaceLocation(locs[i], testSightRadius);
            }
        }
        else
        {
            Debug.Log("  -- loc1 !  -- No waypoints generated.");
        }

        GameObject           loc2       = T_PlaceLocation(loc2Offset, testLocationRadius);
        LocationObjectScript loc2Script = loc2.GetComponent <LocationObjectScript>();
        LocationSubject      loc2Sub    = loc2Script.Subject as LocationSubject;

        Vector3[] locs2 = loc2Sub.GetAreaWaypoints(testSightRadius);
        if (locs2.Length > 0)
        {
            for (int i = 0; i <= locs2.Length - 1; i++)
            {
                //Debug.Log(i + " : " + locs[i].x + "," + locs[i].y + "," + locs[i].z + "\n");
                T_PlaceLocation(locs2[i], testSightRadius);
            }
        }
        else
        {
            Debug.Log(" -- loc2 !  -- No waypoints generated.");
        }
    }