Example #1
0
 /// <summary>
 /// Shot UbhBullet object.
 /// </summary>
 protected void ShotBullet(UbhBullet bullet, float speed, float angle,
                           bool homing = false, Transform homingTarget = null, float homingAngleSpeed = 0f, float maxHomingAngle = 0f,
                           bool wave   = false, float waveSpeed        = 0f, float waveRangeSize = 0f)
 {
     if (bullet == null)
     {
         return;
     }
     bullet.Shot(speed, angle, m_angleSpeed, m_accelerationSpeed,
                 homing, homingTarget, homingAngleSpeed, maxHomingAngle,
                 wave, waveSpeed, waveRangeSize,
                 m_usePauseAndResume, m_pauseTime, m_resumeTime);
 }
Example #2
0
 /// <summary>
 /// Update Bullets Move
 /// </summary>
 public void UpdateBullets(float deltaTime)
 {
     for (int i = m_bulletList.Count - 1; i >= 0; i--)
     {
         UbhBullet bullet = m_bulletList[i];
         if (bullet == null)
         {
             m_bulletList.Remove(bullet);
             continue;
         }
         bullet.UpdateMove(deltaTime);
     }
 }
    protected virtual void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        if (m_delayTimer >= 0f)
        {
            m_delayTimer -= UbhTimer.instance.deltaTime;
            if (m_delayTimer >= 0f)
            {
                return;
            }
        }

        List <int> lineData = m_paintData[m_nowIndex];

        for (int i = 0; i < lineData.Count; i++)
        {
            if (lineData[i] == 1)
            {
                UbhBullet bullet = GetBullet(transform.position);
                if (bullet == null)
                {
                    break;
                }

                float angle = m_paintStartAngle + (m_betweenAngle * i);

                ShotBullet(bullet, m_bulletSpeed, angle);
            }
        }

        FiredShot();

        m_nowIndex++;
        if (m_nowIndex >= m_paintData.Count)
        {
            FinishedShot();
        }
        else
        {
            m_delayTimer = m_nextLineDelay;
            if (m_delayTimer <= 0f)
            {
                Update();
            }
        }
    }
Example #4
0
 /// <summary>
 /// Shot UbhBullet object.
 /// </summary>
 protected void ShotBullet(UbhBullet bullet, float speed, float angle,
                           bool homing = false, Transform homingTarget = null, float homingAngleSpeed = 0f,
                           bool wave   = false, float waveSpeed        = 0f, float waveRangeSize = 0f)
 {
     if (bullet == null)
     {
         return;
     }
     bullet.Shot(speed, angle, _AccelerationSpeed, _AccelerationTurn,
                 homing, homingTarget, homingAngleSpeed,
                 wave, waveSpeed, waveRangeSize,
                 _UsePauseAndResume, _PauseTime, _ResumeTime,
                 ShotCtrl != null ? ShotCtrl._AxisMove : UbhUtil.AXIS.X_AND_Y);
 }
Example #5
0
    protected virtual void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        if (m_delayTimer >= 0f)
        {
            m_delayTimer -= UbhTimer.instance.deltaTime;
            if (m_delayTimer >= 0f)
            {
                return;
            }
        }

        UbhBullet bullet = GetBullet(transform.position);

        if (bullet == null)
        {
            FinishedShot();
            return;
        }

        float bulletSpeed = Random.Range(m_randomSpeedMin, m_randomSpeedMax);

        float centerAngle = m_startAngle + (m_shiftAngle * m_nowIndex);
        float minAngle    = centerAngle - (m_randomRangeSize / 2f);
        float maxAngle    = centerAngle + (m_randomRangeSize / 2f);
        float angle       = Random.Range(minAngle, maxAngle);

        ShotBullet(bullet, bulletSpeed, angle);
        FiredShot();

        m_nowIndex++;

        if (m_nowIndex >= m_bulletNum)
        {
            FinishedShot();
        }
        else
        {
            m_delayTimer = Random.Range(m_randomDelayMin, m_randomDelayMax);
            if (m_delayTimer <= 0f)
            {
                Update();
            }
        }
    }
