Exemplo n.º 1
0
        /// <summary>
        /// Changes key in runtime to access listener in all dictionaries.
        /// </summary>
        /// <param name="listener">Input listener to be changed</param>
        /// <param name="from">Old key</param>
        /// <param name="to">New key</param>
        public void ChangeKey(string listener, KeyCode from, KeyCode to)
        {
            InputListener temp;

            Pressed.TryGetValue(from, out temp);
            if (temp != null && temp.Name == listener && !Pressed.ContainsKey(to))
            {
                Pressed.Remove(from);
                Pressed.Add(to, temp);
            }

            JustPressed.TryGetValue(from, out temp);
            if (temp != null && temp.Name == listener && !JustPressed.ContainsKey(to))
            {
                JustPressed.Remove(from);
                JustPressed.Add(to, temp);
            }

            JustReleased.TryGetValue(from, out temp);
            if (temp != null && temp.Name == listener && !JustReleased.ContainsKey(to))
            {
                JustReleased.Remove(from);
                JustReleased.Add(to, temp);
            }

            SaveHandler();
        }
Exemplo n.º 2
0
    //public void Update() {
    //if (Main.Ins.GameBattleEx != null && Main.Ins.GameBattleEx.BattleFinished())
    //    return;
    //if (CombatData.Ins.Replay && FrameReplay.Instance.Started) {

    //} else {
    //    if (Main.Ins.LocalPlayer != null) {
    //        if (Main.Ins.LocalPlayer.meteorController.InputLocked)
    //            return;
    //    }
    //    getButtons();
    //}
    //getAxis();
    //}

    public void ProcessKey(KeyState keyState)
    {
        Pressed.Clear();
        Released.Clear();
        Pressing.Clear();
        if (keyMapping.ContainsKey(keyState.Key))
        {
            JoyKeyState js  = keyMapping[keyState.Key];
            bool        old = js.PointDown;
            js.PointDown = Input.GetKey(js.key);
            if (old && !js.PointDown)
            {
                Released.Add(js);
            }
            if (!old && js.PointDown)
            {
                Pressed.Add(js);
            }
            if (old && js.PointDown)
            {
                Pressing.Add(js);
            }
            //先按下
            for (int i = 0; i < Pressed.Count; i++)
            {
                if (Pressed[i].OnPress != null)
                {
                    Pressed[i].OnPress.Invoke();
                }
            }
            //再蓄力
            for (int i = 0; i < Pressing.Count; i++)
            {
                if (Pressing[i].OnPressing != null)
                {
                    Pressing[i].OnPressing.Invoke();
                }
            }
            //再弹起
            for (int i = 0; i < Released.Count; i++)
            {
                if (Released[i].OnRelease != null)
                {
                    Released[i].OnRelease.Invoke();
                }
            }
        }
    }
Exemplo n.º 3
0
    void PressKey(int Press)
    {
        keys[Press].AddInteractionPunch(0.2f);
        Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.BigButtonPress, keys[Press].transform);
        if (!solved)
        {
            if (scores[Press] == order[Stage] && new[] { Press }.Any(c => !Pressed.Contains(c)))
            {
                Debug.LogFormat("[Colored Letters #{0}] You pressed Button {1}. That was correct.", moduleId, Press + 1);
                Stage++;
                Pressed.Add(Press);
                if (Stage == 4)
                {
                    int SolveText = rnd.Range(0, messagePool.Length);
                    Debug.LogFormat("[Colored Letters #{0}] Module solved.", moduleId);
                    Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.CorrectChime, transform);
                    Module.HandlePass();
                    StopAllCoroutines();
                    for (int x = 0; x < 4; x++)
                    {
                        texts[x].text  = messagePool[SolveText][x].ToString();
                        texts[x].color = Color.green;
                    }
                    solved = true;
                }
            }

            else
            {
                Debug.LogFormat("[Colored Letters #{0}] You pressed Button {1}. That was incorrect. The module resets", moduleId, Press + 1);
                for (int i = 0; i < 4; i++)
                {
                    scores[i] = 0;
                }
                Module.HandleStrike();
                StopAllCoroutines();
                Activate();
            }
        }
    }
Exemplo n.º 4
0
        /// <summary>
        /// Fills dictionaries with InputListeners from the saving file.
        /// If file doesn't exist - with default data filled from the Editor.
        /// <remark> Called from InputManager Awake() </remark>
        /// </summary>
        public bool Init()
        {
            if (_inited)
            {
                return(false);
            }

            List <InputListener> JustPressedSource;
            List <InputListener> PressedSource;
            List <InputListener> JustReleasedSource;

            var savedHandler = InputSaver.ReadHandler(this.Name);

            if (savedHandler != null)
            {
                JustPressedSource  = savedHandler.JustPressed;
                PressedSource      = savedHandler.Pressed;
                JustReleasedSource = savedHandler.JustReleased;
                _axes = savedHandler.Axes;
            }
            else
            {
                JustPressedSource  = JustPressedTemplate;
                PressedSource      = PressedTemplate;
                JustReleasedSource = JustReleasedTemplate;
            }

            foreach (var l in JustPressedSource)
            {
                if (l.Positive != KeyCode.None)
                {
                    JustPressed.Add(l.Positive, l);
                }
                if (l.Alternative != KeyCode.None)
                {
                    JustPressed.Add(l.Alternative, l);
                }

                if (!AllListeners.ContainsKey(l.Name))
                {
                    AllListeners.Add(l.Name, l);
                }
            }

            foreach (var l in PressedSource)
            {
                if (l.Positive != KeyCode.None)
                {
                    Pressed.Add(l.Positive, l);
                }
                if (l.Alternative != KeyCode.None)
                {
                    Pressed.Add(l.Alternative, l);
                }

                if (!AllListeners.ContainsKey(l.Name))
                {
                    AllListeners.Add(l.Name, l);
                }
            }

            foreach (var l in JustReleasedSource)
            {
                if (l.Positive != KeyCode.None)
                {
                    JustReleased.Add(l.Positive, l);
                }
                if (l.Alternative != KeyCode.None)
                {
                    JustReleased.Add(l.Alternative, l);
                }

                if (!AllListeners.ContainsKey(l.Name))
                {
                    AllListeners.Add(l.Name, l);
                }
            }

            _inited = true;

            if (savedHandler == null)
            {
                SaveHandler();
            }

            return(true);
        }