private void ButtSlappedHandler(SuggestionButton butt) { _CommandLocation.text = butt.Text + " "; _CommandLocation.Select(); _CommandLocation.ForceLabelUpdate(); // because ForceLabelUpdate() doesnt work StartCoroutine(MoveCaretToEndRoutine(_CommandLocation)); }
private void OnCommandGettingTypedIn(string szCommand) { List <Command> matchingCommands = new List <Command>(); _CommandLocationHelpText.text = "Enter Command..."; // compile list of commands if (string.IsNullOrEmpty(szCommand) == false) { _CommandLocationHelpText.text = ""; _CommandLocationHelpText.enabled = true; string szRawCommand = szCommand.Trim(' '); // grab every command that matches our partial command foreach (Command cmd in _Commands) { // handle if we have a command typed in full if (cmd.Name == szRawCommand) { _CommandLocationHelpText.text = szRawCommand + " " + cmd.ParamDescription; } else if (cmd.Name.Contains(szCommand)) { matchingCommands.Add(cmd); } } } else { _CommandLocationHelpText.enabled = false; } // enable/disable the suggestion view based on the commands we found int nTotalCount = Mathf.Min(matchingCommands.Count, _MaxSuggestions); if (nTotalCount > 0) { _SuggestionPanel.gameObject.SetActive(true); // wipe butts that are out of range while (_SuggestionPanel.childCount > nTotalCount) { Transform child = _SuggestionPanel.GetChild(0); child.SetParent(null); Destroy(child.gameObject); } // add butts that we will need to reach max while (_SuggestionPanel.childCount < nTotalCount) { SuggestionButton newButt = Instantiate(_SuggestionButtonPrefab); newButt.OnButtSlapped += ButtSlappedHandler; Transform newChild = newButt.transform; newChild.SetParent(_SuggestionPanel); } // handle each butt for (int nButtIndex = 0; nButtIndex < nTotalCount; ++nButtIndex) { SuggestionButton childButt = _SuggestionPanel.GetChild(nButtIndex).GetComponent <SuggestionButton>(); childButt.Text = matchingCommands[nButtIndex].Name; } // set the help to be the first Command first = matchingCommands[0]; if (first.Name.StartsWith(szCommand)) { _CommandLocationHelpText.text = first.Name + " " + matchingCommands[0].ParamDescription; } else { _CommandLocationHelpText.enabled = false; } } else { _SuggestionPanel.gameObject.SetActive(false); } }