IndieGame/client/Assets/Ether/Scripts/Tools/Loader/LoaderTools.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00
/********************************************************************
: LoaderTools.cs
:
: 1982614048@qq.com
: 2024/03/29 17:28:19
:
: 2024/04/12 16:55:51
:
*********************************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ether
{
public static class LoaderTools
{
public static T LoadAsset<T>(string assetName) where T : Object
{
return Resources.Load<T>(assetName);
}
public static GameObject LoadGameObjectAndInstantiateAsync(string assetName, Transform parent = null)
{
GameObject asset = Resources.Load<GameObject>(assetName);
GameObject go = GameObject.Instantiate(asset, parent);
if (go != null)
{
go.name = go.name.Replace("(Clone)", "");
}
return go;
}
public static GameObject Instantiate(GameObject asset, Transform parent = null)
{
GameObject go = GameObject.Instantiate(asset, parent);
if (go != null)
{
go.name = go.name.Replace("(Clone)", "");
}
if (!go.activeSelf)
{
go.SetActive(true);
}
return go;
}
}
}