コード例 #1
0
        private Vector3 _rightMostPoint;         //The most right point on the road

        public PointFrame(FXRoad road, float t)
        {
            t      = t;
            Points = new Vector3[road.numOfHorizontalPointsInRoad];
            if (Points.Length < 2)             //check
            {
                return;
            }
            //Creating points

            _center   = road.fx.Pos(t);
            _dir      = road.fx.Dir(t);
            _rightVec = road.fx.Right(t);
            _norm     = road.fx.Norm(t);
            _ang      = road.fx.Ang(t);

            _rightMostPoint     = _center + _rightVec * (road.roadWidth / 2);              //The most right point on the road
            _widthBetweenPoints = road.roadWidth / (road.numOfHorizontalPointsInRoad - 1); //the distance between 2 neighbour points in frame

            for (int i = 0; i < Points.Length; i++)
            {
                Points[i] = _rightMostPoint - (_rightVec * _widthBetweenPoints * i);
            }

            createPrefabs(road, t);
        }
コード例 #2
0
        public void createPrefabs(FXRoad road, float t)
        {
            float pos = road.fx.posibilityForObject();

            if (Random.value >= pos)
            {
                return;
            }

            int numOfPrefabs = (int)((road.numOfHorizontalPointsInRoad - 1) * road.fx.posibilityForObjectInFrame());

            Prefabs = new GameObject[numOfPrefabs];

            float   height = road.step / 2;
            Vector3 hDir   = road.fx.Pos(t + height) - _center;
            Vector3 wDir   = _rightVec * _widthBetweenPoints;

            //hDir - height vector
            //wDir - width vector

            Vector3[] randPosition = new Vector3[road.numOfHorizontalPointsInRoad - 1];


            Vector3 startPoint = _rightMostPoint - wDir / 2;           //start at the most right point on the road minus the half of the width



            //Will work only for even
            //Start random position
            for (int i = 0; i < (randPosition.Length); i++)
            {
                randPosition[i] = startPoint - wDir * i + _norm / 8 + hDir;
            }
            for (int i = 0; i < (randPosition.Length); i++)
            {
                Vector3 temp        = randPosition[i];
                int     randomIndex = Random.Range(i, randPosition.Length);
                randPosition[i]           = randPosition[randomIndex];
                randPosition[randomIndex] = temp;
            }             //end random position


            for (int i = 0; i < numOfPrefabs; i++)
            {
                int        rand   = Random.Range(0, road.obsticlePrefabList.Length);
                GameObject prefab = road.obsticlePrefabList[rand];                    //choose some prefab

                Prefabs[i] = (GameObject)GameObject.Instantiate(prefab);
                Prefabs[i].transform.localPosition = randPosition[i];
                Prefabs[i].transform.LookAt(randPosition[i] + hDir, _norm);
                Prefabs[i].transform.parent = road.parent;
                Prefabs[i].name             = "prefab_" + prefab.name + "_" + numOfInstatiatedPrefabs;
                numOfInstatiatedPrefabs++;
            }
        }
コード例 #3
0
 /***********************************************************
 **	Ctor's
 ***********************************************************/
 /// <summary>
 /// Initializes a new instance of the <see cref="FXRunnerManager"/> class.
 /// </summary>
 /// <param name="parent">Parent.</param>
 /// <param name="fx">Fx.</param>
 /// <param name="lineMaterial">Line material.</param>
 /// <param name="obsticlePrefabList">Obsticle prefab list.</param>
 /// <param name="roadDistanceFromXPosition">Road distance from camera.</param>
 /// <param name="startSpeed">Start speed.</param>
 public FXRunnerManager(Transform parent,
                        IRoadFunction fx,
                        Material lineMaterial,
                        GameObject[] obsticlePrefabList,
                        float roadDistanceFromXPosition,
                        float startSpeed)
 {
     resetTime();
     Fx    = fx;
     speed = startSpeed;
     _roadDistanceFromXPosition = roadDistanceFromXPosition;
     fxRoad = new FXRoad(fx, 60, .3f, lineMaterial, obsticlePrefabList, 20, 8, parent, .5f);
 }