Esempio n. 1
0
        public RoadSystem(LevelGeneratorParameters parameters, ForestBase forest)
        {
            instance = this;

            this.forest = forest;

            character         = parameters.character;
            roadPrefab        = parameters.roadPrefab;
            carPrefab         = parameters.carPrefab;
            inversCarRotation = carPrefab.transform.rotation * Quaternion.AngleAxis(180, Vector3.up);

            Road.character = character;

            roadOffsetByY = parameters.roadOffsetByY;

            roadsRenderingNow      = new Queue <Road>(roadsCount);
            roadsAwaitingRendering = new Queue <Road>(maxLogicRoadsCount);

            var  meshFilter = roadPrefab.GetComponent <MeshFilter>();
            Mesh mesh       = meshFilter.mesh;
            //Debug.Log(mesh.bounds);
            Bounds bounds = mesh.bounds;

            bounds.extents = new Vector3(1000000, 0, 5);
            mesh.bounds    = bounds;


            unusedRoads = new Queue <RoadObject>(roadsCount);
            for (int i = 0; i < roadsCount; i++)
            {
                var gameObject = GameObject.Instantiate(roadPrefab, Vector3.zero, Quaternion.identity);
                gameObject.SetActive(true);
                var renderer = gameObject.GetComponent <Renderer>();
                renderer.enabled = true;
                unusedRoads.Enqueue(new RoadObject(gameObject.transform, renderer));
            }
            usedRoads = new Queue <RoadObject>(roadsCount);

            int carsCount = 8;

            unusedCars = new Queue <Road.Car>(carsCount);
            for (int i = 0; i < carsCount; i++)
            {
                unusedCars.Enqueue(new Road.Car(GameObject.Instantiate(
                                                    carPrefab, Vector3.zero, carPrefab.transform.rotation).GetComponent <Rigidbody>()));
            }
        }
Esempio n. 2
0
        public ForestBase(LevelGeneratorParameters parameters)
        {
            instance = this;

            character       = parameters.character;
            characterCamera = parameters.characterCamera;
            treePrefab      = parameters.treePrefab;

            treeRadius   = parameters.treeRadius;
            halfFOV      = parameters.halfFOV;
            treesSpacing = parameters.treesSpacing;

            gradients = new Vector3[16];
            Vector3 upAxis = Vector3.Cross(groundForward, Vector3.right);

            for (int i = 0; i < gradients.Length; i++)
            {
                gradients[i] = Quaternion.AngleAxis(i * 360 / gradients.Length, upAxis) * groundForward;
            }

            scalePresets = new Vector3[4]
            {
                1.0f * Vector3.one,
                0.8f * Vector3.one,
                1.2f * Vector3.one,
                1.4f * Vector3.one
            };
            spacingDependencyByScale = new float[4]
            {
                1.1f, 1.0f, 0.90f, 0.80f
            };

            rotationPresets = new Quaternion[8];
            for (int i = 0; i < rotationPresets.Length; i++)
            {
                rotationPresets[i] = Quaternion.AngleAxis(i * 360 / rotationPresets.Length, Vector3.up);
            }
        }
Esempio n. 3
0
 public StaticRoadSystem(LevelGeneratorParameters parameters, ForestBase forest) : base(parameters, forest)
 {
 }