예제 #1
0
    /*--------------- OnReloadEndEvent -----------------*/

    /*--------------- AttackEndEvent -----------------*/
    void AttackEndEventFunc()
    {
        if (curWeaponName == WeaponNameType.Knife)
        {
            if (attackType == AimAttackType.attacking)
            {
                if (I_BaseData.curStrength > Constant.minKnifeAttackStrength * GlobalData.diffRate)
                {
                    knifeAttacking = true;
                }
                else
                {
                    // 关闭Knife攻击状态
                    if (isBtnADown)
                    {
                        attackType = AimAttackType.aming;
                    }
                    else
                    {
                        attackType = AimAttackType.none;
                    }
                    knifeAttacking = false;
                    ShowAttackAnim(false);
                }
            }
        }
    }
예제 #2
0
 void ReloadCallback()
 {
     if (isBtnADown)
     {
         attackType      = AimAttackType.unknown;
         btnATouchedTime = 0;
     }
 }
예제 #3
0
    float aimAttackBoundaryTime = 0.25f;     // 当在aimAttackBoundaryTime内A的滑动距离超过attackBoundary则本次AimAttackType为attacking,否则为aming。

    new void Awake()
    {
        base.Awake();
        //I_PlayerManager = transform.GetComponent<PlayerManager>();
        I_AimController = transform.GetComponentInChildren <AimController>();
        I_FollowTarget  = GameObject.FindWithTag("MainCamera").transform.GetComponent <FollowTarget>();
        I_KnifeManager  = transform.Find("Weapons").Find("Knife").GetComponent <MeleeWeaponManager>();
        attackType      = AimAttackType.none;
        rb      = self.GetComponent <Rigidbody>();
        uiScope = GameObject.Find("Scope");
    }
예제 #4
0
    /*--------------------- PlayerFaceEvent ---------------------*/

    /*--------------------- AttackDownEvent ---------------------*/
    void AttackDownEventFunc(Vector2 position)
    {
        isBtnADown = true;
        // Reload
        if (curWeaponType == WeaponType.autoDistant || curWeaponType == WeaponType.singleLoader)
        {
            if (leftBullets < 1)
            {
                DistantWeaponManager dstWeaponManager = (DistantWeaponManager)I_Manager.I_WeaponManager;
                MyDelegate.vfv       myCallback       = new MyDelegate.vfv(ReloadCallback);
                dstWeaponManager.Reload(myCallback);
            }
            else
            {
                attackType      = AimAttackType.unknown;
                btnATouchedTime = 0;
            }
        }
        else if (curWeaponType == WeaponType.melee)
        {
            attackType      = AimAttackType.aming;
            btnATouchedTime = 0;
        }
    }
예제 #5
0
    bool inDelayInit = false;      // 是否出在单发枪延迟归位过程中
    void AttackUpEventFunc(float deltaTime)
    {
        ShowAttackAnim(false);
        // RollState状态下不要重置方向
        if (!inRollState)
        {
            stickLDirection = faceDirection;              // 抬手后需要朝当前faceDirection方向射击。
        }

        // 单次攻击
        if (curWeaponType == WeaponType.melee)
        {
            if (attackType != AimAttackType.attacking && I_BaseData.curStrength >= Constant.minKnifeAttackStrength * GlobalData.diffRate)
            {
                AttackOnce();
            }
            knifeAttacking = false;
        }
        else if (curWeaponType == WeaponType.autoDistant)
        {
            if (leftBullets > 0)
            {
                if (focusTarget != null)
                {
                    AttackOnce();
                }
                else
                {
                    if (btnATouchedTime <= aimAttackBoundaryTime && attackType == AimAttackType.unknown)
                    {
                        // 瞬发需要辅助射击
                        AttackOnceAssist();
                        AttackOnce();
                    }
                }
            }
        }
        else if (curWeaponType == WeaponType.singleLoader)
        {
            if (leftBullets > 0)
            {
                if (focusTarget != null)
                {
                    AttackOnce();
                }
                else
                {
                    if (btnATouchedTime <= aimAttackBoundaryTime)
                    {
                        // 瞬发需要辅助射击
                        AttackOnceAssist();
                        AttackOnce();
                    }
                    else if (attackType == AimAttackType.aming)
                    {
                        AttackOnce();
                    }
                }
            }
        }

        // 单发枪朝Enemy开枪后,镜头延迟归位
        if (curWeaponType == WeaponType.singleLoader && curAimTarget != null)
        {
            Invoke("DelayInitAimTarget", 0.5f);
            inDelayInit = true;
        }
        else
        {
            //aimHitPoint = new Vector3(-1000, -1000, -1000);
            curAimTarget = null;
        }
        attackType      = AimAttackType.none;
        btnATouchedTime = 0;
        isBtnADown      = false;
        // 防止下次按下攻击后直接射击
        if (!inRollState)
        {
            faceDirection   = faceDirection.normalized * 0.01f;
            stickLDirection = stickLDirection.normalized * 0.01f;
        }
    }
