How to Convert FileInfo to TextAsset to add to List

I’m creating a game where there are lots of virtual book to read from, but I’m having trouble when it comes to assigning to a list the pages of the book.

Here’s how it is supposed to work:

  • The books are organized into folders, and the chapters of each book are its sub-folders.
  • When the player chooses the book he wants to read, the script finds that book and organizes all the chapters, and finds all the pages that are inside those chapters folders.

The problem arises here. I need to convert those pages that the script finds to TextAssets and add them to a List of TextAssets. It needs to work this way due to the manner in which the virtual books work: each page is an element of the list.

Here’s where the problem happens:

private void DefineBook()
		//Encontra todos os capitulos do livro escolhido pelo jogador
		BookChapters = BookInQuestion.GetDirectories();
		int a = 0;
		for (int p = 0; p < BookChapters.Length; p++)
			Pages = new DirectoryInfo("" + BookChapters[p].FullName.ToString());
			PagesInfo = Pages.GetFiles();
			foreach(FileInfo f in PagesInfo)
				TotalPages.Add(PagesInfo[a] as TextAsset);
		//CurrentPage_Left = PagesInfo[0];
		//CurrentPage_Right = PagesInfo[_currentPageLeft + 1];
		mostrarLivro = !mostrarLivro;

Then I get the following error: Cannot convert type ‘System.IO.FileInfo’ to ‘Unity.TextAsset’ via built-in conversion.

I mean, I know why it doesn’t work, I just don’t know how to convert those files.
Any help would be much appreciated since I’ve been stuck on this problem for a while.

Do you want to have each page of the book stored in memory, or do you want to stream the pages at you time. If you want to store all the pages and their data in a custom class, just use the Text Reader at the start, and if you want to stream them, just store their paths into a list and then use the Text Reader to load the data into memory when you want. You can also use the pages Directory Info to organize them into books.