Example #6
0
    private void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        if (m_delayTimer >= 0f)
        {
            m_delayTimer -= UbhTimer.instance.deltaTime;
            if (m_delayTimer >= 0f)
            {
                return;
            }
        }

        UbhBullet bullet = GetBullet(transform.position);

        if (bullet == null)
        {
            FinishedShot();
            return;
        }

        if (m_targetTransform == null && m_setTargetFromTag)
        {
            m_targetTransform = UbhUtil.GetTransformFromTagName(m_targetTagName, m_randomSelectTagTarget, m_nearestSelectTagTarget, transform);
        }

        float angle = UbhUtil.GetAngleFromTwoPosition(transform, m_targetTransform, shotCtrl.m_axisMove);

        ShotBullet(bullet, m_bulletSpeed, angle, true, m_targetTransform, m_homingAngleSpeed);
        FiredShot();

        m_nowIndex++;

        if (m_nowIndex >= m_bulletNum)
        {
            FinishedShot();
        }
        else
        {
            m_delayTimer = m_betweenDelay;
            if (m_delayTimer <= 0f)
            {
                Update();
            }
        }
    }
Example #7
0
    public override bool ExcuteAction(PlayerProperty playerProperty)
    {
        CurrentTimeFrame++;

        if (CurrentTimeFrame == 1)
        {
            var playerSpriteTrans = playerProperty.m_spriteReference.transform;
            playerSpriteTrans.rotation        = Quaternion.Euler(0, 0, m_playerLookAngle);
            playerProperty.transform.position = m_playerPosition;
        }

        if (CurrentTimeFrame == (m_actionTimeFrame / 2))
        {
            foreach (var bulletGameObject in m_bullets)
            {
                bulletGameObject.SetActive(true);

                UbhBullet bulletComponent = bulletGameObject.GetComponent <UbhBullet>();
                if (bulletComponent == null)
                {
                    bulletComponent = bulletGameObject.AddComponent <UbhBullet>();
                }

                bulletComponent.m_damage = m_bulletDamage;
                bulletComponent.Shot(m_bulletSpeed,
                                     UbhUtil.GetAngleFromTwoPosition(Vector3.zero, bulletGameObject.transform.up), // shot angle
                                     0, 0,
                                     false, null, 0, 0,
                                     false, 0, 0,
                                     false, 0, 0, true);
            }

            foreach (var bulletPathNode in m_bulletPathNodes)
            {
                UbhObjectPool.Instance.ReleaseGameObject(bulletPathNode);
            }

            return(false);
        }

        if (CurrentTimeFrame > m_actionTimeFrame)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #8
0
        IEnumerator BulletMove(UbhBullet bullet, float angle)
        {
            Transform bulletTrans = bullet.transform;

            float speed          = m_bulletSpeed;
            float accel          = m_accelerationSpeed;
            float angleSpeed     = m_angleSpeed;
            float maxBounceTimes = m_bounceTimes;

            Rect edgeRect = new Rect(m_background.position, m_background.localScale);

            edgeRect.Set(edgeRect.x - edgeRect.width / 2, edgeRect.y - edgeRect.height / 2, edgeRect.width, edgeRect.height);

            if (bulletTrans == null)
            {
                Debug.LogWarning("The shooting bullet is not exist!");
                yield break;
            }

            bulletTrans.SetEulerAnglesZ(angle - 90);

            int bounceTime = 0;

            while (true)
            {
                // turning.
                angle += angleSpeed * UbhTimer.Instance.DeltaTime;
                bulletTrans.SetEulerAnglesZ(angle - 90);

                // acceleration speed
                speed += accel * UbhTimer.Instance.DeltaTime;

                // move
                Vector3 newPosition = bulletTrans.position + bulletTrans.up * speed * UbhTimer.Instance.DeltaTime;
                if (edgeRect.Contains(newPosition) || bounceTime >= maxBounceTimes)
                {
                    bulletTrans.position = newPosition;
                }
                else // cross with edge
                {
                    bulletTrans.position = GetIntersectWithRect(bulletTrans.position, newPosition, ref edgeRect, ref angle);
                    bulletTrans.SetEulerAnglesZ(angle - 90);
                    bounceTime++;
                }

                yield return(0);
            }
        }
Example #9
0
 /// <summary>
 /// Shot UbhBullet object.
 /// </summary>
 protected void ShotBullet(UbhBullet bullet, float speed, float angle,
                           bool homing = false, Transform homingTarget = null, float homingAngleSpeed = 0f,
                           bool wave   = false, float waveSpeed        = 0f, float waveRangeSize = 0f)
 {
     if (bullet == null)
     {
         return;
     }
     bullet.Shot(this,
                 speed, angle, m_accelerationSpeed, m_accelerationTurn,
                 homing, homingTarget, homingAngleSpeed,
                 wave, waveSpeed, waveRangeSize,
                 m_usePauseAndResume, m_pauseTime, m_resumeTime,
                 m_useAutoRelease, m_autoReleaseTime,
                 m_shotCtrl.m_axisMove, m_shotCtrl.m_inheritAngle);
 }
Example #10
0
        /// <summary>
        /// The method for bullet move
        /// </summary>
        /// <param name="bullet"></param>
        /// <param name="beforeAngle"> bullet move angle before waiting</param>
        /// <param name="afterAngle"> bullet move angle after waiting </param>
        /// <param name="destination"> bullet waiting destination </param>
        /// <returns></returns>
        IEnumerator BulletMove(UbhBullet bullet, float beforeAngle, float afterAngle, Vector3 destination)
        {
            Transform bulletTrans = bullet.transform;

            float     timeToReachRect = m_timeToReachRectEdge;
            float     waitTime        = m_waitingTime;
            Transform backgroundRect  = m_background;

            if (bulletTrans == null)
            {
                Debug.LogWarning("The shooting bullet is not exist!");
                yield break;
            }

            bulletTrans.SetEulerAnglesZ(beforeAngle - 90f);

            Vector3 startPosition = bulletTrans.position;
            float   timer         = 0f;

            // Bullet movement before waiting.
            while (true)
            {
                float t = timer / timeToReachRect;
                bulletTrans.position = Vector3.Lerp(startPosition, destination, t);
                timer += UbhTimer.Instance.DeltaTime;

                if (t >= 0.995f)
                {
                    break;
                }

                yield return(null);
            }
            bulletTrans.SetEulerAnglesZ(afterAngle - 90);

            // Wait for a while
            yield return(UbhUtil.WaitForSeconds(waitTime));

            // Get bounce shot component
            var bounceShot = bulletTrans.GetChild(0).GetComponent <LinearBounceShot>();

            bounceShot.m_background = backgroundRect;
            bounceShot.m_shotAngle  = afterAngle;
            bounceShot.Shot();
        }
Example #11
0
    /// <summary>
    /// Get UbhBullet object from object pool.
    /// </summary>
    protected UbhBullet GetBullet(Vector3 position, bool forceInstantiate = false)
    {
        if (m_bulletPrefab == null)
        {
            Debug.LogWarning("Cannot generate a bullet because BulletPrefab is not set.");
            return(null);
        }

        // get UbhBullet from ObjectPool
        UbhBullet bullet = UbhObjectPool.instance.GetBullet(m_bulletPrefab, position, forceInstantiate);

        if (bullet == null)
        {
            return(null);
        }

        return(bullet);
    }
Example #12
0
    protected virtual void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        if (m_delayTimer >= 0f)
        {
            m_delayTimer -= UbhTimer.instance.deltaTime;
            if (m_delayTimer >= 0f)
            {
                return;
            }
        }

        UbhBullet bullet = GetBullet(transform.position);

        if (bullet == null)
        {
            FinishedShot();
            return;
        }

        float angle = m_startAngle + (m_shiftAngle * m_nowIndex);

        ShotBullet(bullet, m_bulletSpeed, angle);
        FiredShot();

        m_nowIndex++;

        if (m_nowIndex >= m_bulletNum)
        {
            FinishedShot();
        }
        else
        {
            m_delayTimer = m_betweenDelay;
            if (m_delayTimer <= 0f)
            {
                Update();
            }
        }
    }
