/// <summary>
		/// Destroy existing components on targetGO which were generated by our bake process.
		/// Persistent resources like meshes, materials, textures will be deleted if bDontDeletePersistentResources is true.
		/// Fills in targetAssetPath with targetGO's asset cache path.
		/// </summary>
		/// <param name="targetGO">The gameobject to destroy components of</param>
		/// <param name="bDontDeletePersistantResources">Whether to delete persistant data</param>
		/// <param name="targetAssetPath">targetGO's asset cache path, if used</param>
		public static void DestroyGeneratedMeshMaterialsLODGroups(GameObject targetGO, bool bDontDeletePersistantResources)
		{
			if(targetGO == null)
			{
				return;
			}

			// Delete the target mesh collider's mesh
			// Do this before deleting the mesh below since its stored under the mesh's asset on file
			DestroyMeshCollider(targetGO, bDontDeletePersistantResources);

			// Delete the target mesh filter's mesh
			MeshFilter targetMeshFilter = targetGO.GetComponent<MeshFilter>();
			if (targetMeshFilter != null)
			{
				Mesh targetMesh = targetMeshFilter.sharedMesh;
				if (targetMesh != null)
				{
					if (!bDontDeletePersistantResources || !HEU_EditorUtility.IsPersistant(targetMesh))
					{
						DestroyImmediate(targetMesh, true);
					}

					targetMesh = null;
					targetMeshFilter.sharedMesh = null;
				}
			}

			// Delete existing materials and textures
			MeshRenderer targetMeshRenderer = targetGO.GetComponent<MeshRenderer>();
			if (targetMeshRenderer != null && !bDontDeletePersistantResources)
			{
				Material[] targetMaterials = targetMeshRenderer.sharedMaterials;

				if (targetMaterials != null)
				{
					for (int i = 0; i < targetMaterials.Length; ++i)
					{
						Material material = targetMaterials[i];
						if (material == null)
						{
							continue;
						}

						DestroyGeneratedMaterial(material);
						targetMaterials[i] = null;
					}

					targetMeshRenderer.sharedMaterials = targetMaterials;
				}
			}

			// If has LOD group, delete children as well. Presumably the children are the LOD meshes.
			DestroyLODGroup(targetGO, bDontDeletePersistantResources);
		}
예제 #2
0
		public static void DestroyMeshCollider(GameObject gameObject, bool bDontDeletePersistantResources)
		{
			MeshCollider targetMeshCollider = gameObject != null ? gameObject.GetComponent<MeshCollider>() : null;
			if (targetMeshCollider != null)
			{
				Mesh targetColliderMesh = targetMeshCollider != null ? targetMeshCollider.sharedMesh : null;
				if (targetColliderMesh != null)
				{
					if (!bDontDeletePersistantResources || !HEU_EditorUtility.IsPersistant(targetColliderMesh))
					{
						DestroyImmediate(targetColliderMesh);
					}

					targetColliderMesh = null;
					targetMeshCollider.sharedMesh = null;
				}
			}
		}
		public static void DestroyMeshCollider(GameObject gameObject, bool bDontDeletePersistantResources)
		{
			MeshCollider targetMeshCollider = gameObject != null ? gameObject.GetComponent<MeshCollider>() : null;
			if (targetMeshCollider != null)
			{
				Mesh targetColliderMesh = targetMeshCollider != null ? targetMeshCollider.sharedMesh : null;
				if (targetColliderMesh != null)
				{
					if (!bDontDeletePersistantResources || !HEU_EditorUtility.IsPersistant(targetColliderMesh))
					{
						// Need to call DestroyImmediate with bAllowDestroyingAssets to force deleting the asset file
						DestroyImmediate(targetColliderMesh, bAllowDestroyingAssets: true);
					}

					targetColliderMesh = null;
					targetMeshCollider.sharedMesh = null;
				}
			}
		}