备份CatanBuilding瘦身独立工程
This commit is contained in:
187
Assets/Scripts/UI/SmallGame/EventBankHeistOpponentPopupPanel.cs
Normal file
187
Assets/Scripts/UI/SmallGame/EventBankHeistOpponentPopupPanel.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EventBankHeistOpponentPopupPanel : MonoBehaviour
|
||||
{
|
||||
Button mask;
|
||||
Button btn_close;
|
||||
Toggle tab1;
|
||||
Toggle tab2;
|
||||
GameObject selected_tab1;
|
||||
GameObject selected_tab2;
|
||||
OpponentItem itemRandom;
|
||||
GameObject btn_gray;
|
||||
|
||||
GameObject item1;
|
||||
Transform content;
|
||||
List<OpponentItem> items;
|
||||
List<OpponentItemData> opponentFriend;
|
||||
List<OpponentItemData> opponentEnemy;
|
||||
int changeCount = 0;
|
||||
SmallGameData smallGameData;
|
||||
private void Awake()
|
||||
{
|
||||
smallGameData = GContext.container.Resolve<SmallGameData>();
|
||||
mask = transform.Find("mask").GetComponent<Button>();
|
||||
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
||||
tab1 = transform.Find("root/tab/text_tab1").GetComponent<Toggle>();
|
||||
tab2 = transform.Find("root/tab/text_tab2").GetComponent<Toggle>();
|
||||
selected_tab1 = transform.Find("root/tab/selected_tab1").gameObject;
|
||||
selected_tab2 = transform.Find("root/tab/selected_tab2").gameObject;
|
||||
|
||||
itemRandom = transform.Find("root/ScrollView/Viewport/Content/Item").GetComponent<OpponentItem>();
|
||||
btn_gray = transform.Find("root/ScrollView/Viewport/Content/Item/btn_gray").gameObject;
|
||||
content = transform.Find("root/ScrollView/Viewport/Content");
|
||||
item1 = transform.Find("root/ScrollView/Viewport/Content/Item1").gameObject;
|
||||
item1.SetActive(false);
|
||||
items = new List<OpponentItem>();
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
//smallGameData.LoadData();
|
||||
opponentFriend = smallGameData.opponentFriend;
|
||||
opponentEnemy = smallGameData.GetOpponentEnemy();
|
||||
SelectRandom();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
mask.onClick.AddListener(Close);
|
||||
btn_close.onClick.AddListener(Close);
|
||||
itemRandom.action = RandomPlayer;
|
||||
SetRandomText();
|
||||
tab1.onValueChanged.AddListener((bool isOn) =>
|
||||
{
|
||||
if (isOn)
|
||||
{
|
||||
SelectRandom();
|
||||
}
|
||||
});
|
||||
tab2.onValueChanged.AddListener((bool isOn) =>
|
||||
{
|
||||
if (isOn)
|
||||
{
|
||||
SelectFriend();
|
||||
}
|
||||
});
|
||||
//for (int i = 0; i < itemDatas.Count; i++)
|
||||
//{
|
||||
// GameObject go = Instantiate(item1, content);
|
||||
// go.SetActive(true);
|
||||
// OpponentItem item = go.GetComponent<OpponentItem>();
|
||||
// item.action = SelectPlayer;
|
||||
// items.Add(item);
|
||||
// item.SetData(itemDatas[i]);
|
||||
//}
|
||||
}
|
||||
void SelectRandom()
|
||||
{
|
||||
selected_tab1.SetActive(true);
|
||||
selected_tab2.SetActive(false);
|
||||
int count = items.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
items[i].gameObject.SetActive(false);
|
||||
}
|
||||
itemRandom.gameObject.SetActive(true);
|
||||
if (opponentEnemy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GameObject go;
|
||||
OpponentItem item;
|
||||
for (int i = 0; i < opponentEnemy.Count; i++)
|
||||
{
|
||||
if (i < count)
|
||||
{
|
||||
item = items[i];
|
||||
go = items[i].gameObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
go = Instantiate(item1, content);
|
||||
item = go.GetComponent<OpponentItem>();
|
||||
items.Add(item);
|
||||
item.action = SelectPlayer;
|
||||
}
|
||||
go.SetActive(true);
|
||||
item.SetData(opponentEnemy[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void SelectFriend()
|
||||
{
|
||||
selected_tab1.SetActive(false);
|
||||
selected_tab2.SetActive(true);
|
||||
int count = items.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
items[i].gameObject.SetActive(false);
|
||||
}
|
||||
itemRandom.gameObject.SetActive(false);
|
||||
GameObject go;
|
||||
OpponentItem item;
|
||||
for (int i = 0; i < opponentFriend.Count; i++)
|
||||
{
|
||||
if (i < count)
|
||||
{
|
||||
item = items[i];
|
||||
go = items[i].gameObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
go = Instantiate(item1, content);
|
||||
item = go.GetComponent<OpponentItem>();
|
||||
items.Add(item);
|
||||
item.action = SelectPlayer;
|
||||
}
|
||||
go.SetActive(true);
|
||||
item.SetData(opponentFriend[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void SetRandomText()
|
||||
{
|
||||
int count = GContext.container.Resolve<Tables>().TbAquariumConfig.RaidChangeTimes;
|
||||
itemRandom.SetTextInfo(LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_1", count - changeCount, count));
|
||||
}
|
||||
|
||||
//随机玩家
|
||||
void RandomPlayer(OpponentItemData opponentItemData, bool random)
|
||||
{
|
||||
opponentItemData = smallGameData.RandomItem();
|
||||
if (GContext.container.Resolve<SmallGameData>().opponentData.playFabID == opponentItemData.playFabID)
|
||||
{
|
||||
opponentItemData = smallGameData.RandomItem();
|
||||
}
|
||||
changeCount++;
|
||||
SetRandomText();
|
||||
if (changeCount >= GContext.container.Resolve<Tables>().TbAquariumConfig.RaidChangeTimes)
|
||||
{
|
||||
itemRandom.SetGray();
|
||||
btn_gray.SetActive(true);
|
||||
}
|
||||
SelectPlayer(opponentItemData, true);
|
||||
}
|
||||
//选中一位玩家
|
||||
void SelectPlayer(OpponentItemData opponentItemData, bool random = false)
|
||||
{
|
||||
if (GContext.container.Resolve<SmallGameData>().opponentData.playFabID != opponentItemData.playFabID)
|
||||
{
|
||||
GContext.container.Resolve<SmallGameData>().opponentData = opponentItemData;
|
||||
ChangeSmallGameTargetEvent changeSmallGameTargetEvent = new ChangeSmallGameTargetEvent();
|
||||
changeSmallGameTargetEvent.opponentItemData = opponentItemData;
|
||||
changeSmallGameTargetEvent.random = random;
|
||||
changeSmallGameTargetEvent.ts = new System.Threading.Tasks.TaskCompletionSource<bool>();
|
||||
GContext.Publish(changeSmallGameTargetEvent);
|
||||
}
|
||||
Close();
|
||||
}
|
||||
void Close()
|
||||
{
|
||||
UIManager.Instance.HideUI(UITypes.EventBankHeistOpponentPopupPanel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user