2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace Game
{
public class PrefabManager : ManagerBase<PrefabManager>
{
private const string PrefabPathRoot = "Prefab/";
private Dictionary<string, GameObject> _goModuleDict = new Dictionary<string, GameObject>();
public PrefabManager()
{
}
public override void OnCreate()
{
}
public override void Update()
{
}
public override void OnDestroy()
{
}
public GameObject CreateGo(string path)
{
var pathReal = $"{PrefabPathRoot}{path}";
if (!_goModuleDict.ContainsKey(pathReal))
{
var res = Resources.Load<GameObject>(pathReal);
if (res is null)
{
Util.Print("prefab不存在:", pathReal);
return null;
}
_goModuleDict[pathReal] = res;
}
return Object.Instantiate(_goModuleDict[pathReal]);
}
public GameObject CreateGo(GameObject goModule)
{
return Object.Instantiate(goModule);
}
}
}