Beispiel #1
0
    public void addVehicle(Setup.VehicleSetup vehicleSetup)
    {
        setup.vehicles.Add(vehicleSetup);
        setup.vehicles.Sort((v1, v2) => Mathf.RoundToInt((v1.time - v2.time) * 100));

        if (placeVehicles == null)
        {
            restart();
        }
    }
Beispiel #2
0
    public IEnumerator placeOutVehicles()
    {
        yield return(null);

        while (setup.vehicles.Count > 0 && setup.vehicles [0].time == -1)
        {
            Setup.VehicleSetup vehicle = setup.vehicles [0];
            Game.instance.createNewCar(vehicle);
            setup.vehicles.RemoveAt(0);
        }
        while (setup.vehicles.Count > 0)
        {
            Setup.VehicleSetup vehicle = setup.vehicles [0];
            float inTime = vehicle.time - GameTimer.elapsedTime();
            yield return(new WaitForSeconds(inTime));

            Game.instance.createNewCar(vehicle);
            setup.vehicles.RemoveAt(0);
        }
        placeVehicles = null;
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        Setup.VehicleSetup data = GetComponent <Vehicle> ().characteristics;
        if (data != null)
        {
//			name = data.name;
//			brand = brand != null ? brand : data.brand;

            if (data.model != null)
            {
                model = data.model;
            }
            else
            {
                model = ModelGeneratorVehicles.generate(brand);
            }
            if (data.year != 0)
            {
                year = data.year;
            }
            else
            {
                year = DateTime.Now.Year - Misc.randomRange(0, 10);
            }
            numberOfPassengers = data.passengerIds.Count;

            // Set color
            GameObject   materialGameObject = transform.Find(materialGameObjectName).gameObject;
            MeshRenderer meshRenderer       = materialGameObject.GetComponent <MeshRenderer> ();

            Material mainColorMaterial = getMainColorMaterial(meshRenderer.materials);
            if (mainColorMaterial != null)
            {
                if (data.color != null)
                {
                    Color color = Misc.parseColor(data.color);
                    // Parse and set this color from data
                    mainColorMaterial.SetColor("_Color", color);
                }
                else
                {
                    // Try to get color to use from level setup - if not specified, will use default color
                    string colorForBrand = Game.instance.loadedLevel.vehicleColors.getRandomColorForBrand(brand);
                    if (colorForBrand != null)
                    {
                        Color color = Misc.parseColor(colorForBrand);
                        mainColorMaterial.SetColor("_Color", color);
                    }
                }
            }
        }
        else
        {
            model = ModelGeneratorVehicles.generate(brand);
            year  = DateTime.Now.Year - Misc.randomRange(0, 10);

            // Parse and set this color from data
            GameObject   materialGameObject = transform.Find(materialGameObjectName).gameObject;
            MeshRenderer meshRenderer       = materialGameObject.GetComponent <MeshRenderer> ();

            Material mainColorMaterial = getMainColorMaterial(meshRenderer.materials);
            if (mainColorMaterial != null)
            {
                // Try to get color to use from level setup - if not specified, will use default color
                string colorForBrand = Game.instance.loadedLevel.vehicleColors.getRandomColorForBrand(brand);
                if (colorForBrand != null)
                {
                    Color color = Misc.parseColor(colorForBrand);
                    mainColorMaterial.SetColor("_Color", color);
                }
            }
        }
    }