Beispiel #1
0
    public void SetChatacterShootBullet(AllSyncBullet bulletInfo)
    {
        PECommon.Log("在自己的客户端上实例化一个子弹。");

        Vector3 pos = UnityTools.GetV3Value(bulletInfo.originPos);
        Vector3 rot = UnityTools.GetV3Value(bulletInfo.originRot);
        Vector3 dir = UnityTools.GetV3Value(bulletInfo.dir);
        //-----------------------发射子弹
        GameObject tempBullet = null;

        if (bulletPool.Data())
        {
            tempBullet = bulletPool.GetObject();
            tempBullet.transform.position    = pos;
            tempBullet.transform.eulerAngles = rot;
            tempBullet.gameObject.SetActive(true);
        }
        else
        {
            tempBullet      = GameObject.Instantiate(Resources.Load <GameObject>(bulletInfo.prefabName), pos, Quaternion.Euler(rot), bulletParent);
            tempBullet.name = "Bullet";
        }

        if (tempBullet.GetComponent <Bullet>() == null)
        {
            tempBullet.AddComponent <Bullet>();
        }
        Bullet bullet = tempBullet.GetComponent <Bullet>();

        PECommon.Log("这颗子弹的ID从" + bullet.damageID + "改变到" + (bullet.damageID + 1));
        if (bullet.damageID <= lastShootBulletID)
        {
            bullet.damageID = lastShootBulletID + 1;
        }
        else
        {
            bullet.damageID += 1;
        }
        lastShootBulletID = bullet.damageID;
        bullet.SetCasterRoleType(bulletInfo.roleType);
        bullet.PlayAudio();
        if (bulletInfo.shootSky == 1)
        {
            bulletInfo.force *= 10;
        }
        bullet.Shoot(dir, bulletInfo.force, bulletInfo.damage, bulletPool);

        //-------------------------------开火特效
        GameObject fireEffect = null;

        if (fireEffectPool.Data())
        {
            fireEffect = fireEffectPool.GetObject();
            fireEffect.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
            fireEffect.transform.position   = pos;
            //fireEffect.transform.eulerAngles = rot;
            fireEffect.gameObject.SetActive(true);
        }
        else
        {
            fireEffect      = GameObject.Instantiate(Resources.Load <GameObject>(bulletInfo.fireEffect), pos, Quaternion.identity, effectParent);
            fireEffect.name = "FireEffect";
            fireEffect.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
        }
        timerSvc.AddTimeTask((int tid) =>
        {
            fireEffect.gameObject.SetActive(false);
            fireEffectPool.AddObject(fireEffect);
        }, 500);
        //-------------------------------弹壳特效
        GameObject shellEffect = null;
        Vector3    newPos      = new Vector3(pos.x, pos.y, pos.z - 0.5f);

        if (shellEffectPool.Data())
        {
            shellEffect = shellEffectPool.GetObject();
            shellEffect.transform.position    = newPos;
            shellEffect.transform.eulerAngles = rot;
            shellEffect.GetComponent <ShellEffect>().ShellFly(new Vector3(0, 1, Random.Range(0.05f, 0.2f)), 300);
            shellEffect.gameObject.SetActive(true);
        }
        else
        {
            shellEffect      = GameObject.Instantiate(Resources.Load <GameObject>(bulletInfo.shellEffect), newPos, Quaternion.Euler(rot), effectParent);
            shellEffect.name = "ShellEffect";
            shellEffect.GetComponent <ShellEffect>().ShellFly(new Vector3(0, 1, Random.Range(0.05f, 0.2f)), 300);
        }
        if (shellEffect.GetComponent <ShellEffect>() != null)
        {
            shellEffect.GetComponent <ShellEffect>().PlayAudio();
        }
        timerSvc.AddTimeTask((int tid) =>
        {
            shellEffect.gameObject.SetActive(false);
            shellEffectPool.AddObject(shellEffect);
        }, 500);
    }
Beispiel #2
0
    public void AllSyncBullet(GameMsg msg)
    {
        AllSyncBullet allSyncBullet = msg.allSyncBullet;

        battleMgr.SetChatacterShootBullet(allSyncBullet);
    }