NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System.Collections;
using System.Collections.Generic;
using UnityEditor.SceneManagement;
using UnityEngine;
using System.Linq;
using UnityEngine.UIElements;
using Unity.VisualScripting;
public class CupAnswerManager : MonoBehaviour
{
[SerializeField] private GameObject holdeCupListItem, table;
[SerializeField] private int totalCupListItem = 5;
[SerializeField] private CupListItem prefabCupListItem;
[SerializeField] private CupSlotManager slotManager;
[SerializeField] private Cup prefabCup;
public List<CupListItem> listCupListItems;
public int totalCups, totalColor, countCorrect;
private int lengthCupListItems, lengthSlots;
private List<int> listCupListItemColor;
public List<int> listCenterCreatedLI_colors;
public List<Slot> listCheckSlots;
private float timerCheck, timerCheckWL;
private int _indexSlot, countNextCycle;
public List<DataCup> listCollectionCups;
public List<List<DataCup>> listDataCups = new();
private Queue<DataCup> cupQueue = new Queue<DataCup>();
public int indexSlot
{
get => _indexSlot;
set
{
_indexSlot = value;
if (_indexSlot > lengthSlots - 1) _indexSlot = 0;
// print("Index: " + _indexSlot);
}
}
private bool nextLoop;
public void Init()
{
nextLoop = false;

slotManager.Init();
int oneItemCupLength = totalCups / totalCupListItem;
int uldegdelItemCupLength = totalCups % totalCupListItem;
print(totalCups + " + " + totalCupListItem + " + " + oneItemCupLength + "/" + uldegdelItemCupLength + " color: " + totalColor);
//Get created cup all colors....
List<int> listAllColorIndex = new List<int>();
int length = listCenterCreatedLI_colors.Count;
for (int i = 0; i < length; i++)
{
// print("color: " + listCenterCreatedLI_colors[i]);
for (int j = 0; j < countCorrect; j++)
{
int colorId = listCenterCreatedLI_colors[i];
listAllColorIndex.Add(colorId);
}
}
List<int> listRndColorIndex = MyUtils.UniqueRandomInt(0, listAllColorIndex.Count);
//Random mixering color...
List<int> listAllMixerColor = new List<int>();
for (int i = 0; i < listAllColorIndex.Count; i++)
{
listAllMixerColor.Add(listAllColorIndex[listRndColorIndex[i]]);
}
print("All color: " + listAllColorIndex.Count + " All mixer color: " + listAllMixerColor.Count);

listCupListItemColor = new List<int>();
for (int i = 0; i < totalCupListItem; i++)
{
listCupListItemColor.Add(oneItemCupLength);
}
List<int> rndChooseLI = MyUtils.UniqueRandomInt(0, totalCupListItem);
for (int i = 0; i < uldegdelItemCupLength; i++)
{
int ind = rndChooseLI[i];
listCupListItemColor[ind]++;
}
//Create cup....
listCupListItems = new List<CupListItem>();
float zaiX = 0;
float offset = table.transform.localScale.x / totalCupListItem;
for (int i = 0; i < totalCupListItem; i++)
{
int cutLength = listCupListItemColor[i];
List<int> cutColor = listAllMixerColor.GetRange(0, cutLength);
listAllMixerColor.RemoveRange(0, cutLength);
// print("itemLen: " + listCupListItemColor[i]);
Vector3 pos = holdeCupListItem.transform.localPosition;
zaiX = offset * i;
pos.x = zaiX;
CupListItem cupListItem = Instantiate(prefabCupListItem, pos, Quaternion.identity, holdeCupListItem.transform);
cupListItem.idCol = i;
cupListItem.cupLength = cutLength;
cupListItem.listTypeIndex = cutColor;
cupListItem.Init();
listCupListItems.Add(cupListItem);
}
Vector3 posHolder = holdeCupListItem.transform.localPosition;
posHolder.x -= zaiX / 2;
holdeCupListItem.transform.localPosition = posHolder;


lengthCupListItems = listCupListItems.Count;
lengthSlots = slotManager.slots.Count;

listCheckSlots = new List<Slot>();
for (int i = 0; i < lengthSlots; i++)
{
listCheckSlots.Add(slotManager.slots[i]);
}
indexSlot = 0;

}
private void Update()
{
if (GameManager._gm.State != GameState.IsPlaying) return;
// Actions.OnCheckLost_SlotManager?.Invoke();
timerCheck += Time.deltaTime;
if (timerCheck >= 0.5f)
{
// GameManager._gm.countClick = 0;
listDataCups = new List<List<DataCup>>();
timerCheck = 0;
}
// if (timerCheck > 0.5f && nextLoop)
// {

// timerCheck = 0;
// nextLoop = false;
// // InsertCupToSlot();

// }
}

private void OnCheckingProcess(Slot _slot)
{
print(".......................Check start..........................." + _slot.ID);
timerCheck = 0;
listCollectionCups = new List<DataCup>();

// _slot.listDataCups = new List<DataCup>();
// for (int i = 0; i < lengthSlots; i++)
// {
// listCheckSlots[i].listDataCups = new List<DataCup>();
// }

lengthCupListItems = listCupListItems.Count;

StartCoroutine(SequenceCoroutine());

IEnumerator SequenceCoroutine()
{
yield return new WaitForSeconds(0.5f);

for (int i = 0; i < lengthCupListItems; i++)
{
if (listCupListItems[i].selectLastCup == null) continue;
Cup answerLastCup = listCupListItems[i].selectLastCup;
// answerLastCup.listDataCups = new List<DataCup>();
// print("++++++++++++ Dealer: " + i + "-n last color: " + answerLastCup.Type);
for (int j = 0; j < lengthSlots; j++)
{
Slot slot = listCheckSlots[j];
if (slot.cups.Count > 0)
{

// print(" slot: " + slot.ID + " ------ " + j + " --- "+slot.lastCup.Type);
if (answerLastCup.Type == slot.lastCup.Type)
{
answerLastCup.slot = slot;
answerLastCup.transform.parent = answerLastCup.slot.holderCup.transform;
answerLastCup.cupListItem.GetLastIndex();
// slot.listDataCups.Add(GameManager._gm.GetDataCup(answerLastCup));
listCollectionCups.Add(GameManager._gm.GetDataCup(answerLastCup));
// Destroy(answerLastCup.gameObject,0.3f);
_slot.AddCups(answerLastCup, slot);
StartCoroutine(MoveCupAndDestroy(answerLastCup));
yield return new WaitForSeconds(0.5f);

// print("slot cup len: " + slot.cups.Count + " slot: " + slot.ID + " color " + answerLastCup.Type);
}
}

yield return null;
}
}
listDataCups.Add(listCollectionCups);

yield return null;
//RunMoveCups(listCollectionCups);


//InsertCupToSlot();
}


//_slot.AddCups(_cup);
//timerCheck = 0;
//nextLoop = false;
//countNextCycle = 0;
}
private void OnClickJumpDone()//(List<DataCup> _dataCups, Slot _slot)
{
print(GameManager._gm.clickCount + "...Jump done..." + listDataCups.Count);
// RunMoveCups(listDataCups[listDataCups.Count - 1]);

if (GameManager._gm.clickCount == listDataCups.Count)
{
print("Run...");
RunMoveCups(listDataCups);
}

}

/*private void RunMoveCups(List<List<DataCup>> _listCups)
{
int lengthValidCups = _listCups.Count;
for (int i = 0; i < lengthValidCups; i++)
{
int lengthC = _listCups[i].Count;
print(" ~~~~~~~~~ " + lengthC);
for (int j = 0; j < lengthC; j++)
{
// print(i + ":" + j + " = T: " + _listCups[i][j].type + " SID: " + _listCups[i][j].slot.ID);
CreateCups(_listCups[i][j]);
}
}
GameManager._gm.clickCount = 0;
// print("M-" + lengthValidCups);
// for (int i = 0; i < lengthValidCups; i++)
// {
// print(i + ": " + _listCups[i].type + " : " + _listCups[i].slot.ID);

// }

}*/
private IEnumerator MoveCupAndDestroy(Cup cup)
{
cup.MoveToSlot(cup.slot, cup);
yield return new WaitForSeconds(0.5f);
//Destroy(cup.gameObject);

}
private void RunMoveCups(List<List<DataCup>> _listCups)
{
foreach (var cupList in _listCups)
{
foreach (var dataCup in cupList)
{
cupQueue.Enqueue(dataCup);
}
}
MoveNextCup();
}

private void MoveNextCup()
{
if (cupQueue.Count == 0)
{
return;
}
DataCup nextCup = cupQueue.Dequeue();
CreateCups(nextCup);
}


private void CreateCups(DataCup _dataCup)
{
Vector3 pos = _dataCup.mPosition;
Cup cup = Instantiate(prefabCup, pos, Quaternion.identity, transform);
cup.ID = _dataCup.ID;
cup.Type = _dataCup.type;
cup.isLock = _dataCup.isLock;
cup.slot = _dataCup.slot;
cup.MoveToSlot(cup.slot, cup);
//StartCoroutine(MoveNextAfterDelay());
}

public IEnumerator MoveNextAfterDelay()
{
yield return new WaitForSeconds(0.2f);
MoveNextCup();

}
//private IEnumerator DestroyCupAfterDelay(Cup cup)
//{
// yield return new WaitForSeconds(0.5f);
// Destroy(cup.gameObject);

//}

/*private void CreateCups(DataCup _dataCup)
{
Vector3 pos = _dataCup.mPosition;
Cup cup = Instantiate(prefabCup, pos, Quaternion.identity, transform);
cup.ID = _dataCup.ID;
cup.Type = _dataCup.type;
cup.isLock = _dataCup.isLock;
cup.slot = _dataCup.slot;
// cup.Init();
cup.MoveToSlot(cup.slot, cup);
}*/

private void RunMoveCups1(List<Cup> _listCups)
{
int lengthValidCups = _listCups.Count;
print("M-" + lengthValidCups);
for (int i = 0; i < lengthValidCups; i++)
{
print(i + " : " + _listCups[i].slot.ID);
_listCups[i].slot.AddCups(_listCups[i], _listCups[i].slot);
}
Coroutine coroutine = null;
int counter = 0;
coroutine = StartCoroutine(enumeratorCheckLI());
IEnumerator enumeratorCheckLI()
{
while (counter < lengthValidCups)
{
if (_listCups[counter] != null)
{
Cup selectCup = _listCups[counter];
// print(" --- --- ---> " + counter);
selectCup.MoveToSlot(selectCup.slot, selectCup);
// selectCup.gameObject.SetActive(false);
// Destroy(selectCup.gameObject,0.3f);
yield return new WaitForSeconds(0.1f);
counter++;
}
}
}
// StopCoroutine(coroutine);
// for (int i = 0; i < length; i++)
// {

// }
}

private void InsertCupToSlot()
{
Coroutine coroutine = null;
// int index = _slot.ID;
// indexSlot = index;
int counter = 0;
lengthCupListItems = listCupListItems.Count;

coroutine = StartCoroutine(enumeratorCheckLI());
IEnumerator enumeratorCheckLI()
{
while (counter < lengthCupListItems)// && listCupListItems[counter].listCups.Count > 0
{
Cup lastCup = listCupListItems[counter].selectLastCup;
// print(" --- --- --- "+counter);
yield return new WaitForSeconds(0.1f);
for (int j = 0; j < lengthSlots; j++)
{
Slot slot = listCheckSlots[j];
if (lastCup != null && slot.lastCup != null && lastCup.Type == slot.lastCup.Type)
{
lastCup.RefreshData();
if (!slot.InValidAddCup())
{
GameManager._gm.CreateNewCup(lastCup, slot, listCupListItems[counter], slot.holderCup.transform);
}
break;
}
}
print(" ----------------> " + counter);
counter++;
}
nextLoop = true;
countNextCycle++;
print(" --------------------------------------------------- " + countNextCycle);
if (countNextCycle == GameManager._gm.countCorrect + 1)
{
countNextCycle = 0;
CheckWin();
}
// StopCoroutine(coroutine);
coroutine = null;
yield return null;
}
// listCupListItems.RemoveAll(item => item.listCups.Count < 1);
}


private void CheckWin()
{
int count = 0;
for (int i = 0; i < lengthCupListItems; i++)
{
if (listCupListItems[i].isEmpty)
{
count++;
}
}
// print(holdeCupListItem.transform.childCount + "....... WIN WIN WIN .......");
if (count >= lengthCupListItems)
{
nextLoop = false;
GameManager._gm.LevelComleted();
}

int countLose = 0;
int lengthC = slotManager.slots.Count;
for (int i = 0; i < lengthC; i++)
{
if (slotManager.slots[i].cups.Count > 0)
{
countLose++;
}
}
if (countLose >= lengthSlots)
{
nextLoop = false;
GameManager._gm.GameOver();
}
}
public void ResetSlots()
{
int length = slotManager.slots.Count;
for (int i = 0; i < length; i++)
{
int lengthC = slotManager.slots[i].cups.Count;
for (int j = 0; j < length; j++)
{
slotManager.slots[i].cups.RemoveAll(item => item == null);
}
// slotManager.slots.RemoveAll(x => x.cups.)
}

/*foreach (Slot x in slotManager.slots)
{
if (x == targetSlot)
{
Debug.LogError(x.transform.GetSiblingIndex() + "Reset slot position");
//reset x
x.cups.Clear();
return;
}
}*/
}
private void OnEnable()
{
Actions.OnCheck_CupAnswerManager += OnCheckingProcess;
Actions.OnClickJumpDone_CupAnswerManager += OnClickJumpDone;
}
private void OnDisable()
{
Actions.OnCheck_CupAnswerManager -= OnCheckingProcess;
Actions.OnClickJumpDone_CupAnswerManager -= OnClickJumpDone;
}
// private void Update()
// {
// if (Input.GetMouseButtonDown(0))
// {
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// RaycastHit hit;

// if (Physics.Raycast(ray, out hit, 100))
// {
// if (hit.transform.CompareTag("BoxIListtem"))
// {
// // Debug.Log(hit.transform.gameObject.name);
// CupListItem cupListItem = hit.transform.GetComponent<CupListItem>();
// cupListItem.OnClick();
// }
// }
// }
// }
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.