Example #1
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());
			}
		}