Skip to content

Commit

Permalink
Fix bug with UnityBeacon gameobject; (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
mismirnov authored May 24, 2023
1 parent 215bb81 commit 1ee1a05
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]
### Fixed
- [Bug](https://github.com/trilitech/tezos-unity-sdk/issues/68) with UnityBeacon gameobject

## [1.4.0] - 2023-05-18
### Fixed
- [Bug](https://github.com/trilitech/tezos-unity-sdk/issues/57) with BeaconConnectorWebGl
Expand Down
27 changes: 16 additions & 11 deletions Runtime/Scripts/BeaconSDK/BeaconMessageReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,49 @@ public class BeaconMessageReceiver : MonoBehaviour

public void OnClientCreated(string result)
{
// Debug.LogWarning("From unity, OnClientCreated: " + result);
Logger.LogDebug("From unity, OnClientCreated: " + result);
ClientCreated?.Invoke(result);
}

public void OnAccountConnected(string address)
{
// result is the json permission response
// Debug.Log("From unity, OnAccountConnected: " + address);
Logger.LogDebug("From unity, OnAccountConnected: " + address);
AccountConnected?.Invoke(address);
}

public void OnAccountFailedToConnect(string result)
{
// result is the json error
// Debug.Log("From unity, OnAccountFailedToConnect: " + result);
Logger.LogDebug("From unity, OnAccountFailedToConnect: " + result);
AccountConnectionFailed?.Invoke(result);
}

public void OnAccountDisconnected(string result)
{
// Debug.Log("From unity, OnAccountDisconnect: " + result);
Logger.LogDebug("From unity, OnAccountDisconnect: " + result);
AccountDisconnected?.Invoke(result);
}

public void OnContractCallCompleted(string result)
{
// result is the json of transaction response
// Debug.Log("From unity, OnContractCallCompleted: " + result);
Logger.LogDebug("From unity, OnContractCallCompleted: " + result);
ContractCallCompleted?.Invoke(result);
}

public void OnContractCallInjected(string result)
{
// result is the json of transaction response
// Debug.Log("From unity, OnContractCallInjected: " + result);
Logger.LogDebug("From unity, OnContractCallInjected: " + result);
ContractCallInjected?.Invoke(result);
}

private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}

[Serializable]
struct ContractCallInjectionResult
{
Expand Down Expand Up @@ -109,33 +114,33 @@ public IEnumerator TrackTransaction(string transactionHash)
public void OnContractCallFailed(string result)
{
// result is error or empty
// Debug.Log("From unity, OnContractCallFailed: " + result);
Logger.LogDebug("From unity, OnContractCallFailed: " + result);
ContractCallFailed?.Invoke(result);
}

public void OnPayloadSigned(string signature)
{
// result is the json string of payload signing result
// Debug.Log("From unity, OnPayloadSigned: " + signature);
Logger.LogDebug("From unity, OnPayloadSigned: " + signature);
PayloadSigned?.Invoke(signature);
}

public void OnHandshakeReceived(string handshake)
{
// result is serialized p2p pairing request
// Debug.Log("From unity, OnHandshakeReceived: " + handshake);
Logger.LogDebug("From unity, OnHandshakeReceived: " + handshake);
HandshakeReceived?.Invoke(handshake);
}

public void OnPairingCompleted(string message)
{
// Debug.Log("From unity, OnPairingCompleted: " + message);
Logger.LogDebug("From unity, OnPairingCompleted: " + message);
PairingCompleted?.Invoke(message);
}

public void OnAccountReceived(string message)
{
// Debug.Log("From unity, OnAccountReceived: " + message);
Logger.LogDebug("From unity, OnAccountReceived: " + message);
AccountReceived?.Invoke(message);
}
}
Expand Down
7 changes: 5 additions & 2 deletions Runtime/Scripts/Tezos/Wallet/BeaconWalletProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public BeaconWalletProvider()

private void InitBeaconConnector()
{
// Create a WalletMessageReceiver Game object to receive callback messages
MessageReceiver = new GameObject("UnityBeacon").AddComponent<WalletMessageReceiver>();
// Create or get a WalletMessageReceiver Game object to receive callback messages
var unityBeacon = GameObject.Find("UnityBeacon");
MessageReceiver = unityBeacon != null
? unityBeacon.GetComponent<WalletMessageReceiver>()
: new GameObject("UnityBeacon").AddComponent<WalletMessageReceiver>();

// Assign the BeaconConnector depending on the platform.
#if !UNITY_EDITOR && UNITY_WEBGL
Expand Down

0 comments on commit 1ee1a05

Please sign in to comment.