public virtual void Awake() { LogOutputLine("Start Log."); // Grab the MeshRenderers. We'll be using the material colour to visually show status helpMesh = helpPanel.GetComponent <MeshRenderer>(); sphereMesh = roomSphere.GetComponent <MeshRenderer>(); floorMesh = roomFloor.GetComponent <MeshRenderer>(); // Set up the local player localTrackingSpace = this.transform.Find("OVRCameraRig/TrackingSpace").gameObject; localPlayerHead = this.transform.Find("OVRCameraRig/TrackingSpace/CenterEyeAnchor").gameObject; // make sure only one instance of this manager ever exists if (s_instance != null) { Destroy(gameObject); return; } s_instance = this; DontDestroyOnLoad(gameObject); TransitionToState(State.INITIALIZING); Core.AsyncInitialize().OnComplete(InitCallback); roomManager = new RoomManager(); p2pManager = new P2PManager(); voipManager = new VoipManager(); }
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; } } }
void OnLaunchInviteWorkflowComplete(Message msg) { if (msg.IsError) { SocialPlatformManager.TerminateWithError(msg); return; } }
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); } }
public void LeaveCurrentRoom() { if (roomID != 0) { Rooms.Leave(roomID); roomID = 0; } SocialPlatformManager.TransitionToState(SocialPlatformManager.State.LEAVING_A_ROOM); }
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); } }
void InitializeComponents() { Application.targetFrameRate = 30; settings = new SettingsManager(); socialPlat = new SocialPlatformManager(); adManager = new AdManager(this); soundManager = GetComponentInChildren <SoundManager>(); assetManager = GetComponentInChildren <AssetManager>(); LoadLevelData(); LoadUnlockData(); }
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); } }
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); } }
void Awake() { if (!instance) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } }
public void Disconnect(ulong userID) { if (userID != 0) { Net.Close(userID); RemotePlayer remote = SocialPlatformManager.GetRemoteUser(userID); if (remote != null) { remote.p2pConnectionState = PeerConnectionState.Unknown; } } }
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); }
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); }
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); }
// 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(); } }
void ProcessRoomData(Message <Room> msg) { if (msg.Data.OwnerOptional != null && msg.Data.OwnerOptional.ID == SocialPlatformManager.MyID) { amIServer = true; } else { amIServer = false; } // if the caller left while I was in the process of joining, just use that as our new room if (msg.Data.UsersOptional != null && msg.Data.UsersOptional.Count == 1) { SocialPlatformManager.TransitionToState(SocialPlatformManager.State.WAITING_IN_A_ROOM); } else { SocialPlatformManager.TransitionToState(SocialPlatformManager.State.CONNECTED_IN_A_ROOM); } // Look for users that left SocialPlatformManager.MarkAllRemoteUsersAsNotInRoom(); if (msg.Data.UsersOptional != null) { foreach (User user in msg.Data.UsersOptional) { if (user.ID != SocialPlatformManager.MyID) { if (!SocialPlatformManager.IsUserInRoom(user.ID)) { SocialPlatformManager.AddRemoteUser(user.ID); } else { SocialPlatformManager.MarkRemoteUserInRoom(user.ID); } } } } SocialPlatformManager.ForgetRemoteUsersNotInRoom(); SocialPlatformManager.SetFloorColorForState(amIServer); }
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); } } }
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); } } }
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); }
void CreateAndJoinPrivateRoomCallback(Message <Room> msg) { if (msg.IsError) { SocialPlatformManager.TerminateWithError(msg); return; } roomID = msg.Data.ID; if (msg.Data.OwnerOptional != null && msg.Data.OwnerOptional.ID == SocialPlatformManager.MyID) { amIServer = true; } else { amIServer = false; } SocialPlatformManager.TransitionToState(SocialPlatformManager.State.WAITING_IN_A_ROOM); SocialPlatformManager.SetFloorColorForState(amIServer); }
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); }
public void JoinExistingRoom(ulong roomID) { SocialPlatformManager.TransitionToState(SocialPlatformManager.State.JOINING_A_ROOM); Rooms.Join(roomID, true).OnComplete(JoinRoomCallback); }