示例#1
0
 private void NormalCameraWithoutVR()
 {
     foreach (var camera in UnityEngine.Camera.allCameras.Except(_CheckedCameras).ToList())
     {
         if (camera != null && Camera != null)
         {
             _CheckedCameras.Add(camera);
             // 元々あったカメラは通常通り画面に表示.
             if (camera.name != Camera.CameraName)
             {
                 VRLog.Info($"Founded Camera {camera.name} Show HMD is Canceld.");
                 camera.gameObject.RemoveComponent <AudioListener>();
                 camera.stereoTargetEye = StereoTargetEyeMask.None;
             }
         }
     }
 }
示例#2
0
        public void SetMode(ControlMode.ModeType Mode)
        {
            VRLog.Info($"SetMode ModeType:{Mode}");
            if (Mode != _ControlMode.Mode)
            {
                var go = _ControlMode.gameObject;
                DestroyImmediate(_ControlMode);

                if (Mode == ControlMode.ModeType.SeatedMode)
                {
                    _ControlMode = go.AddComponent <SeatedMode>();
                }
                else
                {
                    _ControlMode = go.AddComponent <StandingMode>();
                }
            }
        }
示例#3
0
        private ResourceManager()
        {
            VRLog.Info("Resource Manager Create");
            // AssetBundleのロード.
            _AssetBundle = AssetBundle.LoadFromMemory(AssetBundleMemory);

            if (_AssetBundle != null)
            {
                VRLog.Info("Asset Bundle is Loaded.");
                LoadMaterials();
                WarmUpShader();
                LoadMeshes();
            }
            else
            {
                VRLog.Error("AssetBundle Load Failed.");
            }
        }
示例#4
0
        protected override void OnAwake()
        {
            // 自分自身の位置と回転を初期化.
            VRLog.Info("OnAWake");
            transform.Reset();
#if UNITY_2018_3_OR_NEWER
            UnityEngine.XR.XRSettings.showDeviceView = false;
#else
            UnityEngine.VR.VRSettings.showDeviceView = false;
#endif

#if UNITY_2018_3_OR_NEWER
            UnityEngine.XR.XRSettings.eyeTextureResolutionScale = VR.Settings.IPDScale;
#else
            UnityEngine.VR.VRSettings.renderScale = VR.Settings.IPDScale;
#endif

            DontDestroyOnLoad(gameObject);
        }
示例#5
0
        protected override void OnAwake()
        {
            VRLog.Info("OnAWake");
            transform.Reset();
            VRLog.Info("Create VR Camera");
            // VR用の設定を反映.


            VRLog.Info("Add Audio Component");
            gameObject.AddComponent <AudioListener>();
            VRLog.Info("Add Camera Component");
            // VR設定の反映.
            var camera = gameObject.AddComponent <Camera>();

            camera.stereoTargetEye = StereoTargetEyeMask.Both;
            camera.nearClipPlane   = VR.Settings.NearClipPlane;
            camera.cameraType      = CameraType.VR;

            _SteamVR_Camera = gameObject.AddComponent <SteamVR_Camera>();

            return;
        }
示例#6
0
 protected override void OnLevel(int level)
 {
     VRLog.Info("OnLevel");
     VRLog.Info($"Level:{level}");
     _CheckedCameras.Clear();
 }
