Пример #1
0
        /****************************************************************************************/

        private void Update()
        {
            /* bits of popupCloseTriggerOutside:
             *      bit 16: active
             *      bits 0 or 1: trigger is up
             *      bits 8 or 9: controller was outside the whole time trigger was down
             */
            if (popupShown == null || !popupShown)
            {
                popupCloseTriggerOutside = 0;
            }

            if (popupCloseTriggerOutside != 0)
            {
                int i = 0;
                foreach (var ctrl in Baroque.GetControllers())
                {
                    if (ctrl.CurrentHoverTracker() == this)
                    {
                        popupCloseTriggerOutside &= ~(0x0100 << i);   /* remove bit 8/9: we are inside */
                    }
                    if (ctrl.GetButton(EControllerButton.Trigger))
                    {
                        if ((popupCloseTriggerOutside & (0x01 << i)) != 0)    /* was up, pressing just now */
                        {
                            popupCloseTriggerOutside &= ~(0x01 << i);         /* remove bit 0/1: we are down */
                            if (ctrl.CurrentHoverTracker() != this)
                            {
                                popupCloseTriggerOutside |= (0x0100 << i);    /* set bit 8/9 if we are outside */
                            }
                        }
                    }
                    else
                    {
                        if ((popupCloseTriggerOutside & (0x01 << i)) == 0)    /* was down, releasing just now */
                        {
                            popupCloseTriggerOutside |= (0x01 << i);

                            if ((popupCloseTriggerOutside & (0x0100 << i)) != 0)    /* was outside the whole time trigger was down */
                            {
                                /* we tracked a press and a release entirely outside, so close the dialog */
                                Destroy(popupShown.gameObject);
                            }
                        }
                    }
                    i += 1;
                }
            }
        }
Пример #2
0
        ControllerTracker FindHandler(EEventSet event_set)
        {
            /* returns either tracker_hover or a global tracker, but one
             * that can handle the event_set. */
            if (tracker_hover != null && (tracker_hover._event_sets & event_set) != 0)
            {
                return(tracker_hover);
            }
            else
            {
                /* look for global trackers */
                ControllerTracker best          = null;
                float             best_priority = float.NegativeInfinity;

                foreach (var ct in global_trackers.Values)
                {
                    if ((ct._event_sets & event_set) != 0 && ct.isActiveAndEnabled)
                    {
                        float priority = ct.computePriority(this);
                        if (priority != float.NegativeInfinity)
                        {
                            ct.PickIfBetter(priority, ref best, ref best_priority);
                        }
                    }
                }
                /* If it's a non-concurrent tracker and it is used by the other controller, cancel */
                if (best != null && !best.isConcurrent)
                {
                    foreach (var ctrl in Baroque.GetControllers())
                    {
                        if (ctrl != this && ctrl.ActiveWith(best))
                        {
                            return(null);
                        }
                    }
                }
                return(best);
            }
        }
Пример #3
0
 public static Controller[] GetControllers()
 {
     return(Baroque.GetControllers());
 }
Пример #4
0
 public static Controller GetController(int index)
 {
     return(Baroque.GetControllers()[index]);
 }
Пример #5
0
        private void OnBeforeRender()
        {
            if (camera_rig)
            {
#if false
                /* hide the ghost hands, only show the controllers */
                Action <OvrAvatarHand> disable_mesh_renderer = (hand) =>
                {
                    var skinned_mesh_render = hand.GetComponentInChildren <SkinnedMeshRenderer>();
                    if (skinned_mesh_render != null)
                    {
                        skinned_mesh_render.enabled = false;
                    }
                };
                disable_mesh_renderer(avatar.HandLeft);
                disable_mesh_renderer(avatar.HandRight);
#endif

                /* invoke the main processing loop for BaroqueUI.Controller */
                Baroque._OnNewPosesApplied();

#if false
                /* We don't need transparent controllers, but we want them to combine
                 * correctly with transparent pointers, for example, so make them opaque.
                 * Also tweak the texture to be AlbedoWithMask instead of the standard one:
                 * it has only the Green component relevant for the albedo; the Red and Blue
                 * components are used to identify various parts of the controller, and we
                 * use them as (u, v) into the _Components 4x4 texture.  For example, the
                 * border of the B button is drawn with Red = 0 and Blue = 1/3.  When
                 * mapping the coordinates (0, 1/3) in the 4x4 texture, we arrive at the
                 * 4th pixel, in the list of all 16 pixels.  That's why
                 * EColorizableComponent.MenuBorder = 4.
                 */
                foreach (var ctrl in Baroque.GetControllers())
                {
                    MonoBehaviour avatar_ctrl;
                    switch (ctrl.index)
                    {
                    case 0: avatar_ctrl = avatar.ControllerLeft; break;

                    case 1: avatar_ctrl = avatar.ControllerRight; break;

                    default: continue;
                    }
                    var skinned_mesh_render = avatar_ctrl.GetComponentInChildren <SkinnedMeshRenderer>();
                    if (skinned_mesh_render == null)
                    {
                        continue;
                    }
                    var mat = skinned_mesh_render.material;
                    mat.renderQueue = 2400;

                    Shader shader = Baroque._oculus_touch_controllers_shader;
                    if (shader == null)
                    {
                        shader = Resources.Load <Shader>("BaroqueUI/ControllerOculusTouch/DefaultOculusTouchShader");
                        Baroque._oculus_touch_controllers_shader = shader;
                    }
                    if (mat.shader != shader)
                    {
                        mat.shader = shader;
                    }
                    mat.SetTexture("_Albedo", controller_albedo_with_mask);
                    mat.SetTexture("_Components", GetComponentColors(ctrl).Apply());
                }
                ;
#endif
            }
        }
Пример #6
0
        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;
                    }
                }
            }
        }