void Start() { inputFocuse = GetComponent <InputFocus>(); DontDestroyOnLoad(gameObject); NetworkingManager.Singleton.OnClientConnectedCallback += ServerAndConnectingClientOnly_OnClientConnectedCallback; NetworkingManager.Singleton.OnClientDisconnectCallback += ServerAndDisconnectingClientOnly_OnClientDisconnectCallback; NetworkingManager.Singleton.OnServerStarted += Singleton_OnServerStarted; }
/// <summary> /// If your form needs this kind of input focus, be sure to say so. /// Really, this only makes sense for mouse, but I've started building it out for other things /// Why is this receiving a control, but actually using it as a Form (where the WantingMouseFocus is checked?) /// Because later we might change it to work off the control, specifically, if a control is supplied (normally actually a Form will be supplied) /// </summary> public void ControlInputFocus(Control c, InputFocus types, bool wants) { if (types.HasFlag(InputFocus.Mouse) && wants) { _wantingMouseFocus.Add(c); } if (types.HasFlag(InputFocus.Mouse) && !wants) { _wantingMouseFocus.Remove(c); } }
/// <summary> /// If your form needs this kind of input focus, be sure to say so. /// Really, this only makes sense for mouse, but I've started building it out for other things /// Why is this receiving a control, but actually using it as a Form (where the WantingMouseFocus is checked?) /// Because later we might change it to work off the control, specifically, if a control is supplied (normally actually a Form will be supplied) /// </summary> public void ControlInputFocus(System.Windows.Forms.Control c, InputFocus types, bool wants) { if (types.HasFlag(InputFocus.Mouse) && wants) { WantingMouseFocus.Add(c); } if (types.HasFlag(InputFocus.Mouse) && !wants) { WantingMouseFocus.Remove(c); } }
private void HandleButton(string button, bool newState, InputFocus source) { ModifierKey currentModifier = ButtonToModifierKey(button); if (EnableIgnoreModifiers && currentModifier != ModifierKey.None) { return; } if (_lastState[button] == newState) { return; } // apply // NOTE: this is not quite right. if someone held leftshift+rightshift it would be broken. seems unlikely, though. if (currentModifier != ModifierKey.None) { if (newState) { _modifiers |= currentModifier; } else { _modifiers &= ~currentModifier; } } // don't generate events for things like Ctrl+LeftControl ModifierKey mods = _modifiers; if (currentModifier != ModifierKey.None) { mods &= ~currentModifier; } var ie = new InputEvent { EventType = newState ? InputEventType.Press : InputEventType.Release, LogicalButton = new LogicalButton(button, mods), Source = source }; _lastState[button] = newState; // track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers // this is an interesting idea, which we may need later, but not yet. // for example, you may see this series of events: press:ctrl+c, release:ctrl, release:c // but you might would rather have press:ctrl+c, release:ctrl+c // this code relates the releases to the original presses. // UPDATE - this is necessary for the frame advance key, which has a special meaning when it gets stuck down // so, i am adding it as of 11-sep-2011 if (newState) { _modifierState[button] = ie.LogicalButton; } else { if (_modifierState.TryGetValue(button, out var buttonModifierState)) { if (buttonModifierState != ie.LogicalButton && !_ignoreEventsNextPoll) { _newEvents.Add( new InputEvent { LogicalButton = buttonModifierState, EventType = InputEventType.Release, Source = source }); } _modifierState.Remove(button); } } if (!_ignoreEventsNextPoll) { _newEvents.Add(ie); } }
/// <summary> /// If your form needs this kind of input focus, be sure to say so. /// Really, this only makes sense for mouse, but I've started building it out for other things /// Why is this receiving a control, but actually using it as a Form (where the WantingMouseFocus is checked?) /// Because later we might change it to work off the control, specifically, if a control is supplied (normally actually a Form will be supplied) /// </summary> public void ControlInputFocus(System.Windows.Forms.Control c, InputFocus types, bool wants) { if (types.HasFlag(InputFocus.Mouse) && wants) WantingMouseFocus.Add(c); if (types.HasFlag(InputFocus.Mouse) && !wants) WantingMouseFocus.Remove(c); }
void HandleButton(string button, bool newState, InputFocus source) { bool isModifier = IgnoreKeys.Contains(button); if (EnableIgnoreModifiers && isModifier) { return; } if (LastState[button] && newState) { return; } if (!LastState[button] && !newState) { return; } //apply //NOTE: this is not quite right. if someone held leftshift+rightshift it would be broken. seems unlikely, though. if (button == "LeftShift") { _Modifiers &= ~ModifierKey.Shift; if (newState) { _Modifiers |= ModifierKey.Shift; } } if (button == "RightShift") { _Modifiers &= ~ModifierKey.Shift; if (newState) { _Modifiers |= ModifierKey.Shift; } } if (button == "LeftControl") { _Modifiers &= ~ModifierKey.Control; if (newState) { _Modifiers |= ModifierKey.Control; } } if (button == "RightControl") { _Modifiers &= ~ModifierKey.Control; if (newState) { _Modifiers |= ModifierKey.Control; } } if (button == "LeftAlt") { _Modifiers &= ~ModifierKey.Alt; if (newState) { _Modifiers |= ModifierKey.Alt; } } if (button == "RightAlt") { _Modifiers &= ~ModifierKey.Alt; if (newState) { _Modifiers |= ModifierKey.Alt; } } if (UnpressState.ContainsKey(button)) { if (newState) { return; } Console.WriteLine($"Removing Unpress {button} with {nameof(newState)} {newState}"); UnpressState.Remove(button); LastState[button] = false; return; } //dont generate events for things like Ctrl+LeftControl ModifierKey mods = _Modifiers; if (button == "LeftShift") { mods &= ~ModifierKey.Shift; } if (button == "RightShift") { mods &= ~ModifierKey.Shift; } if (button == "LeftControl") { mods &= ~ModifierKey.Control; } if (button == "RightControl") { mods &= ~ModifierKey.Control; } if (button == "LeftAlt") { mods &= ~ModifierKey.Alt; } if (button == "RightAlt") { mods &= ~ModifierKey.Alt; } var ie = new InputEvent { EventType = newState ? InputEventType.Press : InputEventType.Release, LogicalButton = new LogicalButton(button, mods), Source = source }; LastState[button] = newState; //track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers //this is an interesting idea, which we may need later, but not yet. //for example, you may see this series of events: press:ctrl+c, release:ctrl, release:c //but you might would rather have press:ctr+c, release:ctrl+c //this code relates the releases to the original presses. //UPDATE - this is necessary for the frame advance key, which has a special meaning when it gets stuck down //so, i am adding it as of 11-sep-2011 if (newState) { ModifierState[button] = ie.LogicalButton; } else { if (ModifierState[button] != null) { LogicalButton alreadyReleased = ie.LogicalButton; var ieModified = new InputEvent { LogicalButton = (LogicalButton)ModifierState[button], EventType = InputEventType.Release, Source = source }; if (ieModified.LogicalButton != alreadyReleased) { _NewEvents.Add(ieModified); } } ModifierState[button] = null; } _NewEvents.Add(ie); }