private void Update() { if (prefabManager != null && prefabManager.isActiveAndEnabled) { Rigidbody rb; for (int i = 0; i < _enteredInstances.Count; i++) { if (!IsInsideCollider(_enteredInstances[i])) { rb = _enteredInstances[i].GetComponent <Rigidbody>(); if (rb != null && !rb.IsSleeping()) { continue; } GPUInstancerAPI.EnableInstancingForInstance(prefabManager, _enteredInstances[i]); _enteredInstances.Remove(_enteredInstances[i]); i--; } else if (_enteredInstances[i].state != PrefabInstancingState.Disabled) { prefabManager.DisableIntancingForInstance(_enteredInstances[i]); } } } }
/// <summary> /// <para>Disables GPU instancing and enables Unity renderers for the given prefab instance without removing it from the list of registerd prefabs.</para> /// <para>Use this if you want to pause GPU Instancing for a prefab (e.g. to enable physics).</para> /// <para>Note that the prefab must be enabled for runtime modifications in the manager in order for this to work (for performance reasons).</para> /// <para>Also note that you can also add <seealso cref="GPUInstancerModificationCollider"/> to a game object to use its collider to automatically /// enable/disable instancing when a prefab instance enters/exits its collider.</para> /// </summary> /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param> /// <param name="prefabInstance">The prefab instance to disable the GPU Instancing of.</param> /// <param name="setRenderersEnabled">If set to false Mesh Renderer components will not be enabled after disabling instancing which will make the /// instance invisible.</param> public static void DisableIntancingForInstance(GPUInstancerPrefabManager manager, GPUInstancerPrefab prefabInstance, bool setRenderersEnabled = true) { manager.DisableIntancingForInstance(prefabInstance, setRenderersEnabled); }
/// <summary> /// <para>Disables GPU instancing and enables Unity renderers for the given prefab instance without removing it from the list of registerd prefabs.</para> /// <para>Use this if you want to pause GPU Instancing for a prefab (e.g. to enable physics).</para> /// <para>Note that the prefab must be enabled for runtime modifications in the manager in order for this to work (for performance reasons).</para> /// <para>Also note that you can also add <seealso cref="GPUInstancerModificationCollider"/> to a game object to use its collider to automatically /// enable/disable instancing when a prefab instance enters/exits its collider.</para> /// </summary> /// <param name="manager">The manager that defines the prototypes you want to GPU instance.</param> /// <param name="prefabInstance">The prefab instance to disable the GPU Instancing of.</param> public static void DisableIntancingForInstance(GPUInstancerPrefabManager manager, GPUInstancerPrefab prefabInstance) { manager.DisableIntancingForInstance(prefabInstance); }