コード例 #1
0
        public static void CopyData(this CommandInfo info, ExecutableCommandAttribute attribute, Type type)
        {
            string[] paths = null;
            if (attribute.name != null)
            {
                info.fullPath = attribute.name;
                paths         = attribute.name.Trim('/').Split('/');
            }

            if (paths == null || paths.Length == 0)
            {
                info.categories = new string[0];
                info.name       = type.Name.GetReadableName();
            }
            else
            {
                info.name       = paths[paths.Length - 1];
                info.categories = new string[paths.Length - 1];
                if (paths.Length > 1)
                {
                    Array.Copy(paths, info.categories, paths.Length - 1);
                }
            }

            info.description = attribute.description;
            info.order       = attribute.order;
        }
コード例 #2
0
		void InitCommands()
		{
			Type[] commandTypes = TypeCollector.GetClassesOfClass(typeof(Command));
			List<Command> executableCommands = new List<Command>();
			List<Command> settingCommands = new List<Command>();

			// Init executable command
			foreach (var commandType in commandTypes)
			{
				ExecutableCommandAttribute attribute = commandType.GetCustomAttribute<ExecutableCommandAttribute>();
				if (attribute != null)
				{
					Command command = (Command)Activator.CreateInstance(commandType);
					command.CacheVariableInfos(commandType);
					command.CacheCustomButtonInfos(commandType, typeof(ButtonAttribute));
					command.info.CopyData(attribute, commandType);
					
					try
					{
						command.InitDefaultVariableValue();
						command.LoadSavedValue();
                        command.OnVariableValueLoaded();
                    }
					catch
					{
						Debug.LogErrorFormat("There is something wrong with command: {0}", commandType.Name);
					}
					
					executableCommands.Add(command);
				}
			}
			_commandViewBuilder = new CommandViewBuilder(executableCommands);
			_commands.AddRange(executableCommands);

			// Init setting command
			foreach (var commandType in commandTypes)
			{
				SettingCommandAttribute attribute = commandType.GetCustomAttribute<SettingCommandAttribute>();
				if (attribute != null)
				{
					Command command = (Command)Activator.CreateInstance(commandType);
					command.CacheVariableInfos(commandType);
					command.info.CopyData(attribute, commandType);

					try
					{
						command.InitDefaultVariableValue();
						command.LoadSavedValue();
                        command.OnVariableValueLoaded();
                    }
					catch
					{
						Debug.LogErrorFormat("There is something wrong with command: {0}", commandType.Name);
					}

					settingCommands.Add(command);
				}
			}

			_settingViewBuilder = new SettingViewBuilder(settingCommands);
			_commands.AddRange(settingCommands);


			// Notify event
			_hasCommandsCreated = true;
			if (OnCommandsCreated != null)
			{
				OnCommandsCreated(_commands.AsReadOnly());
			}
		}