Example #13
0
    private void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        int wayIndex = 0;

        float bulletSpeed = m_bulletSpeed;

        for (int i = 0; i < m_bulletNum; i++)
        {
            if (m_wayNum <= wayIndex)
            {
                wayIndex = 0;

                bulletSpeed -= m_diffSpeed;
                while (bulletSpeed <= 0)
                {
                    bulletSpeed += Mathf.Abs(m_diffSpeed);
                }
            }

            UbhBullet bullet = GetBullet(transform.position);
            if (bullet == null)
            {
                break;
            }

            float baseAngle = m_wayNum % 2 == 0 ? m_centerAngle - (m_betweenAngle / 2f) : m_centerAngle;

            float angle = UbhUtil.GetShiftedAngle(wayIndex, baseAngle, m_betweenAngle);

            ShotBullet(bullet, bulletSpeed, angle);

            wayIndex++;
        }

        FiredShot();

        FinishedShot();
    }
Example #14
0
    private void HitCheck(Transform colTrans)
    {
        // *It is compared with name in order to separate as Asset from project settings.
        //  However, it is recommended to use Layer or Tag.
        string goName = colTrans.name;

        if (goName.Contains(UbhPlayer.NAME_ENEMY_BULLET) ||
            goName.Contains(UbhEnemy.NAME_PLAYER_BULLET))
        {
            UbhBullet bullet = colTrans.parent.GetComponentInParent <UbhBullet>();
            if (bullet != null && bullet.isActive)
            {
                UbhObjectPool.instance.ReleaseBullet(bullet);
            }
        }
        else if (goName.Contains(UbhEnemy.NAME_PLAYER) == false)
        {
            Destroy(colTrans.gameObject);
        }
    }
    private void HitCheck(Transform colTrans)
    {
        // *It is compared with name in order to separate as Asset from project settings.
        //  However, it is recommended to use Layer or Tag.
        string goName = colTrans.name;

        if (goName.Contains(NAME_ENEMY_BULLET))
        {
            UbhBullet bullet = colTrans.GetComponentInParent <UbhBullet>();
            if (bullet.isActive)
            {
                UbhObjectPool.instance.ReleaseBullet(bullet);
                Damage();
            }
        }
        else if (goName.Contains(NAME_ENEMY))
        {
            Damage();
        }
    }
