浏览代码

Add ResetObject to GameObjectOneWayCache

/h-i
Jon Hogins 3 年前
当前提交
d2457a59
共有 1 个文件被更改,包括 38 次插入4 次删除
  1. 42
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Utilities/GameObjectOneWayCache.cs

42
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Utilities/GameObjectOneWayCache.cs


m_NumObjectsActive[i] = 0;
foreach (var cachedObjectData in m_InstantiatedObjects[i])
{
// Position outside the frame
cachedObjectData.instance.transform.localPosition = new Vector3(10000, 0, 0);
foreach (var tag in cachedObjectData.randomizerTags)
tag.Unregister();
ResetObjectState(cachedObjectData);
}
/// <summary>
/// Returns the given cache object back to an inactive state
/// </summary>
/// <param name="gameObject">The object to make inactive</param>
/// <exception cref="ArgumentException">Thrown when gameObject is not an active cached object.</exception>
public void ResetObject(GameObject gameObject)
{
for (var i = 0; i < m_InstantiatedObjects.Length; ++i)
{
var instantiatedObjectList = m_InstantiatedObjects[i];
int indexFound = -1;
for (var j = 0; j < instantiatedObjectList.Count && indexFound < 0; j++)
{
if (instantiatedObjectList[j].instance == gameObject)
indexFound = j;
}
if (indexFound >= 0)
{
ResetObjectState(instantiatedObjectList[indexFound]);
instantiatedObjectList.RemoveAt(indexFound);
m_NumObjectsActive[i]--;
return;
}
}
throw new ArgumentException("Passed GameObject is not an active object in the cache.");
}
private static void ResetObjectState(CachedObjectData cachedObjectData)
{
// Position outside the frame
cachedObjectData.instance.transform.localPosition = new Vector3(10000, 0, 0);
foreach (var tag in cachedObjectData.randomizerTags)
tag.Unregister();
}
static bool IsPrefab(GameObject obj)

正在加载...
取消
保存