五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

代碼優(yōu)化(3)

2020-05-26 11:21 作者:unity_某某師_高錦錦  | 我要投稿

對象池

using UnityEngine;

using System.Collections;

using System.Collections.Generic;


public interface IPoolableObject{

void New();

void Respawn();

}


public class ObjectPool<T> where T : IPoolableObject, new() {

private List<T> _pool;

private int _currentIndex = 0;

public ObjectPool(int initialCapacity) {

_pool = new List<T>(initialCapacity);

for(int i = 0; i < initialCapacity; ++i) {

Spawn (); // instantiate a pool of N objects

}

Reset ();

}

public int Count {

get { return _pool.Count; }

}

public void Reset() {

_currentIndex = 0;

}

public T Spawn() {

if (_currentIndex < Count) {

T obj = _pool[_currentIndex];

_currentIndex++;

IPoolableObject ip = obj as IPoolableObject;

ip.Respawn();

return obj;

} else {

T obj = new T();

_pool.Add(obj);

_currentIndex++;

IPoolableObject ip = obj as IPoolableObject;

ip.New();

return obj;

}

}

}

use

using UnityEngine;

using System.Collections;


public class TestObject : IPoolableObject {

public void New() {

// very first initialization here

}

public void Respawn() {

// reset data which allows the object to be recycled here

}


public int Test(int num) {

return num * 2;

}

}



public class ObjectPoolTester : MonoBehaviour {


private ObjectPool<TestObject> _objectPool = new ObjectPool<TestObject>(100);

void Update () {

if (Input.GetKeyDown (KeyCode.Space)) {

? ? ? ? ? ? print("is print.");

_objectPool.Reset ();

int sum = 0;

for(int i = 0; i < 100; ++i) {

TestObject obj = _objectPool.Spawn ();

sum += obj.Test(i);

}

//Debug.Log (string.Format ("(Sum 1-to-100) *2 = {0}", sum));

}

}

}


代碼優(yōu)化(3)的評論 (共 條)

分享到微博請遵守國家法律
夏河县| 富川| 嘉鱼县| 营山县| 团风县| 延吉市| 北京市| 镇江市| 静安区| 武宣县| 大关县| 张北县| 宣化县| 松桃| 敦煌市| 兖州市| 穆棱市| 兴和县| 昌乐县| 海安县| 钦州市| 丰顺县| 蕉岭县| 丹棱县| 宝丰县| 上高县| 原平市| 武夷山市| 溆浦县| 上虞市| 中西区| 扬中市| 江永县| 正镶白旗| 莒南县| 合山市| 兴山县| 赣州市| 漯河市| 定南县| 锦屏县|