Example #16
0
    private IEnumerator AutoReleaseBulletCoroutine(UbhBullet bullet)
    {
        float countUpTime = 0f;

        while (true)
        {
            if (bullet == null || bullet.gameObject == null || bullet.gameObject.activeSelf == false)
            {
                yield break;
            }

            if (m_autoReleaseTime <= countUpTime)
            {
                break;
            }

            yield return(null);

            countUpTime += UbhTimer.instance.deltaTime;
        }

        UbhObjectPool.instance.ReleaseBullet(bullet);
    }
Example #17
0
    void DamagePlayerByState(PlayerProperty.PlayerStateType enemyType, UbhBullet enemyBullet)
    {
        if (enemyBullet == null)
        {
            return;
        }

        Debug.Log(enemyType);

        if (enemyType == m_playerProperty.m_playerState)
        {
            m_playerProperty.m_playerHealth--;
            if (m_playerProperty.m_playerHealth <= 0)
            {
                PlayerDeath();
            }
            UbhObjectPool.Instance.ReleaseGameObject(enemyBullet.gameObject);
        }
        else
        {
            PlayerDeath();
        }
    }
Example #18
0
    /// <summary>
    /// Releases bullet (back to pool or destroy).
    /// </summary>
    public void ReleaseBullet(UbhBullet bullet, bool destroy = false)
    {
        if (bullet == null || bullet.gameObject == null)
        {
            return;
        }

        UbhBulletManager.instance.RemoveBullet(bullet);

#if USING_CORE_GAME_KIT
        // +++++ Replace PoolingSystem with DarkTonic's CoreGameKit. +++++
        InitializePoolBoss();
        PoolBoss.Despawn(bullet.transform);
#else
        if (destroy)
        {
            Destroy(bullet.gameObject);
            Destroy(bullet);
            bullet = null;
            return;
        }
        bullet.gameObject.SetActive(false);
#endif
    }
