public static GameObject CreateNewAsset(HEU_HoudiniAsset.HEU_AssetType assetType, string rootName = "HoudiniAsset", Transform parentTransform = null, HEU_SessionBase session = null, bool bBuildAsync = true) { if (session == null) { session = HEU_SessionManager.GetOrCreateDefaultSession(); } if (!session.IsSessionValid()) { Debug.LogWarning("Invalid Houdini Engine session!"); return(null); } // This will be the root GameObject for the HDA. Adding HEU_HoudiniAssetRoot // allows to use a custom Inspector. GameObject rootGO = new GameObject(); HEU_HoudiniAssetRoot assetRoot = rootGO.AddComponent <HEU_HoudiniAssetRoot>(); // Set the game object's name to the asset's name rootGO.name = string.Format("{0}{1}", rootName, rootGO.GetInstanceID()); // Under the root, we'll add the HEU_HoudiniAsset onto another GameObject // This will be marked as EditorOnly to strip out for builds GameObject hdaGEO = new GameObject(HEU_PluginSettings.HDAData_Name); hdaGEO.transform.parent = rootGO.transform; // This holds all Houdini Engine data HEU_HoudiniAsset asset = hdaGEO.AddComponent <HEU_HoudiniAsset>(); // Marking as EditorOnly to be excluded from builds if (HEU_GeneralUtility.DoesUnityTagExist(HEU_PluginSettings.EditorOnly_Tag)) { hdaGEO.tag = HEU_PluginSettings.EditorOnly_Tag; } // Bind the root to the asset assetRoot._houdiniAsset = asset; // Populate asset with what we know asset.SetupAsset(assetType, null, rootGO, session); // Build it in Houdini Engine asset.RequestReload(bBuildAsync); if (parentTransform != null) { rootGO.transform.parent = parentTransform; rootGO.transform.localPosition = Vector3.zero; } else { rootGO.transform.position = Vector3.zero; } return(rootGO); }
/// <summary> /// Load and instantiate an HDA asset in Unity and Houdini, for the asset located at given path. /// </summary> /// <param name="filePath">Full path to the HDA in Unity project</param> /// <param name="initialPosition">Initial location to create the instance in Unity.</param> /// <returns>Returns the newly created gameobject for the asset in the scene, or null if creation failed.</returns> public static GameObject InstantiateHDA(string filePath, Vector3 initialPosition, HEU_SessionBase session, bool bBuildAsync) { if (filePath == null || !HEU_Platform.DoesFileExist(filePath)) { return(null); } // This will be the root GameObject for the HDA. Adding HEU_HoudiniAssetRoot // allows to use a custom Inspector. GameObject rootGO = new GameObject(HEU_Defines.HEU_DEFAULT_ASSET_NAME); HEU_HoudiniAssetRoot assetRoot = rootGO.AddComponent <HEU_HoudiniAssetRoot>(); // Under the root, we'll add the HEU_HoudiniAsset onto another GameObject // This will be marked as EditorOnly to strip out for builds GameObject hdaGEO = new GameObject(HEU_PluginSettings.HDAData_Name); hdaGEO.transform.parent = rootGO.transform; // This holds all Houdini Engine data HEU_HoudiniAsset asset = hdaGEO.AddComponent <HEU_HoudiniAsset>(); // Marking as EditorOnly to be excluded from builds if (HEU_GeneralUtility.DoesUnityTagExist(HEU_PluginSettings.EditorOnly_Tag)) { hdaGEO.tag = HEU_PluginSettings.EditorOnly_Tag; } // Bind the root to the asset assetRoot._houdiniAsset = asset; // Populate asset with what we know asset.SetupAsset(HEU_HoudiniAsset.HEU_AssetType.TYPE_HDA, filePath, rootGO, session); // Build it in Houdini Engine asset.RequestReload(bBuildAsync); // Apply Unity transform and possibly upload to Houdini Engine rootGO.transform.position = initialPosition; Debug.LogFormat("{0}: Created new HDA asset from {1} of type {2}.", HEU_Defines.HEU_NAME, filePath, asset.AssetType); return(rootGO); }