private void Awake() { LettersLoader = new PKKeyboardLettersLoader(_keyboardConfiguration); //Set Special Keys Confirm.Text = LettersLoader.Confirm; Cancel.Text = LettersLoader.Cancel; Backspace.Text = LettersLoader.Backspace; ClearAll.Text = LettersLoader.ClearAll; SpecialKey.Text = LettersLoader.Pages[1].SpecialLetter; //Getting normal keys component reference Letters = new PKKeyButton[Lines.Length][]; for (int i = 0; i < Letters.Length; i++) { PKKeyButton[] lettersCompornt = Lines[i].GetComponentsInChildren <PKKeyButton>(); Letters[i] = new PKKeyButton[lettersCompornt.Length]; for (int j = 0; j < lettersCompornt.Length; j++) { Letters[i][j] = lettersCompornt[j]; } } SetPage(0, 1); }
void OnRelasedKeyButton(PYButton sender, bool isMouseOver) { CancelDefaultInvokes(); EnableButtons(); // If user clicked in a disabled key // the pressedKey var will be null, so just return if (_pressedKey == null) { return; } PKKeyButton keyButton = (sender != null) ? (PKKeyButton)sender : null; if ((keyButton != null) && ((isMouseOver && sender == _pressedKey.OwnGameObject))) { if (OnKeyUp != null) { OnKeyUp(_pressedKey.Text); } } _pressedKey.ChangeState(PYButtonState.Idle); _pressedKey = null; EnableButtons(); CheckMuteState(); }
void OnEnable() { targetRef = (PKKeyButton)target; targetRef.Graphic = targetRef.transform.FindChild("KeyGraphic").GetComponentInChildren <SpriteRenderer>(); if (targetRef.Text != null) { keyText = targetRef.Text; } }
public void DisableKey(PKKeyButton key, bool conditionToDisable) { if (conditionToDisable) { key.ChangeState(PYButtonState.Disabled); if (_pressedKey == key) { _pressedKey = null; } } else { key.ChangeState(PYButtonState.Idle); } }
private void Keyboard_OnType(Playmove.PKKeyButton key) { if (_withDisplay) { return; } if (_firstInput) { FieldToType.Text = ""; } _firstInput = false; switch (key.Type) { case Playmove.PKKeyType.Letter: SetText(key.Text); break; case Playmove.PKKeyType.Space: SetText(" "); break; case Playmove.PKKeyType.Backspace: FieldToType.Text = FieldToType.Text.Remove((int)Mathf.Clamp(Position - 1, 0, Mathf.Infinity), 1); Position--; break; case Playmove.PKKeyType.CursorNavigationLeft: Position = (int)Mathf.Clamp(Position - 1, 0, Mathf.Infinity); break; case Playmove.PKKeyType.CursorNavigationRight: Position = Mathf.Clamp(Position + 1, 0, FieldToType.Text.Length); break; case Playmove.PKKeyType.ClearAllText: FieldToType.Text = ""; Position = 0; break; case Playmove.PKKeyType.Point: SetText("."); break; } }
private void Initialize() { BannedWordsManager.LoadBannedWords(); _keys = GetComponentsInChildren <PKKeyButton>(true); _tween = PYTweenAnimation.Add(gameObject).SetDuration(1.5f).SetEaseType(Ease.Type.InOutExpo); if (_voiceSource == null) { GameObject o = new GameObject("VoiceSource"); o.transform.parent = transform; _voiceSource = o.AddComponent <AudioSource>(); _voiceSource.playOnAwake = false; } foreach (PKKeyButton key in _keys) { if (key.Type == PKKeyType.Cancel) { _cancelBtn = key; } if (key.Type == PKKeyType.Confirm) { _confirmBtn = key; } key.onDown.AddListener(TouchManagerOnClick); key.onClick.AddListener((sender) => { OnRelasedKeyButton(sender, sender.IsPointerInside); }); if (key.Type == PKKeyType.Mute) { _muteKey = key; } } CheckMuteState(); ChangeState(CurrentState); NormalKeys.SetActiveCapsLockBtn(_activeCapsLock); }
public void Show() { IsShowing = true; Box.gameObject.SetActive(true); if (AlternativeChars.Length > keys.Count) { int keyCount = keys.Count; for (int x = 0; x < AlternativeChars.Length - keyCount; x++) { GameObject key = (GameObject)Instantiate(AlternativeCharKey); key.SetActive(false); keys.Add(key); } } for (int i = 0; i < AlternativeChars.Length; i++) { Box.transform.localScale = Vector3.one; keys[i].transform.position = new Vector3(boxBounds.min.x + (keySize.x * i) + keySize.x / 2, Box.transform.position.y, Box.transform.position.z - 5); keys[i].transform.parent = Box.transform; keys[i].transform.localScale = Vector3.one; PKKeyButton keyButton = keys[i].GetComponent <PKKeyButton>(); //keyButton.Graphic.transform.localScale = keySize; keyButton.Text = AlternativeChars[i]; keys[i].SetActive(true); } Box.enabled = false; tween.SetDuration(0.75f); tween.SetEaseType(Ease.Type.OutElastic); tween.Play(); }
void TouchManagerOnClick(PYButton sender) { if (!_isEnabled) { return; } for (int i = 0; i < _keys.Length; i++) // Identify wich key was clicked { if (sender.OwnGameObject == _keys[i].OwnGameObject && _keys[i].State != PYButtonState.Disabled) { _pressedKey = _keys[i]; _pressedKey.ChangeState(PYButtonState.Pressed); if (OnKeyDown != null) { OnKeyDown(_keys[i].Text); } break; } } if (_pressedKey == null) // If clicked key is null, do nothing { return; } PKKeyButton keyButton = (sender != null) ? (PKKeyButton)sender : null; if ((keyButton != null) && ((sender.OwnGameObject == _pressedKey.OwnGameObject))) { _launchTextChange = true; PlayKeySound(); PlayKeyVoice(); if (_pressedKey != null && OnType != null) { OnType(_pressedKey); } switch (_pressedKey.Type) { case PKKeyType.Letter: if (Text.Length >= 20) { break; } if (CursorPosition < Text.Length) { Text = Text.Substring(0, CursorPosition) + _pressedKey.Text + Text.Substring(CursorPosition); ChangeDisplayCursorPosition(1); if (OnTextChange != null) { OnTextChange(Text); } } else { Text += _pressedKey.Text; if (OnTextChange != null) { OnTextChange(Text); } } if (CursorPosition >= Text.Length - 1 && CursorPosition < Display.MaxChars) { ChangeDisplayCursorPosition(1); } else { ChangeDisplayCursorPosition(0); } //voltar para a pagina normal autamaticamente if (!IsNormalPage) { KeyActionSpecial(0); } break; case PKKeyType.Space: KeyActionSpace(); break; case PKKeyType.Backspace: if (!_hasAutomaticPressed) { KeyActionBackspace(); } _hasAutomaticPressed = false; break; case PKKeyType.Confirm: KeyActionConfirm(); _launchTextChange = false; break; case PKKeyType.Cancel: KeyActionCancel(); _launchTextChange = false; break; case PKKeyType.Special: KeyActionSpecial(); _launchTextChange = false; break; case PKKeyType.CursorNavigationLeft: if (!_hasAutomaticPressed) { KeyActionCursorNavigation(-1); } _hasAutomaticPressed = false; _launchTextChange = false; break; case PKKeyType.CursorNavigationRight: if (!_hasAutomaticPressed) { KeyActionCursorNavigation(1); } _hasAutomaticPressed = false; _launchTextChange = false; break; case PKKeyType.ClearAllText: ClearText(); break; case PKKeyType.Mute: Mute = !Mute; _launchTextChange = false; break; case PKKeyType.Point: if (CursorPosition < Text.Length) { StringBuilder sb = new StringBuilder(Text + ""); sb[CursorPosition] = ".".ToCharArray()[0]; Text = sb.ToString(); if (OnTextChange != null) { OnTextChange(Text); } } else { Text += "."; if (OnTextChange != null) { OnTextChange(Text); } } if (CursorPosition >= Text.Length - 1 && CursorPosition < Display.MaxChars) { ChangeDisplayCursorPosition(1); } else { ChangeDisplayCursorPosition(0); } if (!IsNormalPage) //Back to normal page automaticaly { KeyActionSpecial(); } break; } } // If user keep holding the key, we execute the action automatic // based in the timeTick if (_pressedKey != null) { if (_pressedKey.Type == PKKeyType.Backspace) { if (!IsInvoking("KeyActionBackspace")) { InvokeRepeating("KeyActionBackspace", TimeTickPressed, TimeTickPressed); } } else if (_pressedKey.Type == PKKeyType.CursorNavigationLeft) { if (!IsInvoking("KeyActionCursorNavigationLeft")) { InvokeRepeating("KeyActionCursorNavigationLeft", TimeTickPressed, TimeTickPressed); } } else if (_pressedKey.Type == PKKeyType.CursorNavigationRight) { if (!IsInvoking("KeyActionCursorNavigationRight")) { InvokeRepeating("KeyActionCursorNavigationRight", TimeTickPressed, TimeTickPressed); } } } }