新增脚本

This commit is contained in:
2025-12-26 20:35:52 +08:00
parent 875960d3fd
commit 45129be7dc
60 changed files with 3384 additions and 70247 deletions

View File

@@ -1,5 +1,7 @@
using NBC;
using NBC.Asset;
using NBF.Utils;
using UnityEngine;
namespace NBF
{
@@ -17,7 +19,44 @@ namespace NBF
public static string GetModelPath(this ItemConfig config)
{
return "gfx/" + config.Model;
return $"Assets/ResRaw/gfx/{config.Model}.prefab";
}
public static GameObject GetModelPrefab(this ItemConfig config)
{
return Assets.Load<GameObject>(config.GetModelPath());
}
public static GameObject Instantiate(this ItemConfig config, Transform parent, Vector3 position,
Quaternion rotation)
{
return Object.Instantiate(config.GetModelPrefab(), position, rotation, parent);
}
public static T InstantiateAndComponent<T>(this ItemConfig config, Transform parent, Vector3 position,
Quaternion rotation) where T : MonoBehaviour
{
var obj = config.Instantiate(parent, position, rotation);
var com = obj.GetComponent<T>();
if (com == null)
{
com = obj.AddComponent<T>();
}
return com;
}
public static T InstantiateAndComponent<T>(this ItemConfig config) where T : MonoBehaviour
{
var obj = Object.Instantiate(config.GetModelPrefab());
var com = obj.GetComponent<T>();
if (com == null)
{
com = obj.AddComponent<T>();
}
return com;
}
}
}