Skip to content

Commit

Permalink
feat(abi): ✨ add AbiContractImporter and ContractAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonboukheir committed Oct 24, 2023
1 parent 10cc011 commit a6456da
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Editor/Algorand.Unity.Editor/Importers/AbiContractImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.IO;
using UnityEditor.AssetImporters;
using UnityEngine;

namespace Algorand.Unity.Experimental.Abi.Editor
{
[ScriptedImporter(1, "contract.json")]
public class AbiContractImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
var fileName = Path.GetFileNameWithoutExtension(ctx.assetPath);
var json = File.ReadAllText(ctx.assetPath);
var asset = ScriptableObject.CreateInstance<ContractAsset>();
asset.contract = AlgoApiSerializer.DeserializeJson<Contract>(json);
asset.name = fileName;
ctx.AddObjectToAsset("contract", asset);
ctx.SetMainObject(asset);
}
}
}
11 changes: 11 additions & 0 deletions Editor/Algorand.Unity.Editor/Importers/AbiContractImporter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Runtime/Algorand.Unity/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Algorand.Unity.Editor")]
[assembly: InternalsVisibleTo("Algorand.Unity.Tests")]
16 changes: 16 additions & 0 deletions Runtime/Algorand.Unity/Experimental/Abi/ContractAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using UnityEngine;

namespace Algorand.Unity.Experimental.Abi
{
[HelpURL(DocUrl.Api + "Algorand.Unity.Experimental.Abi.ContractAsset.html")]
[CreateAssetMenu(menuName = "Algorand/Experimental/Abi Contract")]
public class ContractAsset : ScriptableObject
{
public Contract contract;

public static implicit operator Contract(ContractAsset asset)
{
return asset.contract;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Algorand.Unity/Experimental/Abi/ContractAsset.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a6456da

Please sign in to comment.