Supported Parameter Types/Type

From ReflexCLI
Revision as of 07:51, 23 September 2017 by Rtm223 (talk | contribs) (Created page with "The <code>System.Type</code> type is supported into the console, so it is possible to write functions that take a type argument. An example of this in operation is the Comp...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The System.Type type is supported into the console, so it is possible to write functions that take a type argument.

An example of this in operation is the Component.FindInScenes command, which allows you to search the scene for all components of a specific type (similar to Unity's GameObject.FindObjectsOfType(System.Type type) function.

Filtering by SubType

As it is unlikely your command will want to handle every type that exists in the system, you can filter the valid input (and the suggestions it produces, by using a [SubtypeOf()] attribute on the Type parameter in code. For example, the Component.FindInScenes command looks like the following, in code:

    [ConsoleCommand]
    private static string FindInScenes([SubtypeOf(typeof(Component))] Type type, bool includeInactive=false)

This will then only show types derived from UnityEngine.Component in the suggestions, and will reject entry of types that do not match.