Example #19
0
    // Player wants to shot.
    void Shot()
    {
        // it is not enough time after the last shot, shot cancel
        if (_timer < _playerProperty.m_shootInterval)
        {
            return;
        }

        if (m_shootList == null || m_shootList.Count <= 0)
        {
            Debug.LogWarning("Cannot shot because ShotList is not set.");
            return;
        }

        for (int i = 0; i < m_shootList.Count; i++)
        {
            Vector3 shotStartPoint = m_shootList[i].position;
            Vector3 shotDirection  = m_shootList[i].up;
            float   angle          = UbhUtil.GetAngleFromTwoPosition(Vector3.zero, shotDirection);

            UbhBullet bullet = GetBullet(shotStartPoint, Quaternion.Euler(0, 0, angle));
            if (bullet == null)
            {
                break;
            }
            bullet.Shot(_playerProperty.m_bulletSpeed, angle,
                        0, 0,
                        false, null, 0, 0,
                        false, 0, 0,
                        false, 0, 0, false);
            bullet.m_damage = _playerProperty.m_bulletDamage;
        }

        // finish a shot, reset timer
        _timer = 0f;
    }
Example #20
0
    private void HitCheck(Transform colTrans)
    {
        // *It is compared with name in order to separate as Asset from project settings.
        //  However, it is recommended to use Layer or Tag.
        string goName = colTrans.name;

        if (goName.Contains(NAME_ENEMY_BULLET))
        {
            UbhBullet bullet = colTrans.parent.GetComponent <UbhBullet>();
            UbhObjectPool.instance.ReleaseBullet(bullet);
        }

        if (goName.Contains(NAME_ENEMY))
        {
            if (m_manager != null)
            {
                m_manager.GameOver();
            }

            m_spaceship.Explosion();

            Destroy(gameObject);
        }
    }
Example #21
0
    /// <summary>
    /// Get Bullet from object pool or instantiate.
    /// </summary>
    public UbhBullet GetBullet(GameObject goPrefab, Vector3 position, bool forceInstantiate = false)
    {
        if (goPrefab == null)
        {
            return(null);
        }

        UbhBullet bullet = null;

#if USING_CORE_GAME_KIT
        // +++++ Replace PoolingSystem with DarkTonic's CoreGameKit. +++++
        InitializePoolBoss();
        Transform trans = PoolBoss.Spawn(goPrefab.transform, position, UbhUtil.QUATERNION_IDENTITY, transform);
        if (trans == null)
        {
            return(null);
        }

        bullet = trans.gameObject.GetComponent <UbhBullet>();
        if (bullet == null)
        {
            bullet = trans.gameObject.AddComponent <UbhBullet>();
        }
#else
        int key = goPrefab.GetInstanceID();

        if (m_pooledBulletDic.ContainsKey(key) == false)
        {
            m_pooledBulletDic.Add(key, new PoolingParam());
        }

        PoolingParam poolParam = m_pooledBulletDic[key];

        if (forceInstantiate == false && poolParam.m_bulletList.Count > 0)
        {
            if (poolParam.m_searchStartIndex < 0 || poolParam.m_searchStartIndex >= poolParam.m_bulletList.Count)
            {
                poolParam.m_searchStartIndex = poolParam.m_bulletList.Count - 1;
            }

            for (int i = poolParam.m_searchStartIndex; i >= 0; i--)
            {
                if (poolParam.m_bulletList[i] == null || poolParam.m_bulletList[i].gameObject == null)
                {
                    poolParam.m_bulletList.RemoveAt(i);
                    continue;
                }
                if (poolParam.m_bulletList[i].isActive == false)
                {
                    poolParam.m_searchStartIndex = i - 1;
                    bullet = poolParam.m_bulletList[i];
                    bullet.SetActive(true);
                    break;
                }
            }
            if (bullet == null)
            {
                for (int i = poolParam.m_bulletList.Count - 1; i > poolParam.m_searchStartIndex; i--)
                {
                    if (poolParam.m_bulletList[i] == null || poolParam.m_bulletList[i].gameObject == null)
                    {
                        poolParam.m_bulletList.RemoveAt(i);
                        continue;
                    }
                    if (i < poolParam.m_bulletList.Count && poolParam.m_bulletList[i].isActive == false)
                    {
                        poolParam.m_searchStartIndex = i - 1;
                        bullet = poolParam.m_bulletList[i];
                        bullet.SetActive(true);
                        break;
                    }
                }
            }
        }

        if (bullet == null)
        {
            //edit by feng


            GameObject go = Instantiate(goPrefab, transform);
            bullet = go.GetComponent <UbhBullet>();
            if (bullet == null)
            {
                bullet = go.AddComponent <UbhBullet>();
            }
            poolParam.m_bulletList.Add(bullet);
            poolParam.m_searchStartIndex = poolParam.m_bulletList.Count - 1;
            bullet.SetActive(true);
        }

        bullet.transform.SetPositionAndRotation(position, UbhUtil.QUATERNION_IDENTITY);
#endif

        UbhBulletManager.instance.AddBullet(bullet);

        return(bullet);
    }
