Skip to content

Commit

Permalink
⚡ Improve Unity compatibility & bug Fixing (#55)
Browse files Browse the repository at this point in the history
* ⚡ Improve Unity compatibility & bug Fixing

* Delete CODE_OF_CONDUCT.md.meta

* Delete CONTRIBUTING.md.meta

* 🙈 Update gitignore

* 🔥 Remove unused asmdef

* ⚡ Add faster RPC
  • Loading branch information
GabrielePicco authored Feb 23, 2023
1 parent 4b8812e commit 2f00727
Show file tree
Hide file tree
Showing 32 changed files with 10,939 additions and 9,856 deletions.
16 changes: 0 additions & 16 deletions Editor/com.solana.unity_sdk.Editor.asmdef

This file was deleted.

Binary file modified Packages/Solana.Unity.Extensions.dll
Binary file not shown.
Binary file modified Packages/Solana.Unity.Rpc.dll
Binary file not shown.
28 changes: 9 additions & 19 deletions Runtime/Plugins/WebGLSupport/WebGLInput/Mobile/WebGLInputMobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ namespace WebGLSupport
{
class WebGLInputMobilePlugin
{
#if UNITY_WEBGL && !UNITY_EDITOR
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")]
public static extern int WebGLInputMobileRegister(Action<int> OnTouchEnd);

[DllImport("__Internal")]
public static extern void WebGLInputMobileOnFocusOut(int id, Action<int> OnFocusOut);
#else
/// <summary>
/// ID を割り振り
/// </summary>
/// <returns></returns>
#else
public static int WebGLInputMobileRegister(Action<int> OnTouchEnd) { return 0; }

public static void WebGLInputMobileOnFocusOut(int id, Action<int> OnFocusOut) {}
#endif
#endif
}

public class WebGLInputMobile : MonoBehaviour, IPointerDownHandler
Expand All @@ -35,16 +31,11 @@ public class WebGLInputMobile : MonoBehaviour, IPointerDownHandler

private void Awake()
{
#if !(UNITY_WEBGL && !UNITY_EDITOR)
// WebGL 以外、更新メソッドは動作しないようにします
#if !(UNITY_WEBGL && !UNITY_EDITOR)
enabled = false;
#endif
#endif
}

/// <summary>
/// 押されたら、touchend イベントを登録する
/// </summary>
/// <param name="eventData"></param>

public void OnPointerDown(PointerEventData eventData)
{
if (id != -1) return;
Expand Down Expand Up @@ -73,8 +64,8 @@ static void OnFocusOut(int id)
@this.StartCoroutine(ExecFocusOut(id));
}

static IEnumerator ExecFocusOut(int id)
{
static IEnumerator ExecFocusOut(int id)
{
yield return null; // wait one frame.
var @this = instances[id];
@this.GetComponent<WebGLInput>().DeactivateInputField();
Expand All @@ -83,5 +74,4 @@ static IEnumerator ExecFocusOut(int id)
instances.Remove(id);
}
}
}

}
12 changes: 8 additions & 4 deletions Runtime/codebase/WalletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Solana.Unity.Wallet;
using Solana.Unity.Wallet.Bip39;
using UnityEngine;
using WebSocketSharp;

// ReSharper disable once CheckNamespace

Expand All @@ -36,7 +37,7 @@ public abstract class WalletBase : IWalletBase
};

protected readonly string CustomRpcUri;
protected readonly string CustomStreamingRpcUri;
protected string CustomStreamingRpcUri;

private IRpcClient _activeRpcClient;
public IRpcClient ActiveRpcClient => StartConnection();
Expand Down Expand Up @@ -235,10 +236,9 @@ public virtual async Task<RequestResult<string>> SignAndSendTransaction
/// <param name="amount">Amount of sol</param>
/// <param name="commitment"></param>
/// <returns>Amount of sol</returns>
public async Task<string> RequestAirdrop(ulong amount = SolLamports, Commitment commitment = Commitment.Finalized)
public async Task<RequestResult<string>> RequestAirdrop(ulong amount = SolLamports, Commitment commitment = Commitment.Finalized)

This comment has been minimized.

Copy link
@Woody4618

Woody4618 Feb 23, 2023

Collaborator

I think it would be good to change all commitments to confirmed

{
var result = await ActiveRpcClient.RequestAirdropAsync(Account.PublicKey, amount, commitment);
return result.Result;
return await ActiveRpcClient.RequestAirdropAsync(Account.PublicKey, amount, commitment); ;
}

