public void AddTouch() { var ct = Controller.HoverTracker(this); ct.onTouchDown += (ctrl) => { Seen(ctrl, "OnTouchDown@" + ctrl.position.x + "," + ctrl.position.y + "," + ctrl.position.z); }; ct.onTouchDrag += (ctrl) => { Seen(ctrl, "OnTouchDrag@" + ctrl.position.x + "," + ctrl.position.y + "," + ctrl.position.z); }; ct.onTouchUp += (ctrl) => { Seen(ctrl, "OnTouchUp@" + ctrl.position.x + "," + ctrl.position.y + "," + ctrl.position.z); }; }
public void TestStarts() { var ct = Controller.HoverTracker(this); ct.onEnter += (ctrl) => { Seen(ctrl, "OnEnter"); }; ct.onMoveOver += (ctrl) => { Seen(ctrl, "OnMoveOver"); }; ct.onLeave += (ctrl) => { Seen(ctrl, "OnLeave"); }; }
Dictionary <MeshRenderer, MeshRenderer> extra_renderers; /* only if showOutline is true */ public virtual void Start() { var ct = Controller.HoverTracker(this); ct.onEnter += OnEnter; ct.onLeave += OnLeave; ct.onTriggerDown += OnTriggerDown; ct.onTriggerDrag += OnTriggerDrag; ct.onTriggerUp += OnTriggerUp; }
void Start() { if (!alreadyPositioned) { gameObject.SetActive(false); return; } CreateLayer(); RecSetLayer(UI_layer, includeInactive: true); foreach (InputField inputField in GetComponentsInChildren <InputField>(includeInactive: true)) { if (inputField.GetComponent <KeyboardVRInput>() == null) { inputField.gameObject.AddComponent <KeyboardVRInput>(); } } StartAutomaticKeyboard(); if (renderTexture == null) /* else, no automatic controllers */ { var ct = Controller.HoverTracker(this); ct.computePriority = GetPriority; ct.onEnter += OnEnter; ct.onMoveOver += MouseMove; ct.onLeave += OnLeave; ct.onTriggerDown += MouseDown; ct.onTriggerDrag += MouseMove; ct.onTriggerUp += MouseUp; ct.onTouchDown += MouseTouchDown; ct.onTouchDrag += MouseTouchMove; ct.onTouchUp += MouseTouchUp; ct.onTouchPressDown += MousePressDown; ct.onTouchPressDrag += MousePressMove; ct.onTouchPressUp += MousePressUp; ct.onTouchScroll += OnTouchScroll; } UpdateRenderingOnce(); }
public void AddTouchScroll() { var ct = Controller.HoverTracker(this); ct.onTouchScroll += (ctrl, position) => { Seen(ctrl, "OnTouchScroll(" + position.x + ", " + position.y + ")"); }; }
void Start() { key_infos = new Dictionary <Button, KeyInfo>(); Button key_altgr = null; bool use_ctrl_alt = false; Dictionary <int, string[]> all_regular_scancodes = new Dictionary <int, string[]>(); foreach (var btn in GetComponentsInChildren <Button>(includeInactive: true)) { string name = btn.gameObject.name; int scancode; char scancodeextra = '\0'; string text0, text1, text2; if (name.StartsWith("X") && name.Length > 2) { scancodeextra = name[1]; name = "S" + name.Substring(2); } if (name.StartsWith("S") && Int32.TryParse(name.Substring(1), out scancode)) { if (scancode == SCAN_BACKSPACE || scancode == SCAN_TAB || scancode == SCAN_ENTER || scancode == SCAN_ALTGR || scancode == SCAN_ESC) { if (scancode == SCAN_TAB && !enableTabKey || scancode == SCAN_ENTER && !enableEnterKey || scancode == SCAN_ESC && !enableEscKey) { Destroy(btn.gameObject); continue; } text0 = text1 = text2 = btn.GetComponentInChildren <Text>().text; if (scancode == SCAN_ALTGR) { key_altgr = btn; } if (scancode == SCAN_ENTER) { text2 = ""; } } else if (scancode == SCAN_SPACE) { text0 = text1 = text2 = " "; all_regular_scancodes.Add(scancode, new string[] { text0, text1 }); } else { text0 = GetCharsFromKeys(scancode, false, false); text1 = GetCharsFromKeys(scancode, true, false); text2 = GetCharsFromKeys(scancode, false, true); if (scancode == SCAN_EXTRA && text0 == GetCharsFromKeys(SCAN_BACKSLASH, false, false) && text1 == GetCharsFromKeys(SCAN_BACKSLASH, true, false) && text2 == GetCharsFromKeys(SCAN_BACKSLASH, false, true)) { text0 = ""; /* key SCAN_EXTRA is completely equivalent to SCAN_BACKSLASH, hide it */ } if (text0 == "") { Destroy(btn.gameObject); continue; } use_ctrl_alt |= (text2 != ""); all_regular_scancodes.Add(scancode, new string[] { text0, text1 }); } } else if (name.StartsWith("K-") && name.Length == 4) { scancode = SCAN_UNKNOWN; text0 = name[2].ToString(); text1 = name[3].ToString(); text2 = ""; } else { continue; } if (scancodeextra == '\0') { switch (scancode) { case SCAN_ENTER: scancodeextra = '\n'; break; case SCAN_TAB: scancodeextra = '\t'; break; } } var info = new KeyInfo(); info.scan_code = scancode; info.scan_code_extra = scancodeextra; info.current_text = text0; info.texts = new string[] { text0, text1, text2 }; info.image = btn.GetComponent <Image>(); info.text = btn.GetComponentInChildren <Text>(); info.Update(); key_infos[btn] = info; } if (!use_ctrl_alt && key_altgr != null) { key_infos.Remove(key_altgr); Destroy(key_altgr.gameObject); } dead_keys_combinations = new Dictionary <string, Dictionary <string, string> >(); foreach (var info in key_infos.Values) { AddDeadKeyCombination(all_regular_scancodes, info.texts[0], info.scan_code, false, false); AddDeadKeyCombination(all_regular_scancodes, info.texts[1], info.scan_code, true, false); AddDeadKeyCombination(all_regular_scancodes, info.texts[2], info.scan_code, false, true); } foreach (Canvas canvas in GetComponentsInChildren <Canvas>(includeInactive: true)) { canvas.worldCamera = GetControllerCamera(); } locals = new List <Local>(); var ct = Controller.HoverTracker(this); ct.SetPriorityFromDistance(controllerPriority); ct.isConcurrent = true; ct.onEnter += OnEnter; ct.onControllersUpdate += OnControllersUpdate; ct.onLeave += OnLeave; ct.onTouchDown += (ctrl) => { }; /* ^^^ needed in addition to next line: otherwise, touching "Enter" closes the keyboard, * and then finishing our movement and actually pressing---that message would be sent * wherever the controller is now, without the line above. */ ct.onTouchPressDown += (ctrl) => { }; /* needed to grab interest in the touchpad / A button */ bool is_oculus = Baroque.GetControllers().Any(ctrl => ctrl.controllerModel == Controller.Model.OculusTouch); if (is_oculus) { ct.onMenuClick += (ctrl) => { } } ; /* needed to grab interest in the B button */ if (reactToTriggerToo) { ct.onTriggerDown += (ctrl) => { } } ; } void AddDeadKeyCombination(Dictionary <int, string[]> all_regular_scancodes, string key_text, int scan_code, bool with_shift, bool with_altgr) { if (!key_text.StartsWith(DEAD_KEY)) { return; } var k = key_text.Substring(DEAD_KEY.Length); dead_keys_combinations[k] = new Dictionary <string, string>(); foreach (var kv in all_regular_scancodes) { for (int i = 1; i >= 0; i--) { if (kv.Value[i].StartsWith(DEAD_KEY)) { continue; } string combined = GetCharsFromKeys(scan_code, with_shift, with_altgr, next_scancode: kv.Key, next_shift: i == 1); if (combined != k + kv.Value[i]) { dead_keys_combinations[k][kv.Value[i]] = combined; } } } }
void Start() { key_infos = new Dictionary <Button, KeyInfo>(); Button key_altgr = null; bool use_ctrl_alt = false; Dictionary <int, string[]> all_regular_scancodes = new Dictionary <int, string[]>(); foreach (var btn in GetComponentsInChildren <Button>()) { string name = btn.gameObject.name; int scancode; string text0, text1, text2; if (name.StartsWith("S") && Int32.TryParse(name.Substring(1), out scancode)) { if (scancode == SCAN_BACKSPACE || scancode == SCAN_TAB || scancode == SCAN_ENTER || scancode == SCAN_ALTGR || scancode == SCAN_ESC) { if (scancode == SCAN_TAB && !enableTabKey || scancode == SCAN_ENTER && !enableEnterKey || scancode == SCAN_ESC && !enableEscKey) { Destroy(btn.gameObject); continue; } text0 = text1 = text2 = btn.GetComponentInChildren <Text>().text; if (scancode == SCAN_ALTGR) { key_altgr = btn; } if (scancode == SCAN_ENTER) { text2 = ""; } } else if (scancode == SCAN_SPACE) { text0 = text1 = text2 = " "; all_regular_scancodes.Add(scancode, new string[] { text0, text1 }); } else { text0 = GetCharsFromKeys(scancode, false, false); text1 = GetCharsFromKeys(scancode, true, false); text2 = GetCharsFromKeys(scancode, false, true); if (scancode == SCAN_EXTRA && text0 == GetCharsFromKeys(SCAN_BACKSLASH, false, false) && text1 == GetCharsFromKeys(SCAN_BACKSLASH, true, false) && text2 == GetCharsFromKeys(SCAN_BACKSLASH, false, true)) { text0 = ""; /* key SCAN_EXTRA is completely equivalent to SCAN_BACKSLASH, hide it */ } if (text0 == "") { Destroy(btn.gameObject); continue; } use_ctrl_alt |= (text2 != ""); all_regular_scancodes.Add(scancode, new string[] { text0, text1 }); } } else if (name.StartsWith("K-") && name.Length == 4) { scancode = SCAN_UNKNOWN; text0 = name[2].ToString(); text1 = name[3].ToString(); text2 = ""; } else { continue; } var info = new KeyInfo(); info.scan_code = scancode; info.current_text = text0; info.texts = new string[] { text0, text1, text2 }; info.image = btn.GetComponent <Image>(); info.text = btn.GetComponentInChildren <Text>(); info.Update(); key_infos[btn] = info; } if (!use_ctrl_alt && key_altgr != null) { key_infos.Remove(key_altgr); Destroy(key_altgr.gameObject); } dead_keys_combinations = new Dictionary <string, Dictionary <string, string> >(); foreach (var info in key_infos.Values) { AddDeadKeyCombination(all_regular_scancodes, info.texts[0], info.scan_code, false, false); AddDeadKeyCombination(all_regular_scancodes, info.texts[1], info.scan_code, true, false); AddDeadKeyCombination(all_regular_scancodes, info.texts[2], info.scan_code, false, true); } foreach (Canvas canvas in GetComponentsInChildren <Canvas>()) { canvas.worldCamera = GetControllerCamera(); } locals = new List <Local>(); var ct = Controller.HoverTracker(this); ct.SetPriorityFromDistance(controllerPriority); ct.isConcurrent = true; ct.onEnter += OnEnter; ct.onControllersUpdate += OnControllersUpdate; ct.onLeave += OnLeave; ct.onTouchDown += (ctrl) => { }; /* needed to grab interest in the touchpad */ }