void Update() { if (Input.GetMouseButtonDown(0)) { MyObjectPool.Spawn(this.cube, this.transform, Vector3.zero, Quaternion.identity); } }
void Start() { _instance = this; //根据配置文件,初始化池子,并创建对象 for (int i = 0; i < this.poolconfigs.Length; i++) { CreatePool(this.poolconfigs[i].prefab, this.poolconfigs[i].count); } }
private void CreatePool(ConnectionSettings connectionSettings, int connectionPoolSize, ILogger log) { var ascPool = new AscClient[connectionPoolSize]; for (int i = 0; i < connectionPoolSize; i++) { ascPool[i] = new AscClient(connectionSettings, log); ascPool[i].StartClient(); } pool = new MyObjectPool <AscClient>(ascPool); }
private void CreateNewPool(GameObject objToPool, int initialPoolSize, int maxPoolSize, bool shouldBeNetworked) { MyObjectPool nPool; nPool = new MyObjectPool(); if (objToPool.CompareTag("Hills")) { nPool.SetPool(objToPool, initialPoolSize, maxPoolSize, shouldBeNetworked, hillsParrent); } else if (objToPool.CompareTag("Meteor")) { nPool.SetPool(objToPool, initialPoolSize, maxPoolSize, shouldBeNetworked, meteorParrent); } else if (objToPool.CompareTag("RaiseObstacle")) { nPool.SetPool(objToPool, initialPoolSize, maxPoolSize, shouldBeNetworked, boostersParrent); } else if (objToPool.CompareTag("RaiseObstacle")) { nPool.SetPool(objToPool, initialPoolSize, maxPoolSize, shouldBeNetworked, boostersParrent); } objectPools.Add(objToPool.name, nPool); }
public MyObject() { impl = MyObjectPool.Get(); }
IEnumerator RecyleObject() { yield return(new WaitForSeconds(2)); MyObjectPool.Recyle(this.gameObject, this.Recyle); }