static GameObject dialogShown; /* a single one for now */ public void ShowPopup(Controller ctr, ref GameObject shown) { bool should_hide = false; if (dialogShown != null && dialogShown) { should_hide = (shown == dialogShown); GameObject.Destroy(dialogShown); } shown = dialogShown = null; ctr.SetPointer(null); if (should_hide) { CancelBuildDialog(); return; } Dialog dialog = BuildDialog(); Transform transform = dialog.transform; Vector3 head_forward = ctr.position - BaroqueUI.GetHeadTransform().position; Vector3 forward = ctr.transform.forward + head_forward.normalized; forward.y = 0; transform.forward = forward; transform.position = ctr.position + 0.15f * transform.forward; dialog.DisplayDialog(); shown = dialogShown = dialog.gameObject; }
void ChangeLocation() { Transform camera_rig = BaroqueUI.GetSteamVRManager().transform; Transform steamvr_camera = BaroqueUI.GetHeadTransform(); Vector3 v = camera_rig.position + destination_position - steamvr_camera.position; v.y = destination_position.y; camera_rig.position = v; FadeToColor(Color.clear, 0.2f); }
public static Controller GetController(int index) { return(BaroqueUI.GetControllers()[index]); }
void PrepareForRendering() { /* XXX picking two hopefully-unused layer numbers... */ if (UI_layer < 0) { for (int i = 29; i >= 1; i--) { if ((LayerMask.LayerToName(i) == null || LayerMask.LayerToName(i) == "") && (LayerMask.LayerToName(i + 1) == null || LayerMask.LayerToName(i + 1) == "")) { UI_layer = i; break; } } Debug.Assert(UI_layer >= 1); } RectTransform rtr = transform as RectTransform; pixels_per_unit = GetComponent <CanvasScaler>().dynamicPixelsPerUnit; render_texture = new RenderTexture((int)(rtr.rect.width * pixels_per_unit + 0.5), (int)(rtr.rect.height * pixels_per_unit + 0.5), 0); Transform tr1 = transform.Find("Ortho Camera"); if (tr1 != null) { ortho_camera = tr1.GetComponent <Camera>(); } else { ortho_camera = new GameObject("Ortho Camera").AddComponent <Camera>(); } ortho_camera.enabled = false; ortho_camera.transform.SetParent(transform); ortho_camera.transform.position = rtr.TransformPoint( rtr.rect.width * (0.5f - rtr.pivot.x), rtr.rect.height * (0.5f - rtr.pivot.y), 0); ortho_camera.transform.rotation = rtr.rotation; ortho_camera.clearFlags = CameraClearFlags.SolidColor; ortho_camera.backgroundColor = new Color(1, 1, 1); ortho_camera.cullingMask = 2 << UI_layer; ortho_camera.orthographic = true; ortho_camera.orthographicSize = rtr.TransformVector(0, rtr.rect.height * 0.5f, 0).magnitude; ortho_camera.nearClipPlane = -10; ortho_camera.farClipPlane = 10; ortho_camera.targetTexture = render_texture; RecSetLayer(UI_layer); BaroqueUI.GetHeadTransform().GetComponent <Camera>().cullingMask &= ~(3 << UI_layer); quad = GameObject.CreatePrimitive(PrimitiveType.Quad).transform; quad.SetParent(transform); quad.position = ortho_camera.transform.position; quad.rotation = ortho_camera.transform.rotation; quad.localScale = new Vector3(rtr.rect.width, rtr.rect.height, 1); DestroyImmediate(quad.GetComponent <Collider>()); quad.GetComponent <MeshRenderer>().material = Resources.Load <Material>("BaroqueUI/Dialog Material"); quad.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", render_texture); back_quad = GameObject.CreatePrimitive(PrimitiveType.Quad).transform; back_quad.SetParent(transform); back_quad.position = ortho_camera.transform.position; back_quad.rotation = ortho_camera.transform.rotation * Quaternion.LookRotation(new Vector3(0, 0, -1)); back_quad.localScale = new Vector3(rtr.rect.width, rtr.rect.height, 1); DestroyImmediate(back_quad.GetComponent <Collider>()); if (active_dialogs == null) { active_dialogs = new Dictionary <Canvas, Dialog>(); } foreach (var canvas in GetComponentsInChildren <Canvas>()) { canvas.worldCamera = ortho_camera; active_dialogs.Add(canvas, this); } StartCoroutine(UpdateRendering()); }
protected void Awake() { creation_order = ++NUMBER; BaroqueUI.EnsureStarted(); }
void Update() { if (active_controller == null) { foreach (var ctrl in BaroqueUI.GetControllers()) { if (ctrl.Matches(controllerSelection) && ctrl.GetButton(controllerButton)) { BaseControllerTracker tracker = ctrl.HoverControllerTracker(); if (tracker == null || tracker.CanStartTeleportAction(ctrl)) { arc.Show(); active_controller = ctrl; break; } } } if (active_controller == null) { return; } } if (active_controller.GetButton(controllerButton)) { bool saved = Physics.queriesHitTriggers; try { Physics.queriesHitTriggers = false; Transform tr = active_controller.transform; arc.SetArcData(tr.position, tr.TransformDirection(new Vector3(0, beamUpVelocity, beamForwardVelocity)), true, false); destination_valid = false; bool show_invalid = false; RaycastHit hitInfo; if (arc.DrawArc(out hitInfo)) { /* The teleport destination is accepted if we fit a capsule here. More precisely: * the capsule starts at ABOVE_GROUND above the hit point of the beam; on top * of that we check the capsule. The height of that capsule above around is thus * from ABOVE_GROUND to ABOVE_GROUND + RADIUS + DISTANCE + RADIUS. The parameters * are chosen so that planes of above ~30° cannot be teleported to, because the * bottom of the capsule always intersects that plane. */ const float ABOVE_GROUND = 0.1f, RADIUS = 0.32f, DISTANCE = 1.1f; if (Physics.CheckCapsule(hitInfo.point + (ABOVE_GROUND + RADIUS) * Vector3.up, hitInfo.point + (ABOVE_GROUND + RADIUS + DISTANCE) * Vector3.up, RADIUS, traceLayerMask, QueryTriggerInteraction.Ignore)) { /* invalid position */ invalid_reticle.position = hitInfo.point; invalid_reticle.rotation = Quaternion.LookRotation(hitInfo.normal) * Quaternion.Euler(90, 0, 0); show_invalid = true; } else { /* valid position */ invalid_reticle.gameObject.SetActive(false); destination_reticle.position = destination_position = hitInfo.point; destination_valid = true; } } invalid_reticle.gameObject.SetActive(show_invalid); destination_reticle.gameObject.SetActive(destination_valid); arc.SetColor(destination_valid ? validArcColor : invalidArcColor); } finally { Physics.queriesHitTriggers = saved; } } else { active_controller = null; arc.Hide(); invalid_reticle.gameObject.SetActive(false); destination_reticle.gameObject.SetActive(false); if (destination_valid) { StartTeleporting(); } } }