Expands/Cleans up a lot of the asset functionality, including management, file association, and creation/importing

This commit is contained in:
Areloch 2019-05-04 11:49:42 -05:00
parent a366f65047
commit 4422082035
73 changed files with 4468 additions and 1876 deletions

View file

@ -8,103 +8,26 @@ function AssetBrowser_editAsset::saveAsset(%this)
Canvas.popDialog(AssetBrowser_editAsset);
}
function AssetBrowser::editAsset(%this)
function AssetBrowser::editAsset(%this, %assetDef)
{
//Find out what type it is
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
//If the passed-in definition param is blank, then we're likely called via a popup
if(%assetDef $= "")
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = %assetDef.getClassName();
if(%assetType $= "MaterialAsset")
{
//if(EditorSettings.materialEditMode $= "MaterialEditor")
//{
%assetDef.materialDefinitionName.reload();
EditorGui.setEditor(MaterialEditorPlugin);
MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName;
MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName );
AssetBrowser.hideDialog();
/*}
else
{
Canvas.pushDialog(ShaderEditor);
ShaderEditorGraph.loadGraph(%assetDef.shaderGraph);
$ShaderGen::targetShaderFile = filePath(%assetDef.shaderGraph) @"/"@fileBase(%assetDef.shaderGraph);
}*/
}
else if(%assetType $= "StateMachineAsset")
{
eval("AssetBrowser.tempAsset = new " @ %assetDef.getClassName() @ "();");
AssetBrowser.tempAsset.assignFieldsFrom(%assetDef);
//Build out the edit command
%buildCommand = %this @ ".edit" @ %assetType @ "(" @ %assetDef @ ");";
eval(%buildCommand);
}
function AssetBrowser::appendSubLevel(%this)
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = %assetDef.getClassName();
SMAssetEditInspector.inspect(AssetBrowser.tempAsset);
AssetBrowser_editAsset.editedAssetId = EditAssetPopup.assetId;
AssetBrowser_editAsset.editedAsset = AssetBrowser.tempAsset;
//remove some of the groups we don't need:
for(%i=0; %i < SMAssetEditInspector.getCount(); %i++)
{
%caption = SMAssetEditInspector.getObject(%i).caption;
if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing"
|| %caption $= "Persistence" || %caption $= "Dynamic Fields")
{
SMAssetEditInspector.remove(SMAssetEditInspector.getObject(%i));
%i--;
}
}
Canvas.pushDialog(StateMachineEditor);
StateMachineEditor.loadStateMachineAsset(EditAssetPopup.assetId);
StateMachineEditor-->Window.text = "State Machine Editor ("@EditAssetPopup.assetId@")";
}
else if(%assetType $= "ComponentAsset")
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%scriptFile = %assetDef.scriptFile;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
else if(%assetType $= "GameObjectAsset")
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%scriptFile = %assetDef.scriptFilePath;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
else if(%assetType $= "ScriptAsset")
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%scriptFile = %assetDef.scriptFilePath;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
else if(%assetType $= "ShapeAsset")
{
%this.hideDialog();
ShapeEditorPlugin.openShapeAsset(EditAssetPopup.assetId);
}
else if(%assetType $= "ShapeAnimationAsset")
{
%this.hideDialog();
ShapeEditorPlugin.openShapeAsset(EditAssetPopup.assetId);
}
else if(%assetType $= "LevelAsset")
{
schedule( 1, 0, "EditorOpenMission", %assetDef.LevelFile);
}
else if(%assetType $= "GUIAsset")
{
if(!isObject(%assetDef.assetName))
{
exec(%assetDef.GUIFilePath);
exec(%assetDef.mScriptFilePath);
}
GuiEditContent(%assetDef.assetName);
}
schedule( 1, 0, "EditorOpenSceneAppend", %assetDef);
}
function AssetBrowser::editAssetInfo(%this)
@ -164,20 +87,24 @@ function AssetBrowser::renameAsset(%this)
AssetBrowser.selectedAssetPreview-->AssetNameLabel.setFirstResponder();
}
function AssetNameField::onReturn(%this)
function AssetBrowser::performRenameAsset(%this, %originalAssetName, %newName)
{
//if the name is different to the asset's original name, rename it!
%newName = %this.getText();
if(%this.originalAssetName !$= %this.getText())
if(%originalAssetName !$= %newName)
{
%moduleName = AssetBrowser.selectedModule;
//do a rename!
%success = AssetDatabase.renameDeclaredAsset(%moduleName @ ":" @ %this.originalAssetName, %moduleName @ ":" @ %this.getText());
%success = AssetDatabase.renameDeclaredAsset(%moduleName @ ":" @ %originalAssetName, %moduleName @ ":" @ %newName);
if(%success)
echo("AssetBrowser - renaming of asset " @ %moduleName @ ":" @ %originalAssetName @ " to " @ %moduleName @ ":" @ %newName @ " was a success.");
else
echo("AssetBrowser - renaming of asset " @ %moduleName @ ":" @ %originalAssetName @ " to " @ %moduleName @ ":" @ %newName @ " was a failure.");
if(%success)
{
%newAssetId = %moduleName @ ":" @ %this.getText();
%newAssetId = %moduleName @ ":" @ %newName;
%assetPath = AssetDatabase.getAssetFilePath(%newAssetId);
//Rename any associated files as well
@ -187,160 +114,44 @@ function AssetNameField::onReturn(%this)
//rename the file to match
%path = filePath(%assetPath);
if(%assetType $= "ComponentAsset")
{
%oldScriptFilePath = %assetDef.scriptFile;
%scriptFilePath = filePath(%assetDef.scriptFile);
%scriptExt = fileExt(%assetDef.scriptFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml";
%assetDef.componentName = %newName;
%assetDef.scriptFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
}
else if(%assetType $= "StateMachineAsset")
{
%oldScriptFilePath = %assetDef.stateMachineFile;
%scriptFilePath = filePath(%assetDef.stateMachineFile);
%scriptExt = fileExt(%assetDef.stateMachineFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml";
%assetDef.stateMachineFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
}
else if(%assetType $= "GameObjectAsset")
{
%oldScriptFilePath = %assetDef.scriptFilePath;
%scriptFilePath = filePath(%assetDef.scriptFilePath);
%scriptExt = fileExt(%assetDef.scriptFilePath);
%oldGOFilePath = %assetDef.TAMLFilePath;
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml";
%newGOFile = %path @ "/" @ %this.getText() @ ".taml";
%assetDef.gameObjectName = %newName;
%assetDef.scriptFilePath = %newScriptFileName;
%assetDef.TAMLFilePath = %newGOFile;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
pathCopy(%oldGOFilePath, %newGOFile);
fileDelete(%oldGOFilePath);
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
//Rename in the TAML file as well
%file = new FileObject();
if ( %file.openForRead( %newGOFile ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newGOFile);
%file.writeline(%editedFileContents);
%file.close();
}
}
//Do the rename command
%buildCommand = %this @ ".rename" @ %assetType @ "(" @ %assetDef @ "," @ %newAssetId @ ");";
eval(%buildCommand);
}
}
//Make sure everything is refreshed
AssetBrowser.loadFilters();
}
function AssetNameField::onReturn(%this)
{
%this.clearFirstResponder();
%this.setActive(false);
AssetBrowser.performRenameAsset(%this.originalAssetName, %this.getText());
}
//------------------------------------------------------------
function AssetBrowser::duplicateAsset(%this)
function AssetBrowser::duplicateAsset(%this, %targetModule)
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
if(%targetModule $= "")
{
//we need a module to duplicate to first
Canvas.pushDialog(AssetBrowser_selectModule);
AssetBrowser_selectModule.callback = "AssetBrowser.duplicateAsset";
return;
}
%this.setupCreateNewAsset(%assetDef.getClassName(), AssetBrowser.selectedModule);
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId);
//this acts as a redirect based on asset type and will enact the appropriate function
//so for a GameObjectAsset, it'll become %this.duplicateGameObjectAsset(%assetDef, %targetModule);
//and call to the tools/assetBrowser/scripts/assetTypes/gameObject.cs file for implementation
if(%this.isMethod("duplicate"@%assetType))
eval(%this @ ".duplicate"@%assetType@"("@%assetDef@","@%targetModule@");");
}
function AssetBrowser::deleteAsset(%this)
@ -358,8 +169,15 @@ function AssetBrowser::confirmDeleteAsset(%this)
%currentSelectedItem = AssetBrowserFilterTree.getSelectedItem();
%currentItemParent = AssetBrowserFilterTree.getParentItem(%currentSelectedItem);
AssetDatabase.deleteAsset(EditAssetPopup.assetId, false);
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId);
//Do any cleanup required given the type
if(%this.isMethod("delete"@%assetType))
eval(%this @ ".delete"@%assetType@"("@%assetDef@");");
AssetDatabase.deleteAsset(EditAssetPopup.assetId, false);
%this.loadFilters();
if(!AssetBrowserFilterTree.selectItem(%currentSelectedItem))