Ejemplo n.º 1
0
    public void GetRemotePackets()
    {
        Packet packet;

        while ((packet = Net.ReadPacket()) != null)
        {
            byte[] receiveBuffer = new byte[packet.Size];
            packet.ReadBytes(receiveBuffer);

            int         offset      = 0;
            MessageType messageType = (MessageType)ReadByte(receiveBuffer, ref offset);

            ulong        remoteUserID = ReadULong(receiveBuffer, ref offset);
            RemotePlayer remote       = SocialPlatformManager.GetRemoteUser(remoteUserID);
            if (remote == null)
            {
                SocialPlatformManager.LogOutput("Unknown remote player: " + remoteUserID);
                continue;
            }

            if (messageType == MessageType.Update)
            {
                processAvatarPacket(remote, ref receiveBuffer, ref offset);
            }
            else
            {
                SocialPlatformManager.LogOutput("Invalid packet type: " + packet.Size);
                continue;
            }
        }
    }
Ejemplo n.º 2
0
 public void ConnectTo(ulong userID)
 {
     // ID comparison is used to decide who calls Connect and who calls Accept
     if (SocialPlatformManager.MyID < userID)
     {
         Net.Connect(userID);
         SocialPlatformManager.LogOutput("P2P connect to " + userID);
     }
 }
Ejemplo n.º 3
0
 public void ConnectTo(ulong userID)
 {
     // ID comparison is used to decide who initiates and who gets the Callback
     if (SocialPlatformManager.MyID < userID)
     {
         Voip.Start(userID);
         SocialPlatformManager.LogOutput("Voip connect to " + userID);
     }
 }
Ejemplo n.º 4
0
    void PeerConnectRequestCallback(Message <NetworkingPeer> msg)
    {
        SocialPlatformManager.LogOutput("P2P request from " + msg.Data.ID);

        RemotePlayer remote = SocialPlatformManager.GetRemoteUser(msg.Data.ID);

        if (remote != null)
        {
            SocialPlatformManager.LogOutput("P2P request accepted from " + msg.Data.ID);
            Net.Accept(msg.Data.ID);
        }
    }
Ejemplo n.º 5
0
    void VoipConnectRequestCallback(Message <Oculus.Platform.Models.NetworkingPeer> msg)
    {
        SocialPlatformManager.LogOutput("Voip request from " + msg.Data.ID);

        RemotePlayer remote = SocialPlatformManager.GetRemoteUser(msg.Data.ID);

        if (remote != null)
        {
            SocialPlatformManager.LogOutput("Voip request accepted from " + msg.Data.ID);
            Voip.Accept(msg.Data.ID);
        }
    }
Ejemplo n.º 6
0
    void RoomUpdateCallback(Message <Room> msg)
    {
        if (msg.IsError)
        {
            SocialPlatformManager.TerminateWithError(msg);
            return;
        }

        var ownerOculusId = msg.Data.OwnerOptional != null ? msg.Data.OwnerOptional.OculusID : "null";
        var userCount     = msg.Data.UsersOptional != null ? msg.Data.UsersOptional.Count : 0;

        SocialPlatformManager.LogOutput("Room Update " + msg.Data.ID + " owner: " + ownerOculusId + " count: " + userCount);
        ProcessRoomData(msg);
    }
Ejemplo n.º 7
0
    void JoinRoomCallback(Message <Room> msg)
    {
        if (msg.IsError)
        {
            // is reasonable if caller called more than 1 person, and I didn't answer first
            return;
        }

        var ownerOculusId = msg.Data.OwnerOptional != null ? msg.Data.OwnerOptional.OculusID : "null";
        var userCount     = msg.Data.UsersOptional != null ? msg.Data.UsersOptional.Count : 0;

        SocialPlatformManager.LogOutput("Joined Room " + msg.Data.ID + " owner: " + ownerOculusId + " count: " + userCount);
        roomID = msg.Data.ID;
        ProcessRoomData(msg);
    }
Ejemplo n.º 8
0
    void InitCallback(Message <PlatformInitialize> msg)
    {
        if (msg.IsError)
        {
            TerminateWithError(msg);
            return;
        }

        LaunchDetails launchDetails = ApplicationLifecycle.GetLaunchDetails();

        SocialPlatformManager.LogOutput("App launched with LaunchType " + launchDetails.LaunchType);

        // First thing we should do is perform an entitlement check to make sure
        // we successfully connected to the Oculus Platform Service.
        Entitlements.IsUserEntitledToApplication().OnComplete(IsEntitledCallback);
    }
Ejemplo n.º 9
0
    // Callback to check whether the User accepted an invite
    void AcceptingInviteCallback(Message <string> msg)
    {
        if (msg.IsError)
        {
            SocialPlatformManager.TerminateWithError(msg);
            return;
        }

        SocialPlatformManager.LogOutput("Launched Invite to join Room: " + msg.Data);

        invitedRoomID = Convert.ToUInt64(msg.GetString());

        if (startupDone)
        {
            CheckForInvite();
        }
    }