/// <summary>
Expand Down Expand Up @@ -272,6 +272,10 @@ private IRpcClient StartConnection()
/// <returns></returns>
private IStreamingRpcClient StartStreamingConnection()
{
if (_activeStreamingRpcClient == null && CustomStreamingRpcUri.IsNullOrEmpty())
{
CustomStreamingRpcUri = ActiveRpcClient.NodeAddress.AbsoluteUri.Replace("https://", "wss://");
}
try
{
if (_activeStreamingRpcClient != null) return _activeStreamingRpcClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

// ReSharper disable once CheckNamespace

namespace Solana.Unity.SDK.Example
namespace Solana.Unity.SDK
{
public enum StorageMethod { Json, SimpleTxt }

[RequireComponent(typeof(MainThreadDispatcher))]
public class WalletH : MonoBehaviour
public class Web3 : MonoBehaviour
{
[SerializeField]
private RpcCluster rpcCluster = RpcCluster.DevNet;
Expand All @@ -20,8 +18,6 @@ public class WalletH : MonoBehaviour
public bool autoConnectOnStartup;
public string webSocketsRpc;

private StorageMethod _storageMethod;

public Web3AuthWalletOptions web3AuthWalletOptions;

public PhantomWalletOptions phantomWalletOptions;
Expand All @@ -30,7 +26,7 @@ public class WalletH : MonoBehaviour

public WalletBase Wallet;

public static WalletH Instance;
public static Web3 Instance;

// Convenience shortnames for accessing commonly used wallet methods
public static IRpcClient Rpc => Instance != null ? Instance.Wallet?.ActiveRpcClient : null;
Expand All @@ -49,28 +45,6 @@ public void Awake()
Destroy(gameObject);
}
}

public void Start()
{
ChangeState(_storageMethod.ToString());
if (PlayerPrefs.HasKey(StorageMethodStateKey))
{
var storageMethodString = LoadPlayerPrefs(StorageMethodStateKey);

if(storageMethodString != _storageMethod.ToString())
{
storageMethodString = _storageMethod.ToString();
ChangeState(storageMethodString);
}

if (storageMethodString == StorageMethod.Json.ToString())
StorageMethodReference = StorageMethod.Json;
else if (storageMethodString == StorageMethod.SimpleTxt.ToString())
StorageMethodReference = StorageMethod.SimpleTxt;
}
else
StorageMethodReference = StorageMethod.SimpleTxt;
}

public async Task<Account> LoginInGameWallet(string password)
{
Expand Down Expand Up @@ -119,8 +93,8 @@ public void RpcNodeDropdownSelected(int value)
rpcCluster = RpcCluster.Custom;
customRpc = value switch
{
(int) RpcCluster.MainNet => "https://rpc.ankr.com/solana",
_ => "https://rpc.ankr.com/solana_devnet"
(int) RpcCluster.MainNet => "https://red-boldest-uranium.solana-mainnet.quiknode.pro/190d71a30ba3170f66df5e49c8c88870737cd5ce/",
_ => "https://api.devnet.solana.com"
};
}

Expand All @@ -130,17 +104,6 @@ public void Logout()
Wallet = null;
}

private void ChangeState(string state)
{
SavePlayerPrefs(StorageMethodStateKey, _storageMethod.ToString());
}

public StorageMethod StorageMethodReference
{
get => _storageMethod;
private set { _storageMethod = value; ChangeState(_storageMethod.ToString()); }
}

#region Data Functions

private static void SavePlayerPrefs(string key, string value)
Expand All @@ -164,12 +127,26 @@ public static void Setup()
}
}

/// <summary>
/// Keeps WalletH for compatibility with older versions of the SDK
/// </summary>
[Obsolete("Deprecated, use Web3 instead", true)]
public static class WalletH
{
public static Web3 Instance => Web3.Instance;
public static IRpcClient Rpc => Instance != null ? Instance.Wallet?.ActiveRpcClient : null;
public static IStreamingRpcClient WsRpc => Instance != null ? Instance.Wallet?.ActiveStreamingRpcClient : null;
public static Account Account => Instance != null ? Instance.Wallet?.Account : null;
public static WalletBase Base => Instance != null ? Instance.Wallet : null;
}


/// <summary>
/// Keeps SimpleWallet for compatibility with older versions of the SDK
/// </summary>
[Obsolete("Deprecated, use WalletH instead", true)]
[Obsolete("Deprecated, use Web3 instead", true)]
public static class SimpleWallet
{
public static WalletH Instance => WalletH.Instance;
public static Web3 Instance => Web3.Instance;
}
}

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

Loading

0 comments on commit 2f00727

Please sign in to comment.