首次提交
This commit is contained in:
28
Assets/Scripts/Common/Extensions/GObjectExtensions.cs
Normal file
28
Assets/Scripts/Common/Extensions/GObjectExtensions.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using FairyGUI;
|
||||
using NBF.Utils;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class GObjectExtensions
|
||||
{
|
||||
public static void SetQuality(this GImage image, int quality)
|
||||
{
|
||||
image.color = ItemHelper.GetItemQualityColor(quality);
|
||||
}
|
||||
|
||||
public static void SetQuality(this GTextField image, int quality)
|
||||
{
|
||||
image.strokeColor = ItemHelper.GetItemQualityColor(quality);
|
||||
}
|
||||
|
||||
public static void SetTitleQuality(this GButton com, int quality)
|
||||
{
|
||||
com.GetTextField().strokeColor = ItemHelper.GetItemQualityColor(quality);
|
||||
}
|
||||
|
||||
public static void SetTitleQuality(this GTextField com, int quality)
|
||||
{
|
||||
com.strokeColor = ItemHelper.GetItemQualityColor(quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e39c262c800477e8b6e353aa1d62383
|
||||
timeCreated: 1761058048
|
||||
53
Assets/Scripts/Common/Extensions/IConfigTableExtensions.cs
Normal file
53
Assets/Scripts/Common/Extensions/IConfigTableExtensions.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using NBC;
|
||||
using NBC.Asset;
|
||||
using NBF.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class IConfigTableExtensions
|
||||
{
|
||||
|
||||
public static string GetModelPath(this cfg.Item config)
|
||||
{
|
||||
return $"Assets/ResRaw/gfx/{config.Model}.prefab";
|
||||
}
|
||||
|
||||
public static GameObject GetModelPrefab(this cfg.Item config)
|
||||
{
|
||||
return Assets.Load<GameObject>(config.GetModelPath());
|
||||
}
|
||||
|
||||
public static GameObject Instantiate(this cfg.Item config, Transform parent, Vector3 position,
|
||||
Quaternion rotation)
|
||||
{
|
||||
return Object.Instantiate(config.GetModelPrefab(), position, rotation, parent);
|
||||
}
|
||||
|
||||
|
||||
public static T InstantiateAndComponent<T>(this cfg.Item 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 cfg.Item config) where T : MonoBehaviour
|
||||
{
|
||||
var obj = Object.Instantiate(config.GetModelPrefab());
|
||||
var com = obj.GetComponent<T>();
|
||||
if (com == null)
|
||||
{
|
||||
com = obj.AddComponent<T>();
|
||||
}
|
||||
|
||||
return com;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08653a1add0a416cb39ccabdf4bd8280
|
||||
timeCreated: 1760875056
|
||||
Reference in New Issue
Block a user