Skip to content

Commit 250f6db

Browse files
committed
Added lots of comments and changed access level for some methods.
1 parent c9f109b commit 250f6db

File tree

5 files changed

+600
-140
lines changed

5 files changed

+600
-140
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Added Color as a supported parameter type.
1616
- Added command: "colour" - displays the provided colour in the developer console.
1717
- Changed DevConsole.InvokeCoroutine method to return the Coroutine instance.
18+
- Changed some method access levels from internal to public.
1819
- Fixed Unity logs from other threads not showing in the developer console log.
1920
- Fixed generic or nullable parameter types not having their type displayed nicely.
2021
- Fixed log scroll view not snapping to bottom intuitively.

Runtime/Command.cs

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ internal static Command Create(DevConsoleCommandAttribute commandAttribute, Meth
149149

150150
#region Constructors
151151

152-
private Command() { }
152+
private Command()
153+
{
154+
}
153155

154156
#endregion
155157

@@ -158,17 +160,22 @@ private Command() { }
158160
/// <summary>
159161
/// Name of the command.
160162
/// </summary>
161-
internal string Name { get; private set; }
163+
public string Name { get; private set; }
162164

163165
/// <summary>
164-
/// Optional command names.
166+
/// Description of the command.
165167
/// </summary>
166-
internal string[] Aliases { get; private set; }
168+
public string HelpText { get; private set; }
167169

168170
/// <summary>
169-
/// Description of the command.
171+
/// Whether the command is a custom command (not a built-in command).
170172
/// </summary>
171-
internal string HelpText { get; private set; }
173+
public bool IsCustomCommand { get; private set; }
174+
175+
/// <summary>
176+
/// Optional command names.
177+
/// </summary>
178+
internal string[] Aliases { get; private set; }
172179

173180
/// <summary>
174181
/// Array of parameters required to execute the command.
@@ -186,11 +193,6 @@ private Command() { }
186193
/// </summary>
187194
internal Action DefaultCallback { get; private set; }
188195

189-
/// <summary>
190-
/// Whether the command is a custom command.
191-
/// </summary>
192-
internal bool IsCustomCommand { get; private set; }
193-
194196
#endregion
195197

196198
#region Methods
@@ -200,6 +202,62 @@ public override string ToString()
200202
return Name;
201203
}
202204

205+
/// <summary>
206+
/// Get the command syntax as a formatted string.
207+
/// </summary>
208+
/// <returns></returns>
209+
public string ToFormattedString()
210+
{
211+
string result = GetFormattedName();
212+
for (int i = 0; i < Parameters.Length; i++)
213+
{
214+
if (i < Parameters.Length)
215+
{
216+
result += " ";
217+
}
218+
219+
result += GetFormattedParameter(i);
220+
}
221+
return result;
222+
}
223+
224+
/// <summary>
225+
/// Get the command name as a formatted string.
226+
/// </summary>
227+
/// <returns></returns>
228+
public string GetFormattedName()
229+
{
230+
return $"<b>{Name}</b>";
231+
}
232+
233+
/// <summary>
234+
/// Get a parameter as a formatted string.
235+
/// </summary>
236+
/// <param name="parameterIndex"></param>
237+
/// <returns></returns>
238+
public string GetFormattedParameter(int parameterIndex)
239+
{
240+
return Parameters[parameterIndex].ToFormattedString();
241+
}
242+
243+
/// <summary>
244+
/// Get the command aliases.
245+
/// </summary>
246+
/// <returns></returns>
247+
public IReadOnlyList<string> GetAliases()
248+
{
249+
return Aliases;
250+
}
251+
252+
/// <summary>
253+
/// Get the command parameters.
254+
/// </summary>
255+
/// <returns></returns>
256+
public IReadOnlyList<Parameter> GetParameters()
257+
{
258+
return Parameters;
259+
}
260+
203261
/// <summary>
204262
/// Ensure the command name is valid.
205263
/// </summary>
@@ -247,44 +305,6 @@ internal void SetAsCustomCommand()
247305
IsCustomCommand = true;
248306
}
249307

250-
/// <summary>
251-
/// Get the command name as a formatted string.
252-
/// </summary>
253-
/// <returns></returns>
254-
internal string GetFormattedName()
255-
{
256-
return $"<b>{Name}</b>";
257-
}
258-
259-
/// <summary>
260-
/// Get a parameter as a formatted string.
261-
/// </summary>
262-
/// <param name="parameterIndex"></param>
263-
/// <returns></returns>
264-
internal string GetFormattedParameter(int parameterIndex)
265-
{
266-
return Parameters[parameterIndex].ToFormattedString();
267-
}
268-
269-
/// <summary>
270-
/// Get the command syntax as a formatted string.
271-
/// </summary>
272-
/// <returns></returns>
273-
internal string ToFormattedString()
274-
{
275-
string result = GetFormattedName();
276-
for (int i = 0; i < Parameters.Length; i++)
277-
{
278-
if (i < Parameters.Length)
279-
{
280-
result += " ";
281-
}
282-
283-
result += GetFormattedParameter(i);
284-
}
285-
return result;
286-
}
287-
288308
#endregion
289309
}
290310
}

Runtime/DevConsole.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static bool IsKeyBindingsEnabled
9191
public static InputKey? ToggleKey
9292
{
9393
get => _console.ConsoleToggleKey;
94-
set => _console.SetToggleKey(value);
94+
set => _console.ConsoleToggleKey = value;
9595
}
9696

9797
#endregion
@@ -160,6 +160,37 @@ public static bool RunCommand(string input)
160160
return _console.RunCommand(input);
161161
}
162162

163+
/// <summary>
164+
/// Get a command instance by name.
165+
/// </summary>
166+
/// <param name="name"></param>
167+
/// <returns></returns>
168+
public static Command GetCommand(string name)
169+
{
170+
if (string.IsNullOrEmpty(name))
171+
{
172+
throw new ArgumentNullException(nameof(name));
173+
}
174+
175+
return _console.GetCommand(name);
176+
}
177+
178+
/// <summary>
179+
/// Get a command instance by name.
180+
/// </summary>
181+
/// <param name="name"></param>
182+
/// <param name="command"></param>
183+
/// <returns></returns>
184+
public static bool GetCommand(string name, out Command command)
185+
{
186+
if (string.IsNullOrEmpty(name))
187+
{
188+
throw new ArgumentNullException(nameof(name));
189+
}
190+
191+
return _console.GetCommand(name, out command);
192+
}
193+
163194
/// <summary>
164195
/// Add a parameter type to the dev console database.
165196
/// This will allow the provided type to be used as a parameter in commands.
@@ -289,7 +320,7 @@ public static void LogCommand(string name)
289320
/// <param name="toggleKey"></param>
290321
public static void SetToggleKey(InputKey? toggleKey)
291322
{
292-
_console.SetToggleKey(toggleKey);
323+
_console.ConsoleToggleKey = toggleKey;
293324
}
294325

295326
/// <summary>

0 commit comments

Comments
 (0)