-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathHyperPlayConnectionProvider.cs
More file actions
65 lines (51 loc) · 2.25 KB
/
HyperPlayConnectionProvider.cs
File metadata and controls
65 lines (51 loc) · 2.25 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
using System.Threading.Tasks;
using ChainSafe.Gaming.LocalStorage;
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.Gaming.UnityPackage.Connection;
using ChainSafe.Gaming.Web3.Build;
using ChainSafe.Gaming.Web3.Evm.Wallet;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using UnityEngine;
using UnityEngine.UI;
namespace ChainSafe.Gaming.HyperPlay
{
/// <summary>
/// Connection provider for connecting via HyperPlay Launcher.
/// </summary>
[CreateAssetMenu(menuName = "ChainSafe/Connection Provider/HyperPlay", fileName = nameof(HyperPlayConnectionProvider))]
public class HyperPlayConnectionProvider : ConnectionProvider, IHyperPlayConfig
{
[field: SerializeField, DefaultAssetValue("Packages/io.chainsafe.web3-unity.hyperplay/Runtime/Sprites/HyperPlay.png")]
public override Sprite ButtonIcon { get; protected set; }
[field: SerializeField] public override string ButtonText { get; protected set; } = "HyperPlay";
public string SignMessageRpcMethodName => "personal_sign";
public string SignTypedMessageRpcMethodName => "eth_signTypedData_v3";
bool IHyperPlayConfig.RememberSession => RememberSession;
public override bool IsAvailable => Application.isEditor || !Application.isMobilePlatform;
private bool _storedSessionAvailable;
#if UNITY_WEBGL && !UNITY_EDITOR
public override Task Initialize(bool rememberSession)
{
return Task.CompletedTask;
}
#endif
protected override void ConfigureServices(IWeb3ServiceCollection services)
{
#if UNITY_WEBGL && !UNITY_EDITOR
services.UseHyperPlay<HyperPlayWebGLProvider>(this);
services.Replace(ServiceDescriptor.Singleton<ILocalStorage, WebDataStorage>());
#else
services.UseHyperPlay(this);
#endif
services.UseWalletSigner().UseWalletTransactionExecutor();
}
public override async Task<bool> SavedSessionAvailable()
{
var data = new HyperPlayData();
await data.LoadOneTime();
_storedSessionAvailable = data.RememberSession;
return _storedSessionAvailable;
}
}
}