private IEnumerator CreateWebView() { bool serverReady = false; float time = Time.time; do { WWW www = new WWW(m_RTCServerURL); yield return(www); if (string.IsNullOrEmpty(www.error) || (www.error.IndexOf("Could not resolve host", 0) < 0 && www.error.IndexOf("Connection refused", 0) < 0)) { serverReady = true; } else { yield return(new WaitForSeconds(10.0f)); } } while (!serverReady && Time.time - time < 60.0f); if (serverReady) { m_VRRTCWebView = new vrWebView("", m_RTCServerURL); } }
protected void Start() { // Check if we are running MiddleVR if (MiddleVR.VRKernel == null) { Debug.Log("[X] VRManager is missing from the scene !"); enabled = false; return; } if (SystemInfo.graphicsDeviceID == 0) { Debug.Log("[~] Running in batchmode - disabling VRWebView script"); enabled = false; return; } m_VirtualMousePosition = new Vector2(0, 0); if (Application.isEditor) { // Get the vrCameras corresponding Cameras m_Cameras = new List <Camera>(); uint camerasNb = MiddleVR.VRDisplayMgr.GetCamerasNb(); for (uint i = 0; i < camerasNb; ++i) { vrCamera vrcamera = MiddleVR.VRDisplayMgr.GetCameraByIndex(i); GameObject cameraObj = GameObject.Find(vrcamera.GetName()); Camera camera = cameraObj.GetComponent <Camera>(); if (camera != null) { m_Cameras.Add(camera); } } } m_Texture = new Texture2D(m_Width, m_Height, TextureFormat.ARGB32, false); m_Texture.wrapMode = TextureWrapMode.Clamp; // Create vrImage and Texture2D #if VRWEBVIEW_UNITY_FREE // Texture2D.SetPixels takes RGBA. m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_RGBA); m_Pixels = m_Texture.GetPixels32(0); m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned); #else // OpenGL and Direct3D 9: Memory order for texture upload is BGRA (little-endian representation of ARGB32) // Direct3D 11: Unity seems to ignore TextureFormat.ARGB32 and always creates an RGBA texture. // We let vrImage do the pixel format conversion because this operation is done in another thread. if (SystemInfo.graphicsDeviceVersion.Contains("Direct3D 11")) { m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_RGBA); } else { m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_BGRA); } #endif // Fill texture Color32[] colors = new Color32[(m_Width * m_Height)]; for (int i = 0; i < (m_Width * m_Height); i++) { colors[i].r = 0; colors[i].g = 0; colors[i].b = 0; colors[i].a = 0; } m_Texture.SetPixels32(colors); m_Texture.Apply(false, false); #if !VRWEBVIEW_UNITY_FREE m_NativeTexturePtr = m_Texture.GetNativeTexturePtr(); #endif // Attach texture if (gameObject != null && gameObject.GetComponent <GUITexture>() == null && gameObject.GetComponent <Renderer>() != null) { var renderer = gameObject.GetComponent <Renderer>(); // Assign the material/shader to the object attached renderer.material = Resources.Load("VRWebViewMaterial", typeof(Material)) as Material; renderer.material.mainTexture = this.m_Texture; } else if (gameObject != null && gameObject.GetComponent <GUITexture>() != null) { gameObject.GetComponent <GUITexture>().texture = this.m_Texture; } else { MiddleVR.VRLog(2, "VRWebView must be attached to a GameObject with a renderer or a GUITexture !"); enabled = false; return; } // Handle Cluster if (MiddleVR.VRClusterMgr.IsServer() && !MiddleVR.VRKernel.GetEditorMode()) { MiddleVR.VRClusterMgr.AddSynchronizedObject(m_Image); } if (!MiddleVR.VRClusterMgr.IsClient()) { if (m_DirectoryProviders.Length == 0 && m_ArchiveProviders.Length == 0) { m_WebView = new vrWebView("", GetAbsoluteURL(m_URL), (uint)m_Width, (uint)m_Height, m_Image); } else { m_WebView = new vrWebView("", "", (uint)m_Width, (uint)m_Height, m_Image); int order = 0; foreach (VRWebViewDirectoryProvider directoryProvider in m_DirectoryProviders) { m_WebView.AddDirectoryProvider(directoryProvider.m_URL, Application.dataPath + System.IO.Path.DirectorySeparatorChar + directoryProvider.m_DirectoryPath, order, "VRWebViewProvider" + order); order++; } foreach (VRWebViewArchiveProvider archiveProvider in m_ArchiveProviders) { m_WebView.AddArchiveProvider(archiveProvider.m_URL, Application.dataPath + System.IO.Path.DirectorySeparatorChar + archiveProvider.m_ArchivePath, archiveProvider.m_Password, order, "VRWebViewProvider" + order); order++; } m_WebView.SetURL(GetAbsoluteURL(m_URL)); } m_WebView.SetZoom(m_Zoom); } }
protected void Start () { // Check if we are running MiddleVR if(MiddleVR.VRKernel == null) { Debug.Log("[X] VRManager is missing from the scene !"); enabled = false; return; } m_VirtualMousePosition = new Vector2(0, 0); if (Application.isEditor) { // Get the vrCameras corresponding Cameras m_Cameras = new List<Camera>(); uint camerasNb = MiddleVR.VRDisplayMgr.GetCamerasNb(); for (uint i = 0; i < camerasNb; ++i) { vrCamera vrcamera = MiddleVR.VRDisplayMgr.GetCameraByIndex(i); GameObject cameraObj = GameObject.Find(vrcamera.GetName()); Camera camera = cameraObj.GetComponent<Camera>(); if (camera != null) { m_Cameras.Add(camera); } } } m_Texture = new Texture2D(m_Width, m_Height, TextureFormat.ARGB32, false); m_Texture.wrapMode = TextureWrapMode.Clamp; // Create vrImage and Texture2D #if VRWEBVIEW_UNITY_FREE // Texture2D.SetPixels takes RGBA. m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_RGBA); m_Pixels = m_Texture.GetPixels32 (0); m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned); #else // OpenGL and Direct3D 9: Memory order for texture upload is BGRA (little-endian representation of ARGB32) // Direct3D 11: Unity seems to ignore TextureFormat.ARGB32 and always creates an RGBA texture. // We let vrImage do the pixel format conversion because this operation is done in another thread. if (SystemInfo.graphicsDeviceVersion.Contains("Direct3D 11")) { m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_RGBA); } else { m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_BGRA); } #endif // Fill texture Color32[] colors = new Color32[(m_Width * m_Height)]; for (int i = 0; i < (m_Width * m_Height); i++) { colors[i].r = 0; colors[i].g = 0; colors[i].b = 0; colors[i].a = 0; } m_Texture.SetPixels32(colors); m_Texture.Apply(false, false); #if !VRWEBVIEW_UNITY_FREE m_NativeTexturePtr = m_Texture.GetNativeTexturePtr(); #endif // Attach texture if (gameObject != null && gameObject.GetComponent<GUITexture>() == null && gameObject.GetComponent<Renderer>() != null) { var renderer = gameObject.GetComponent<Renderer>(); // Assign the material/shader to the object attached renderer.material = Resources.Load("VRWebViewMaterial", typeof(Material)) as Material; renderer.material.mainTexture = this.m_Texture; } else if (gameObject != null && gameObject.GetComponent<GUITexture>() != null ) { gameObject.GetComponent<GUITexture>().texture = this.m_Texture; } else { MiddleVR.VRLog(2, "VRWebView must be attached to a GameObject with a renderer or a GUITexture !"); enabled = false; return; } // Handle Cluster if ( MiddleVR.VRClusterMgr.IsServer() && ! MiddleVR.VRKernel.GetEditorMode() ) { MiddleVR.VRClusterMgr.AddSynchronizedObject( m_Image ); } if( ! MiddleVR.VRClusterMgr.IsClient() ) { if (m_DirectoryProviders.Length == 0 && m_ArchiveProviders.Length == 0) { m_WebView = new vrWebView("", GetAbsoluteURL(m_URL), (uint)m_Width, (uint)m_Height, m_Image); } else { m_WebView = new vrWebView("", "", (uint)m_Width, (uint)m_Height, m_Image); int order = 0; foreach(VRWebViewDirectoryProvider directoryProvider in m_DirectoryProviders) { m_WebView.AddDirectoryProvider(directoryProvider.m_URL, Application.dataPath + System.IO.Path.DirectorySeparatorChar + directoryProvider.m_DirectoryPath, order, "VRWebViewProvider" + order); order++; } foreach(VRWebViewArchiveProvider archiveProvider in m_ArchiveProviders) { m_WebView.AddArchiveProvider(archiveProvider.m_URL, Application.dataPath + System.IO.Path.DirectorySeparatorChar + archiveProvider.m_ArchivePath, archiveProvider.m_Password, order, "VRWebViewProvider" + order); order++; } m_WebView.SetURL(GetAbsoluteURL(m_URL)); } m_WebView.SetZoom( m_Zoom ); } }
void Start() { m_MyCommand = new vrCommand("MyCommand", CommandHandler); m_webView = GetComponent <VRWebView>().webView; }
protected void CallJavascript() { vrWebView webView = GetComponent <VRWebView>().webView; webView.ExecuteJavascript("AddResult('Button was clicked!')"); }