Unity中用C#加载Houdini HDA
在项目中我们虽然用houdini做了好多好用的工具,但在使用的时候需要手动一个一个拖到场中,这样无形中繁琐了好多(尤其在给不懂houdini的美术同学使用的时候, 他们是喜欢傻瓜式的使用方式),这就需要我们有时候把hda做成命令的方式,点一下就完成!
首先先展示怎么用c#自动加载hda,相信有c#基础的同学一看就会
public GameObject loadHDA(string asset_path)
{
HEU_SessionBase session = HEU_SessionManager.GetDefaultSession();
HEU_SessionData sedata = session.GetSessionData();
if(sedata == null)
{
HEU_SessionManager.RestartSession();
}
string fullpath = HEU_AssetDatabase.GetAssetFullPath(asset_path);
if(string.IsNullOrEmpty(fullpath))
{
Debug.LogErrorFormat("Unable to load hda at path:{0}", fullpath);
return null;
}
Debug.Log(fullpath);
GameObject rootGO = HEU_HAPIUtility.InstantiateHDA(fullpath, Vector3.zero, session, true);
if(rootGO != null)
{
HEU_EditorUtility.SelectObject(rootGO);
}
return rootGO;
}
我们看到它返回的结果是GameObject,我们还需要把它转成hda资产,然后cook一下,这样才正式启动了这个hda工具`
GameObject hdaasset = loadHDA(asset_path);
_hdaasset = hdaasset.GetComponent<HEU_HoudiniAssetRoot>() != null ? hdaasset.GetComponent<HEU_HoudiniAssetRoot>()._houdiniAsset : null;
_hdaasset.RequestCook(true, false, true, true);
今天就到这,下篇文章我们将介绍怎么用c#和hda里的参数交互!