Exemplo n.º 1
0
 public void StartDrawing()
 {
     if (m_CurrentLine == null)
     {
         DefaultPoolObject poolObject = m_LinePool.Pop(Vector3.zero);
         m_CurrentLine = poolObject.transform.GetComponent <Line>();
         m_CurrentLine.linePoolObject = poolObject;
         m_Lines.Add(m_CurrentLine);
     }
     else
     {
         m_CurrentLine.ReInitialize();
     }
 }
Exemplo n.º 2
0
        public void SpawnObstacles()
        {
            if (possibleObstacles.Length == 0 || possibleObstaclePositions.Length == 0)
            {
                return;
            }

            //Get obstacleCount
            int obstacleCount = Random.Range(minObstacleCount, maxObstacleCount + 1);

            if (obstacleCount > possibleObstaclePositions.Length)
            {
                obstacleCount = possibleObstaclePositions.Length;
            }

            m_TempPositions.Clear();
            m_TempPositions.InsertRange(0, possibleObstaclePositions);

            for (int i = 0; i < obstacleCount; i++)
            {
                //Get obstacle to use
                Obstacle obstacleToUse = possibleObstacles[Random.Range(0, possibleObstacles.Length)];

                //Get position to use
                Vector2 positionToUse = m_TempPositions[Random.Range(0, m_TempPositions.Count)];
                m_TempPositions.Remove(positionToUse);

                //Spawn obstacle from pool
                DefaultObjectPool poolToUse      = DefaultObjectPool.GetObjectPool(obstacleToUse.gameObject, 1);
                DefaultPoolObject obstacleObject = poolToUse.Pop((endPoint.position - startPoint.position) * positionToUse.x + Vector3.up * positionToUse.y + startPoint.position);
                Obstacle          obstacle       = obstacleObject.transform.GetComponent <Obstacle>();
                obstacle.poolObject = obstacleObject;
                obstacle.OnSpawn();
                m_Obstacles.Add(obstacle);
            }
        }
        protected void SpawnNewSegment()
        {
            if (trackSegments.Length == 0)
            {
                return;
            }

            //Init random seed
            if (m_TrackSeed != -1)
            {
                Random.InitState(m_TrackSeed);
            }
            else
            {
                Random.InitState((int)System.DateTime.Now.Ticks);
            }


            //Spawn segment
            TrackSegment segmentToUse;
            bool         spawnObstacles = true;

            //Use safe segment
            if (m_CurrentSafeSegmentCount < m_MaxSafeSegmentCount)
            {
                segmentToUse = trackSegments[0];
                m_CurrentSafeSegmentCount++;
                spawnObstacles = false;
            }
            else
            {
                //Random track to spawn
                int randomIndex = Random.Range(0, trackSegments.Length);
                segmentToUse = trackSegments[randomIndex];
            }

            //Calculate spawn position
            Vector3 spawnPosition;

            if (m_CurrentSegment == null)
            {
                spawnPosition = transform.position;
            }
            else
            {
                spawnPosition = m_CurrentSegment.endPoint.position + (segmentToUse.transform.position - segmentToUse.startPoint.position);
            }

            //Spawn segment from object pool
            DefaultObjectPool poolToUse  = DefaultObjectPool.GetObjectPool(segmentToUse.gameObject, 1);
            DefaultPoolObject poolObject = poolToUse.Pop(spawnPosition);

            m_CurrentSegment            = poolObject.transform.GetComponent <TrackSegment>();
            m_CurrentSegment.poolObject = poolObject;
            //Spawn obstacles
            if (spawnObstacles)
            {
                m_CurrentSegment.SpawnObstacles();
            }

            //Add to list
            m_CurrentSegments.Add(m_CurrentSegment);
        }