private InspectorField InstantiateDrawer(InspectorField drawer, Transform drawerParent) { List <InspectorField> drawerPool; if (drawersPool.TryGetValue(drawer.GetType(), out drawerPool)) { for (int i = drawerPool.Count - 1; i >= 0; i--) { InspectorField instance = drawerPool[i]; drawerPool.RemoveAt(i); if (instance != null && !instance.Equals(null)) { instance.transform.SetParent(drawerParent, false); instance.gameObject.SetActive(true); return(instance); } } } InspectorField newDrawer = (InspectorField)Instantiate(drawer, drawerParent, false); newDrawer.Initialize(); return(newDrawer); }
public void PoolDrawer(InspectorField drawer) { List <InspectorField> drawerPool; if (!drawersPool.TryGetValue(drawer.GetType(), out drawerPool)) { drawerPool = new List <InspectorField>(poolCapacity); drawersPool[drawer.GetType()] = drawerPool; } if (drawerPool.Count < poolCapacity) { drawer.gameObject.SetActive(false); drawer.transform.SetParent(poolParent, false); drawerPool.Add(drawer); } else { Destroy(drawer.gameObject); } }