示例#1
0
        private static void LoadCommandsFromMember(MemberInfo member, MethodInfo method)
        {
            IEnumerable <CommandAttribute> commandAttributes    = member.GetCustomAttributes <CommandAttribute>();
            CommandDescriptionAttribute    descriptionAttribute = member.GetCustomAttribute <CommandDescriptionAttribute>();

            foreach (CommandAttribute commandAttribute in commandAttributes)
            {
                if (!commandAttribute.Valid)
                {
                    if (loggingLevel >= LoggingLevel.Warnings)
                    {
                        Debug.LogWarning($"Quantum Processor Warning: Could not add '{commandAttribute.Alias}' to the table as it is invalid.");
                    }
                }
                else
                {
                    CommandPlatformAttribute platformAttribute = member.GetCustomAttribute <CommandPlatformAttribute>();
                    Platform commandPlatforms = platformAttribute?.SupportedPlatforms ?? commandAttribute.SupportedPlatforms;
                    if (commandPlatforms.HasFlag(Application.platform.ToPlatform()))
                    {
                        IEnumerable <CommandData> newCommands = CreateCommandOverloads(method, commandAttribute, descriptionAttribute);
                        foreach (CommandData command in newCommands)
                        {
                            TryAddCommand(command);
                        }
                    }
                }
            }
        }
示例#2
0
 public CommandData(MethodInfo methodData, CommandAttribute commandAttribute, CommandDescriptionAttribute descriptionAttribute, int defaultParameterCount = 0)
     : this(methodData, commandAttribute, defaultParameterCount)
 {
     if ((descriptionAttribute?.Valid ?? false) && string.IsNullOrWhiteSpace(commandAttribute.Description))
     {
         CommandDescription = descriptionAttribute.Description;
     }
 }
示例#3
0
        private static IEnumerable <CommandData> CreateCommandOverloads(MethodInfo method, CommandAttribute commandAttribute, CommandDescriptionAttribute descriptionAttribute)
        {
            int defaultParameters = method.GetParameters().Count((ParameterInfo x) => x.HasDefaultValue);

            for (int i = 0; i < defaultParameters + 1; i++)
            {
                CommandData command = new CommandData(method, commandAttribute, descriptionAttribute, i);
                yield return(command);
            }
        }