-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathABIConverter.cs
More file actions
85 lines (65 loc) 路 2.86 KB
/
Copy pathABIConverter.cs
File metadata and controls
85 lines (65 loc) 路 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using UnityEngine;
using UnityEditor;
using System.Text.RegularExpressions;
public class ABIWindow : EditorWindow
{
// The ABI string
string ABI;
// Our Text Area ScrollView
Vector2 TextArea;
// Where is the window menu located
[MenuItem("ChainSafe SDK/ABI Formatter")]
// Show our window
public static void ShowWindow()
{
GetWindow<ABIWindow>("ChainSafe ABI Formatter");
}
private void OnGUI()
{
// Ensure our labels are using Rich text for added customization
var style = new GUIStyle(GUI.skin.label);
style.richText = true;
// Window Header
GUILayout.Space(10);
GUILayout.Label("<b><size=15>ChainSafe ABI Formatter</size></b>", style);
GUILayout.Label("Copy/Paste is supported.", style);
GUILayout.Space(10);
// Window Body (Our TextArea)
TextArea = EditorGUILayout.BeginScrollView(TextArea, GUILayout.Height(200));
GUILayout.Space(10);
ABI = EditorGUILayout.TextArea(ABI);
GUILayout.Space(10);
GUILayout.EndScrollView();
// The logic for formatting our ABI
if (GUILayout.Button("Convert", GUILayout.Height(30)))
{
string RemoveNewLines = ABI.Replace("\n", "");
string RemoveWhiteSpaces = Regex.Replace(RemoveNewLines, @"\s", "");
string ImprovedABI = RemoveWhiteSpaces.Replace("\"", "\\\"");
// Copy the results to the users clipboard
GUIUtility.systemCopyBuffer = "\"" + ImprovedABI + "\";";
Debug.Log("ABI Conversion Complete. Results copied to clipboard!");
}
// Window Footer (Instructions)
GUILayout.Space(10);
GUILayout.Label("This tool will automatically convert your ABI for use with the web3.unity SDK. \n", EditorStyles.largeLabel);
GUILayout.Label("<b>=============</b>", style);
GUILayout.Label("<b> INSTRUCTIONS</b>", style);
GUILayout.Label("<b>=============</b> \n", style);
GUILayout.Label(" 1. Copy your ABI from https://remix.ethereum.org/ \n 2. Paste it in the field above \n 3. Click on \"Convert\" \n 4. The new ABI should automatically be copied to your clipboard! \n 5. Add the ABI to your contract manager or custom code.", EditorStyles.largeLabel);
GUILayout.Space(10);
// Start of our footer buttons
GUILayout.BeginHorizontal();
// Our documentation button
if (GUILayout.Button("Documentation", GUILayout.Width(110), GUILayout.Height(25)))
{
Application.OpenURL("https://docs.gaming.chainsafe.io/current/getting-started");
}
// Our discord button
if (GUILayout.Button("Join Discord", GUILayout.Width(110), GUILayout.Height(25)))
{
Application.OpenURL("https://discord.gg/MM67VQwaKX");
}
GUILayout.EndHorizontal();
}
}