예제 #1
0
 private BountyData GenerateRandomBounty()
 {
     return(new BountyData
     {
         carData = new CarData
         {
             vehicleColor = ColorPercentage.PickColor(randomVehicleColorOptions).color,
             vehicleIndex = (uint)whiteListedVehicles[Random.Range(0, whiteListedVehicles.Length)].index,
             vehicleLicense = Carability.GetRandomLicense(),
         },
         reward = (uint)Random.Range(minBounty, maxBounty + 1),
         headingNorth = (Random.value * 2 - 1) >= 0,
         position = highway.target.position.z + Mathf.Sign(Random.value * 2 - 1) * Random.Range(GetMinDistance(), GetMaxDistance()),
         lane = Random.Range(0, carSpawner.halfRoadLaneCount)
     });
 }
예제 #2
0
    public static ColorPercentage PickColor(params ColorPercentage[] choices)
    {
        ColorPercentage choice = default;

        if (choices != null && choices.Length > 0)
        {
            choice = choices[0];
            if (choices.Length > 1)
            {
                float rng = Random.value;
                foreach (var possiblity in choices)
                {
                    if (possiblity.percent >= rng && possiblity.percent <= choice.percent)
                    {
                        choice = possiblity;
                    }
                }
            }
        }
        return(choice);
    }
예제 #3
0
    public BotDriver SpawnBot(bool spawnOnRight, int spawnIndex, bool setRandomSpeed = true, float speed = 0, CarData carData = null)
    {
        var roadPoints = rightRoadPoints;

        if (!spawnOnRight)
        {
            roadPoints = leftRoadPoints;
        }

        //Get vehicle speed relative to highway
        float vehicleToAdjustTrafficToHighwaySpeed = 0;

        if (driverToAdjustTrafficTo != null)
        {
            var vehicleToAdjustTrafficTo = driverToAdjustTrafficTo.GetVehicle();
            if (vehicleToAdjustTrafficTo != null)
            {
                float percentDirection = vehicleToAdjustTrafficTo.vehicleRigidbody.velocity.normalized.PercentDirection(Vector3.forward);
                vehicleToAdjustTrafficToHighwaySpeed = vehicleToAdjustTrafficTo.currentTotalSpeed * percentDirection;
            }
        }

        //Switch spawn side depending on vehicle speed relative to highway
        int offsetIndex = 0;

        if (vehicleToAdjustTrafficToHighwaySpeed > speedLimit - maxLimitDeviation && spawnOnRight)
        {
            offsetIndex = halfRoadLaneCount;
        }
        else if (vehicleToAdjustTrafficToHighwaySpeed < -speedLimit + maxLimitDeviation && !spawnOnRight)
        {
            offsetIndex = halfRoadLaneCount;
        }

        Transform spawnPoint = roadPoints[offsetIndex + spawnIndex];

        Transform[] targets = GetTargets(roadPoints, halfRoadLaneCount);

        if (setRandomSpeed)
        {
            speed = Random.Range(speedLimit - maxLimitDeviation, speedLimit + maxLimitDeviation);
        }

        currentSpawnedVehicleCount++;
        lastSpawn = Time.time;

        return(BotCars.Get <BotDriver>((bot) =>
        {
            Color vehicleColor;
            int vehicleIndex;

            if (carData != null)
            {
                vehicleIndex = (int)carData.vehicleIndex;
                bot.GetCarability().license = carData.vehicleLicense;
                vehicleColor = carData.vehicleColor;
            }
            else
            {
                vehicleIndex = whiteListedVehicles[Random.Range(0, whiteListedVehicles.Length)].index;
                bot.GetCarability().RandomizeLicense();
                vehicleColor = ColorPercentage.PickColor(randomVehicleColorOptions).color;
            }

            bot.Respawn(spawnPoint.position, spawnPoint.rotation, vehicleIndex, speed);

            var carAppearance = bot.GetCarAppearance();
            if (carAppearance != null)
            {
                carAppearance.showSiren = false;
                carAppearance.color = vehicleColor;
            }

            bot.GetVehicle().vehicleHealth.SetPercent(1);
            bot.GetCarHUD().showLicense = false;
            bot.GetCarHUD().showPointer = false;
            bot.targets = targets;
            bot.currentTargetIndex = spawnIndex;
            bot.onFall += Bot_onFall;
        }));
    }