Пример #1
0
    void CheckPlayerOneFireBt()
    {
        if (XKPlayerCamera.IndexPlayerNum != 0)
        {
            return;
        }

        if (!ScreenDanHeiCtrl.IsStartGame)
        {
            SetQianGuanTwRot(PlayerEnum.PlayerOne, false);
            return;
        }

        if (!XkGameCtrl.IsActivePlayerOne)
        {
            SetQianGuanTwRot(PlayerEnum.PlayerOne, false);
            return;
        }

        if (!IsActiveFireBtOne)
        {
            SetQianGuanTwRot(PlayerEnum.PlayerOne, false);
            return;
        }
        SetQianGuanTwRot(PlayerEnum.PlayerOne, true);

//		if (DaoJiShiCtrl.GetInstance().GetIsPlayDaoJishi()) {
//			return;
//		}

        if (!XkGameCtrl.IsTiaoGuoStartCartoon)
        {
            if (!ZhunXingCtrl.GetInstanceOne().GetActiveZhunXing() || !ZhunXingTeXiaoCtrl.IsOverTeXiaoZhunXing)
            {
                return;
            }
        }

        if (Camera.main == null)
        {
            return;
        }
//		if (GameOverCtrl.IsShowGameOver || JiFenJieMianCtrl.GetInstance().GetIsShowFinishTask()) {
//			IsActiveFireBtOne = false;
//			return;
//		}

//		if (PlayerStEnum == PlayerTypeEnum.FeiJi && XkGameCtrl.GameJiTaiSt != GameJiTaiType.FeiJiJiTai) {
//			IsActiveFireBtOne = false;
//			return;
//		}

//		if (PlayerStEnum == PlayerTypeEnum.TanKe && XkGameCtrl.GameJiTaiSt != GameJiTaiType.TanKeJiTai) {
//			IsActiveFireBtOne = false;
//			return;
//		}

        if (XkGameCtrl.GaoBaoDanNumPOne <= 0 &&
            Time.time < LastFireTimeOne + 1f / Frequency)
        {
            return;
        }

        if (XkGameCtrl.GaoBaoDanNumPOne > 0 &&
            Time.time < LastFireTimeOne + 1f / FrequencyGaoBao)
        {
            return;
        }
        LastFireTimeOne = Time.time;
        Vector3    ammoSpawnPos = AmmoStartPosOne[0].position;
        GameObject obj          = null;

        CheckFireAudioPlayerOne();

        bool isSpawnGaoBaoDan = false;

        if (XkGameCtrl.GaoBaoDanNumPOne <= 0)
        {
            if (AmmoParticle[0] != null)
            {
                obj = SpawnParticleCom.SpawnParticleObject(AmmoParticle[0], ammoSpawnPos, AmmoStartPosOne[0].rotation);
                obj.transform.parent = AmmoStartPosOne[0];
            }
            obj = GetPlayerAmmo(PlayerAmmoType.PuTongAmmo, ammoSpawnPos, AmmoStartPosOne[0].rotation);
        }
        else
        {
            isSpawnGaoBaoDan = true;
            if (GaoBaoAmmoParticle[0] != null)
            {
                obj = SpawnParticleCom.SpawnParticleObject(GaoBaoAmmoParticle[0], ammoSpawnPos, AmmoStartPosOne[0].rotation);
                obj.transform.parent = AmmoStartPosOne[0];
            }
            XkGameCtrl.GetInstance().SubGaoBaoDanNumPOne();
            obj = GetPlayerAmmo(PlayerAmmoType.GaoBaoAmmo, ammoSpawnPos, AmmoStartPosOne[0].rotation);
        }
        obj.transform.parent = XkGameCtrl.PlayerAmmoArray;
        PlayerAmmoCtrl ammoScript = obj.GetComponent <PlayerAmmoCtrl>();

        ammoScript.SetIsDonotHurtNpc(false);

        Vector3    mousePosInput = pcvr.GetPlayerMousePos(PlayerEnum.PlayerOne);
        Vector3    firePos       = Vector3.zero;
        Vector3    mousePos      = mousePosInput + Vector3.forward * OffsetForward;
        Vector3    posTmp        = Camera.main.ScreenToWorldPoint(mousePos);
        Vector3    ammoForward   = Vector3.Normalize(posTmp - ammoSpawnPos);
        Ray        ray           = Camera.main.ScreenPointToRay(mousePosInput);
        RaycastHit hit;

        if (!IsPSAutoFire)
        {
            firePos = FirePosValTmp * ammoForward + ammoSpawnPos;
            if (Physics.Raycast(ray, out hit, FireRayDirLen, FireLayer.value))
            {
                //Debug.Log("Player fire obj -> "+hit.collider.name);
                firePos = hit.point;
                if (ammoScript.AmmoType == PlayerAmmoType.PuTongAmmo)
                {
                    XKNpcHealthCtrl healthScript = hit.collider.GetComponent <XKNpcHealthCtrl>();
                    if (healthScript != null && !healthScript.GetIsDeathNpc())
                    {
                        healthScript.OnDamageNpc(ammoScript.AmmoType, PlayerEnum.PlayerOne);
                    }
                }

                BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>();
                if (buJiBaoScript != null)
                {
                    buJiBaoScript.RemoveBuJiBao(PlayerEnum.PlayerOne);                     //buJiBaoScript
                }
            }
        }
        else
        {
            ammoForward = obj.transform.forward;
            firePos     = FirePosValTmp * ammoForward + ammoSpawnPos;
            if (Physics.Raycast(ammoSpawnPos, ammoForward, out hit, FireRayDirLen, FireLayer.value))
            {
                //Debug.Log("Player fire obj -> "+hit.collider.name);
                firePos = hit.point;
                if (ammoScript.AmmoType == PlayerAmmoType.PuTongAmmo)
                {
                    XKNpcHealthCtrl healthScript = hit.collider.GetComponent <XKNpcHealthCtrl>();
                    if (healthScript != null && !healthScript.GetIsDeathNpc())
                    {
                        healthScript.OnDamageNpc(ammoScript.AmmoType, PlayerEnum.PlayerOne);
                    }
                }

                BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>();
                if (buJiBaoScript != null)
                {
                    buJiBaoScript.RemoveBuJiBao(PlayerEnum.PlayerOne);                     //buJiBaoScript
                }
            }
        }

        if (hit.collider == null)
        {
            ammoScript.StartMoveAmmo(firePos, PlayerEnum.PlayerOne);
        }
        else
        {
            ammoScript.StartMoveAmmo(firePos, PlayerEnum.PlayerOne, null, hit.collider.gameObject);
        }

        if (isSpawnGaoBaoDan)
        {
            //Call OtherPort Show AmmoParticle
            PlayerScript.CallOtherPortSpawnPlayerAmmoParticle(1, 2, firePos);
        }
        else
        {
            //Call OtherPort Show AmmoParticle
            PlayerScript.CallOtherPortSpawnPlayerAmmoParticle(1, 0, firePos);
        }
    }