¡¡¥«¡¼¥É¥¹¥í¥Ã¥È¤ò´ÉÍý¤¹¤ë¤¿¤á¤Î¥¯¥é¥¹¤Ç¤¹¡£
¡¡¥³¥ó¥¹¥È¥é¥¯¥¿Æâ¤Ë¤Ï¤Þ¤ÀÀ©ºî¤·¤Æ¤¤¤Ê¤¤¥¯¥é¥¹¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤¿¤á¡¢¤½¤Î¤Þ¤Þ¤Ç¤¹¤È¥¨¥é¡¼¤¬½Ð¤Þ¤¹¡£
°ìö¡¢¥³¥ó¥¹¥È¥é¥¯¥¿Á´ÂΤò¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£
CardSlotManager.cs
<= ¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤¤Þ¤¹¡£
using System.Collections.Generic;
using System.Linq;
using UniRx;
public class CardSlotManager
{
public List<CardSlot> CardSlotList { get; private set; } // new¤Ç½é´ü²½¤â¤Ç¤¤ë
private CompositeDisposable disposables = new(); // CompositeDisposable¤ò½é´ü²½
// ¥Ç¥Ð¥Ã¥°ÍÑ
private OwnerStatus[] slotStatus = new OwnerStatus[4]
{
OwnerStatus.Player, OwnerStatus.Player, OwnerStatus.Opponent, OwnerStatus.Opponent
};
public List<CardController> setPlayerCardList = new(); // ¥¹¥í¥Ã¥È¤Ë¥»¥Ã¥È¤·¤¿¥×¥ì¥¤¥ä¡¼¤Î¥«¡¼¥É·²
/// <summary>
/// ¥³¥ó¥¹¥È¥é¥¯¥¿
/// </summary>
/// <param name="battleEventManager"></param>
/// <param name="newCardSlotList"></param>
public CardSlotManager(BattleEventManager battleEventManager, List<CardSlot> newCardSlotList)
{
CardSlotList = new(newCardSlotList);
foreach (var cardSlot in CardSlotList)
{
cardSlot.OnClickAsObservable
.Where(_ => battleEventManager.selectedCard != null)
.Where(_ => cardSlot.owner == OwnerStatus.Player)
.Where(_ => cardSlot.cardController == null)
.Subscribe(_ =>
{
// ¥¹¥í¥Ã¥È¤Ë¥«¡¼¥É¤òÇÛÃÖ
OnClickCardSlot(cardSlot, battleEventManager.selectedCard);
setPlayerCardList.Add(battleEventManager.selectedCard);
// ÁªÂò¤·¤Æ¤¤¤¿¥«¡¼¥É¤ò²ò½ü
battleEventManager.RemoveCard();
PopupManager.instance.HideDescription();
// Á´¤Æ¤Î¥¹¥í¥Ã¥È¤Ë¥«¡¼¥É¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤«³Îǧ
if (CardSlotList.All(slot => slot.cardController != null))
{
battleEventManager.OnCardSet();
}
})
.AddTo(disposables);
}
}
/// <summary>
/// ¥¹¥í¥Ã¥È¤Ë¥«¡¼¥É¤òÇÛÃÖ
/// </summary>
/// <param name="cardSlot"></param>
/// <param name="cardController"></param>
private void OnClickCardSlot(CardSlot cardSlot, CardController selectedCard)
{
cardSlot.SetCard(selectedCard);
}
/// <summary>
/// ÉÔɬÍפʥ꥽¡¼¥¹¤ò¤Þ¤È¤á¤Æ²òÊü
/// </summary>
public void Dispose()
{
disposables.Dispose();
}
/// <summary>
/// ¥«¡¼¥É¥¹¥í¥Ã¥È¤Î¥é¥ó¥À¥à¤Ê2²Õ½ê¤òÂÐÀïÁê¼êÍѤΥ¹¥í¥Ã¥È¤ËÀßÄê
/// </summary>
public void SetOpponentCardSlotsRandomly()
{
slotStatus = slotStatus.OrderBy(_ => UnityEngine.Random.value).ToArray();
for (int i = 0; i < slotStatus.Length; i++)
{
CardSlotList[i].ChangeStatus(slotStatus[i]);
}
}
/// <summary>
/// ¥¹¥í¥Ã¥È¤Ë¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¥«¡¼¥É¤Î¤¦¤Á¡¢»ØÄꤷ¤¿OwnerStatus¤Î¥«¡¼¥É¤òÇË´þ
/// </summary>
/// <param name="target"></param>
public void DeleteCardsFromSlots(OwnerStatus target)
{
foreach (var slot in CardSlotList)
{
if (slot.owner == target && slot.cardController != null)
{
slot.DeleteCard();
}
}
// ¾åµ¤òLinq¤Ç
//CardSlotList
// .Where(slot => slot.owner == target && slot.cardController != null)
// .ToList()
// .ForEach(slot => slot.DeleteCard());
if (target == OwnerStatus.Player)
{
setPlayerCardList.Clear();
}
}
/// <summary>
/// ¥¹¥í¥Ã¥È¤Ë¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ëÁ´¤Æ¤Î¥«¡¼¥É¤òÇË´þ
/// </summary>
public void DeleteAllCardsFromSlots()
{
foreach (var slot in CardSlotList)
{
if (slot.cardController != null)
{
slot.DeleteCard();
}
}
// ¾åµ¤òLinq¤Ç
//CardSlotList
// .Where(slot => slot.cardController != null)
// .ToList()
// .ForEach(slot => slot.DeleteCard());
setPlayerCardList.Clear();
}
}
¥³¥á¥ó¥È¤ò¤«¤¯