yasirkula / UnityIngameDebugConsole

A uGUI based console to see debug messages and execute commands during gameplay in Unity
MIT License
2.14k stars 224 forks source link

Add obj.toggletype and obj.typealiases commands #74

Closed tonygiang closed 1 year ago

tonygiang commented 1 year ago

The main addition of this PR is the obj.toggletype command.

obj.toggletype takes a keyword, finds a Component with a type name that contains that keyword (case-insensitive) from all runtime assemblies, finds the first GameObject that contains that Component, then toggles its active state.

Alternatively, the keyword argument can be a shortened alias to a full type name. The alias-to-type-name mappings are open for registration by programmers through IngameDebugConsole.Commands.ObjectCommands.TypeAliases. Type names registered here are expected to be FullName.

The 2 aliases pre-registered for this command are rin.rh & rin.ri, which map to the Runtime Hierachy & Inspector respectively. This PR began as a command that turns on & off Runtime Hierachy & Inspector, but expanded into a general-purpose command. It still ships with built-in Runtime Hierachy & Inspector integration so that you can turn on & off those objects with obj.toggletype rin.rh.

obj.typealiases is a companion command to print out the current content of the IngameDebugConsole.Commands.ObjectCommands.TypeAliases Dictionary.

yasirkula commented 1 year ago

Thank you for this pull request! I was initially thinking that we could set an object's active state with this command by typing that object's name and optionally its type. Specifying only the type limits the use-cases of the command in my opinion because basically, it can work on singleton objects only. And I'd want this command to be as simple as possible so if object name parameter had already existed, I'd have still wanted you to remove TypeAliases from the command.

Thanks again for the PR! I'll close it if it's fine for you.

tonygiang commented 1 year ago

The PR is yours to update.

This did start out as a Runtime Hierarchy & Inspector toggling command and was made general-purpose for Singleton and Singleton-like objects. There is room for more search-and-toggle commands here for sure, this PR is not exactly meant to be a comprehensive suite of such commands.

I can update this PR with an overload to take in an argument for the exact state to switch the found object to. I can remove TypeAliases too though that will also cost the ability to type really short type names. Are you sure this is in the interest of developers?

yasirkula commented 1 year ago

I want the built-in commands to be as simple and general-case as possible and then the developers can implement specialized commands on their own. I'm OK with an obj.active(string name, bool active) command (I've removed the type parameter as well for simplicity's sake, it should no longer be necessary since we're typing the object's name here) but it's now practically a different command than yours and I wouldn't ask you to edit your PR like that.

tonygiang commented 1 year ago

Toggling by name and toggling by type don't have to be mutually exclusive. I added a obj.togglename command to toggle an object by name and overloads for both commands that take in an explicit state. I put the state as the first argument since the keyword is likely to be the argument that will get modified more frequently by developers than the state argument.

yasirkula commented 1 year ago

I'm sorry for my late response. Thanks again for your latest update to the PR. I want the built-in commands to be very simple and I find the current commands too complex to my liking. I've decided not to add an obj.active command at the moment either, I appreciate your time and effort in this PR though ⭐