public void HandleDisconnect(DisconnectCause cause) { VRDF_Components.DebugVRDFMessage("Trying to rejoin the server ..."); switch (cause) { case DisconnectCause.Exception: case DisconnectCause.ServerTimeout: case DisconnectCause.ClientTimeout: case DisconnectCause.DisconnectByServerLogic: case DisconnectCause.AuthenticationTicketExpired: case DisconnectCause.DisconnectByServerReasonUnknown: TryToReconnect(); break; case DisconnectCause.OperationNotAllowedInCurrentState: case DisconnectCause.CustomAuthenticationFailed: case DisconnectCause.DisconnectByClientLogic: case DisconnectCause.InvalidAuthentication: case DisconnectCause.ExceptionOnConnect: case DisconnectCause.MaxCcuReached: case DisconnectCause.InvalidRegion: case DisconnectCause.None: break; default: throw new ArgumentOutOfRangeException("cause", cause, "cause not supported"); } }
/// <summary> /// Event raised when we want to create or join a room /// </summary> /// <param name="roomName">The name of the room we wanna create / join. Can be Empty if joining random room.</param> /// <param name="roomOptions">Contains the parameters for the room we want to create. Let it at null if you want to join a room</param> /// <param name="roomNeedCreation">Is the user joining a room or do we need to create it ?</param> /// <param name="connectToRandomRoom">Do you want to connect to a random room ?</param> public static void ConnectOrCreateRoom(string roomName, RoomOptions roomOptions = null, bool roomNeedCreation = true, bool connectToRandomRoom = false) { if (!PhotonNetwork.IsConnectedAndReady) { VRDF_Components.DebugVRDFMessage("You are NOT connected to the Photon Servers. Call one of the PhotonNetwork.Connect method before trying to create / join a room.", true); return; } if (roomNeedCreation) { if (!PhotonNetwork.InLobby || !RoomListFetcher.AvailableRooms.ContainsKey(roomName)) { VRDF_Components.DebugVRDFMessage("Trying to create a Room with name: {0}.", debugParams: roomName); // #Critical we need at this point to create a Room. PhotonNetwork.CreateRoom(roomName, roomOptions); } else { VRDF_Components.DebugVRDFMessage("Room with name {0} already exists, can't create it. Joining instead.", debugParams: roomName); JoinRoom(connectToRandomRoom, roomName); } } else { JoinRoom(connectToRandomRoom, roomName); } }
/// <summary> /// Only check if the _showConsoleMessages is set at true, and if so, display a message in the Console. /// </summary> /// <param name="message">The message to display in the console</param> /// <param name="isErrorMessage">Is this message supposed to be an error ?</param> /// <param name="debugParams">the parameters to put at the end of the Debug.LogFormat</param> private void DebugMessage(string message, bool isErrorMessage = false, params object[] debugParams) { if (_showConsoleMessages) { VRDF_Components.DebugVRDFMessage(message, isErrorMessage, debugParams); } }
/// <summary> /// Setup the LocalPlayer instance Transform /// </summary> private void AddFollowerScripts() { // Add the follower scripts for the Camera, RightController and LeftController AddFollowerScript(LocalPlayerGameObjectInstance, VRDF_Components.VRCamera.transform); TryGetObjectWithName("RightController", VRDF_Components.RightController.transform); TryGetObjectWithName("LeftController", VRDF_Components.LeftController.transform); /// <summary> /// Try to fetch an object under the LocalPlayerInstance using a name. If found, we add a FollowerScript to it. /// </summary> void TryGetObjectWithName(string objectName, Transform toFollow) { var toLookFor = LocalPlayerGameObjectInstance.transform.Find(objectName); if (toLookFor == null) { VRDF_Components.DebugVRDFMessage("Couldn't find object with name {0} under the Local Player Instance. Not adding any Follower Script.", true, objectName); } else { AddFollowerScript(toLookFor.gameObject, toFollow); } } /// <summary> /// Add a VRDFTransformFollower to the transToFollow object, so it can follow the position and rotation of the toFollow object /// </summary> void AddFollowerScript(GameObject transToFollow, Transform toFollow) { VRDFTransformFollower transFollower = transToFollow.AddComponent <VRDFTransformFollower>(); transFollower.ToFollow = toFollow; } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (!VRDF_Components.SetupVRIsReady) { return(inputDeps); } NativeArray <float3> rotationAxisOutput = new NativeArray <float3>(1, Allocator.TempJob); NativeArray <float> currentSpeedOutput = new NativeArray <float>(1, Allocator.TempJob); var job = new RotationJob { DeltaTime = Time.DeltaTime, RotationAxis = rotationAxisOutput, CurrentSpeed = currentSpeedOutput }.Schedule(this, inputDeps); job.Complete(); VRDF_Components.RotateVRCameraAround(rotationAxisOutput[0], currentSpeedOutput[0]); rotationAxisOutput.Dispose(); currentSpeedOutput.Dispose(); return(inputDeps); }
public override void OnConnectedToMaster() { if (TriedToReconnect) { VRDF_Components.DebugVRDFMessage("<Color=green>Reconnection successful !</Color>"); TriedToReconnect = false; } }
/// <summary> /// Callback for when a room was correctly created. /// </summary> public override void OnCreatedRoom() { if (_loadSceneOnRoomCreated && !TryToLoadMultiplayerScene()) { VRDF_Components.DebugVRDFMessage("Can't load the Multiplayer Scene. Check the name and index of your multiplayer scene, and be sure that this scene was added in the Build Settings. Stopping app.", true); Application.Quit(); } }
protected virtual void Start() { // in case we started this demo with the wrong scene being active, simply load the connection scene if (!PhotonNetwork.IsConnectedAndReady) { VRDF_Components.DebugVRDFMessage("You're not connected to the Photon Network ! Sending back to Connection Scene.", true); SceneManager.LoadScene(_connectionSceneName); } }
/// <summary> /// Photon callback for when the room was rejoined /// </summary> public override void OnJoinedRoom() { _tokenSource?.Cancel(true); if (TriedToReconnect) { VRDF_Components.DebugVRDFMessage("<Color=green>Rejoin successful !</Color>"); TriedToReconnect = false; } }
/// <summary> /// Instantiate the local player using PhotonNetwork.Instantiate. /// Only needs to be done localy, as Photon automatically instantiate a Player GameObject for the remote players. /// </summary> private void InstantiateLocalPlayer() { if (_playersPrefab == null) { VRDF_Components.DebugVRDFMessage("Missing playerPrefab Reference in VRDFPlayerInstantiater, can't instantiate local player.", true); } else { VRDFPlayerManager.LocalPlayerGameObjectInstance = PhotonNetwork.Instantiate(_playerPrefabName, Vector3.zero, Quaternion.identity); } }
protected virtual void Awake() { if (Instance != null) { VRDF_Components.DebugVRDFMessage("Another instance of VRDFConnectionManager exist. Be sure to only have one VRDFConnectionManager in your Scene.", true); Destroy(this); return; } Instance = this; }
/// <summary> /// Method called to join a room, simply call PhotonNetwork.JoinRandomRoom or PhotonNetwork.JoinRoom. /// </summary> /// <param name="connectToRandomRoom">Do you want to join a random room ?</param> /// <param name="roomName">The name of the room we want to join. Can be let empty if joining random room.</param> public static void JoinRoom(bool connectToRandomRoom = true, string roomName = "") { if (connectToRandomRoom) { VRDF_Components.DebugVRDFMessage("Joining Random Room"); PhotonNetwork.JoinRandomRoom(); } else { VRDF_Components.DebugVRDFMessage("Joining Room {0}", debugParams: roomName); PhotonNetwork.JoinRoom(roomName); } }
/// <summary> /// Try to load a scene based on its name /// </summary> /// <returns>true if the scene was correctly loaded</returns> public bool TryToLoadMultiplayerScene() { try { VRDF_Components.DebugVRDFMessage("Trying to load the scene with name '{0}'.", debugParams: MultiplayerSceneName); PhotonNetwork.LoadLevel(MultiplayerSceneName); return(true); } catch { VRDF_Components.DebugVRDFMessage("Couldn't load scene with name '{0}'.", true, MultiplayerSceneName); return(false); } }
/// <summary> /// Whenever the user is disconnected from the Server and he already tried to reconnect, /// we either try one more time or send him back to the connection scene if he isn't there already. /// </summary> /// <returns>Whether or not we try to reconnect again when existing this method</returns> public override bool OnReconnectionFailed() { VRDF_Components.DebugVRDFMessage("Reconnect failed, client disconnected.", true); if (RetryToReconnectOnFail) { VRDF_Components.DebugVRDFMessage("Trying to reconnect one more time."); TriedToReconnect = PhotonNetwork.Reconnect(); return(true); } else { return(false); } }
/// <summary> /// Whenever the user is disconnected from the room and he already tried to rejoin, /// we either try one more time or send him back to the connection scene. /// </summary> /// <returns>Whether or not we can start the DisconnectionWaitingThread when exiting this method.</returns> public override bool OnReconnectionFailed() { VRDF_Components.DebugVRDFMessage("Rejoin has failed, the client is still disconnected.", true); if (RetryToReconnectOnFail) { VRDF_Components.DebugVRDFMessage("Trying to rejoin one more time."); TriedToReconnect = PhotonNetwork.ReconnectAndRejoin(); return(true); } else { SendBackUserToConnectionRoom(); return(false); } }
protected override void OnUpdate() { Entities.ForEach((Entity teleportEntity, ref CurveTeleporterCalculations ctc, ref ParabolPointsParameters ppp, ref ParabolCalculations parabolCalc, ref GeneralTeleportParameters gtp, ref TeleportNavMesh tnm, ref VRRaycastParameters raycastParam) => { if (gtp.CurrentTeleportState == ETeleportState.Selecting) { NativeArray <Translation> pointsTranslation = new NativeArray <Translation>(ppp.PointCount, Allocator.Temp); Transform controller = parabolCalc.Origin == Core.Controllers.EHand.LEFT ? VRDF_Components.LeftController.transform : VRDF_Components.RightController.transform; // Calculate Parabola Points parabolCalc.Velocity = ParaboleCalculationsHelper.ForceUpdateCurrentAngle(ctc, controller.TransformDirection(ctc.InitialVelocity)); parabolCalc.Normal = ParaboleCalculationsHelper.ParabolaPointsCalculations(ref pointsTranslation, ref ctc, ppp, tnm, controller.position, raycastParam.ExcludedLayer, parabolCalc.Velocity); var index = 0; Entities.WithAll <ParabolPointTag>().ForEach((Entity point, ref Translation translation) => { if (_entityManager.GetSharedComponentData <ParabolPointParent>(point).TeleporterEntityIndex == teleportEntity.Index) { translation.Value = pointsTranslation[index].Value; index++; } }); pointsTranslation.Dispose(); } else if (gtp.CurrentTeleportState == ETeleportState.Teleporting && !gtp.HasTeleported) { if (ctc.PointOnNavMesh || ctc.PointOnTeleportableLayer) { if (gtp.IsUsingFadingEffect) { OnFadingOutEndedEvent.Listeners += TeleportUser; _tempPointToGoTo = ctc.PointToGoTo; new StartFadingOutEvent(true); } else { VRDF_Components.SetVRCameraPosition(ctc.PointToGoTo); } } gtp.HasTeleported = true; } }); }
protected virtual void Awake() { if (Instance != null) { VRDF_Components.DebugVRDFMessage("Another instance of VRDFConnectionManager exist. Be sure to only have one VRDFConnectionManager in your Scene.", true); Destroy(this); return; } Instance = this; PhotonNetwork.AutomaticallySyncScene = _automaticallySyncScene; // Check for when the user just left a room and is coming back to the Connection Scene if (!PhotonNetwork.IsConnectedAndReady) { // Connect to Photon Online Server VRDF_Components.DebugVRDFMessage("Connecting with Photon Server ..."); PhotonNetwork.ConnectUsingSettings(); } }
protected override void OnUpdate() { if (!VRDF_Components.SetupVRIsReady) { return; } Entities.ForEach((ref NonLinearUserRotation nlur, ref ControllersInteractionType cit, ref BaseInputCapture bic, ref TouchpadInputCapture tic, ref InteractionThumbPosition itp) => { if (!nlur.HasAlreadyRotated && InteractionChecker.IsInteractingTouchpad(bic, cit, itp, tic)) { VRDF_Components.RotateVRCameraAround(new float3(0.0f, tic.ThumbPosition.x, 0.0f), nlur.DegreesToRotate); nlur.HasAlreadyRotated = true; } else if (nlur.HasAlreadyRotated && InteractionChecker.IsNotInteractingTouchpad(bic, cit, itp, tic)) { nlur.HasAlreadyRotated = false; } }); }
static void InstantiateGameManager(MenuCommand menuCommand) { var connectionManager = FindObjectOfType <VRDFMultiplayerGameManager>(); if (connectionManager != null) { VRDF_Components.DebugVRDFMessage("A VRDFMultiplayerGameManager script is already in your scene, no need for a second one !", true); Selection.activeObject = connectionManager; return; } // Create a custom game object GameObject newMultiObject = (GameObject)PrefabUtility.InstantiatePrefab(VRDFPrefabReferencer.GetPrefab("VRDFMultiplayerGameManager")); // Ensure it gets reparented if this was a context click (otherwise does nothing) GameObjectUtility.SetParentAndAlign(newMultiObject, menuCommand.context as GameObject); // Register the creation in the undo system Undo.RegisterCreatedObjectUndo(newMultiObject, "Create " + newMultiObject.name); Selection.activeObject = newMultiObject; }
/// <summary> /// Check for each GameObject that the field set in editor is correct, and if not, look for those object using a tag /// </summary> private void SetVRDFComponents() { VRDF_Components.CameraRig = CheckProvidedGameObject(_cameraRig, "RESERVED_CameraRig"); VRDF_Components.FloorOffset = CheckProvidedGameObject(_floorOffset, "Floor_Offset"); VRDF_Components.VRCamera = CheckProvidedGameObject(_vrCamera, "MainCamera"); VRDF_Components.LeftController = CheckProvidedGameObject(_leftController, "RESERVED_LeftController"); VRDF_Components.RightController = CheckProvidedGameObject(_rightController, "RESERVED_RightController"); VRDF_Components.SetVRCameraPosition(_cameraRig.transform.position); GameObject CheckProvidedGameObject(GameObject toCheck, string tag) { // We set the references to the Right COntroller if (toCheck == null) { Debug.LogErrorFormat("<b>[VRDF] :</b> No {0} was references in VRObjectsAuthoring. Trying to fetch it using tag {1}.", toCheck.transform.name, tag, gameObject); toCheck = GameObject.FindGameObjectWithTag(tag); } return(toCheck); } }
private void TeleportUser(OnFadingOutEndedEvent info) { OnFadingOutEndedEvent.Listeners -= TeleportUser; VRDF_Components.SetVRCameraPosition(_tempPointToGoTo); }