Skip to content

Commit 9809aea

Browse files
Upgrade MetaMask SDK to 2.0.1 (#185)
Signed-off-by: Eddie Penta <eddie.penta@consensys.net> Co-authored-by: 0xFirekeeper <0xFirekeeper@gmail.com>
1 parent 2a4b264 commit 9809aea

File tree

144 files changed

+7536
-886
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+7536
-886
lines changed

Assets/Thirdweb/Core/Plugins/MetaMask.NEthereum/MetaMaskNEthereumExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace MetaMask.NEthereum
55
{
66
public static class MetaMaskNEthereumExtensions
77
{
8-
public static Web3 CreateWeb3(this MetaMaskUnity metaMaskUnity)
8+
public static Web3 CreateWeb3(this IMetaMaskSDK metaMaskUnity)
99
{
1010
return metaMaskUnity.Wallet.CreateWeb3();
1111
}

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/EditorGUI/MetaMaskWindow.cs

Lines changed: 0 additions & 537 deletions
This file was deleted.

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/README.html

Lines changed: 1648 additions & 0 deletions
Large diffs are not rendered by default.

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/README.html.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/Scripts.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/Scripts/Editor.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/EditorGUI.meta renamed to Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/Scripts/Editor/DecoratorDrawers.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
4+
namespace MetaMask.Editor.NaughtyAttributes.Editor
5+
{
6+
[CustomPropertyDrawer(typeof(HorizontalLineAttribute))]
7+
public class HorizontalLineDecoratorDrawer : DecoratorDrawer
8+
{
9+
public override float GetHeight()
10+
{
11+
HorizontalLineAttribute lineAttr = (HorizontalLineAttribute)attribute;
12+
return EditorGUIUtility.singleLineHeight + lineAttr.Height;
13+
}
14+
15+
public override void OnGUI(Rect position)
16+
{
17+
Rect rect = EditorGUI.IndentedRect(position);
18+
rect.y += EditorGUIUtility.singleLineHeight / 3.0f;
19+
HorizontalLineAttribute lineAttr = (HorizontalLineAttribute)attribute;
20+
NaughtyEditorGUI.HorizontalLine(rect, lineAttr.Height, lineAttr.Color.GetColor());
21+
}
22+
}
23+
}

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/EditorGUI/MetaMaskWindow.cs.meta renamed to Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/Scripts/Editor/DecoratorDrawers/HorizontalLineDecoratorDrawer.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace MetaMask.Editor.NaughtyAttributes.Editor
5+
{
6+
[CustomPropertyDrawer(typeof(InfoBoxAttribute))]
7+
public class InfoBoxDecoratorDrawer : DecoratorDrawer
8+
{
9+
public override float GetHeight()
10+
{
11+
return GetHelpBoxHeight();
12+
}
13+
14+
public override void OnGUI(Rect rect)
15+
{
16+
InfoBoxAttribute infoBoxAttribute = (InfoBoxAttribute)attribute;
17+
18+
float indentLength = NaughtyEditorGUI.GetIndentLength(rect);
19+
Rect infoBoxRect = new Rect(
20+
rect.x + indentLength,
21+
rect.y,
22+
rect.width - indentLength,
23+
GetHelpBoxHeight());
24+
25+
DrawInfoBox(infoBoxRect, infoBoxAttribute.Text, infoBoxAttribute.Type);
26+
}
27+
28+
private float GetHelpBoxHeight()
29+
{
30+
InfoBoxAttribute infoBoxAttribute = (InfoBoxAttribute)attribute;
31+
float minHeight = EditorGUIUtility.singleLineHeight * 2.0f;
32+
float desiredHeight = GUI.skin.box.CalcHeight(new GUIContent(infoBoxAttribute.Text), EditorGUIUtility.currentViewWidth);
33+
float height = Mathf.Max(minHeight, desiredHeight);
34+
35+
return height;
36+
}
37+
38+
private void DrawInfoBox(Rect rect, string infoText, EInfoBoxType infoBoxType)
39+
{
40+
MessageType messageType = MessageType.None;
41+
switch (infoBoxType)
42+
{
43+
case EInfoBoxType.Normal:
44+
messageType = MessageType.Info;
45+
break;
46+
47+
case EInfoBoxType.Warning:
48+
messageType = MessageType.Warning;
49+
break;
50+
51+
case EInfoBoxType.Error:
52+
messageType = MessageType.Error;
53+
break;
54+
}
55+
56+
NaughtyEditorGUI.HelpBox(rect, infoText, messageType);
57+
}
58+
}
59+
}

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/Scripts/Editor/DecoratorDrawers/InfoBoxDecoratorDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Reflection;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace MetaMask.Editor.NaughtyAttributes.Editor
8+
{
9+
[CanEditMultipleObjects]
10+
[CustomEditor(typeof(UnityEngine.Object), true)]
11+
public class NaughtyInspector : UnityEditor.Editor
12+
{
13+
private List<SerializedProperty> _serializedProperties = new List<SerializedProperty>();
14+
private IEnumerable<FieldInfo> _nonSerializedFields;
15+
private IEnumerable<PropertyInfo> _nativeProperties;
16+
private IEnumerable<MethodInfo> _methods;
17+
private Dictionary<string, SavedBool> _foldouts = new Dictionary<string, SavedBool>();
18+
19+
private bool isInvalid;
20+
21+
protected virtual void OnEnable()
22+
{
23+
_nonSerializedFields = ReflectionUtility.GetAllFields(
24+
target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0);
25+
26+
_nativeProperties = ReflectionUtility.GetAllProperties(
27+
target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0);
28+
29+
_methods = ReflectionUtility.GetAllMethods(
30+
target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0);
31+
32+
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
33+
}
34+
35+
private void OnPlayModeStateChanged(PlayModeStateChange state)
36+
{
37+
if (state != PlayModeStateChange.ExitingEditMode || !isInvalid) return;
38+
39+
EditorApplication.isPlaying = false;
40+
41+
EditorUtility.DisplayDialog("Error", "You must fix the configuration errors inside MetaMask SDK before entering play mode.", "OK");
42+
}
43+
44+
protected virtual void OnDisable()
45+
{
46+
ReorderableListPropertyDrawer.Instance.ClearCache();
47+
48+
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
49+
}
50+
51+
public override void OnInspectorGUI()
52+
{
53+
GetSerializedProperties(ref _serializedProperties);
54+
55+
bool anyNaughtyAttribute = _serializedProperties.Any(p => PropertyUtility.GetAttribute<INaughtyAttribute>(p) != null);
56+
if (!anyNaughtyAttribute)
57+
{
58+
DrawDefaultInspector();
59+
}
60+
else
61+
{
62+
DrawSerializedProperties();
63+
}
64+
65+
DrawNonSerializedFields();
66+
DrawNativeProperties();
67+
DrawButtons();
68+
}
69+
70+
protected void GetSerializedProperties(ref List<SerializedProperty> outSerializedProperties)
71+
{
72+
outSerializedProperties.Clear();
73+
using (var iterator = serializedObject.GetIterator())
74+
{
75+
if (iterator.NextVisible(true))
76+
{
77+
do
78+
{
79+
outSerializedProperties.Add(serializedObject.FindProperty(iterator.name));
80+
}
81+
while (iterator.NextVisible(false));
82+
}
83+
}
84+
}
85+
86+
protected void DrawSerializedProperties()
87+
{
88+
serializedObject.Update();
89+
90+
// Draw non-grouped serialized properties
91+
bool allPropertiesValid = true;
92+
foreach (var property in GetNonGroupedProperties(_serializedProperties))
93+
{
94+
if (property.name.Equals("m_Script", System.StringComparison.Ordinal))
95+
{
96+
using (new EditorGUI.DisabledScope(disabled: true))
97+
{
98+
EditorGUILayout.PropertyField(property);
99+
}
100+
}
101+
else
102+
{
103+
allPropertiesValid &= NaughtyEditorGUI.PropertyField_Layout(property, includeChildren: true);
104+
}
105+
}
106+
107+
isInvalid = !allPropertiesValid;
108+
109+
serializedObject.ApplyModifiedProperties();
110+
}
111+
112+
protected void DrawNonSerializedFields(bool drawHeader = false)
113+
{
114+
if (_nonSerializedFields.Any())
115+
{
116+
if (drawHeader)
117+
{
118+
EditorGUILayout.Space();
119+
EditorGUILayout.LabelField("Non-Serialized Fields", GetHeaderGUIStyle());
120+
NaughtyEditorGUI.HorizontalLine(
121+
EditorGUILayout.GetControlRect(false), HorizontalLineAttribute.DefaultHeight, HorizontalLineAttribute.DefaultColor.GetColor());
122+
}
123+
124+
foreach (var field in _nonSerializedFields)
125+
{
126+
NaughtyEditorGUI.NonSerializedField_Layout(serializedObject.targetObject, field);
127+
}
128+
}
129+
}
130+
131+
protected void DrawNativeProperties(bool drawHeader = false)
132+
{
133+
if (_nativeProperties.Any())
134+
{
135+
if (drawHeader)
136+
{
137+
EditorGUILayout.Space();
138+
EditorGUILayout.LabelField("Native Properties", GetHeaderGUIStyle());
139+
NaughtyEditorGUI.HorizontalLine(
140+
EditorGUILayout.GetControlRect(false), HorizontalLineAttribute.DefaultHeight, HorizontalLineAttribute.DefaultColor.GetColor());
141+
}
142+
143+
foreach (var property in _nativeProperties)
144+
{
145+
NaughtyEditorGUI.NativeProperty_Layout(serializedObject.targetObject, property);
146+
}
147+
}
148+
}
149+
150+
protected void DrawButtons(bool drawHeader = false)
151+
{
152+
if (_methods.Any())
153+
{
154+
if (drawHeader)
155+
{
156+
EditorGUILayout.Space();
157+
EditorGUILayout.LabelField("Buttons", GetHeaderGUIStyle());
158+
NaughtyEditorGUI.HorizontalLine(
159+
EditorGUILayout.GetControlRect(false), HorizontalLineAttribute.DefaultHeight, HorizontalLineAttribute.DefaultColor.GetColor());
160+
}
161+
162+
foreach (var method in _methods)
163+
{
164+
NaughtyEditorGUI.Button(serializedObject.targetObject, method);
165+
}
166+
}
167+
}
168+
169+
private static IEnumerable<SerializedProperty> GetNonGroupedProperties(IEnumerable<SerializedProperty> properties)
170+
{
171+
return properties.Where(p => PropertyUtility.GetAttribute<IGroupAttribute>(p) == null);
172+
}
173+
174+
private static GUIStyle GetHeaderGUIStyle()
175+
{
176+
GUIStyle style = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
177+
style.fontStyle = FontStyle.Bold;
178+
style.alignment = TextAnchor.UpperCenter;
179+
180+
return style;
181+
}
182+
}
183+
}

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Core/Plugins/MetaMask/Editor/NaughtyAttributes/Scripts/Editor/PropertyDrawers.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)