Пример #1
0
    private void HandleCombatAnimations()
    {
        if (m_PlayerCombatHandler == null)
        {
            return;
        }

        if (m_PlayerCombatHandler.GetAttackedInCurrentFrame())
        {
            m_Animator.SetTrigger("Attack");
            return;
        }

        if (m_PlayerMovement.DodgedBackwardsInCurrentFrame())
        {
            m_Animator.SetTrigger("Backstep");
            return;
        }

        if (m_PlayerMovement.DodgedInCurrentFrame())
        {
            m_Animator.SetTrigger("Roll");
            return;
        }

        m_Animator.SetBool("Block", m_PlayerCombatHandler.IsBlocking());
    }
Пример #2
0
    private void Update()
    {
        if (m_PlayerNetworkObject == null)
        {
            return;
        }

        if (m_PlayerNetworkObject.IsOwner)
        {
            if (m_PlayerMovement == null || m_PlayerAnimation == null || m_HealthHandler == null || m_PlayerStance == null)
            {
                Debug.LogWarning("Movement/Animation/Health/Stance script not found on local player");
                return;
            }

            // Send movement state
            m_PlayerNetworkObject.position = transform.position;
            m_PlayerNetworkObject.rotation = transform.rotation;

            // Send animation state
            m_PlayerNetworkObject.axisDelta    = m_PlayerMovement.GetInputAxis();
            m_PlayerNetworkObject.vertVelocity = m_PlayerMovement.GetVelocity().y;
            m_PlayerNetworkObject.grounded     = m_PlayerMovement.IsGrounded();

            // Combat states
            m_PlayerNetworkObject.weaponIndex = (int)m_PlayerStance.GetStance();
            m_PlayerNetworkObject.blocked     = m_PlayerCombatHandler.IsBlocking();
            m_PlayerNetworkObject.skillIndex  = m_SkillHandler.GetCurrentActiveSkill();

            // Fun misc
            if (m_PlayerAnimationLookat != null)
            {
                m_PlayerNetworkObject.lookatDir = m_PlayerAnimationLookat.GetLookatDirection();
            }

            if (m_PlayerCombatHandler.GetAttackedInCurrentFrame())
            {
                Debug.Assert(m_PlayerNetworkObject.weaponIndex != 0, "Attacking unarmed, wtf?");
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_ATTACK, Receivers.All);
            }

            if (m_PlayerMovement.DodgedBackwardsInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_BACK_DASH, Receivers.All);
            }
            else if (m_PlayerMovement.DodgedInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_DASH, Receivers.All);
            }


            if (m_PlayerMovement.JumpedInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_JUMP, Receivers.All);
            }

            // Send health state
            if (m_HealthHandler.DamagedInCurrentFrame())
            {
                m_PlayerNetworkObject.SendRpc(Player.RPC_TRIGGER_DAMAGED, Receivers.All);
            }
        }
        else
        {
            // Receive movement state
            transform.position = m_PlayerNetworkObject.position;
            transform.rotation = m_PlayerNetworkObject.rotation;

            // Receive animation state
            if (m_Animator == null)
            {
                Debug.LogWarning("Animator does not exist on player");
                return;
            }
            m_Animator.SetFloat("Velocity-XZ-Normalized-01", m_PlayerNetworkObject.axisDelta.magnitude);
            m_Animator.SetFloat("Velocity-X-Normalized", m_PlayerNetworkObject.axisDelta.x);
            m_Animator.SetFloat("Velocity-Z-Normalized", m_PlayerNetworkObject.axisDelta.y);
            m_Animator.SetFloat("Velocity-Y-Normalized", m_PlayerNetworkObject.vertVelocity);
            m_Animator.SetBool("Grounded", m_PlayerNetworkObject.grounded);
            m_Animator.SetInteger("WeaponIndex", m_PlayerNetworkObject.weaponIndex);
            m_Animator.SetBool("Block", m_PlayerNetworkObject.blocked);
            m_Animator.SetInteger("SkillsIndex", m_PlayerNetworkObject.skillIndex);

            // Show and hide sword
            // TODO: add delay or make it work with animation callbacks
            m_Player.SetWeaponActive(m_PlayerNetworkObject.weaponIndex != 0);

            // Misc
            if (m_PlayerAnimationLookat != null)
            {
                m_PlayerAnimationLookat?.SetLookatDirection(m_PlayerNetworkObject.lookatDir);
                m_PlayerAnimationLookat?.SetLookatType(PlayerAnimationLookat.LookAtType.LOOKAT_NETWORKED);
            }
        }
    }