133 lines
4.5 KiB
C#
133 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using Continentis.MainGame.Character;
|
|
using Continentis.MainGame.UI;
|
|
using Lean.Pool;
|
|
using UnityEngine;
|
|
|
|
namespace Continentis.MainGame.Card
|
|
{
|
|
public partial class CardInstance
|
|
{
|
|
[Header("References")]
|
|
public DeckSubmodule deck;
|
|
//public string currentPileName;
|
|
public ICardOwner owner;
|
|
public CharacterBase user;
|
|
public CombatTeam team;
|
|
public CardLogicBase cardLogic;
|
|
public CardLocation cardLocation;
|
|
public HandCardView handCardView;
|
|
public IntentionCardView intentionCardView;
|
|
|
|
public CardInstance(CardLogicBase cardLogic, ICardOwner owner, string initialPileName, int index = -1)
|
|
{
|
|
cardLogic.cardInstance = this;
|
|
this.cardLogic = cardLogic;
|
|
|
|
this.owner = owner;
|
|
this.user = owner as CharacterBase;
|
|
if (this.owner is CombatTeam team)
|
|
{
|
|
this.team = team;
|
|
}
|
|
else if (this.owner is CharacterBase character)
|
|
{
|
|
this.team = character.team;
|
|
}
|
|
|
|
this.deck = owner.deckSubmodule;
|
|
this.cardLocation = new CardLocation(initialPileName, index);
|
|
|
|
if (index < 0)
|
|
{
|
|
this.deck.Pile(cardLocation.pileName).Add(this);
|
|
}
|
|
else
|
|
{
|
|
this.deck.Pile(cardLocation.pileName).Insert(index, this);
|
|
}
|
|
}
|
|
|
|
public HandCardView GenerateHandCardView(string pileName, int index = -1)
|
|
{
|
|
PileBase pile = CombatUIManager.Instance.combatMainPage.Pile(pileName);
|
|
return GenerateHandCardView(pile, index);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成手牌
|
|
/// </summary>
|
|
/// <param name="pile">手牌生成位置</param>
|
|
/// <param name="index">插入位置,-1为末尾</param>
|
|
/// <returns></returns>
|
|
public HandCardView GenerateHandCardView(PileBase pile, int index = -1)
|
|
{
|
|
GameObject handCardObjectPrefab = MainGameManager.Instance.basePrefabs.handCardObject;
|
|
HandCardView handCardView = LeanPool.Spawn(handCardObjectPrefab, pile.rectTransform).GetComponent<HandCardView>();
|
|
if (index >= 0)
|
|
{
|
|
pile.InsertCard(handCardView, index);
|
|
}
|
|
else
|
|
{
|
|
pile.AddCard(handCardView);
|
|
}
|
|
|
|
handCardView.cardInstance = this;
|
|
this.handCardView = handCardView;
|
|
|
|
handCardView.transform.localScale = pile is HandPile ? Vector3.one : Vector3.zero;
|
|
|
|
handCardView.Setup(this);
|
|
handCardView.currentPile = pile;
|
|
handCardView.cardOrb.gameObject.SetActive(false);
|
|
|
|
return handCardView;
|
|
}
|
|
|
|
public void DestroyHandCardView()
|
|
{
|
|
if (handCardView != null)
|
|
{
|
|
handCardView.currentPile.RemoveCard(handCardView);
|
|
LeanPool.Despawn(handCardView.gameObject);
|
|
handCardView = null;
|
|
}
|
|
}
|
|
|
|
public IntentionCardView GenerateIntentionCardView()
|
|
{
|
|
GameObject intentionCardObjectPrefab = MainGameManager.Instance.basePrefabs.intentionCardObject;
|
|
HUD_Intention intention = user.characterView.hudContainer.enablingHUDs["Intention"] as HUD_Intention;
|
|
IntentionCardView intentionCardView = LeanPool.Spawn(intentionCardObjectPrefab, intention.hudTransform).GetComponent<IntentionCardView>();
|
|
intention.AddCard(intentionCardView);
|
|
intentionCardView.cardInstance = this;
|
|
this.intentionCardView = intentionCardView;
|
|
intentionCardView.transform.localScale = Vector3.one;
|
|
intentionCardView.Setup(this);
|
|
return intentionCardView;
|
|
}
|
|
|
|
public void DestroyIntentionCardView()
|
|
{
|
|
if (intentionCardView != null)
|
|
{
|
|
HUD_Intention intention = user.characterView.hudContainer.enablingHUDs["Intention"] as HUD_Intention;
|
|
intention.RemoveCard(intentionCardView);
|
|
intentionCardView = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class CardLocation
|
|
{
|
|
public string pileName;
|
|
public int index;
|
|
|
|
public CardLocation(string pileName, int index)
|
|
{
|
|
this.pileName = pileName;
|
|
this.index = index;
|
|
}
|
|
}
|
|
} |