public void CreateBullet(Vector3 position, float direction, float speedMultiplier)
        {
            if (parentController.CanAddBullet())
            {
                GameObject bulletObj = new GameObject();
                bulletObj.name = "DMKBullet";

                DMKBullet bullet = bulletObj.AddComponent <DMKBullet> ();

                bullet.bulletInfo.CopyFrom(this.bulletInfo, speedMultiplier);
                if (followParentDirection && this.gameObject)
                {
                    direction += this.gameObject.transform.rotation.eulerAngles.z - 90;
                }

                bullet.bulletInfo.direction = direction * Mathf.Deg2Rad;
                SpriteRenderer renderer = bulletObj.AddComponent <SpriteRenderer> ();
                renderer.sprite         = this.bulletInfo.bulletSprite;
                renderer.color          = this.bulletInfo.bulletColor;
                renderer.sortingOrder   = DMKSettings.instance.sortingOrder;
                renderer.sortingLayerID = DMKSettings.instance.sortingLayerIndex;

                if (bulletContainer != null)
                {
                    bullet.transform.parent = bulletContainer.transform;
                }

                bullet.transform.localScale = new Vector3(this.bulletInfo.scale.x, this.bulletInfo.scale.y, 1);
                bullet.transform.rotation   = Quaternion.AngleAxis(direction + 90, Vector3.forward);

                float   ctime  = (_currentFrame + _internalFrame) * DMKSettings.instance.frameInterval;
                Vector2 offset = this.positionOffset.Evaluate(ctime);
                position.x += offset.x;
                position.y += offset.y;
                if (positionOffset.type != DMKPositionOffsetType.Absolute && this.gameObject != null)
                {
                    position += this.gameObject.transform.position;
                }
                bullet.transform.position = position;

                bullet.tag           = this.tag;
                bullet.parentEmitter = this;

                parentController.bulletContainer.Add(bullet);

                if (subController != null)
                {
                    subController.OnShootBullet(bullet);
                }
            }
            else
            {
            }
        }
Example #2
0
 public void OnShoot(BulletInfo info)
 {
     if (info.bulletRef.IsAlive)
     {
         DMKBullet bullet = (info.bulletRef.Target as DMKBullet);
         if (bullet != null)
         {
             internalController.gameObject = bullet.gameObject;
             internalController.shooter.OnShoot(info.currentFrame);
         }
     }
 }
Example #3
0
        public void OnShootBullet(DMKBullet bullet)
        {
            if (!this.internalController.editorEnabled)
            {
                return;
            }

            if (trackingBullets == null)
            {
                trackingBullets = new List <BulletInfo>();
            }
            trackingBullets.Add(new BulletInfo(this, bullet));
        }
Example #4
0
 public BulletInfo(DMKSubBulletShooterController p, DMKBullet b)
 {
     currentCooldown = currentInterval = prevFrame = currentFrame = 0;
     this.parent     = p;
     this.bulletRef  = new WeakReference(b);
 }