/// <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; } }
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); } }
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."); } }
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."); } }
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>()); }