Ejemplo n.º 1
0
    public static void UnregisterHotKey(KeyCode keyCode, UnityAction func, HotKeyMode keyMode = HotKeyMode.GetKeyDown, UpdateMode updateMode = UpdateMode.Update)
    {
        var pool = GetTargetPool(keyMode, updateMode);

        if (pool.TryGetValue(keyCode, out var listeners))
        {
            listeners.RemoveListener(func);
        }
    }
Ejemplo n.º 2
0
    public static void RegisterHotKey(KeyCode keyCode, UnityAction func, HotKeyMode keyMode = HotKeyMode.GetKeyDown, UpdateMode updateMode = UpdateMode.Update)
    {
        if (hotKeyMgr == null)
        {
            hotKeyMgr = Singleton.GetInstance <HotKeyMgr>();
        }
        var pool = GetTargetPool(keyMode, updateMode);

        if (!pool.TryGetValue(keyCode, out var listeners))
        {
            listeners = new UnityEvent();
            pool.Add(keyCode, listeners);
        }
        listeners.AddListener(func);
    }
Ejemplo n.º 3
0
    private static Dictionary <KeyCode, UnityEvent> GetTargetPool(HotKeyMode keymode, UpdateMode updateMode)
    {
        switch (updateMode)
        {
        case UpdateMode.Update:
            switch (keymode)
            {
            case HotKeyMode.GetKeyDown:
                return(keyDownPool);

            case HotKeyMode.GetKeyUp:
                return(keyUpPool);

            case HotKeyMode.GetKey:
                return(KeyPool);

            default:
                return(new Dictionary <KeyCode, UnityEvent>());
            }

        case UpdateMode.FixedUpdate:
            switch (keymode)
            {
            case HotKeyMode.GetKeyDown:
                return(fixedKeyDownPool);

            case HotKeyMode.GetKeyUp:
                return(fixedKeyUpPool);

            case HotKeyMode.GetKey:
                return(fixedKeyPool);

            default:
                return(new Dictionary <KeyCode, UnityEvent>());
            }

        default:
            return(new Dictionary <KeyCode, UnityEvent>());
        }
    }