using DG.Tweening; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; using static UnityEngine.UIElements.UxmlAttributeDescription; public class Allother : MonoBehaviour { public List otherWonius; // public List House;//蜗牛进入的父物体 public GameObject OtherWoniuPre;//其他蜗牛预制体 public AllHouseContro allHouseContro; public List JiaWoniu;//场下留下的假蜗牛 private List hiddenSnails = new List(); // 用来记录未显示的蜗牛 public Transform ReTurnPos;//返回点 // Start is called before the first frame update void Start() { //ControWoniuToMove(); //StartCoroutine(WoniuToMove()); } //public IEnumerator WoniuToMove() //{ // CreateWoniu();//创建蜗牛 //} //public async void ControWoniuToMove() // { // foreach (otherWoniu item in otherWonius) // { // await Task.Delay(1000); // item.OtherWoniuMove(); // } // } public void HideJiaWoniu() { // 初始化时将所有蜗牛隐藏,并添加到未显示列表 foreach (GameObject go in JiaWoniu) { go.SetActive(false); hiddenSnails.Add(go); } } public void Reflash() // 随机显示假蜗牛 { if (hiddenSnails.Count == 0) { //Debug.Log("所有假蜗牛都已显示!"); return; } // 每次随机显示一定数量(例如 1 到 3 个) int numToShow = Random.Range(1, Mathf.Min(4, hiddenSnails.Count + 1)); for (int i = 0; i < numToShow; i++) { // 随机选择一个未显示的蜗牛 int randomIndex = Random.Range(0, hiddenSnails.Count); GameObject snail = hiddenSnails[randomIndex]; // 设置位置 snail.GetComponent().anchoredPosition = new Vector2( Random.Range(-350, 550), Random.Range(0, 40) ); // 显示蜗牛 snail.SetActive(true); // 从未显示列表中移除 hiddenSnails.RemoveAt(randomIndex); } } //笼子里的蜗牛全部清空 public void ClearAllWoniu() { foreach (HouseBtn house in allHouseContro.HouseBtnList) { if (house.otherWonius != null) { house.otherWonius.Clear(); } } for (int i=0;i().EndPos = ReTurnPos; allHouseContro.HouseBtnList[i].otherWonius[j].GetComponent().ReTurnStartPosMove(); yield return new WaitForSeconds(0.3f); } allHouseContro.HouseBtnList[i].otherWonius.Clear(); } } } //public void CreateWoniu() //{ // foreach (HouseBtn house in allHouseContro.HouseBtnList) // { // for (int i = 0; i < house.roomUserNo-house.otherWonius.Count; i++) // { // // 在指定范围内随机生成位置 // float randomX = Random.Range(-250f, 250f); // X轴范围 // float randomY = Random.Range(-80f, 80f); // Y轴范围 // Vector2 randomPosition = new Vector2(randomX, randomY); // // 实例化蜗牛 // GameObject ot = Instantiate(OtherWoniuPre, transform); // ot.GetComponent().anchoredPosition = randomPosition; // // 添加到蜗牛列表并设置其行为 // house.otherWonius.Add(ot.GetComponent()); // ot.GetComponent().OtherWoniuMove(house); // 移动到目标房间 // Debug.Log("生成蜗牛,随机位置:" + randomPosition); // } // } //} public void startIEmove() { StartCoroutine(IECreateWoniu()); Reflash(); } public IEnumerator IECreateWoniu() { foreach (HouseBtn house in allHouseContro.HouseBtnList) { for (int i = 0; i < house.roomUserNo-house.otherWonius.Count; i++) { GameObject ot = Instantiate(OtherWoniuPre, transform); ot.GetComponent().anchoredPosition = new Vector2(Random.Range(-250, 250), Random.Range(-80, 0)); house.otherWonius.Add(ot.GetComponent()); otherWonius.Add(ot.GetComponent()); ot.GetComponent().OtherWoniuMove(house);//进房间 //Debug.Log("生成蜗牛"); yield return new WaitForSeconds(0.1f); } } } }