This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AW_2025/Assets/Scripts/Manager/ResourceManager.cs
2025-02-24 15:18:12 +09:00

64 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using Noah;
namespace Noah
{
public class ResourceManager
{
public Dictionary<string, Sprite> _sprites = new Dictionary<string, Sprite>();
public void Init()
{
}
public T Load<T>(string path) where T : Object
{
if (typeof(T) == typeof(Sprite))
{
if (_sprites.TryGetValue(path, out Sprite sprite))
return sprite as T;
Sprite sp = Resources.Load<Sprite>(path);
_sprites.Add(path, sp);
return sp as T;
}
return Resources.Load<T>(path);
}
public GameObject Instantiate(string path, Transform parent = null)
{
GameObject prefab = Load<GameObject>($"Prefabs/{path}");
if (prefab == null)
{
Debug.Log($"Failed to load prefab : {path}");
return null;
}
return Instantiate(prefab, parent);
}
public GameObject Instantiate(GameObject prefab, Transform parent = null)
{
GameObject go = Object.Instantiate(prefab, parent);
go.name = prefab.name;
return go;
}
public void Destroy(GameObject go)
{
if (go == null)
return;
Object.Destroy(go);
}
}
}