Ejemplo n.º 10
0
    void VoipStateChangedCallback(Message <Oculus.Platform.Models.NetworkingPeer> msg)
    {
        SocialPlatformManager.LogOutput("Voip state to " + msg.Data.ID + " changed to  " + msg.Data.State);

        RemotePlayer remote = SocialPlatformManager.GetRemoteUser(msg.Data.ID);

        if (remote != null)
        {
            remote.voipConnectionState = msg.Data.State;

            // ID comparison is used to decide who initiates and who gets the Callback
            if (msg.Data.State == PeerConnectionState.Timeout && SocialPlatformManager.MyID < msg.Data.ID)
            {
                // keep trying until hangup!
                Voip.Start(msg.Data.ID);
                SocialPlatformManager.LogOutput("Voip re-connect to " + msg.Data.ID);
            }
        }
    }
Ejemplo n.º 11
0
    void ConnectionStateChangedCallback(Message <NetworkingPeer> msg)
    {
        SocialPlatformManager.LogOutput("P2P state to " + msg.Data.ID + " changed to  " + msg.Data.State);

        RemotePlayer remote = SocialPlatformManager.GetRemoteUser(msg.Data.ID);

        if (remote != null)
        {
            remote.p2pConnectionState = msg.Data.State;

            if (msg.Data.State == PeerConnectionState.Timeout &&
                // ID comparison is used to decide who calls Connect and who calls Accept
                SocialPlatformManager.MyID < msg.Data.ID)
            {
                // keep trying until hangup!
                Net.Connect(msg.Data.ID);
                SocialPlatformManager.LogOutput("P2P re-connect to " + msg.Data.ID);
            }
        }
    }
Ejemplo n.º 12
0
    void GetLoggedInUserFriendsAndRoomsCallback(Message <UserAndRoomList> msg)
    {
        if (msg.IsError)
        {
            return;
        }

        foreach (UserAndRoom el in msg.Data)
        {
            // see if any friends are in a joinable room
            if (el.User == null)
            {
                continue;
            }
            if (el.RoomOptional == null)
            {
                continue;
            }
            if (el.RoomOptional.IsMembershipLocked == true)
            {
                continue;
            }
            if (el.RoomOptional.Joinability != RoomJoinability.CanJoin)
            {
                continue;
            }
            if (el.RoomOptional.JoinPolicy == RoomJoinPolicy.None)
            {
                continue;
            }

            SocialPlatformManager.LogOutput("Trying to join room " + el.RoomOptional.ID + ", friend " + el.User.OculusID);
            roomManager.JoinExistingRoom(el.RoomOptional.ID);
            return;
        }

        SocialPlatformManager.LogOutput("No friend to join. Creating my own room.");
        // didn't find any open rooms, start a new room
        roomManager.CreateRoom();
        TransitionToState(State.CREATING_A_ROOM);
    }
Ejemplo n.º 13
0
    void GetLoggedInUserCallback(Message <User> msg)
    {
        if (msg.IsError)
        {
            TerminateWithError(msg);
            return;
        }

        myID       = msg.Data.ID;
        myOculusID = msg.Data.OculusID;

        localAvatar = Instantiate(localAvatarPrefab);
        localAvatar.CanOwnMicrophone = false;
        localTrackingSpace           = this.transform.Find("OVRCameraRig/TrackingSpace").gameObject;

        localAvatar.transform.SetParent(localTrackingSpace.transform, false);
        localAvatar.transform.localPosition = new Vector3(0, 0, 0);
        localAvatar.transform.localRotation = Quaternion.identity;

        if (UnityEngine.Application.platform == RuntimePlatform.Android)
        {
            helpPanel.transform.SetParent(localAvatar.transform.Find("body"), false);
            helpPanel.transform.localPosition = new Vector3(0, 1.0f, 1.0f);
            helpMesh.material = gearMaterial;
        }
        else
        {
            helpPanel.transform.SetParent(localAvatar.transform.Find("hand_left"), false);
            helpPanel.transform.localPosition = new Vector3(0, 0.2f, 0.2f);
            helpMesh.material = riftMaterial;
        }

        localAvatar.oculusUserID               = myID.ToString();
        localAvatar.RecordPackets              = true;
        localAvatar.PacketRecorded            += OnLocalAvatarPacketRecorded;
        localAvatar.EnableMouthVertexAnimation = true;

        Quaternion rotation = Quaternion.identity;

        switch (UnityEngine.Random.Range(0, 4))
        {
        case 0:
            rotation.eulerAngles         = START_ROTATION_ONE;
            this.transform.localPosition = START_POSITION_ONE;
            this.transform.localRotation = rotation;
            break;

        case 1:
            rotation.eulerAngles         = START_ROTATION_TWO;
            this.transform.localPosition = START_POSITION_TWO;
            this.transform.localRotation = rotation;
            break;

        case 2:
            rotation.eulerAngles         = START_ROTATION_THREE;
            this.transform.localPosition = START_POSITION_THREE;
            this.transform.localRotation = rotation;
            break;

        case 3:
        default:
            rotation.eulerAngles         = START_ROTATION_FOUR;
            this.transform.localPosition = START_POSITION_FOUR;
            this.transform.localRotation = rotation;
            break;
        }

        TransitionToState(State.CHECKING_LAUNCH_STATE);

        // If the user launched the app by accepting the notification, then we want to
        // join that room.  If not, try to find a friend's room to join
        if (!roomManager.CheckForInvite())
        {
            SocialPlatformManager.LogOutput("No invite on launch, looking for a friend to join.");
            Users.GetLoggedInUserFriendsAndRooms()
            .OnComplete(GetLoggedInUserFriendsAndRoomsCallback);
        }
        Voip.SetMicrophoneFilterCallback(MicFilter);
    }