/// <summary> /// /// </summary> /// <param name="eType"></param> /// <returns></returns> public GameObject Spwan(string sKey) { CObjectPoolWrapper <GameObject> obj = null; CObjectPool <GameObject> objectPool = null; int key = CRC32.GetHashForAnsi(sKey); if (poolList.TryGetValue(key, out objectPool)) { obj = objectPool.Take(); PoolObject info = obj.Value.GetComponent <PoolObject>(); if (info == null) { info = obj.Value.AddComponent <PoolObject>(); } info.obj = obj; info.hashKey = key; obj.Value.transform.parent = null; obj.Value.SetActive(true); return(obj.Value); } return(null); }
public void Despawn(GameObject go) { if (go == null) { return; } PoolObject info = go.GetComponent <PoolObject>(); if (info != null) { CObjectPool <GameObject> objectPool = null; int hashkey = info.hashKey; if (poolList.TryGetValue(hashkey, out objectPool)) { objectPool.Release(info.obj); } } else { // Remove if not pool object GameObject.Destroy(go); } }
public ChunkMachine(int LODs, float MinCellSize, int MaxNumChunksToPrepare, int Resolution, ComputeShader NoiseComputeShader, GameObject ChunkPrefab, Transform ChunkParent) { this.LODs = LODs; this.MinCellSize = MinCellSize; this.Resolution = Resolution; this.ChunkPrefab = ChunkPrefab; this.MaxNumToPrepare = MaxNumChunksToPrepare; this.NoiseComputeShader = NoiseComputeShader; this.ChunkParent = ChunkParent; this.ActiveJob = false; PreparingChunksMode = false; CurrentlyManagingChunks = false; ChunkJobQueuer.Initialize(); this.LoadedChunks = new Hashtable(); this.ResultPool = new CObjectPool <ChunkManageResult>(() => new ChunkManageResult()); UsedInput = new ChunkManageInput(); LoadedChunksCenter = new Vector3(float.MinValue, float.MinValue, float.MinValue); UnloadedChunksCenter = new Vector3(float.MinValue, float.MinValue, float.MinValue); UsedInput.LoadedChunks = LoadedChunks; UsedInput.LODs = LODs; UsedInput.MinSizeOfCell = MinCellSize; UsedInput.Resolution = Resolution; }
/// <summary> /// Add pooling to that type. Return value is true only when newly added. /// </summary> public int CreatePool(string sKey, GameObject pPoolingTarget, GameObject _parent, int nInitCreateCount = 1, int nExpandCreateCount = 1) { parent = _parent; int key = CRC32.GetHashForAnsi(sKey); GameObject go = null; pPoolingTarget.transform.SetParent(parent.transform); pPoolingTarget.SetActive(false); if (!poolObject.TryGetValue(key, out go)) { poolObject.Add(key, pPoolingTarget); } else { poolObject[key] = pPoolingTarget; } CObjectPool <GameObject> objectPool = null; if (!poolList.TryGetValue(key, out objectPool)) { objectPool = new CObjectPool <GameObject>() { InitializeCreateCount = nInitCreateCount, ExpandCreateCount = nExpandCreateCount, OnObjectDestroy = (GameObject v) => { GameObject.Destroy(v); }, OnTake = (GameObject v) => { }, OnRelease = (GameObject v) => { if (v) { v.transform.SetParent(parent.transform); v.SetActive(false); } }, OnCreate = () => { var data = EAFrameUtil.AddChild(parent, poolObject[key]); return(data); } }; poolList.Add(key, objectPool); } return(key); }
void Awake() { if (Inst != null) { Destroy(this.gameObject); return; } Inst = this; }
void Start() { interpretNodePool = new CObjectPool <CPoolableObject>(5, () => { //GameObject prefab = Instantiate(f) as GameObject; GameObject prefab = Instantiate(Resources.Load("Prefab/InterpretNode")) as GameObject; InterpretNode node = prefab.GetComponent <InterpretNode>(); node.Create(interpretNodePool); return(node); }); interpretNodePool.Allocate(); }
GameObject containerObject; //컨테이너 오브젝트 void Awake() { if (current == null) { current = this; //오브젝트 풀 객체의 static 참조를 함 } else { Destroy(gameObject); //재생성 시 이전 오브젝트를 파괴함. } //빈 오브젝트 형태로(new GameObject) 오브젝트 풀을 생성함. containerObject = new GameObject("ObjectPool"); //오브젝트 풀 리스트 배열을 생성함(프리팹 배열 크기와 일치) pooledObjects = new List <GameObject> [prefabs.Length]; int index = 0; //오브젝트 풀 리스트 배열에 리스트를 생성함. foreach (GameObject objectPrefab in prefabs) { pooledObjects[index] = new List <GameObject>(); //버퍼 크기를 로드함. int bufferAmount; //인덱스가 오브젝트 버퍼 크기 배열의 길이보다 작다면 if (index < amountToBuffer.Length) { bufferAmount = amountToBuffer[index]; } else { bufferAmount = defaultBufferAmount; //기본 버퍼 크기를 설정함. } //버퍼에 오브젝트를 생성함. for (int i = 0; i < bufferAmount; i++) { //오브젝트 생성. GameObject obj = (GameObject)Instantiate(objectPrefab); //생성한 오브젝트의 이름을 프리팹으로 설정함. obj.name = objectPrefab.name; //오브젝트 풀에 생성한 오브젝트를 넣음. PoolObject(obj); } index++; } }
internal CPlatformSpriteFactory(CServiceLocatorNode aParent) : base(aParent) { var c = typeof(CPlatformSpriteEnum).GetEnumMaxValue() + 1; var aEntries = new CEntry[c]; for (var i = 0; i < c; ++i) { var aObjectPool = new CObjectPool <CPlatformSprite>(); var aEntry = new CEntry(aObjectPool); aEntries[i] = aEntry; } this.Entries = aEntries; }
private GameObject _containerObject = null; // 컨테이너 오브젝트 void Awake() { if (current == null) { current = this; } else { Destroy(gameObject); // 재생성 시 이전 오브젝트를 파괴함 } _containerObject = new GameObject("ObjectPool"); pooledObjects = new List <GameObject> [prefabs.Length]; int index = 0; foreach (GameObject objectPrefab in prefabs) { pooledObjects[index] = new List <GameObject>(); int bufferAmount; if (index < amountToBuffer.Length) { bufferAmount = amountToBuffer[index]; } else { bufferAmount = defaultBufferAmount; } for (int i = 0; i < bufferAmount; i++) { GameObject obj = (GameObject)Instantiate(objectPrefab); obj.name = objectPrefab.name; PoolObject(obj); } index++; } }
public ChunkQueuer(Transform Viewer, Transform Parent, int LODs, int Resolution, int Radius, int MinimumChunkSize, GameObject ChunkPrefab) { Debug.Assert(LODs >= 1); this.Viewer = Viewer; this.Parent = Parent; this.LODs = LODs; this.Resolution = Resolution; this.MinimumChunkSize = MinimumChunkSize; this.Radius = Radius; this.Initialized = false; this.ChunkPrefab = ChunkPrefab; ChunkArraySize = 4 * Radius; ChunkStorage = new Chunk[LODs][, , ]; ChunkLinearArrayMin = 0; ChunkLinearArrayMax = 0; for (int i = 0; i < LODs; i++) { ChunkStorage[i] = new Chunk[ChunkArraySize, ChunkArraySize, ChunkArraySize]; } UnityObjectPool = new CObjectPool <GameObject>(() => { var obj = Object.Instantiate(ChunkPrefab, new Vector3(0, 0, 0), Quaternion.identity); obj.GetComponent <MeshFilter>().mesh = new Mesh(); obj.GetComponent <Renderer>().enabled = false; return(obj); }); ChunksToMesh = new ConcurrentBag <Chunk>(); ChunksToUpload = new ConcurrentBag <Chunk>(); ObjectsToClear = new ConcurrentBag <GameObject>(); ChunksToAppear = new List <Chunk>(); ChunksToClear = new List <Chunk>(); ChunkLinearArray = new Chunk[ChunkArraySize * ChunkArraySize * ChunkArraySize * 500]; AddCommands(); }
/// <summary> /// The return value is when the key registered in m_mpPoolingType is deleted. /// </summary> /// <param name="eType"></param> /// <returns></returns> public bool DeletePool(string sKey) { int key = CRC32.GetHashForAnsi(sKey); GameObject go = null; if (poolObject.TryGetValue(key, out go)) { GameObject.Destroy(go); } poolObject.Remove(key); CObjectPool <GameObject> objectPool = null; if (poolList.TryGetValue(key, out objectPool)) { objectPool.Dispose(); poolList.Remove(key); } return(true); }
void Awake() { instance = this; interpretNodePool = new CObjectPool <CPoolableObject>(); }
public virtual void Create(CObjectPool <CPoolableObject> objectPull) { this.objectPull = objectPull; gameObject.SetActive(false); }
public override void Create(CObjectPool <CPoolableObject> pool) { base.Create(pool); }
internal CEntry(CObjectPool <CPlatformSprite> aObjectPool) { this.ObjectPool = aObjectPool; }
/// <summary> /// Constructor /// </summary> public CActionDispatcher() { m_EventActionList = new QuickList <UInt32, CHandleInfo>(); m_EventInfoPool = new CObjectPool(); m_ListenedEvent = new SafeQueue(32); }
/// <summary> /// Constructor /// </summary> public CTimerHeap() { m_uNextTimerID = 1; m_TimerList = new List <CTimer>(); m_TimerPool = new CObjectPool(); }
public CObjectPoolWrapper(CObjectPool <T> pool) { _parent = pool; }
public CObjectPoolWrapper(CObjectPool <T> pool, T value) { _parent = pool; _value = value; }