Beispiel #1
0
        private void HandleMultiPlayerLobby()
        {
            try
            {
                if (MultiplayerSession.LobbyContoroller == null || !MultiplayerSession.LobbyContoroller.isActiveAndEnabled || Config.MultiPlayerNumber == 0)
                {
                    return;
                }
                if (MultiplayerSession.LobbyAvatarPlaceList.Count == 0)
                {
                    MultiplayerSession.LoadLobbyAvatarPlace();
                }

                for (int i = 0; i < MultiplayerSession.LobbyAvatarPlaceList.Count; i++)
                {
                    if (i == Config.MultiPlayerNumber - 1)
                    {
                        OffsetPosition = MultiplayerSession.LobbyAvatarPlaceList[i].position;
                        OffsetAngle    = MultiplayerSession.LobbyAvatarPlaceList[i].eulerAngles;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"HandleMultiPlayerLobby Error {ex.Message}", LogLevel.Error);
            }
        }
 private void OnDestroy()
 {
     MultiplayerSession.Close();
     SceneManager.activeSceneChanged -= this.OnActiveSceneChanged;
     Logger.log?.Debug($"{name}: OnDestroy()");
     instance = null; // This MonoBehaviour is being destroyed, so set the static instance property to null.
 }
Beispiel #3
0
 public void OnApplicationQuit()
 {
     MultiplayerSession.Close();
     _harmony.UnpatchAll("com.brian91292.beatsaber.cameraplus");
 }
Beispiel #4
0
        protected IEnumerator DelayedInit()
        {
            yield return(_waitForMainCamera);

            _mainCamera = Camera.main;
            //      _menuStrip = null;
            if (_contextMenu == null)
            {
                MenuObj      = new GameObject("CameraPlusMenu");
                _contextMenu = MenuObj.AddComponent <ContextMenu>();
            }
            XRSettings.showDeviceView = false;


            var gameObj = Instantiate(_mainCamera.gameObject);

            Config.ConfigChangedEvent += PluginOnConfigChangedEvent;

            gameObj.SetActive(false);
            gameObj.name = "Camera Plus";
            gameObj.tag  = "Untagged";
            while (gameObj.transform.childCount > 0)
            {
                DestroyImmediate(gameObj.transform.GetChild(0).gameObject);
            }
            //DestroyImmediate(gameObj.GetComponent(typeof(CameraRenderCallbacksManager)));
            DestroyImmediate(gameObj.GetComponent("AudioListener"));
            DestroyImmediate(gameObj.GetComponent("MeshCollider"));

            _cam = gameObj.GetComponent <Camera>();
            _cam.stereoTargetEye = StereoTargetEyeMask.None;
            _cam.enabled         = true;
            _cam.name            = Path.GetFileName(Config.FilePath);

            var _liv = _cam.GetComponent <LIV.SDK.Unity.LIV>();

            if (_liv)
            {
                Destroy(_liv);
            }

            _screenCamera = new GameObject("Screen Camera").AddComponent <ScreenCameraBehaviour>();
            _screenCamera.isMainCamera = _isMainCamera;
            _screenCamera.Config       = Config;

            if (_previewMaterial == null)
            {
                _previewMaterial = new Material(Shader.Find("Hidden/BlitCopyWithDepth"));
            }

            gameObj.SetActive(true);

            var camera = _mainCamera.transform;

            transform.position = camera.position;
            transform.rotation = camera.rotation;
            Logger.Log($"near clipplane \"{Camera.main.nearClipPlane}");

            gameObj.transform.parent        = transform;
            gameObj.transform.localPosition = Vector3.zero;
            gameObj.transform.localRotation = Quaternion.identity;
            gameObj.transform.localScale    = Vector3.one;

            _cameraCubeGO = GameObject.CreatePrimitive(PrimitiveType.Cube);
            DontDestroyOnLoad(_cameraCubeGO);
            _cameraCubeGO.SetActive(ThirdPerson);
            _cameraCube            = _cameraCubeGO.transform;
            _cameraCube.localScale = new Vector3(0.15f, 0.15f, 0.22f);
            _cameraCube.name       = "CameraCube";
            _cameraCubeGO.layer    = Plugin.Instance._rootConfig.CameraQuadLayer;

            _quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
            DontDestroyOnLoad(_quad);
            DestroyImmediate(_quad.GetComponent <Collider>());
            _quad.GetComponent <MeshRenderer>().material = _previewMaterial;
            _quad.transform.parent           = _cameraCube;
            _quad.transform.localPosition    = new Vector3(-1f * ((_cam.aspect - 1) / 2 + 1), 0, 0.22f);
            _quad.transform.localEulerAngles = new Vector3(0, 180, 0);
            _quad.transform.localScale       = new Vector3(_cam.aspect, 1, 1);
            _cameraPreviewQuad = _quad;
            _quad.layer        = Plugin.Instance._rootConfig.CameraQuadLayer;

            ReadConfig();

            if (ThirdPerson)
            {
                ThirdPersonPos = Config.Position;
                ThirdPersonRot = Config.Rotation;

                transform.position    = ThirdPersonPos;
                transform.eulerAngles = ThirdPersonRot;

                _cameraCube.position    = ThirdPersonPos;
                _cameraCube.eulerAngles = ThirdPersonRot;
            }

            // Add our camera movement script if the movement script path is set
            if (Config.movementScriptPath != String.Empty || Config.songSpecificScript)
            {
                AddMovementScript();
            }

            SetCullingMask();
            CameraMovement.CreateExampleScript();

            Plugin.Instance.ActiveSceneChanged += SceneManager_activeSceneChanged;
            //      FirstPersonOffset = Config.FirstPersonPositionOffset;
            //       FirstPersonRotationOffset = Config.FirstPersonRotationOffset;
            SceneManager_activeSceneChanged(new Scene(), new Scene());
            Logger.Log($"Camera \"{Path.GetFileName(Config.FilePath)}\" successfully initialized! {Convert.ToString(_cam.cullingMask,16)}");

            if (!Plugin.Instance.MultiplayerSessionInit)
            {
                Plugin.Instance.MultiplayerSessionInit = true;
                MultiplayerSession.Init();
            }
        }