예제 #6
0
    void LateUpdate()
    {
        if (canControl)
        {
            Vector3 trueMoveDir = moveDir;
            if (trueMoveDir != Vector3.zero && inDelayInit)
            {
                // 在延迟归位过程中,移动Player,则退出延迟归位。
                DelayInitAimTarget();
            }
#if KEYBOARD_CONTROL
            // 人物转向
            Vector3 mouseV = mainCamera.ScreenToWorldPoint(Input.mousePosition) - transform.position;
            mouseV.y = 0;
            //body.rotation = Quaternion.Euler(new Vector3(90, 0, GetAngle(Vector3.right, mouseV)));
            transform.eulerAngles = new Vector3(0, Utils.GetAnglePY(Vector3.forward, mouseV), 0);
            // 攻击状态
            ShowAttackAnim(Input.GetButton("Fire1"));
            if (moveDir.sqrMagnitude < 0.01)
            {
                trueMoveDir = moveDirPC;
            }
#else
            // Player 面朝方向
            if (focusTarget)
            {
                Vector3 player2Target = focusTarget.position - transform.position;
                player2Target.y       = 0;
                transform.eulerAngles = new Vector3(0, Utils.GetAnglePY(Vector3.forward, player2Target), 0);
            }
            else
            {
                Vector3 faceDirection3D = new Vector3(faceDirection.x, 0, faceDirection.y);
                transform.eulerAngles = new Vector3(0, Utils.GetAnglePY(Vector3.forward, faceDirection3D), 0);
            }

            // 攻击状态
            if (focusTarget)
            {
                if (curWeaponType == WeaponType.autoDistant)
                {
                    if (attackType != AimAttackType.none)
                    {
                        if (leftBullets > 0)
                        {
                            // 攻击
                            attackType = AimAttackType.attacking;
                            ShowAttackAnim(true);
                        }
                    }
                }
            }
            else
            {
                if (curWeaponType == WeaponType.singleLoader)
                {
                }
                else if (curWeaponType == WeaponType.melee)
                {
                }
                else if (curWeaponType == WeaponType.autoDistant)
                {
                    float trueAttackBoundary = attackBoundary;
                    if (curAimTarget != null)
                    {
                        // 如果当前有瞄准对象,则降低激发条件
                        trueAttackBoundary *= 0.6f;
                    }
                    else
                    {
                        if (attackType == AimAttackType.aming)
                        {
                            trueAttackBoundary *= atkBoundaryRate;
                        }
                    }
                    if (faceDirection.sqrMagnitude > trueAttackBoundary * trueAttackBoundary && leftBullets > 0)
                    {
                        // 攻击
                        attackType = AimAttackType.attacking;
                        ShowAttackAnim(true);
                    }
                }
            }
            SetRangeAngle();
            SetAimTriangle();
            SetCamera();
            SetScopeCamera();
#endif
            // Move the player
            rb.velocity = Vector3.Lerp(rb.velocity, trueMoveDir * speed, Time.fixedDeltaTime * moveSmooth);
            // 始终以最快速度移动
            //rb.velocity = Vector3.Lerp(rb.velocity, trueMoveDir.normalized * speed, Time.fixedDeltaTime * moveSmooth);
            // 设置状态机
            ShowWalkAnim(rb.velocity.magnitude / speed);
            ChangeAttackSpeed();
            // 改变Leg的朝向
            leg.eulerAngles = new Vector3(-90, Utils.GetAnglePY(Vector3.forward, trueMoveDir), -90);
        }
    }
예제 #7
0
    new void Update()
    {
        base.Update();
        // 增加耐力
        if (!inRollState && !knifeAttacking)
        {
            float delta = Constant.strengthRestoreSpeed * Time.deltaTime;
            I_BaseData.ChangeCurStrength(delta);
        }
        if (!canControl)
        {
            return;
        }
        // 确定武器的攻击状态
        if (attackType != AimAttackType.none)
        {
            btnATouchedTime += Time.deltaTime;
            if (curWeaponType == WeaponType.singleLoader)
            {
                if (faceDirection.sqrMagnitude >= 0.64 * attackBoundary * attackBoundary)
                {
                    attackType = AimAttackType.aming;
                }
                else
                {
                    attackType = AimAttackType.unknown;
                }
            }
            else if (curWeaponType == WeaponType.autoDistant)
            {
                if (attackType == AimAttackType.unknown)
                {
                    if (btnATouchedTime >= aimAttackBoundaryTime)
                    {
                        attackType = AimAttackType.aming;
                    }
                    else
                    {
                        if (faceDirection.sqrMagnitude >= 1.21f * attackBoundary * attackBoundary && leftBullets > 0)
                        {
                            attackType = AimAttackType.attacking;
                            ShowAttackAnim(true);
                        }
                    }
                }
            }
            else if (curWeaponType == WeaponType.melee)
            {
                // 开启Knife攻击状态
                if (I_BaseData.curStrength > Constant.minKnifeAttackStrength * GlobalData.diffRate)
                {
                    if (attackType == AimAttackType.aming)
                    {
                        bool hasEnemy = I_KnifeManager.GetEnemyInRange().Count > 0;
                        if (hasEnemy || faceDirection.sqrMagnitude >= 1.21f * attackBoundary * attackBoundary)
                        {
                            attackType = AimAttackType.attacking;
                            ShowAttackAnim(true);
                            knifeAttacking = true;
                        }
                    }
                }
            }
        }
#if UNITY_EDITOR
        //float x = Input.GetAxisRaw("Horizontal");
        //float y = Input.GetAxisRaw("Vertical");
        //moveDirPC = new Vector3(x, 0, y).normalized;
#endif
    }
예제 #8
0
 void Reset()
 {
     attackType    = AimAttackType.none;
     moveDir       = Vector3.zero;
     faceDirection = transform.forward;
 }