public override void Initialize() { base.Initialize(); this.ForEachChild<View>(x => x.Deactivate(), false); if(!Application.isPlaying) return; // TODO: Hardcoded values Height.DirectValue = ElementSize.FromPixels(480f); Width.DirectValue = ElementSize.FromPixels(620f); LayoutChanged(); var height = (int) ActualHeight; var width = (int) ActualWidth; var plane = GameObject.CreatePrimitive(PrimitiveType.Plane); //plane.transform.position = new Vector3(0f, -0.005f, -0.01f); plane.transform.rotation = Quaternion.Euler(90, 180, 0); plane.transform.localScale = new Vector3(width * 0.0001f, 1f, height * 0.0001f); plane.transform.parent = transform; plane.transform.localPosition = new Vector3(0f, 0f, -0.01f); //plane.GetComponent<MeshCollider>().convex = true; var planeRigidbody = plane.AddComponent<Rigidbody>(); planeRigidbody.useGravity = false; planeRigidbody.isKinematic = true; plane.AddComponent<VRActor>().Grabable = false; _vrWebView = plane.AddComponent<VRWebView>(); _vrWebView.m_Width = width * 2; _vrWebView.m_Height = height * 2; }
private void Start() { // Create commands m_ButtonCommand = new vrCommand("GUIMenuSample.ButtonCommand", ButtonHandler); m_CheckboxCommand = new vrCommand("GUIMenuSample.CheckboxCommand", CheckboxHandler); m_RadioCommand = new vrCommand("GUIMenuSample.RadioCommand", RadioHandler); m_ColorPickerCommand = new vrCommand("GUIMenuSample.ColorPickerCommand", ColorPickerHandler); m_SliderCommand = new vrCommand("GUIMenuSample.SliderCommand", SliderHandler); m_ListCommand = new vrCommand("GUIMenuSample.ListCommand", ListHandler); // Create GUI m_GUIRendererWeb = null; VRWebView webViewScript = GetComponent <VRWebView>(); if (webViewScript == null) { MVRTools.Log(0, "[X] VRGUIMenuSample does not have a WebView."); enabled = false; return; } m_GUIRendererWeb = new vrGUIRendererWeb("", webViewScript.webView); m_Menu = new vrWidgetMenu("GUIMenuSample.MainMenu", m_GUIRendererWeb); m_Button1 = new vrWidgetButton("GUIMenuSample.Button1", m_Menu, "Button", m_ButtonCommand); new vrWidgetSeparator("GUIMenuSample.Separator1", m_Menu); m_Checkbox = new vrWidgetToggleButton("GUIMenuSample.Checkbox", m_Menu, "Toggle Button", m_CheckboxCommand, true); m_Submenu = new vrWidgetMenu("GUIMenuSample.SubMenu", m_Menu, "Sub Menu"); m_Submenu.SetVisible(true); m_Radio1 = new vrWidgetRadioButton("GUIMenuSample.Radio1", m_Submenu, "Huey", m_RadioCommand, "Huey"); m_Radio2 = new vrWidgetRadioButton("GUIMenuSample.Radio2", m_Submenu, "Dewey", m_RadioCommand, "Dewey"); m_Radio3 = new vrWidgetRadioButton("GUIMenuSample.Radio3", m_Submenu, "Louie", m_RadioCommand, "Louie"); m_Picker = new vrWidgetColorPicker("GUIMenuSample.ColorPicker", m_Menu, "Color Picker", m_ColorPickerCommand, new vrVec4(0, 0, 0, 0)); m_Slider = new vrWidgetSlider("GUIMenuSample.Slider", m_Menu, "Slider", m_SliderCommand, 50.0f, 0.0f, 100.0f, 1.0f); vrValue listContents = vrValue.CreateList(); listContents.AddListItem("Item 1"); listContents.AddListItem("Item 2"); m_List = new vrWidgetList("GUIMenuSample.List", m_Menu, "List", m_ListCommand, listContents, 0); }
public override void Initialize() { base.Initialize(); this.ForEachChild <View>(x => x.Deactivate(), false); if (!Application.isPlaying) { return; } // TODO: Hardcoded values Height.DirectValue = ElementSize.FromPixels(480f); Width.DirectValue = ElementSize.FromPixels(800f); LayoutChanged(); var height = (int)ActualHeight; var width = (int)ActualWidth; var plane = GameObject.CreatePrimitive(PrimitiveType.Plane); //plane.transform.position = new Vector3(0f, -0.005f, -0.01f); plane.transform.rotation = Quaternion.Euler(90, 180, 0); plane.transform.localScale = new Vector3(width * 0.0001f, 1f, height * 0.0001f); plane.transform.parent = transform; plane.transform.localPosition = new Vector3(0f, 0f, -0.01f); //plane.GetComponent<MeshCollider>().convex = true; var planeRigidbody = plane.AddComponent <Rigidbody>(); planeRigidbody.useGravity = false; planeRigidbody.isKinematic = true; // VRActor needed for mouse / flystick interactions plane.AddComponent <VRActor>().Grabable = false; _vrWebView = plane.AddComponent <VRWebView>(); _vrWebView.Width = (int)(width * 1.5); _vrWebView.Height = (int)(height * 1.5); _vrWebView.MouseInteractionsIn3D = true; }
void Awake() { m_VRWebViewScript = (VRWebView)target; }
protected void Start() { // Retrieve the VRManager VRManagerScript[] foundVRManager = FindObjectsOfType(typeof(VRManagerScript)) as VRManagerScript[]; if (foundVRManager.Length != 0) { m_VRManager = foundVRManager[0]; } else { MVRTools.Log("[X] VRMenu: impossible to retrieve the VRManager."); return; } // Start listening to MiddleVR events m_Listener = new vrEventListener(EventListener); MiddleVR.VRInteractionMgr.AddEventListener(m_Listener); // Create commands // General m_ResetCurrentButtonCommand = new vrCommand("VRMenu.ResetCurrentButtonCommand", ResetCurrentButtonHandler); m_ResetZeroButtonCommand = new vrCommand("VRMenu.ResetZeroButtonCommand", ResetZeroButtonHandler); m_ExitButtonCommand = new vrCommand("VRMenu.ExitButtonCommand", ExitButtonHandler); m_FramerateCheckboxCommand = new vrCommand("VRMenu.FramerateCheckboxCommand", FramerateCheckboxHandler); m_ProxiWarningCheckboxCommand = new vrCommand("VRMenu.ProxiWarningCheckboxCommand", ProxiWarningCheckboxHandler); // Navigation m_FlyCheckboxCommand = new vrCommand("VRMenu.FlyCheckboxCommand", FlyCheckboxHandler); m_CollisionsCheckboxCommand = new vrCommand("VRMenu.CollisionsCheckboxCommand", CollisionsCheckboxHandler); // Manipulation m_ReturnObjectsCheckboxCommand = new vrCommand("VRMenu.ReturnObjectsCheckboxCommand", ReturnObjectsCheckboxHandler); // Create GUI m_GUIRendererWeb = null; VRWebView webViewScript = GetComponent <VRWebView>(); if (webViewScript == null) { MVRTools.Log(1, "[X] VRMenu does not have a WebView."); return; } m_GUIRendererWeb = new vrGUIRendererWeb("", webViewScript.webView); m_Menu = new vrWidgetMenu("VRMenu.VRManagerMenu", m_GUIRendererWeb); // Navigation m_NavigationOptions = new vrWidgetMenu("VRMenu.NavigationOptions", m_Menu, "Navigation"); CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationWandJoystick"), "Joystick", m_NavigationOptions, NavigationJoystickHandler); CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationElastic"), "Elastic", m_NavigationOptions, NavigationElasticHandler); CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionNavigationGrabWorld"), "Grab The World", m_NavigationOptions, NavigationGrabWorldHandler); m_NavigationSeparator = new vrWidgetSeparator("VRMenu.NavigationSeparator", m_NavigationOptions); m_FlyCheckbox = new vrWidgetToggleButton("VRMenu.FlyCheckbox", m_NavigationOptions, "Fly", m_FlyCheckboxCommand, m_VRManager.Fly); m_CollisionsCheckbox = new vrWidgetToggleButton("VRMenu.CollisionsCheckbox", m_NavigationOptions, "Navigation Collisions", m_CollisionsCheckboxCommand, m_VRManager.NavigationCollisions); // Manipulation m_ManipulationOptions = new vrWidgetMenu("VRMenu.ManipulationOptions", m_Menu, "Manipulation"); CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionManipulationRay"), "Ray", m_ManipulationOptions, ManipulationRayHandler); CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionManipulationHomer"), "Homer", m_ManipulationOptions, ManipulationHomerHandler); m_ManipulationSeparator = new vrWidgetSeparator("VRMenu.ManipulationSeparator", m_ManipulationOptions); m_ReturnObjectsCheckbox = new vrWidgetToggleButton("VRMenu.ReturnObjectsCheckbox", m_ManipulationOptions, "Return Objects", m_ReturnObjectsCheckboxCommand, m_VRManager.ManipulationReturnObjects); // Virtual Hand m_VirtualHandOptions = new vrWidgetMenu("VRMenu.VirtualHandOptions", m_Menu, "Virtual Hand"); CreateInteractionToggleButton(MiddleVR.VRInteractionMgr.GetInteraction("InteractionVirtualHandGogo"), "Gogo", m_VirtualHandOptions, VirtualHandGogoButtonHandler); // General m_GeneralSeparator = new vrWidgetSeparator("VRMenu.GeneralSeparator", m_Menu); m_GeneralOptions = new vrWidgetMenu("VRMenu.GeneralOptions", m_Menu, "General Options"); m_FramerateCheckbox = new vrWidgetToggleButton("VRMenu.FramerateCheckbox", m_GeneralOptions, "Show Frame Rate", m_FramerateCheckboxCommand, m_VRManager.ShowFPS); m_ProxiWarningCheckbox = new vrWidgetToggleButton("VRMenu.ProxiWarningCheckbox", m_GeneralOptions, "Show Proximity Warning", m_ProxiWarningCheckboxCommand, m_VRManager.ShowScreenProximityWarnings); // Reset and Exit m_ResetButtonMenu = new vrWidgetMenu("VRMenu.ResetButtonMenu", m_Menu, "Reset Simulation"); m_ResetCurrentButton = new vrWidgetButton("VRMenu.ResetCurrentButton", m_ResetButtonMenu, "Reload current level", m_ResetCurrentButtonCommand); m_ResetZeroButton = new vrWidgetButton("VRMenu.ResetZeroButton", m_ResetButtonMenu, "Reload level zero", m_ResetZeroButtonCommand); m_ExitButtonMenu = new vrWidgetMenu("VRMenu.ExitButtonMenu", m_Menu, "Exit Simulation"); m_ExitButton = new vrWidgetButton("VRMenu.ExitButton", m_ExitButtonMenu, "Yes, Exit Simulation", m_ExitButtonCommand); }
protected void _RaySelection() { // Ray picking Vector3 rayOrigin = transform.position; Vector3 rayDirection = transform.TransformDirection(Vector3.forward); VRSelection newSelection = null; foreach (RaycastHit raycastHit in Physics.RaycastAll(rayOrigin, rayDirection, m_Wand.GetDefaultRayLength())) { if (newSelection != null && raycastHit.distance >= newSelection.SelectionDistance) { continue; } GameObject objectHit = raycastHit.collider.gameObject; if (objectHit.name != "VRWand") { // Ignore GameObject without the VRActor component if (objectHit.GetComponent <VRActor>() == null) { continue; } VRWebView webView = objectHit.GetComponent <VRWebView>(); VRRaycastHit completeHit = null; if (webView != null) { completeHit = webView.RaycastMesh(rayOrigin, rayDirection); } else { completeHit = new VRRaycastHit(raycastHit); } if (completeHit != null) { // Special case : pass through transparent pixels of web views. if (webView != null) { if (!webView.GetComponent <Renderer>().enabled || webView.IsPixelEmpty(completeHit.textureCoord)) { continue; } } // Create selection if it does not exist if (newSelection == null) { newSelection = new VRSelection(); } newSelection.SourceWand = m_Wand; newSelection.SelectedObject = objectHit; newSelection.TextureCoordinate = completeHit.textureCoord; newSelection.SelectionDistance = completeHit.distance; newSelection.SelectionContact = completeHit.point; newSelection.SelectionNormal = completeHit.normal; } } } m_LastSelection = m_SelectionMgr.GetSelection(); m_SelectionMgr.SetSelection(newSelection); }
void Start() { gameManager = GameObject.Find("GameManager").GetComponent <Modelisation.GameManager>(); menuManager = GameObject.Find("Utilisateur").GetComponent <MenuManager>(); // Retrieve the VRManager VRManagerScript[] foundVRManager = FindObjectsOfType(typeof(VRManagerScript)) as VRManagerScript[]; if (foundVRManager.Length != 0) { m_VRManager = foundVRManager[0]; } else { MVRTools.Log("[X] VRMenu: impossible to retrieve the VRManager."); return; } // Start listening to MiddleVR events m_Listener = new vrEventListener(EventListener); MiddleVR.VRKernel.AddEventListener(m_Listener); // Create commands // General m_ResetButtonCommand = new vrCommand("VRMenu.ResetButtonCommand", ResetButtonHandler); m_ExitButtonCommand = new vrCommand("VRMenu.ExitButtonCommand", ExitButtonHandler); // Mode modeAssisteCommand = new vrCommand("VRMenu.modeAssisteCommand", ModeAssisteHandler); modeLibreCommand = new vrCommand("VRMenu.modeLibreCommand", ModeLibreHandler); // Scenario scenarioAppelCommand = new vrCommand("VRMenu.ScenarioAppelCommand", ScenarioAppelHandler); scenarioInfirmierCommand = new vrCommand("VRMenu.ScenarioInfirmierCommand", ScenarioInfirmierHandler); scenarioInconnuCommand = new vrCommand("VRMenu.ScenarioInconnuCommand", ScenarioInconnuHandler); // Create GUI m_GUIRendererWeb = null; VRWebView webViewScript = GetComponent <VRWebView>(); if (webViewScript == null) { MVRTools.Log(1, "[X] VRMenu does not have a WebView."); return; } m_GUIRendererWeb = new vrGUIRendererWeb("", webViewScript.webView); m_Menu = new vrWidgetMenu("VRMenu.VRManagerMenu", m_GUIRendererWeb); // Mode menuChoixMode = new vrWidgetMenu("VRMenu.ChoixMode", m_Menu, "Modes"); modeAssiste = new vrWidgetButton("VRMenu.ModeAssisteButton", menuChoixMode, "Passer en mode assisté", modeAssisteCommand); modeLibre = new vrWidgetButton("VRMenu.ModeLibreButton", menuChoixMode, "Passer en mode libre", modeLibreCommand); // Scénario menuChoixScenar = new vrWidgetMenu("VRMenu.ChoixScenario", m_Menu, "Scenarios"); scenarAppel = new vrWidgetButton("VRMenu.ScenarAppelButton", menuChoixScenar, "Appel téléphonique", scenarioAppelCommand); scenarInfirmier = new vrWidgetButton("VRMenu.ScenarInfirmierButton", menuChoixScenar, "Infirmier à l'entrée", scenarioInfirmierCommand); scenarInconnu = new vrWidgetButton("VRMenu.ScenarInconnuButton", menuChoixScenar, "Inconnu à l'entrée", scenarioInconnuCommand); // Reset and Exit m_ResetButton = new vrWidgetButton("VRMenu.ResetCurrentButton", m_Menu, "Reload simulation", m_ResetButtonCommand); m_ExitButton = new vrWidgetButton("VRMenu.ExitButton", m_Menu, "Exit simulation", m_ExitButtonCommand); }
private void _RaySelection() { // Ray picking RaycastHit[] hits; Vector3 dir = transform.localToWorldMatrix * Vector3.forward; hits = Physics.RaycastAll(transform.position, dir, m_Wand.GetDefaultRayLength()); bool foundActor = false; int currentHitId = 0; int foundHitId = 0; float distance = Mathf.Infinity; while (currentHitId < hits.Length) { RaycastHit hit = hits[currentHitId]; if (hit.distance < distance && hit.collider.name != "VRWand") { if (hit.collider.GetComponent <VRActor>() == null) { currentHitId++; continue; } // Pass through empty/transparent GUI pixels VRWebView webView = hit.collider.GetComponent <VRWebView>(); if (webView != null) { if (!webView.GetComponent <Renderer>().enabled || webView.IsPixelEmpty(hit.textureCoord)) { currentHitId++; continue; } } foundActor = true; foundHitId = currentHitId; distance = hit.distance; } currentHitId++; } m_LastSelection = m_SelectionMgr.GetSelection(); // If something found, select if (foundActor) { RaycastHit selectionHit = hits[foundHitId]; VRSelection newSelection = new VRSelection(); newSelection.SourceWand = m_Wand; newSelection.SelectedObject = selectionHit.collider.gameObject; newSelection.TextureCoordinate = selectionHit.textureCoord; newSelection.SelectionDistance = selectionHit.distance; newSelection.SelectionContact = selectionHit.point; newSelection.SelectionNormal = selectionHit.normal; m_SelectionMgr.SetSelection(newSelection); } else { m_SelectionMgr.SetSelection(null); } }
private void Start() { // Automatically register all methods with the [VRCommand] attribute MVRTools.RegisterCommands(this); // Create GUI VRWebView webViewScript = GetComponent <VRWebView>(); if (webViewScript == null) { MVRTools.Log(0, "[X] VRGUIMenuSample does not have a WebView."); enabled = false; return; } var GUIRendererWeb = new vrGUIRendererWeb("", webViewScript.webView); // Register the object so the garbage collector does not collect it after this method. // The object will be disposed when the GameObject is destroyed. MVRTools.RegisterObject(this, GUIRendererWeb); var menu = new vrWidgetMenu("GUIMenuSample.MainMenu", GUIRendererWeb); MVRTools.RegisterObject(this, menu); var button1 = new vrWidgetButton("GUIMenuSample.Button1", menu, "Button", MVRTools.GetCommand("ButtonHandler")); MVRTools.RegisterObject(this, button1); var separator = new vrWidgetSeparator("GUIMenuSample.Separator1", menu); MVRTools.RegisterObject(this, separator); m_Checkbox = new vrWidgetToggleButton("GUIMenuSample.Checkbox", menu, "Toggle Button", MVRTools.GetCommand("CheckboxHandler"), true); MVRTools.RegisterObject(this, m_Checkbox); var submenu = new vrWidgetMenu("GUIMenuSample.SubMenu", menu, "Sub Menu"); submenu.SetVisible(true); MVRTools.RegisterObject(this, submenu); var radio1 = new vrWidgetRadioButton("GUIMenuSample.Radio1", submenu, "Huey", MVRTools.GetCommand("RadioHandler"), "Huey"); MVRTools.RegisterObject(this, radio1); var radio2 = new vrWidgetRadioButton("GUIMenuSample.Radio2", submenu, "Dewey", MVRTools.GetCommand("RadioHandler"), "Dewey"); MVRTools.RegisterObject(this, radio2); var radio3 = new vrWidgetRadioButton("GUIMenuSample.Radio3", submenu, "Louie", MVRTools.GetCommand("RadioHandler"), "Louie"); MVRTools.RegisterObject(this, radio3); var picker = new vrWidgetColorPicker("GUIMenuSample.ColorPicker", menu, "Color Picker", MVRTools.GetCommand("ColorPickerHandler"), new vrVec4(0, 0, 0, 0)); MVRTools.RegisterObject(this, picker); var slider = new vrWidgetSlider("GUIMenuSample.Slider", menu, "Slider", MVRTools.GetCommand("SliderHandler"), 50.0f, 0.0f, 100.0f, 1.0f); MVRTools.RegisterObject(this, slider); vrValue listContents = vrValue.CreateList(); listContents.AddListItem("Item 1"); listContents.AddListItem("Item 2"); var list = new vrWidgetList("GUIMenuSample.List", menu, "List", MVRTools.GetCommand("ListHandler"), listContents, 0); MVRTools.RegisterObject(this, list); }