/// <summary>
	/// Callback when new prefab instances gets created or updated in Unity scene.
	/// The plugin does not support creating prefab of HDAs directly
	/// so this notifies user and provides a way to clean up the created prefab.
	/// </summary>
	/// <param name="instance">New prefab instance that was created</param>
	private static void OnPrefabInstanceUpdate(GameObject instance)
	{
#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED && UNITY_2017_1_OR_NEWER

	    var heu_root = instance.GetComponent<HEU_HoudiniAssetRoot>();
	    if (heu_root != null && heu_root._houdiniAsset != null &&
		    (HEU_EditorUtility.IsPrefabInstance(instance) || HEU_EditorUtility.IsPrefabAsset(instance)) &&
		    !heu_root._houdiniAsset.WarnedPrefabNotSupported)
	    {
		string prefabPath = HEU_EditorUtility.GetPrefabAssetPath(instance);

		string title = HEU_Defines.HEU_PRODUCT_NAME + " Prefabs Not Supported";
		string message =
				"Creating prefab of an HDA is not supported by HoudniEngine.\n\n" +
				"It is recommended to select 'Remove Prefab' to destroy new prefab " +
				"and revert to original asset.\n\n" +
				"Prefab: " + prefabPath;

		heu_root._houdiniAsset.WarnedPrefabNotSupported = true;
		if (HEU_EditorUtility.DisplayDialog(title, message, "Remove Prefab && Revert", "Keep Prefab"))
		{
		    HEU_EditorUtility.DisconnectPrefabInstance(instance);
		    HEU_AssetDatabase.DeleteAssetAtPath(prefabPath);

		    // Doesn't actually refresh properly, but should be fixed in 2021.2 and 2022.1 
		    HEU_AssetDatabase.SaveAndRefreshDatabase();
		}
	    }
#endif
	}
		public static Texture2D ExtractHoudiniImageToTextureFile(HEU_SessionBase session, HAPI_MaterialInfo materialInfo, string imagePlanes, string assetCacheFolderPath)
		{
			Texture2D textureResult = null;

			// Get the Textures folder in the assetCacheFolderPath. Make sure it exists.
			assetCacheFolderPath = HEU_AssetDatabase.AppendTexturesPathToAssetFolder(assetCacheFolderPath);
			HEU_AssetDatabase.CreatePathWithFolders(assetCacheFolderPath);

			// Need to pass in full path to Houdini to write out the file
			assetCacheFolderPath = HEU_AssetDatabase.GetAssetFullPath(assetCacheFolderPath);
			if (assetCacheFolderPath == null)
			{
				return textureResult;
			}

			HAPI_ImageInfo imageInfo = new HAPI_ImageInfo();
			if (!session.GetImageInfo(materialInfo.nodeId, ref imageInfo))
			{
				return textureResult;
			}

			// This will return null if the current imageInfo file format is supported by Unity, otherwise
			// returns a Unity supported file format.
			string desiredFileFormatName = HEU_MaterialData.GetSupportedFileFormat(session, ref imageInfo);

			// Extract image to file
			string writtenFilePath = null;
			if (!session.ExtractImageToFile(materialInfo.nodeId, desiredFileFormatName, imagePlanes, assetCacheFolderPath, out writtenFilePath))
			{
				return textureResult;
			}
			

			HEU_AssetDatabase.SaveAndRefreshDatabase();

			// Convert full path back to relative in order to work with AssetDatabase
			string assetRelativePath = HEU_AssetDatabase.GetAssetRelativePath(writtenFilePath);

			// Re-import to refresh the project
			HEU_AssetDatabase.ImportAsset(assetRelativePath, HEU_AssetDatabase.HEU_ImportAssetOptions.Default);

			textureResult = HEU_AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(Texture2D)) as Texture2D;
			//Debug.LogFormat("Loaded texture to file {0} with format {1}", writtenFilePath, textureResult != null ? textureResult.format.ToString() : "none");

			return textureResult;
		}