using System
.Collections
;
using System
.Collections
.Generic
;
using UnityEngine
;
public interface ILoader
{
GameObject LoadPrefab(string path
, Transform parent
= null);
}
using System
.Collections
;
using System
.Collections
.Generic
;
using UnityEngine
;
public class ResLoader : ILoader
{
public GameObject LoadPrefab(string path
,Transform parent
= null)
{
GameObject prefab
= Resources
.Load<GameObject>(path
);
GameObject temp
= Object
.Instantiate(prefab
, parent
);
return temp
;
}
}
using System
;
using System
.Collections
;
using System
.Collections
.Generic
;
using UnityEngine
;
public class LoadMgr : NormalSingleton<LoadMgr
> {
private ILoader _loader
;
public LoadMgr()
{
_loader
= new ResLoader();
}
public GameObject LoadPrefab(string path
,Transform parent
= null)
{
GameObject temp
= _loader
.LoadPrefab(path
, parent
);
Type type
= Type
.GetType(temp
.name
.Remove(temp
.name
.Length
- 7));
temp
.AddComponent(type
);
return temp
;
}
}
using System
.Collections
;
using System
.Collections
.Generic
;
using UnityEngine
;
public class LaunchGame : MonoBehaviour {
void Start
() {
LoadMgr
.Instance
.LoadPrefab("Prefab/StartView", transform
);
}
}
转载请注明原文地址: https://lol.8miu.com/read-11290.html