public EnemyStruct(AEnemy e)
 {
     position         = e.transform.position;
     forward          = e.transform.forward;
     up               = e.transform.up;
     movement         = e.Movement?.Invoke() ?? Vector3.zero;
     obstacleDistance = e.obstacleDistance;
     obstacleLayer    = e.obstacleLayer;
     mapLayer         = e.mapLayer;
     speedThrust      = e.speedThrust;
     rot              = e.transform.rotation;
     rotation         = e.Rotation?.Invoke() ?? e.transform.rotation;
 }
Beispiel #2
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);
            }
        }