继续
This commit is contained in:
@@ -28,8 +28,9 @@ namespace Continentis.MainGame.Card
|
||||
[CreateAssetMenu(menuName = "Continentis/MainGame/Card/CardData", fileName = "CardData")]
|
||||
public partial class CardData : ScriptableObject
|
||||
{
|
||||
[FormerlySerializedAs("cardLogicClassName")] [Header("Fundamental")]
|
||||
public string classFullName;
|
||||
[Header("Fundamental")]
|
||||
public string modName;
|
||||
public string className;
|
||||
public string displayName;
|
||||
public Rarity cardRarity;
|
||||
public CardType cardType;
|
||||
@@ -64,9 +65,6 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
public partial class CardData
|
||||
{
|
||||
public string ModName => classFullName.Split('_').First();
|
||||
public string ClassName => classFullName.Split('_').Last();
|
||||
|
||||
public bool HasTag(string tag)
|
||||
{
|
||||
return tags.Contains(tag);
|
||||
@@ -88,44 +86,6 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
public partial class CardData
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成卡牌实例
|
||||
/// </summary>
|
||||
/// <param name="owner">卡牌持有者</param>
|
||||
/// <param name="pileName">初始卡堆名称,默认为"Draw"</param>
|
||||
/// <param name="index">插入位置,默认为0</param>
|
||||
public CardInstance GenerateCardInstance(ICardOwner owner, string pileName = "Draw", int index = -1)
|
||||
{
|
||||
CardInstance cardInstance = new CardInstance(GenerateCardLogic(), owner, pileName, index);
|
||||
cardInstance.cardLogic.Initialize();
|
||||
return cardInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成卡牌逻辑实例
|
||||
/// </summary>
|
||||
public CardLogicBase GenerateCardLogic()
|
||||
{
|
||||
Type cardLogicType = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(assembly => assembly.GetTypes())
|
||||
.FirstOrDefault(t => typeof(CardLogicBase).IsAssignableFrom(t) && t.Name == this.classFullName);//TODO: 后续优化为共用字典
|
||||
|
||||
if(cardLogicType == null)
|
||||
{
|
||||
Debug.LogError($"Card class '{classFullName}' not found in assemblies.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Activator.CreateInstance(cardLogicType) is CardLogicBase cardLogic)
|
||||
{
|
||||
cardLogic.cardData = this;
|
||||
cardLogic.Setup();
|
||||
return cardLogic;
|
||||
}
|
||||
|
||||
Debug.LogError($"Card class '{classFullName}' not found or could not be instantiated.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过索引获取衍生卡牌数据
|
||||
|
||||
Reference in New Issue
Block a user