|
|
|
|
|
|
|
|
|
|
Transform m_CacheParent; |
|
|
|
Dictionary<int, int> m_InstanceIdToIndex; |
|
|
|
List<GameObject>[] m_InstantiatedObjects; |
|
|
|
List<CachedObjectData>[] m_InstantiatedObjects; |
|
|
|
int[] m_NumObjectsActive; |
|
|
|
int NumObjectsInCache { get; set; } |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
m_CacheParent = parent; |
|
|
|
m_InstanceIdToIndex = new Dictionary<int, int>(); |
|
|
|
m_InstantiatedObjects = new List<GameObject>[prefabs.Length]; |
|
|
|
m_InstantiatedObjects = new List<CachedObjectData>[prefabs.Length]; |
|
|
|
m_NumObjectsActive = new int[prefabs.Length]; |
|
|
|
|
|
|
|
var index = 0; |
|
|
|
|
|
|
m_InstanceIdToIndex.Add(instanceId, index); |
|
|
|
m_InstantiatedObjects[index] = new List<GameObject>(); |
|
|
|
m_InstantiatedObjects[index] = new List<CachedObjectData>(); |
|
|
|
m_NumObjectsActive[index] = 0; |
|
|
|
++index; |
|
|
|
} |
|
|
|
|
|
|
public GameObject GetOrInstantiate(GameObject prefab) |
|
|
|
{ |
|
|
|
if (!m_InstanceIdToIndex.TryGetValue(prefab.GetInstanceID(), out var index)) |
|
|
|
{ |
|
|
|
} |
|
|
|
GameObject nextObject; |
|
|
|
nextObject = nextInCache; |
|
|
|
foreach (var tag in nextInCache.randomizerTags) |
|
|
|
tag.Register(); |
|
|
|
return nextInCache.instance; |
|
|
|
else |
|
|
|
{ |
|
|
|
++NumObjectsInCache; |
|
|
|
var newObject = Object.Instantiate(prefab, m_CacheParent); |
|
|
|
++m_NumObjectsActive[index]; |
|
|
|
m_InstantiatedObjects[index].Add(newObject); |
|
|
|
nextObject = newObject; |
|
|
|
} |
|
|
|
|
|
|
|
var tags = nextObject.GetComponents<RandomizerTag>(); |
|
|
|
foreach (var tag in tags) |
|
|
|
tag.Register(); |
|
|
|
return nextObject; |
|
|
|
++NumObjectsInCache; |
|
|
|
var newObject = Object.Instantiate(prefab, m_CacheParent); |
|
|
|
++m_NumObjectsActive[index]; |
|
|
|
m_InstantiatedObjects[index].Add(new CachedObjectData(newObject)); |
|
|
|
return newObject; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
for (var i = 0; i < m_InstantiatedObjects.Length; ++i) |
|
|
|
{ |
|
|
|
m_NumObjectsActive[i] = 0; |
|
|
|
foreach (var obj in m_InstantiatedObjects[i]) |
|
|
|
foreach (var cachedObjectData in m_InstantiatedObjects[i]) |
|
|
|
obj.transform.localPosition = new Vector3(10000, 0, 0); |
|
|
|
var tags = obj.GetComponents<RandomizerTag>(); |
|
|
|
foreach (var tag in tags) |
|
|
|
cachedObjectData.instance.transform.localPosition = new Vector3(10000, 0, 0); |
|
|
|
foreach (var tag in cachedObjectData.randomizerTags) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
struct CachedObjectData |
|
|
|
{ |
|
|
|
public GameObject instance; |
|
|
|
public RandomizerTag[] randomizerTags; |
|
|
|
|
|
|
|
public CachedObjectData(GameObject instance) |
|
|
|
{ |
|
|
|
this.instance = instance; |
|
|
|
randomizerTags = instance.GetComponents<RandomizerTag>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |