/// <summary> /// Manually creates a Pool for a prefab. /// </summary> /// <param name="prefab"></param> /// <returns></returns> public static PoolBehaviour CreatePool(GameObject prefab) { CheckInitialize(); GameObject obj = new GameObject("Pool: " + prefab.name); obj.transform.SetParent(s_poolManagerObj.transform); PoolBehaviour bhv = obj.AddComponent <PoolBehaviour>(); bhv.Prefab = prefab; bhv.Initialize(); return(bhv); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUI.changed) { //TODO: initialize only if prefab changes m_target.Initialize(); } int preCachedCount = EditorGUILayout.DelayedIntField("Pre-Cached Instances", m_target.transform.childCount); if (preCachedCount != m_target.transform.childCount) { m_target.PreCacheInstances(preCachedCount); } if (GUILayout.Button("Add Scene Instances to Pool")) { List <GameObject> gameObjects = GetAllObjectsInScene(); foreach (GameObject go in gameObjects) { //Debug.Log(go.name + " --> " + PrefabUtility.GetPrefabObject(go) + ", " + PrefabUtility.GetPrefabParent(go) + ", " + PrefabUtility.GetPrefabType(go)); #if UNITY_2018_3_OR_NEWER if (PrefabUtility.GetCorrespondingObjectFromSource(go) == m_target.Prefab) #else if (PrefabUtility.GetPrefabParent(go) == m_target.Prefab) #endif { if (m_target.TryAddGameObjectToPool(go)) { Debug.Log("Found " + go.name); } } } } }
private void OnEnable() { m_target = target as PoolBehaviour; m_target.Initialize(); }