Hello friends, I am working on file reading app (.pdf, .doc…). Currently I was working on the main menu for the app. In this menu should be shown some buttons that are generated by foreach statement via template (foreach file found there is created a button), buttons are composed of some images, text… so the user gets basic info about file. It sounds great but my autogenerate script seems not to work, I am not able to figure out whats wrong, thanks for help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.IO;
using System.Linq;
public class FileCreatorLinks : MonoBehaviour
{
public Transform Template;
public Transform Parent;
public Image SplitImage;
public void Start(int positionIndex, PDFExtraction pdfExtraction, Sprites sprites)
{
DirectoryInfo directory = new DirectoryInfo("Assets/Resources/");
FileInfo[] info = directory.GetFiles(".pdf");
foreach(FileInfo f in info)
{
CreateFileButton(f, Sprites.GetSprite(Sprites.TypeOfFile.pdf), SplitImage);
}
}
public void CreateFileButton(System.IO.FileInfo f, Sprite TypeOfDoc, Image splitImage)
{
Transform FileLinkTemplate = Instantiate(Template, Parent);
RectTransform TemplateRectTransform = FileLinkTemplate.GetComponent<RectTransform>();
FileLinkTemplate.Find("NameOfFile").GetComponent<TextMeshProUGUI>().SetText(f.Name);
FileLinkTemplate.Find("InfoText").GetComponent<TextMeshProUGUI>().SetText(f.CreationTime.ToString("MM dd, yyyy, hh:mm:ss"));
FileLinkTemplate.Find("TypeOfDoc").GetComponent<Image>().sprite = TypeOfDoc;
FileLinkTemplate.Find("SplitImage").GetComponent<Image>();
}
}