Example #1
0
        public SpawnManager(MonoBehaviour inst, SO_LevelPattern levelPatterns, Transform map)
        {
            this.inst = inst;
            //get values from global variables...
            this.levelPatterns = levelPatterns;
            this.map           = map;

            //create pools
            pools = new ObjectPool <AEnemy> [levelPatterns.enemyPrefabs.Length];
            for (int i = 0; i < pools.Length; i++)
            {
                pools[i] = new ObjectPool <AEnemy>(levelPatterns.enemyPrefabs[i], 100);
            }

            levelIndex = 0;
        }
Example #2
0
        public void Setup(SO_LevelPattern levelPattern, Transform map, SO_Drops allDrops, GameStateInfo info)
        {
            //setup components
            timer  = new TimeManager(timerUI, levelTime);
            points = new PointsManager(pointsUI);

            spawn = new SpawnManager(this, levelPattern, map);
            enemy = new EnemyManager(spawn);
            drop  = new DropManager(allDrops, info.levelDropRate);

            //setup player
            player.Setup(playerHealthUI, info);


            isActive = true;
        }
Example #3
0
        //spawn units one on each frame...
        IEnumerator SpawnUnits(int levelIndex, SO_LevelPattern levelPatterns)
        {
            //int length = levelPatterns.patterns[levelPatterns.patternIndex[levelIndex]].points.Length;

            //calculate points from PatternInfo
            PatternCreator.PatternInfo p = levelPatterns.container.GetValues()[levelPatterns.patternIndex[levelIndex]];

            //calculate points for each pattern info
            Vector3[]      points    = new Vector3[0];
            Vector3[]      normals   = new Vector3[0];
            Vector3        direction = map.position - map.TransformDirection(p.relativePosition);
            List <Vector3> list;

            //call correct shape function
            switch (p.shape)
            {
            case SpawnShape.CIRCLE:
                list = new List <Vector3>(Shapes.Circle(p.radius, p.angleOffset, p.fillerAmount));
                break;

            case SpawnShape.STAR:
                list = new List <Vector3>(Shapes.Star(p.radius, p.radius / 2f, p.fillerAmount));
                break;

            default:
                list = new List <Vector3>(Shapes.Simple(p.shape, p.radius, p.angleOffset, p.fillerAmount));
                break;
            }
            //List<Vector3> list = new List<Vector3>(PatternCreator.Shapes.GetShape(p.shape, p.fillerAmount, p.radius, p.angleOffset));
            //setup rotation
            Vector3    spawnAxis = Quaternion.AngleAxis(p.angleOffset, direction) * p.rotation;
            Quaternion rot       = Quaternion.LookRotation(direction, spawnAxis);

            //apply rotation to points
            for (int i = 0; i < list.Count; i++)
            {
                list[i] = rot * list[i];
            }


            int lengthWithPercent = Mathf.RoundToInt(list.Count * (p.viewPercentage * 0.01f));
            //to properly place points from surface after raycast
            float distanceFromSurface = GameController.Instance.GetDistanceFromSurface();

            //store proper amount of points based on percentage
            if (lengthWithPercent > 0)
            {
                int remove = list.Count - lengthWithPercent;
                list.RemoveRange(lengthWithPercent - 1, remove);
                points  = list.ToArray();
                normals = new Vector3[points.Length];
                //raycast onto map for exact points
                RaycastHit hit;
                Vector3    position      = map.TransformDirection(p.relativePosition);
                float      distanceToMap = direction.magnitude;
                for (int k = 0; k < points.Length; k++)
                {
                    points[k] += position;
                    //calculate raycast direction, depends on which bool is selected
                    //Vector3 dir = towardsCenter ? (map.position - shapePoints[i]).normalized : -transform.up;
                    //Debug.DrawLine(points[k], points[k] + -transform.transform.up, Color.yellow);
                    if (Physics.Raycast(points[k], direction, out hit, distanceToMap))
                    {
                        points[k] = hit.point + hit.normal * distanceFromSurface;
                        //needed for rotation
                        normals[k] = hit.normal;
                    }
                }
            }


            //spawn objects
            for (int i = 0; i < points.Length; i++)
            {
                AEnemy o = pools[levelPatterns.enemyTypeIndex[levelIndex]].Retrieve();

                if (o != null)
                {
                    //get position
                    //o.transform.position = levelPatterns.patterns[levelPatterns.patternIndex[levelIndex]].points[i];
                    o.transform.position = points[i];
                    //point transform down towards map
                    o.transform.rotation = Quaternion.FromToRotation(o.transform.up, normals[i]) * o.transform.rotation;
                }

                yield return(null);
            }
        }