void CreateNewPrefab() { GUILayout.BeginHorizontal(); GUILayout.Label("Create New Poolable Prefab: ", EditorStyles.boldLabel); GUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); //center texture GUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.ExpandWidth(true)); LoadPrefabImage(tileType.name, 120, 120); GUILayout.Label("", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); selectedTile = EditorGUILayout.Popup("Poolable Type", selectedTile, interactablesDB.interactablesNames.ToArray()); tileType = interactablesDB[selectedTile]; instNum = (int)EditorGUILayout.Slider("Instances Number", instNum, 1, 20); prefab = (GameObject)EditorGUILayout.ObjectField("Prefab", prefab, typeof(GameObject), false); EditorGUILayout.Separator(); AddEditButtons(); }
public bool Contains(PoolableType type) { if (poolableList.Any(po => po.type == type)) { return(true); } return(false); }
public void Add(PoolableType tile) { if (!poolableTypeList.Contains(tile)) { poolableTypeList.Add(tile); } interactablesNames.Add(tile.name); }
GameObject ActivateTile(PoolableType type, float xPos) { GameObject tile = ObjectPooler.Instance.GetFromPool(type); tile.transform.position = new Vector3(xPos, tile.transform.position.y, lastSegTrans.position.z + 1); tile.SetActive(true); return(tile); }
public Segment(PoolableType tile) { ListOfTiles = new List <PoolableType>(); for (int i = 0; i < 5; i++) { ListOfTiles.Add(tile); } }
private void OnEnable() { poolableDB = (PoolDatabase)target; string interactablesDBPath = "Assets/Data/Database/InteractablesDatabase.asset"; interactablesDB = AssetDatabase.LoadAssetAtPath <InteractablesDatabase>(interactablesDBPath); tileType = interactablesDB[0]; }
public PoolableObj this[PoolableType type] { get { return(poolableList.FirstOrDefault(po => po.type == type)); } set { int poIndex = poolableList.FindIndex(po => po.type == type); poolableList[poIndex] = value; } }
public void SwapByIndex(int num1, int num2) { PoolableType poolableTemp = poolableTypeList[num1]; poolableTypeList[num1] = poolableTypeList[num2]; poolableTypeList[num2] = poolableTemp; string interactableNameTemp = interactablesNames[num1]; interactablesNames[num1] = interactablesNames[num2]; interactablesNames[num2] = interactableNameTemp; }
public GameObject GetFromPool(PoolableType instType) { if (poolDict.ContainsKey(instType)) { Queue <GameObject> instQueue = poolDict[instType]; if (instQueue.Count > 0) { GameObject pooledObj = instQueue.Dequeue(); return(pooledObj); } return(InstantiateGameObj(pd[instType].prefab));; } Debug.LogError("Instance is invalid: " + instType.name); return(null); }
//Returns first deactivated poolable of chosen type. If none, instanciate one public T GetPoolable <T>(Vector3 position, Quaternion rotation, float size = 1f, PoolableType type = PoolableType.None, Transform parent = null, bool defaultParent = true) where T : IPoolable { T poolable = default(T); foreach (var p in Poolables.ToArray()) { if (Utils.IsNull(p)) { Poolables.Remove(p); continue; } if (type != PoolableType.None && p.PoolableType != type) { continue; } if (p is T && !((MonoBehaviour)p).gameObject.activeSelf) { poolable = (T)p; break; } } //var poolable = (T)Poolables.Where(type == PoolableType.None || x.PoolableType == type).FirstOrDefault(p => p is T && !((MonoBehaviour)p).gameObject.activeSelf); if (poolable != null) { return(SelectPoolable(poolable, position, rotation, size)); } // Create poolable if doesn't exist GameObject poolableModel = null; foreach (var model in _poolableModels) { if (model.TryGetComponent(out IPoolable pool) && pool is T && (type == PoolableType.None || pool.PoolableType == type)) { poolableModel = model; break; } } if (poolableModel == null) { return(default);
public void ReturnToPool(PoolableType instType, GameObject inst) { if (!poolDict.ContainsKey(instType)) { Debug.LogError("Instance is invalid", instType); } ObjectReturner instObjReturner = inst.GetComponent <ObjectReturner>(); if (instObjReturner.inActiveSegment) { instObjReturner.inActiveSegment = false; segmentActiveCount--; } Queue <GameObject> instQueue = poolDict[instType]; inst.SetActive(false); instQueue.Enqueue(inst); }
public PoolableObj(PoolableType _type, int _count, GameObject _prefab) { type = _type; count = _count; prefab = _prefab; }
public bool Remove(PoolableType tile) { interactablesNames.Remove(tile.name); return(poolableTypeList.Remove(tile)); }