public ConsoleCommand(string cmd, string format, ConfigFlags flags, string description, ConsoleCallback callback, object data) { Cmd = cmd; Format = format; Flags = flags; Description = description; Callback = callback; Data = data; }
/// <summary> /// Remove a specified callback /// </summary> /// <param name="type">Type of callback</param> /// <param name="message">Message substring to search for</param> public static void RemoveCallback(LogType type, string message) { var handler = Instance; var c = new ConsoleCallback(type, message); if (handler._callbacks.TryGetValue(c, out c)) { return; } handler._callbacks.Remove(c); }
public override void RegisterCommand(string cmd, string format, ConsoleCallback callback, ConfigFlags flags, string description, object data = null) { if (Commands.ContainsKey(cmd)) { return; } cmd = cmd.Trim(); format = format.Trim().Replace("??", "?"); Commands.Add(cmd, new ConsoleCommand(cmd, format, flags, description, callback, data)); }
/// <summary> /// Add a callback to a specified type of Unity Console log. /// </summary> /// <param name="action">Action to execute on message written</param> /// <param name="type">Type of callback</param> /// <param name="message">Message of callback</param> public static void AddCallback(Action action, LogType type, string message) { var handler = Instance; var c = new ConsoleCallback(type, message); //If a callback with these params already exist, retrieve it if (handler._callbacks.ContainsKey(c)) { c = handler._callbacks[c]; } //Otherwise, continue using the newly-created version and add it else { handler._callbacks.Add(c, c); } c.AddAction(action); }
/// <summary> /// Handles logs sent out by Unity's console /// </summary> /// <param name="logString">String logged</param> /// <param name="stackTrace">Stacktrace associated with message</param> /// <param name="type">Type of message</param> private void HandleLog(string logString, string stackTrace, LogType type) { ConsoleCallback callback = null; foreach (var c in _callbacks.Keys) { if (c.Type != type) { continue; } if (logString.Contains(c.Message)) { callback = c; break; } } if (callback == null) { return; } callback.ExecuteActions(); }
public abstract void RegisterCommand(string cmd, string format, ConsoleCallback callback, ConfigFlags flags, string description, object data = null);
public void ConsoleWrite(string text) { if (this.ConsoleTextBox.InvokeRequired) { ConsoleCallback d = new ConsoleCallback(ConsoleWrite); this.Invoke(d, new object[] { text }); } else { if (ConsoleTextBox.Text != null) this.ConsoleTextBox.AppendText(text); else this.ConsoleTextBox.Text = (text); } }