/// <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(); }
public GameObject Spawn(GameObject obj, int?child, Vector3 pos, Quaternion rot, bool usePosRot) { if (obj == null) { return(null); } // object wasn't defined CheckDict(); if (poolRef.ContainsKey(obj) == true) // reference already created { if (poolRef[obj] != null) // make sure pool still exsists { return(poolRef[obj].Spawn(child, pos, rot, usePosRot)); // create spawn } else // pool no longer exsists { poolRef.Remove(obj); // remove reference return(null); } } else // ref not yet created { AP_Pool childScript = MakePoolRef(obj); // create ref if (childScript == null) // ref not found { return(null); } else { return(childScript.Spawn(child, pos, rot, usePosRot)); // create spawn } } }