Beispiel #1
0
        private void WarmUpShader()
        {
            VRLog.Info("Warm up all shaders");
            Shader.WarmupAllShaders();

            return;
        }
Beispiel #2
0
        protected override void OnStart()
        {
            VRLog.Info("OnStart");
            VRLog.Info("MonitorManager Created");
            _MonitorManager = uDesktopDuplication.Manager.CreateInstance();
            VRLog.Info("TouchManager Created");
            _TouchManager = uTouchInjection.Manager.CreateInstance();
            VRLog.Info("SteamVR Render Created");
            _Render = SteamVR_Render.instance;

            // VR用設定の更新.
            VRLog.Info("VR Camera Created");
            _Camera = VRCamera.Create();
            // モード初期化.
            if ((_ControlMode == null) || (_ControlMode.Mode == ControlMode.ModeType.SeatedMode))
            {
                _ControlMode = new GameObject("Mode").AddComponent <SeatedMode>();
            }
            else
            {
                _ControlMode = new GameObject("Mode").AddComponent <StandingMode>();
            }

            // 生成オブジェクトが破棄されないようにする.
            _MonitorManager.transform.SetParent(transform, true);
            _TouchManager.transform.SetParent(transform, true);
            _Render.transform.SetParent(transform, true);
            _Camera.Origin.SetParent(transform, true);
            _ControlMode.transform.SetParent(transform, true);
        }
Beispiel #3
0
        public void CopyFX(Camera source)
        {
            if (source != null)
            {
                var target = GetComponent <Camera>();

                // Clean
                foreach (var fx in target.gameObject.GetCameraEffects())
                {
                    DestroyImmediate(fx);
                }
                int comps = target.GetComponents <Component>().Length;

                VRLog.Info("Copying FX to {0}...", target.name);
                // Rebuild
                foreach (var fx in source.gameObject.GetCameraEffects())
                {
                    VRLog.Info("Copy FX: {0} (enabled={1})", fx.GetType().Name, fx.enabled);
                    var attachedFx = target.gameObject.CopyComponentFrom(fx);
                    if (attachedFx)
                    {
                        VRLog.Info("Attached!");
                        attachedFx.enabled = fx.enabled;
                    }
                    else
                    {
                        VRLog.Info("Skipping image effect {0}", fx.GetType().Name);
                    }
                }
                VRLog.Info("{0} components before the additions, {1} after", comps, target.GetComponents <Component>().Length);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Loads the settings from a file. Generic to enable handling of sub classes.
 /// </summary>
 /// <typeparam name="T">Type of the settings</typeparam>
 /// <param name="path"></param>
 /// <returns></returns>
 public static T Load <T>(string path) where T : VRSettings
 {
     VRLog.Info("VRSettings Load Start");
     try
     {
         if (!File.Exists(path))
         {
             VRLog.Info("VRSettings Not Exist Create New XML File.");
             var settings = Activator.CreateInstance <T>();
             settings.Save(path);
             return(settings);
         }
         else
         {
             var serializer = new XmlSerializer(typeof(T));
             using (var stream = new FileStream(path, FileMode.Open))
             {
                 var settings = serializer.Deserialize(stream) as T;
                 settings.Path = path;
                 VRLog.Info("VRSettings Load End");
                 return(settings);
             }
         }
     }
     catch (Exception e)
     {
         VRLog.Error("Fatal exception occured while loading XML! (Make sure System.Xml exists!) {0}", e);
         throw e;
     }
 }
Beispiel #5
0
        private void LoadMaterials()
        {
            // uDD_Screen_Unlit.mat
            Material mat = _AssetBundle.LoadAsset <Material>("uDD_Screen_Unlit.mat");

            if (mat != null)
            {
                VRLog.Info("Material uDD_Screen_Unlit.mat is Loaded.");
                mat.SetInt("_Forward", 1);
                mat.DisableKeyword("_FORWARD_Y");
                mat.EnableKeyword("_FORWARD_Z");
                // モニタ表示用テクスチャを取得
                _Materials.Add("uDD_Screen_Unlit", mat);
            }
            else
            {
                VRLog.Error("Material uDD_Screen_Unlit.mat is Load Failed.");
            }

            // uDD_Screen_Standard.mat
            mat = _AssetBundle.LoadAsset <Material>("uDD_Screen_Standard.mat");
            if (mat != null)
            {
                VRLog.Info("Material uDD_Screen_Standard.mat is Loaded.");
                mat.SetInt("_Forward", 1);
                mat.DisableKeyword("_FORWARD_Y");
                mat.EnableKeyword("_FORWARD_Z");
                // モニタ表示用テクスチャを取得
                _Materials.Add("uDD_Screen_Standard", mat);
            }
            else
            {
                VRLog.Error("Material uDD_Screen_Unlit.mat is Load Failed.");
            }

            // uTI_Cursor.mat
            mat = null;
            mat = _AssetBundle.LoadAsset <Material>("uTI_Cursor.mat");
            if (mat != null)
            {
                VRLog.Info("Material uTI_Cursor.mat is Loaded.");
                _Materials.Add("uTI_Cursor", mat);
            }

            // uTI_Ray.mat
            mat = null;
            mat = _AssetBundle.LoadAsset <Material>("uTI_Ray.mat");
            if (mat != null)
            {
                VRLog.Info("Material uTI_Ray.mat is Loaded.");
                _Materials.Add("uTI_Ray", mat);
            }
        }
        private IEnumerator _Invoke(Action action, float delay)
        {
            yield return(new WaitForSeconds(delay));

            try
            {
                action();
            }
            catch (Exception e)
            {
                VRLog.Error(e);
            }
        }
Beispiel #7
0
        private void LoadMeshes()
        {
            Mesh mesh = _AssetBundle.LoadAsset <Mesh>("uDD_Board");

            if (mesh != null)
            {
                VRLog.Info("Mesh uDD_Board.fbx is Loaded.");
                _Meshes.Add("uDD_Board", mesh);
            }
            else
            {
                VRLog.Error("Mesh uDD_Board.fbx is Loaded Failed.");
            }
        }
Beispiel #8
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;
             }
         }
     }
 }
Beispiel #9
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>();
                }
            }
        }
Beispiel #10
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.");
            }
        }
Beispiel #11
0
 /// <summary>
 /// Clone settings from another instance.
 /// </summary>
 /// <param name="settings"></param>
 public void CopyFrom(VRSettings settings)
 {
     foreach (var key in _Listeners.Keys)
     {
         var prop = settings.GetType().GetProperty(key, BindingFlags.Instance | BindingFlags.Public);
         if (prop != null)
         {
             try
             {
                 prop.SetValue(this, prop.GetValue(settings, null), null);
             }
             catch (Exception e)
             {
                 VRLog.Warn(e);
             }
         }
     }
 }
Beispiel #12
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);
        }
Beispiel #13
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;
        }
Beispiel #14
0
 protected override void OnLevel(int level)
 {
     VRLog.Info("OnLevel");
     VRLog.Info($"Level:{level}");
     _CheckedCameras.Clear();
 }
Beispiel #15
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>());
        }