private void GenerateParameterSuggestionButtons() { var lastTypedParameters = _inputField.PreviousCompleteParameters; var commandHandler = DevelopmentCommands.GetCommandWrapper(lastTypedParameters.First()); if (commandHandler == null) { return; } var commandHandlerParameters = commandHandler.Parameters.ToArray(); var currentParameterIndex = _inputField.CurrentParameterIndex; if (currentParameterIndex >= commandHandlerParameters.Length) { return; } var parameterValue = currentParameterIndex + 1 < lastTypedParameters.Length ? lastTypedParameters[currentParameterIndex + 1] : ""; var parameterOptions = commandHandler.Parameters[currentParameterIndex].GetParameterPossibleValues(parameterValue, lastTypedParameters); var isLastParameter = currentParameterIndex == commandHandlerParameters.Length - 1; var commandUpToLastParameter = string.Join(" ", lastTypedParameters.SubArray(0, currentParameterIndex + 1)); _suggestionButtons.AddRange(parameterOptions.Select(x => new SuggestionButton(_skinData, x, commandUpToLastParameter + " " + x, isLastParameter))); }
/// <summary> /// Called automatically when .Command launches, you can add your own Registrations here. /// Don't forget to match your DevelopmentCommands.Register call with a DevelopmentCommands.Unregister call /// by calling DevelopmentCommands.Unregister in CommandRegistration.UnRegisterCommandsOnConsoleExit /// /// Note: You can Register Commands from anywhere you like, if you do it here however, you'll be able to keep the /// registration / unregistration tidy, this method will be called automatically for you at a sensible time. /// /// </summary> public static void RegisterCommandsOnConsoleStartup(bool clearConsoleCommandEnabled, bool deviceIdCommandEnabled, bool inspectCommandEnabled, bool autoScrollCommandEnabled) { // Register Commands by type if (deviceIdCommandEnabled) { DevelopmentCommands.Register(typeof(DeviceIdSampleCommands)); } if (clearConsoleCommandEnabled) { DevelopmentCommands.Register(typeof(ClearConsoleSampleCommands)); } if (autoScrollCommandEnabled) { DevelopmentCommands.Register(typeof(AutoScrollCommands)); } if (inspectCommandEnabled) { DevelopmentCommands.Register(typeof(Inspect)); } // Register Commands by object if (DevelopmentConsole.Instance) { DevelopmentCommands.Register(DevelopmentConsole.Instance); } }
public static void UnRegisterCommandsOnConsoleExit() { DevelopmentCommands.Unregister(typeof(DeviceIdSampleCommands)); DevelopmentCommands.Unregister(typeof(ClearConsoleSampleCommands)); DevelopmentCommands.Unregister(typeof(AutoScrollCommands)); DevelopmentCommands.Unregister(typeof(Inspect)); // Un Register Commands by object DevelopmentCommands.Unregister(DevelopmentConsole.Instance); }
private void GeneratePossibleCommandButtons() { var matchingCommands = DevelopmentCommands.FindCommandFromPartial(_inputField.PreviousCompleteParameters[0]).ToArray(); foreach (var matchingCommand in matchingCommands) { var hasParameters = matchingCommand.Parameters.Length != 0; _suggestionButtons.Add(new SuggestionButton(_skinData, matchingCommand.CommandName, matchingCommand.CommandName, !hasParameters)); } }
/// <summary> /// This class is here to provide users with a single easy location to register all command objects with the Development Console. /// It is for illustration purposes only, you can do something similar to this in your own code. /// /// Note: You can Register Commands from anywhere in runtime code. /// /// </summary> public static void RegisterCommandsOnConsoleStartup() { // Register Commands by type DevelopmentCommands.Register(typeof(DeviceIdSampleCommands)); DevelopmentCommands.Register(typeof(ClearConsoleSampleCommands)); DevelopmentCommands.Register(typeof(AutoScrollCommands)); DevelopmentCommands.Register(typeof(Inspect)); // Register Commands by object DevelopmentCommands.Register(DevelopmentConsole.Instance); }
public override void OnInspectorGUI() { DrawDefaultInspector(); DevelopmentCommands devCommands = (DevelopmentCommands)target; if (GUILayout.Button("PlayerPrefs.DeleteAll")) { devCommands.PlayerPrefsDeleteAll(); } /* * if (GUILayout.Button("RESET")) * { * myScript.Reset(); * }*/ }
private void GenerateRecentCommandButtons() { var commands = DevelopmentConsole.Instance.RecentCommands.ToList(); if (!commands.Any()) { commands.Add("ConsoleScale"); } foreach (var recentCommand in commands) { var commandHandler = DevelopmentCommands.GetCommandWrapper(recentCommand); if (commandHandler == null) { continue; } var hasParameters = commandHandler.Parameters.Length != 0; _suggestionButtons.Add(new SuggestionButton(_skinData, commandHandler.CommandName, commandHandler.CommandName, !hasParameters)); } }
public void Draw(ISkinData skinData, Rect rect) { const float margin = 20.0f; const int rowLimit = 2; var padding = Selector.OnPlatform(_skinData.ButtonSpacing, _skinData.ButtonSpacingTouch); var style = UnityGui.Helper.SuggestionButtonStyle(skinData); var itemHeight = style.CalcHeight(new GUIContent("["), 10.0f); var x = rect.x; var y = rect.y; var rowsRemaining = rowLimit; var itemCount = _suggestionButtons.Count; foreach (var button in _suggestionButtons) { if (rowsRemaining == 0) { var moreItemsLabel = itemCount + " more..."; var moreContent = new GUIContent(moreItemsLabel); var moreMaxWidth = style.CalcSize(moreContent).x; if (x + button.Width + moreMaxWidth > rect.width - margin) { var moreRect = new Rect(x, y, moreMaxWidth, itemHeight); UnityGui.Helper.Label(_skinData, moreRect, moreContent); GUI.Label(moreRect, moreContent, style); break; } } if (x + button.Width > rect.width - margin) { rowsRemaining--; y += itemHeight + padding; x = rect.x; } var itemRect = new Rect(x, y, button.Width, itemHeight); x += button.Width + padding; if (UnityGui.Helper.Button(_skinData, itemRect, button.Content.text)) { if (button.AutomaticallyExecute) { DevelopmentCommands.HandleCommand(button.Input); _inputField.Input = ""; } else { _inputField.Input = button.Input; Event.current.Use(); } _inputField.FinaliseInput(); } itemCount--; } }