TheInitialProject/Assets/Scripts/Component/ResourcesComponent.cs

47 lines
1.1 KiB
C#
Raw Permalink Normal View History

2024-10-23 16:59:02 +08:00
using CaoCao.Runtime;
using CaoCao.XAsset;
using System;
using UnityEngine;
namespace Game
{
public class ResourcesComponent : GameComponent
{
public string m_ServerAddress;
protected override void Awake()
{
base.Awake();
}
public T Load<T>(string path) where T : UnityEngine.Object
{
var request = Asset.Load(path, typeof(T));
if (request == null)
{
Log.Warning($"Resource.Load is failed. path = {path}");
return null;
}
return request.asset as T;
}
public GameObject Clone(string path, Transform t = null)
{
var request = Asset.InstantiateAsync(path, t);
if (request == null)
{
Debug.LogError("request == null. path:" + path + ", t is null:" + (t == null));
return null;
}
request.WaitForCompletion();
return request.gameObject;
}
}
}