Пример #1
0
        public override Pool <ProjectileData> .Node FireProjectile(Vector2 direction, float leakedTime)
        {
            Pool <ProjectileData> .Node node = new Pool <ProjectileData> .Node();

            if (Projectiles.AvailableCount >= TemplatePositions.Count)
            {
                for (int n = 0; n < TemplatePositions.Count; n++)
                {
                    node = Projectiles.Get();

                    node.Item.Position     = transform.position + TemplatePositions[n];
                    node.Item.Scale        = Scale;
                    node.Item.TimeToLive   = TimeToLive - leakedTime;
                    node.Item.Velocity     = Speed * Direction.normalized;
                    node.Item.Position    += node.Item.Velocity * leakedTime;
                    node.Item.Color        = new Color(0.6f, 0.7f, 0.6f, 1);
                    node.Item.Acceleration = Acceleration;

                    // Setup outline if we have one
                    if (ProjectilePrefab.Outline != null && DrawOutlines)
                    {
                        Pool <ProjectileData> .Node outlineNode = ProjectileOutlines.Get();

                        outlineNode.Item.Position = node.Item.Position;
                        outlineNode.Item.Scale    = node.Item.Scale + OutlineSize;
                        outlineNode.Item.Color    = OutlineColor.Evaluate(0);

                        node.Item.Outline = outlineNode;
                    }

                    // Keep track of active projectiles
                    PreviousActiveProjectileIndexes[ActiveProjectileIndexesPosition] = node.NodeIndex;
                    ActiveProjectileIndexesPosition++;
                    if (ActiveProjectileIndexesPosition < ActiveProjectileIndexes.Length)
                    {
                        PreviousActiveProjectileIndexes[ActiveProjectileIndexesPosition] = -1;
                    }
                    else
                    {
                        Debug.Log("Error: Projectile was fired before list of active projectiles was refreshed.");
                    }

                    UpdateProjectile(ref node, leakedTime);
                }



                Direction = Rotate(Direction, RotationSpeed);
            }

            return(node);
        }
        public override Pool <ProjectileData> .Node FireProjectile(Vector2 direction, float leakedTime)
        {
            Pool <ProjectileData> .Node node = new Pool <ProjectileData> .Node();

            Direction = direction;
            RefreshGroups();

            if (!AutoFire)
            {
                if (Interval > 0)
                {
                    return(node);
                }
                else
                {
                    Interval = CoolOffTime;
                }
            }

            for (int g = 0; g < GroupCount; g++)
            {
                if (Projectiles.AvailableCount >= SpokeCount)
                {
                    float rotation = 0;
                    bool  left     = true;

                    for (int n = 0; n < SpokeCount; n++)
                    {
                        node = Projectiles.Get();

                        node.Item.Position   = transform.position;
                        node.Item.Speed      = Speed;
                        node.Item.Scale      = Scale;
                        node.Item.TimeToLive = TimeToLive;
                        node.Item.Gravity    = Gravity;
                        if (UseFollowTarget && FollowTargetType == FollowTargetType.LockOnShot && Target != null)
                        {
                            Groups[g].Direction = (Target.transform.position - transform.position).normalized;
                        }
                        node.Item.Color           = Color.Evaluate(0);
                        node.Item.Acceleration    = Acceleration;
                        node.Item.FollowTarget    = UseFollowTarget;
                        node.Item.FollowIntensity = FollowIntensity;
                        node.Item.Target          = Target;

                        if (left)
                        {
                            node.Item.Velocity = Speed * Rotate(Groups[g].Direction, rotation).normalized;
                            rotation          += SpokeSpacing;
                        }
                        else
                        {
                            node.Item.Velocity = Speed * Rotate(Groups[g].Direction, -rotation).normalized;
                        }

                        // Setup outline if we have one
                        if (ProjectilePrefab.Outline != null && DrawOutlines)
                        {
                            Pool <ProjectileData> .Node outlineNode = ProjectileOutlines.Get();

                            outlineNode.Item.Position = node.Item.Position;
                            outlineNode.Item.Scale    = node.Item.Scale + OutlineSize;
                            outlineNode.Item.Color    = OutlineColor.Evaluate(0);

                            node.Item.Outline = outlineNode;
                        }

                        // Keep track of active projectiles
                        PreviousActiveProjectileIndexes[ActiveProjectileIndexesPosition] = node.NodeIndex;
                        ActiveProjectileIndexesPosition++;
                        if (ActiveProjectileIndexesPosition < ActiveProjectileIndexes.Length)
                        {
                            PreviousActiveProjectileIndexes[ActiveProjectileIndexesPosition] = -1;
                        }
                        else
                        {
                            Debug.Log("Error: Projectile was fired before list of active projectiles was refreshed.");
                        }

                        UpdateProjectile(ref node, leakedTime);

                        left = !left;
                    }

                    if (Groups[g].InvertRotation)
                    {
                        Groups[g].Direction = Rotate(Groups[g].Direction, -RotationSpeed);
                    }
                    else
                    {
                        Groups[g].Direction = Rotate(Groups[g].Direction, RotationSpeed);
                    }
                }
            }

            return(node);
        }