void InitializeAvatars()
    {
        for (int i = 0; i < Constants.MaxClients; ++i)
        {
            RemoteAvatar remoteAvatar = GetRemoteAvatar(i);

            if (!remoteAvatar)
            {
                continue;
            }

            remoteAvatar.SetContext(this);
            remoteAvatar.SetClientIndex(i);
        }
    }
    public void RemoteGrip(RemoteAvatar avatar, RemoteAvatar.Hand hand, int clientId)
    {
        Assert.IsTrue(clientId != context.clientId);
        Release();
        var body = gameObject.GetComponent <Rigidbody>();

        hand.grip             = gameObject;
        body.isKinematic      = true;
        body.detectCollisions = false;
        gameObject.transform.SetParent(hand.transform, true);
        remoteAvatar = avatar;
        remoteHand   = hand;
        holderId     = clientId;
        authorityId  = clientId + 1;
        avatar.CubeAttached(ref hand);
    }
Exemple #3
0
    /*
     * Attach cube to remote player
     */

    public void AttachCubeToRemotePlayer(RemoteAvatar avatar, RemoteAvatar.HandData hand, int clientIndex)
    {
        Assert.IsTrue(clientIndex != m_context.GetClientIndex());

        DetachCubeFromPlayer();

        hand.gripObject = gameObject;

        var rigidBody = gameObject.GetComponent <Rigidbody>();

        rigidBody.isKinematic      = true;
        rigidBody.detectCollisions = false;

        gameObject.transform.SetParent(hand.transform, true);

        m_remoteAvatar    = avatar;
        m_remoteHand      = hand;
        m_holdClientIndex = clientIndex;
        m_authorityIndex  = clientIndex + 1;

        avatar.CubeAttached(ref hand);
    }
    /*
     * Detach cube from any player who is holding it (local or remote).
     */
    public void Release()
    {
        if (!HasHolder())
        {
            return;
        }

        if (localAvatar)
        {
            localAvatar.DetachCube(ref localHand);
            touching.GetComponent <BoxCollider>().isTrigger = true;
        }

        if (remoteAvatar)
        {
            remoteAvatar.DetachCube(ref remoteHand);
        }

        localAvatar  = null;
        localHand    = null;
        remoteHand   = null;
        remoteAvatar = null;
        holderId     = Nobody;
    }
 public bool HeldBy(RemoteAvatar avatar, RemoteAvatar.Hand hand) => remoteAvatar == avatar && remoteHand == hand;
Exemple #6
0
    public static void ApplyRightHandUpdate(ref AvatarState state, int clientIndex, Context context, RemoteAvatar remoteAvatar)
    {
        Assert.IsTrue(clientIndex == state.client_index);

        if (state.right_hand_holding_cube)
        {
            GameObject cube = context.GetCube(state.right_hand_cube_id);

            var networkInfo = cube.GetComponent <NetworkInfo>();

            if (!networkInfo.IsHeldByRemotePlayer(remoteAvatar, remoteAvatar.GetRightHand()))
            {
                networkInfo.AttachCubeToRemotePlayer(remoteAvatar, remoteAvatar.GetRightHand(), state.client_index);
            }

            networkInfo.SetAuthoritySequence(state.right_hand_authority_sequence);
            networkInfo.SetOwnershipSequence(state.right_hand_ownership_sequence);

            networkInfo.MoveWithSmoothingLocal(state.right_hand_cube_local_position, state.right_hand_cube_local_rotation);
        }
    }
    public static void UpdateRightHand(ref AvatarState s, int clientId, Context context, RemoteAvatar avatar)
    {
        Assert.IsTrue(clientId == s.clientId);
        if (!s.isRightHandHoldingCube)
        {
            return;
        }

        var cube = context.cubes[s.rightHandCubeId].GetComponent <NetworkCube>();

        if (!cube.HeldBy(avatar, avatar.GetRightHand()))
        {
            cube.RemoteGrip(avatar, avatar.GetRightHand(), s.clientId);
        }

        cube.authorityPacketId = s.rightHandAuthorityId;
        cube.ownershipId       = s.rightHandOwnershipId;
        cube.LocalSmoothMove(s.rightHandCubeLocalPosition, s.rightHandCubeLocalRotation);
    }
Exemple #8
0
 public bool IsHeldByRemotePlayer(RemoteAvatar remoteAvatar, RemoteAvatar.HandData hand)
 {
     return(m_remoteAvatar == remoteAvatar && m_remoteHand == hand);
 }