ResourcesSampleExtension.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.IO;
  2. using PixiEditor.Extensions.Sdk;
  3. using PixiEditor.Extensions.Sdk.Api.Resources;
  4. using PixiEditor.Extensions.Sdk.Bridge;
  5. namespace ResourcesSample;
  6. public class ResourcesSampleExtension : PixiEditorExtension
  7. {
  8. /// <summary>
  9. /// This method is called when extension is loaded.
  10. /// All extensions are first loaded and then initialized. This method is called before <see cref="OnInitialized"/>.
  11. /// </summary>
  12. public override void OnLoaded()
  13. {
  14. }
  15. /// <summary>
  16. /// This method is called when extension is initialized. After this method is called, you can use Api property to access PixiEditor API.
  17. /// </summary>
  18. public override void OnInitialized()
  19. {
  20. // By default, you can't access any files from the file system, however you can access files from the Resources folder.
  21. // This folder contains files that you put in the Resources folder in the extension project.
  22. // You can use System.File calls to access files in the Resources folder.
  23. // However, if you want to access files that are encrypted, you should use the Resources methods.
  24. // Adding <EncryptResources>true</EncryptResources> to the .csproj file will encrypt the resources in the Resources folder.
  25. Api.Logger.Log(Resources.ReadAllText("Resources/ExampleFile.txt"));
  26. Api.Logger.Log("Writing to file...");
  27. Resources.WriteAllText("Resources/ExampleFile.txt", "Hello from extension!");
  28. Api.Logger.Log(Resources.ReadAllText("Resources/ExampleFile.txt"));
  29. }
  30. }