Example #22
0
    protected virtual void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        if (m_delayTimer >= 0f)
        {
            m_delayTimer -= UbhTimer.instance.deltaTime;
            if (m_delayTimer >= 0f)
            {
                return;
            }
        }

        float spiralWayShiftAngle = 360f / m_spiralWayNum;

        for (int i = 0; i < m_spiralWayNum; i++)
        {
            for (int k = 0; k < m_wayNum; k++)
            {
                UbhBullet bullet = GetBullet(transform.position);
                if (bullet == null)
                {
                    break;
                }

                float centerAngle = m_startAngle + (spiralWayShiftAngle * i) + (m_shiftAngle * Mathf.Floor(m_nowIndex / m_wayNum));

                float baseAngle = m_wayNum % 2 == 0 ? centerAngle - (m_betweenAngle / 2f) : centerAngle;

                float angle = UbhUtil.GetShiftedAngle(k, baseAngle, m_betweenAngle);

                ShotBullet(bullet, m_bulletSpeed, angle);

                m_nowIndex++;
                if (m_nowIndex >= m_bulletNum)
                {
                    break;
                }
            }

            if (m_nowIndex >= m_bulletNum)
            {
                break;
            }
        }

        FiredShot();

        if (m_nowIndex >= m_bulletNum)
        {
            FinishedShot();
        }
        else
        {
            m_delayTimer = m_nextLineDelay;
            if (m_delayTimer <= 0f)
            {
                Update();
            }
        }
    }
Example #23
0
    protected virtual void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        if (m_delayTimer >= 0f)
        {
            m_delayTimer -= UbhTimer.instance.deltaTime;
            if (m_delayTimer >= 0f)
            {
                return;
            }
        }

        List <int> lineData = m_paintData[m_nowIndex];

        for (int i = 0; i < lineData.Count; i++)
        {
            if (lineData[i] == 1)
            {
                UbhBullet bullet = GetBullet(transform.position);
                if (bullet == null)
                {
                    break;
                }

                float angle = m_paintStartAngle + (m_betweenAngle * i);

                ShotBullet(bullet, m_bulletSpeed, angle);

                for (int j = 0; j < m_wayNum; j++)
                {
                    //奇数か偶数かを調べて、
                    float baseAngle = m_wayNum % 2 == 0 ? m_centerAngle - (m_betweenAngle / 2f) : m_centerAngle;
                    //奇数か偶数か精げてWayの角度を決める
                    float m_wayAngle = UbhUtil.GetShiftedAngle(i, baseAngle, m_betweenAngle);

                    ShotBullet(bullet, m_bulletSpeed, m_wayAngle);

                    m_nowIndex++;

                    if (m_nowIndex >= m_bulletNum)
                    {
                        break;
                    }
                }
            }
        }

        FiredShot();

        m_nowIndex++;
        if (m_nowIndex >= m_paintData.Count)
        {
            FinishedShot();
        }
        else
        {
            m_delayTimer = m_bulletNum;
            if (m_delayTimer <= 0f)
            {
                Update();
            }
        }
    }
