Added utility methods to AssetBase:

getAssetDependencyFieldCount
clearAssetDependencyFields
addAssetDependencyField
saveAsset

Updated the saveAsset function for terrain block to utilize utility methods to ensure the terrain asset's material dependencies, so they will load properly.
This commit is contained in:
Areloch 2019-11-07 00:42:55 -06:00
parent 906c7095f1
commit d8cc73f5a1
6 changed files with 120 additions and 100 deletions

View file

@ -83,45 +83,4 @@ function GuiInspectorTypeTerrainAssetPtr::onClick( %this, %fieldName )
function GuiInspectorTypeTerrainAssetPtr::onControlDropped( %this, %payload, %position )
{
}
//AssetDatabase.acquireAsset("pbr:NewTerrain");
function TerrainAsset::saveAsset(%this)
{
%matDepIdx = 0;
while(%this.getFieldValue("terrainMaterialAsset", %matDepIdx) !$= "")
{
%this.setFieldValue("terrainMaterialAsset", "", %matDepIdx);
}
%filePath = AssetDatabase.getAssetFilePath(%this.getAssetId());
%mats = ETerrainEditor.getMaterials();
%assetQuery = new AssetQuery();
AssetDatabase.findAssetType(%assetQuery, "TerrainMaterialAsset");
%count = %assetQuery.getCount();
%matDepIdx = 0;
for( %i = 0; %i < getRecordCount( %mats ); %i++ )
{
%matInternalName = getRecord( %mats, %i );
for(%m=0; %m < %count; %m++)
{
%assetId = %assetQuery.getAsset(%m);
%terrMatAssetDef = AssetDatabase.acquireAsset(%assetId);
if(%terrMatAssetDef.materialDefinitionName $= %matInternalName)
{
%this.setFieldValue("terrainMaterialAsset", "@Asset=" @ %assetId, %matDepIdx);
%matDepIdx++;
}
}
}
%assetQuery.delete();
TAMLWrite(%this, %filePath);
}