三消控制器,判断死图那里Item没有重置回去,写的时候要注意
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using Kernel.core;
namespace Kernel.MusicGame
{
public enum ThreeRemoveType
{
level1 = 0,
level2 = 1,
level3 = 2,
level4 = 3,
level5 = 4
}
public partial class ThreeRemoveCon : MonoBehaviour
{
public Transform ItemPar;
public List<Sprite> splist = new List<Sprite> {
};
public int tableRow = 7;
public int tableCol = 7;
public Vector2 offset = new Vector2(0, 0);
public int width, height;
public ThreeRemoveItem[,] allItems;
public Vector3[,] allPos;
public List<ThreeRemoveItem> sameList = new List<ThreeRemoveItem> {
};
public List<ThreeRemoveItem> boomList = new List<ThreeRemoveItem> {
};
bool isOperation = true;
bool allBoom = false;
bool isFDec = true;
float FDecTimer = 0f;
public Image mask;
Dictionary<int, List<ThreeRemoveItem>> boomDic = new Dictionary<int, List<ThreeRemoveItem>> {
};
bool isGameStart = false;
public Text vicScore;
public int allScore;
public Text score;
public Text txtreduceTimer;
float reduceTimer;
public Button btnSkip;
public Button btnRest;
public UIThreeRemovePanel threeRemovePanel;
KTThreeRemoveCfg cfg;
private void Awake()
{
allItems = new ThreeRemoveItem[tableRow, tableCol];
allPos = new Vector3[tableRow, tableCol];
btnSkip.onClick.AddListener(ClickSkip);
btnRest.onClick.AddListener(ResetGame);
}
public void StartNewGame()
{
ResetProperty();
InitGame();
AllBoom();
}
public void ResetProperty()
{
btnSkip.interactable = true;
isGameStart = false;
isFDec = true;
FDecTimer = 0f;
allScore = 0;
mask.fillAmount = 1f;
cfg = threeRemovePanel.curRoadCfg;
vicScore.text = cfg.victory.ToString();
reduceTimer = cfg.songLength;
}
public void InitGame()
{
for (int i = 0; i < tableRow; i++)
{
for (int j = 0; j < tableCol; j++)
{
if (allItems[i, j] != null)
{
ThreeRemovePool.instance.AddPool(allItems[i, j]);
allItems[i, j] = null;
}
}
}
for (int i = 0; i < tableRow; i++)
{
for (int j = 0; j < tableCol; j++)
{
ThreeRemoveItem item = ThreeRemovePool.instance.GetPool();
item.transform.SetParent(ItemPar);
item.transform.localPosition = new Vector3(j * width, i * height, 0) + new Vector3(offset.x, offset.y, 0)+new Vector3(i*2.5f,j*2.5f,0);
int randomsp = Random.Range(0, splist.Count);
item.Init(i, j, splist[randomsp], (ThreeRemoveType)randomsp, Click);
allItems[i, j] = item;
allPos[i, j] = item.transform.position;
}
}
}
public void AllBoom()
{
bool hasBoom = false;
foreach (var item in allItems)
{
if (item && !item.hasCheck)
{
CheckAround(item);
if (boomList.Count > 0)
{
hasBoom = true;
isOperation = true;
}
}
}
if (!hasBoom)
{
isOperation = false;
}
FDecTimer = 0f;
}
public void Click(ThreeRemoveItem item)
{
if (isOperation)
return;
isOperation = true;
Vector2 dir = item.GetDirection();
if (dir.magnitude != 1)
{
isOperation = false;
return;
}
StartCoroutine(ItemExchange(item, dir));
}
IEnumerator ItemExchange(ThreeRemoveItem item, Vector2 dir)
{
int targetRow = item.itemRow + System.Convert.ToInt32(dir.y);
int targetColumn = item.itemColumn + System.Convert.ToInt32(dir.x);
bool isLagal = CheckRCLegal(targetRow, targetColumn);
if (!isLagal)
{
isOperation = false;
yield break;
}
ThreeRemoveItem target = allItems[targetRow, targetColumn];
ThreeRemoveItem myItem = allItems[item.itemRow, item.itemColumn];
if (!target || !myItem)
{
isOperation = false;
yield break;
}
target.ItemMove(item.itemRow, item.itemColumn, allPos[item.itemRow, item.itemColumn]);
AddAllItems(item.itemRow, item.itemColumn, target);
myItem.ItemMove(targetRow, targetColumn, allPos[targetRow, targetColumn]);