Example #24
0
        // The method for bullet move
        IEnumerator BulletMove(UbhBullet bullet, float angle)
        {
            Transform bulletTrans = bullet.transform;

            float bulletSpeed                  = m_bulletSpeed;
            float accelerationSpeed            = m_accelerationSpeed;
            float angleSpeed                   = m_angleSpeed;
            float addAngleAfterChangeDirection = m_AddAngleAfterChangeDirection;

            float selfTimeCount = 0;

            float pauseBeforeChangeDirection = m_PauseBeforeChangeDirection;
            float bulletSpeedAfterChangeDir  = m_BulletSpeedAfterChangeDir;

            bool  usePauseAndResume = m_usePauseAndResume;
            float pauseTime         = m_pauseTime;
            float resumeTime        = m_resumeTime;

            if (bulletTrans == null)
            {
                Debug.LogWarning("The shooting bullet is not exist!");
                yield break;
            }

            bulletTrans.SetEulerAnglesZ(angle);

            while (true)
            {
                float addAngle = angleSpeed * UbhTimer.Instance.DeltaTime;
                bulletTrans.AddEulerAnglesZ(addAngle);

                bulletSpeed          += accelerationSpeed * UbhTimer.Instance.DeltaTime;
                bulletTrans.position += bulletTrans.up * bulletSpeed * UbhTimer.Instance.DeltaTime;

                yield return(0);

                selfTimeCount += UbhTimer.Instance.DeltaTime;

                // When the speed == 0, shoot two other bullet
                if (selfTimeCount > Mathf.Abs(bulletSpeed / accelerationSpeed))
                {
                    yield return(UbhUtil.WaitForSeconds(pauseBeforeChangeDirection));

                    bulletSpeed = bulletSpeedAfterChangeDir;
                    //angle = UbhUtil.GetAngleFromTwoPosition(bulletTrans, transform, axisMove) - 90;

                    var bulletUpper = GetBullet(bulletTrans.position, bulletTrans.rotation);
                    var bulletUnder = GetBullet(bulletTrans.position, bulletTrans.rotation);
                    if (bulletUpper == null || bulletUnder == null)
                    {
                        break;
                    }

                    ShotChildBullet(bulletUpper, bulletSpeed, angle + addAngleAfterChangeDirection);
                    ShotChildBullet(bulletUnder, bulletSpeed, angle - addAngleAfterChangeDirection);
                    AutoReleaseBulletGameObject(bulletUpper.gameObject);
                    AutoReleaseBulletGameObject(bulletUnder.gameObject);

                    UbhObjectPool.Instance.ReleaseGameObject(bulletTrans.gameObject);
                    FinishedShot();

                    yield break;
                }


                // pause and resume.
                if (usePauseAndResume && pauseTime >= 0f && resumeTime > pauseTime)
                {
                    while (pauseTime <= selfTimeCount && selfTimeCount < resumeTime)
                    {
                        yield return(0);

                        selfTimeCount += UbhTimer.Instance.DeltaTime;
                    }
                }
            }
        }
Example #25
0
    protected virtual void Update()
    {
        if (m_shooting == false)
        {
            return;
        }

        if (m_delayTimer >= 0f)
        {
            m_delayTimer -= UbhTimer.instance.deltaTime;
            if (m_delayTimer >= 0f)
            {
                return;
            }
        }

        int index = Random.Range(0, m_numList.Count);

        UbhBullet bullet = GetBullet(transform.position);

        if (bullet == null)
        {
            return;
        }

        float bulletSpeed = Random.Range(m_randomSpeedMin, m_randomSpeedMax);

        float minAngle = m_randomCenterAngle - (m_randomRangeSize / 2f);
        float maxAngle = m_randomCenterAngle + (m_randomRangeSize / 2f);
        float angle    = 0f;

        if (m_evenlyDistribute)
        {
            float oneDirectionNum = Mathf.Floor((float)m_bulletNum / 4f);
            float quarterIndex    = Mathf.Floor((float)m_numList[index] / oneDirectionNum);
            float quarterAngle    = Mathf.Abs(maxAngle - minAngle) / 4f;
            angle = Random.Range(minAngle + (quarterAngle * quarterIndex), minAngle + (quarterAngle * (quarterIndex + 1f)));
        }
        else
        {
            angle = Random.Range(minAngle, maxAngle);
        }

        ShotBullet(bullet, bulletSpeed, angle);
        FiredShot();

        m_numList.RemoveAt(index);

        if (m_numList.Count <= 0)
        {
            FinishedShot();
        }
        else
        {
            m_delayTimer = Random.Range(m_randomDelayMin, m_randomDelayMax);
            if (m_delayTimer <= 0f)
            {
                Update();
            }
        }
    }