139 lines
4.0 KiB
C#
139 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using static UnityEngine.UIElements.UxmlAttributeDescription;
|
|
|
|
public class Allother : MonoBehaviour
|
|
{
|
|
//public List<otherWoniu> otherWonius=new List<otherWoniu>();
|
|
|
|
// public List<HouseBtn> House;//蜗牛进入的父物体
|
|
public GameObject OtherWoniuPre;//其他蜗牛预制体
|
|
public AllHouseContro allHouseContro;
|
|
|
|
public List<GameObject> JiaWoniu;//场下留下的假蜗牛
|
|
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 Reflash()//假蜗牛随机
|
|
{
|
|
foreach (GameObject go in JiaWoniu)
|
|
{
|
|
go.GetComponent<RectTransform>().anchoredPosition = new Vector2(Random.Range(-350, 350), Random.Range(-80, 80));
|
|
}
|
|
}
|
|
|
|
//笼子里的蜗牛全部清空
|
|
public void ClearAllWoniu()
|
|
{
|
|
foreach (HouseBtn house in allHouseContro.HouseBtnList)
|
|
{
|
|
if (house.otherWonius != null)
|
|
{
|
|
for (int i = 0; i < house.otherWonius.Count; i++)
|
|
{
|
|
Destroy(house.otherWonius[i].gameObject);
|
|
|
|
}
|
|
house.otherWonius.Clear();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//清空指定房间蜗牛
|
|
public void KilltheWoniu(int killNo)
|
|
{
|
|
|
|
|
|
for (int i=0;i<allHouseContro.HouseBtnList.Count;i++)
|
|
{
|
|
if (allHouseContro.HouseBtnList[i].roomNo==killNo)
|
|
{
|
|
for (int j = 0; j< allHouseContro.HouseBtnList[i].otherWonius.Count; j++)
|
|
{
|
|
Destroy(allHouseContro.HouseBtnList[i].otherWonius[i].gameObject);
|
|
}
|
|
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<RectTransform>().anchoredPosition = randomPosition;
|
|
|
|
// 添加到蜗牛列表并设置其行为
|
|
|
|
house.otherWonius.Add(ot.GetComponent<otherWoniu>());
|
|
ot.GetComponent<otherWoniu>().OtherWoniuMove(house); // 移动到目标房间
|
|
|
|
Debug.Log("生成蜗牛,随机位置:" + randomPosition);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void startIEmove()
|
|
{
|
|
StartCoroutine(IECreateWoniu());
|
|
}
|
|
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<RectTransform>().anchoredPosition = new Vector2(Random.Range(-250, 250), Random.Range(-80, 0));
|
|
house.otherWonius.Add(ot.GetComponent<otherWoniu>());
|
|
ot.GetComponent<otherWoniu>().OtherWoniuMove(house);//进房间
|
|
|
|
Debug.Log("生成蜗牛");
|
|
yield return new WaitForSeconds(0.1f);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|