Skip to content

Instantly share code, notes, and snippets.

using System.Collections.Generic;
using UnityEngine;
public class Pool : MonoBehaviour
{
private const int DEFUALT_POOL_SIZE = 100;
private static Dictionary<IPoolable, Pool> pools = new Dictionary<IPoolable, Pool>();
public static Pool GetPool(IPoolable prefab)
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class PoolPreparer : MonoBehaviour
{
[SerializeField]
GameObject[] prefabs;
private void Initialize(IPoolable poolablePrefab, int initialSize = DEFUALT_POOL_SIZE)
{
this.prefab = (poolablePrefab as Component).gameObject;
for (int i = 0; i < initialSize; i++)
{
var pooledObject = (Instantiate(this.prefab) as GameObject).GetComponent<IPoolable>();
(pooledObject as Component).gameObject.name += " " + i;
pooledObject.OnDestroyEvent += () => AddObjectToAvailable(pooledObject);
private IPoolable Get()
{
lock (this)
{
if (objects.Count == 0)
{
int amountToGrowPool = Mathf.Max((disabledObjects.Count / 10), 1);
Initialize(this.prefab.GetComponent<IPoolable>(), amountToGrowPool);
}
public static Pool GetPool(IPoolable prefab)
{
if (pools.ContainsKey(prefab))
{
if (pools[prefab] != null)
return pools[prefab];
else
pools.Remove(prefab);
}
using System;
using UnityEngine;
public class Projectile : MonoBehaviour, IPoolable
{
private void OnDisable() { OnDestroyEvent(); }
}
using UnityEngine;
using UnityEditor;
public class InvertedSphere : EditorWindow
{
private string st = "1.0";
[MenuItem("GameObject/Create Other/Inverted Sphere...")]
public static void ShowWindow()
{
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Video;
public class VideoSelection : MonoBehaviour
{
[SerializeField]
private VideoClip videoClip;
private VideoPlayer videoPlayer;
using UnityEngine;
public class GazeInput : MonoBehaviour
{
private Ray ray;
private RaycastHit hitInfo;
[SerializeField]
[Tooltip("The root object of all menu items")]
private GameObject menuRoot;
[SelectionBase]
public class MyClass : MonoBehaviour
{
}