示例#7
0
        public static DesktopMonitor Create(CreateType createType)
        {
            VRLog.Info($"Create Virtual Desktop Monitor");
            bool       is_mesh = false;
            GameObject go;
            MeshFilter filter;
            Mesh       mesh;
            Renderer   renderer;
            Material   material;

            // メッシュのロードを試す.
            VRLog.Info("Mesh Load Start");
            try
            {
                mesh = VR.Resource.MonitorMesh;
                VRLog.Info("Mesh Load End");
            }
            catch (System.TypeLoadException e)
            {
                VRLog.Info(e.Message);
                mesh = null;
            }

            if (mesh != null)
            {
                // 半径を再計算.
                var aabbScale = mesh.bounds.size;
                aabbScale.y = Mathf.Max(aabbScale.y, aabbScale.x);
                aabbScale.z = Mathf.Max(aabbScale.z, aabbScale.x);
                mesh.bounds = new Bounds(mesh.bounds.center, aabbScale);
                is_mesh     = true;
            }

            if (is_mesh)
            {
                // メッシュからモニタを生成する.
                go          = new GameObject("");
                filter      = go.AddComponent <MeshFilter>();
                filter.mesh = mesh;
                renderer    = go.AddComponent <MeshRenderer>();
            }
            else
            {
                // メッシュが読み込めないので、QUADから生成する.
                go = GameObject.CreatePrimitive(PrimitiveType.Quad);
                go.RemoveComponent <MeshCollider>();
                renderer = go.GetComponent <MeshRenderer>();
            }

            if (Manager.monitorCount > 0)
            {
                Monitor monitor = Manager.monitors[0];
                go.name = monitor.name;
                go.transform.Reset();

                // MaterialはuDD_Unlit/Texureとする.それがだめならFallbackする.
                if (renderer != null)
                {
                    VRLog.Info($"Material Change");
                    VRLog.Info($"Old Material Name is {renderer.material}");

                    try
                    {
                        material = VR.Resource.MonitorMaterial;
                    }
                    catch (System.TypeLoadException e)
                    {
                        VRLog.Info(e.Message);
                        material = null;
                    }
                    if (material != null)
                    {
                        renderer.material = material;
                        VRLog.Info($"Material Name is {renderer.material}");
                        if (renderer.material.shader)
                        {
                            VRLog.Info($"Shader Is : {renderer.material.shader.name}");
                            VRLog.Info($"Shader Is Supported Status : {renderer.material.shader.isSupported}");

                            if (renderer.material.shader.isSupported == false)
                            {
                                VRLog.Info("Fallback uDD_Screen_Standard");
                                material = VR.Resource.MonitorStandardMaterial;

                                if (material != null)
                                {
                                    renderer.material = material;
                                    VRLog.Info($"Material Name is {renderer.material}");
                                    if (renderer.material.shader)
                                    {
                                        VRLog.Info($"Shader Is : {renderer.material.shader.name}");
                                        VRLog.Info($"Shader Is Supported Status : {renderer.material.shader.isSupported}");
                                        if (renderer.material.shader.isSupported == false)
                                        {
                                            VRLog.Info("Fallback Shader Standard");
                                            var shader = Shader.Find("Standard");
                                            if (shader != null)
                                            {
                                                renderer.material.shader = shader;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                material = VR.Resource.MonitorStandardMaterial;
                            }
                            catch (System.TypeLoadException e)
                            {
                                VRLog.Info(e.Message);
                                material = null;
                            }
                            if (material != null)
                            {
                                renderer.material = material;
                                VRLog.Info($"Material Name is {renderer.material}");
                                if (renderer.material.shader)
                                {
                                    VRLog.Info($"Shader Is : {renderer.material.shader.name}");
                                    VRLog.Info($"Shader Is Supported Status : {renderer.material.shader.isSupported}");
                                    if (renderer.material.shader.isSupported == false)
                                    {
                                        VRLog.Info("Fallback Shader Standard");
                                        var shader = Shader.Find("Standard");
                                        if (shader != null)
                                        {
                                            renderer.material.shader = shader;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                VRLog.Info($"Shader Can't load Check the Material Please...");
                            }
                        }
                    }
                    // 描画が反転するので、テクスチャーのスケールを反転させる.
                    if (!is_mesh)
                    {
                        renderer.material.mainTextureScale = new Vector3(1.0f, -1.0f);
                    }
                }
                // Assign monitor
                var texture = go.AddComponent <uDesktopDuplication.Texture>();
                texture.monitorId = 0;

                // デフォルトだと画面が大きすぎるので調整.
                // モニタ解像度(pixel)
                VRLog.Info($"Monitor Created Monitor Resolution Width:{texture.monitor.width}, Height:{texture.monitor.height}");
                var   scale = VR.Settings.MonitorScale;
                float width = 1.0f, height = 1.0f;

#if false // Real Scale
                width  = monitor.widthMeter;
                height = monitor.heightMeter;
#elif false // Fixed Scale
                width  = scale * (monitor.isHorizontal ? monitor.aspect : 1f);
                height = scale * (monitor.isHorizontal ? 1f : 1f / monitor.aspect);
#else // Pixel Scale
                width  = scale * (monitor.isHorizontal ? 1f : monitor.aspect) * ((float)monitor.width / 1920);
                height = scale * (monitor.isHorizontal ? 1f / monitor.aspect : 1f) * ((float)monitor.width / 1920);
#endif
                texture.meshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection.Z;
                var meshForwardDirection = texture.meshForwardDirection;

                if (createType == CreateType.Stationary)
                {
                    width  *= 0.2f;
                    height *= 0.2f;
                }
                else
                {
                    width  *= 0.02f;
                    height *= 0.02f;
                }

                if (!is_mesh)
                {
                    width  *= 10.0f;
                    height *= 10.0f;
                }

                if (meshForwardDirection == uDesktopDuplication.Texture.MeshForwardDirection.Y)
                {
                    go.transform.localScale = new Vector3(width, go.transform.localScale.y, height);
                }
                else
                {
                    go.transform.localScale = new Vector3(width, height, go.transform.localScale.z);
                }

                if (createType == CreateType.RoomScale)
                {
                    go.transform.Rotate(new Vector3(90.0f, 0.0f, 0.0f));
                }


                VRLog.Info($"Monitor Scale is {scale}");
                VRLog.Info($"Monitor Object Size is {go.transform.localScale}");
                // デフォルトでは非表示にしておく.
                VRLog.Info($"monitor Object Created Success for {createType}:{go.name}");
                go.SetActive(false);
            }
            else
            {
                VRLog.Error("Display Can't Detection");
            }
            return(go.AddComponent <DesktopMonitor>());
        }