Skip to content

Commit

Permalink
Use spaces for extra indentation within [csharp]
Browse files Browse the repository at this point in the history
  • Loading branch information
esainane committed Aug 18, 2024
1 parent 0c42a36 commit 45431d3
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions doc/classes/EditorImportPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,40 +278,40 @@
[csharp]
public partial class MyEditorImportPlugin : EditorImportPlugin
{
public override Error _Import(string sourceFile, string savePath, Godot.Collections.Dictionary options, Godot.Collections.Array<string> platformVariants, Godot.Collections.Array<string> genFiles)
{
// Make textures folder if required.
string sourceFileFolder = sourceFile.Substring(0, sourceFile.LastIndexOf('/'));
string texturesFolder = $"{sourceFileFolder}/Textures";
DirAccess.MakeDirRecursiveAbsolute(texturesFolder);

// Simulate image export by copying the source file to the textures folder.
string exportPath = $"{texturesFolder}/Icon.png";
using FileAccess exportImageFile = FileAccess.Open(exportPath, FileAccess.ModeFlags.Write);
exportImageFile.StoreBuffer(FileAccess.GetFileAsBytes("res://Game/MyIcon.png"));
exportImageFile.Close();

// Ensure file visibility for ResourceLoader later.
EditorFileSystem editorFileSystem = EditorInterface.Singleton.GetResourceFilesystem();
editorFileSystem.UpdateFile(texturesFolder);
editorFileSystem.UpdateFile(exportPath);

// Append exported file as external resource.
Error err = AppendImportExternalResource(exportPath);
if (err != Error.Ok)
{
return err;
}

// Load exported image as a Texture2D.
Texture2D exportImageTex = ResourceLoader.Load<Texture2D>(exportPath, nameof(Texture2D), ResourceLoader.CacheMode.Replace);
if (exportImageTex == null)
{
return Error.ScriptFailed;
}

...
}
public override Error _Import(string sourceFile, string savePath, Godot.Collections.Dictionary options, Godot.Collections.Array<string> platformVariants, Godot.Collections.Array<string> genFiles)
{
// Make textures folder if required.
string sourceFileFolder = sourceFile.Substring(0, sourceFile.LastIndexOf('/'));
string texturesFolder = $"{sourceFileFolder}/Textures";
DirAccess.MakeDirRecursiveAbsolute(texturesFolder);

// Simulate image export by copying the source file to the textures folder.
string exportPath = $"{texturesFolder}/Icon.png";
using FileAccess exportImageFile = FileAccess.Open(exportPath, FileAccess.ModeFlags.Write);
exportImageFile.StoreBuffer(FileAccess.GetFileAsBytes("res://Game/MyIcon.png"));
exportImageFile.Close();

// Ensure file visibility for ResourceLoader later.
EditorFileSystem editorFileSystem = EditorInterface.Singleton.GetResourceFilesystem();
editorFileSystem.UpdateFile(texturesFolder);
editorFileSystem.UpdateFile(exportPath);

// Append exported file as external resource.
Error err = AppendImportExternalResource(exportPath);
if (err != Error.Ok)
{
return err;
}

// Load exported image as a Texture2D.
Texture2D exportImageTex = ResourceLoader.Load<Texture2D>(exportPath, nameof(Texture2D), ResourceLoader.CacheMode.Replace);
if (exportImageTex == null)
{
return Error.ScriptFailed;
}

...
}
}
[/csharp]
[/codeblocks]
Expand Down

0 comments on commit 45431d3

Please sign in to comment.