Синтаксис:
Используется csharp
Класс загрузки файлов
using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
public class FileProcessor
{
static public List<string> fileNames;
public FileProcessor(string path)
{
}
public static void ProcessDirectory(string targetDirectory)
{
fileNames = new List<string>();
string[] fileEntries = Directory.GetFiles(targetDirectory, "*.jpg");
foreach (string fileName in fileEntries)
{
ProcessFile(fileName);
}
}
public static void ProcessFile(string path)
{
string str_path = path;
str_path = str_path.Replace(".jpg", "");
str_path = str_path.Replace("Assets/Resources/", "");
fileNames.Add(str_path);
Debug.Log(str_path + " найден");
}
}
Соответственно код обработчика нажатия на кнопку открытия меню:
void ClickOnLeftMenu()
{
leftMenu = Instantiate(Resources.Load<GameObject>("Prefabs/LeftPanel"));
leftMenu.GetComponent<Transform>().SetParent(gui.GetComponent<Transform>(), false);
Transform topPanel = leftMenu.transform.Find("topPanel");
Button closeButton = topPanel.Find("btnClose").GetComponent<Button>();
closeButton.onClick.AddListener(ClickOnCloseMenu);
Transform bodyPanel = leftMenu.transform.Find("bodyPanel");
Image content = bodyPanel.Find("content").GetComponent<Image>();
int i = 1;
foreach (string floorsNames in FileProcessor.fileNames)
{
foorItem = Instantiate(Resources.Load<GameObject>("Prefabs/FloorItem"));
foorItem.GetComponent<Transform>().SetParent(content.GetComponent<Transform>(), false);
foorItem.GetComponent<Transform>().Find("Title").GetComponent<Text>().text = "Этаж " + i++;
Transform floorMask = foorItem.transform.Find("Body");
Image floorImage = floorMask.Find("FloorImage").GetComponent<Image>();
Debug.Log("ОТЛАДКА ИМЯ ФАЙЛА И ПУТЬ "+floorsNames);
floorImage.sprite = Resources.Load<Sprite>(floorsNames);
floorItems.Add(foorItem);
}
}
using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
public class FileProcessor
{
static public List<string> fileNames;
public FileProcessor(string path)
{
}
public static void ProcessDirectory(string targetDirectory)
{
fileNames = new List<string>();
string[] fileEntries = Directory.GetFiles(targetDirectory, "*.jpg");
foreach (string fileName in fileEntries)
{
ProcessFile(fileName);
}
}
public static void ProcessFile(string path)
{
string str_path = path;
str_path = str_path.Replace(".jpg", "");
str_path = str_path.Replace("Assets/Resources/", "");
fileNames.Add(str_path);
Debug.Log(str_path + " найден");
}
}
Соответственно код обработчика нажатия на кнопку открытия меню:
void ClickOnLeftMenu()
{
leftMenu = Instantiate(Resources.Load<GameObject>("Prefabs/LeftPanel"));
leftMenu.GetComponent<Transform>().SetParent(gui.GetComponent<Transform>(), false);
Transform topPanel = leftMenu.transform.Find("topPanel");
Button closeButton = topPanel.Find("btnClose").GetComponent<Button>();
closeButton.onClick.AddListener(ClickOnCloseMenu);
Transform bodyPanel = leftMenu.transform.Find("bodyPanel");
Image content = bodyPanel.Find("content").GetComponent<Image>();
int i = 1;
foreach (string floorsNames in FileProcessor.fileNames)
{
foorItem = Instantiate(Resources.Load<GameObject>("Prefabs/FloorItem"));
foorItem.GetComponent<Transform>().SetParent(content.GetComponent<Transform>(), false);
foorItem.GetComponent<Transform>().Find("Title").GetComponent<Text>().text = "Этаж " + i++;
Transform floorMask = foorItem.transform.Find("Body");
Image floorImage = floorMask.Find("FloorImage").GetComponent<Image>();
Debug.Log("ОТЛАДКА ИМЯ ФАЙЛА И ПУТЬ "+floorsNames);
floorImage.sprite = Resources.Load<Sprite>(floorsNames);
floorItems.Add(foorItem);
}
}