Ejemplo n.º 1
0
        private void Start()
        {
            if (PluginConfig.Instance.ScreenFillBlack)
            {
                _renderTexture         = new RenderTexture(Screen.width, Screen.height, 24);
                _screenCameraBehaviour = this.gameObject.AddComponent <ScreenCameraBehaviour>();
                _screenCameraBehaviour.SetCameraInfo(new Vector2(0, 0), new Vector2(Screen.width, Screen.height), -2000);
                _screenCameraBehaviour.SetRenderTexture(_renderTexture);
            }

            ShaderLoad();
            _cameraMovePointer = this.gameObject.AddComponent <CameraMoverPointer>();
            CameraUtilities.AddNewCamera(Plugin.MainCamera);
            MultiplayerSessionInit = false;

            externalSender = new GameObject("ExternalSender").AddComponent <ExternalSender>();
            externalSender.transform.SetParent(transform);

            if (CustomUtils.IsModInstalled("VMCAvatar"))
            {
                existsVMCAvatar = true;
            }
            _webCamTexture = new WebCamTexture();
            webCamDevices  = WebCamTexture.devices;
        }
Ejemplo n.º 2
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"));
            DestroyImmediate(gameObj.GetComponent("MainCamera"));
            DestroyImmediate(gameObj.GetComponent("VisualEffectsController"));

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

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

            if (_liv)
            {
                Destroy(_liv);
            }

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

            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;

            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)
            {
                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!");
        }
Ejemplo n.º 3
0
        public virtual void Init(Camera mainCamera)
        {
            _mainCamera = mainCamera;

            XRSettings.showDeviceView = false;

            Plugin.Instance.Config.ConfigChangedEvent += PluginOnConfigChangedEvent;
            SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;

            var gameObj = Instantiate(_mainCamera.gameObject);

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

            if (SteamVRCompatibility.IsAvailable)
            {
                DestroyImmediate(gameObj.GetComponent(SteamVRCompatibility.SteamVRCamera));
                DestroyImmediate(gameObj.GetComponent(SteamVRCompatibility.SteamVRFade));
            }

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

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

            _cam = gameObj.GetComponent <Camera>();
            _cam.stereoTargetEye = StereoTargetEyeMask.None;
            _cam.enabled         = true;

            gameObj.SetActive(true);

            var camera = _mainCamera.transform;

            transform.position = camera.position;
            transform.rotation = camera.rotation;

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

            var cameraCube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cameraCube.SetActive(ThirdPerson);
            _cameraCube            = cameraCube.transform;
            _cameraCube.localScale = new Vector3(0.15f, 0.15f, 0.22f);
            _cameraCube.name       = "CameraCube";

            var quad = GameObject.CreatePrimitive(PrimitiveType.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;

            ReadConfig();

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

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

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

            SceneManagerOnSceneLoaded(new Scene(), LoadSceneMode.Single);
        }