/// <summary> /// 创建一个小汽车 /// </summary> public void AddCar() { if (CheckParkingIsFull()) { return; // 检查 } //GameObject car = Instantiate(Car, ParkingCars); //GameObject car = MF_AutoPool.Spawn(Car); //int random = Random.Range(0, CarPools.childCount); //AP_Pool pool = CarPools.GetChild(random).GetComponent<AP_Pool>(); AP_Pool pool = CarPools.GetComponent <AP_Pool>(); //** GameObject car = pool.Spawn(); int index = Random.Range(0, car.transform.childCount); //** car.transform.GetChild(index).gameObject.SetActive(true); //** car.transform.SetParent(ParkingCars); car.transform.position = StartPoint.position; CarList.Add(car); ParkingPoint parkingPoint = GetParkingPoint(); // 获得车位信息 List <Vector3> OutPath; List <Vector3> ComePath = PlanPath(parkingPoint, out OutPath); // 规划路径 Car carScripts = car.GetComponent <Car>(); carScripts.Refresh(index); carScripts.Speed = CarSpeed; carScripts.ComePathPos = ComePath; carScripts.OutPathPos = OutPath; carScripts.parkingPoint = parkingPoint; carScripts.ComeCar(); }
/// <summary> /// 使用停车点 /// </summary> public ParkingPoint GetParkingPoint() { int index = Random.Range(0, ParkingPoints.Count); // 随机车位 ParkingPoint parkingPoint = ParkingPoints[index]; // 车位信息 ParkingPoints.RemoveAt(index); CanParkingNum.text = ParkingPoints.Count.ToString(); return(parkingPoint); }
/// <summary> /// 汽车离开 /// </summary> public void OutCar() { anim.Play(); if (StateStep != 2) { return; } ParkingMgr.Instance.SetParkingPoint(parkingPoint); parkingPoint = null; isCome = false; index = 0;// 重置步骤index MoveCar(OutPathPos); }
// 路径 private List <Vector3> PlanPath(ParkingPoint parkingPoint, out List <Vector3> OutPath) { // 进入路径 List <Vector3> ComePath = new List <Vector3>(); AddPoint(ComePath, ComeTurningPoint);// 进入拐弯点 Vector3 ParkingPoint = parkingPoint.transform.position; ComePath.Add(new Vector3(ParkingPoint.x, 0, ComeTurningPoint[ComeTurningPoint.Count - 1].position.z)); // 计算车位栏点 ComePath.Add(ParkingPoint); // 车位点 float x = parkingPoint.pointType == 0 ? -GridSize * 1.5f : GridSize * 1.5f; // 暂时通过索引区分左右 ComePath.Add(ParkingPoint + new Vector3(x, 0, 0)); // 停车点 // 离开路径 OutPath = new List <Vector3>(); OutPath.Add(ParkingPoint); OutPath.Add(ParkingPoint + new Vector3(0, 0, GridSize));// 倒车点 OutPath.Add(new Vector3(ParkingPoint.x, 0, OutTurningPoint[0].position.z)); AddPoint(OutPath, OutTurningPoint); OutPath.Add(EndPoint.position); return(ComePath); }
/// <summary> /// 归还停车点 /// </summary> public void SetParkingPoint(ParkingPoint parkingPoint) { ParkingPoints.Add(parkingPoint); CanParkingNum.text = ParkingPoints.Count.ToString(); }