Skip to content

Commit

Permalink
Merge pull request #28 from alturanft/bump-unity-2022
Browse files Browse the repository at this point in the history
  • Loading branch information
HakoWave authored Aug 8, 2024
2 parents 5624074 + 235aa80 commit 7bd7622
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 50 deletions.
67 changes: 31 additions & 36 deletions Runtime/ConnectPlayerWallet.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@

using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Events;

namespace AlturaNFT
{
using UnityEngine;
using UnityEngine.Events;
using Internal;

//[AddComponentMenu(AlturaConstants.BaseComponentMenu + AlturaConstants.FeatureName_ConnectUserWallet)]
//[HelpURL(AlturaConstants.Docs_ConnectUserWallet)]
public class ConnectPlayerWallet : MonoBehaviour

{
public string MockconnectedWalletAddress = "0xfb7C2D5c65e00d05C48AfF5c02C6D4682156DF33";
public string MockconnectedNetworkID = "1";
Expand All @@ -20,88 +14,89 @@ public class ConnectPlayerWallet : MonoBehaviour
public string connectedNetworkID;

public UnityEvent afterSuccess;
private UnityAction<string,string> OnCompleteAction;
private UnityAction<string, string> OnCompleteAction;

/// <summary>
/// Initialize creates a gameobject and assings this script as a component. This must be called if it doesn't already exists in the scene on gameObject named PlayerConnect_AlturaNFT.
/// Initialize creates a gameobject and assigns this script as a component. This must be called if it doesn't already exist in the scene on a gameObject named PlayerConnect_AlturaNFT.
/// </summary>
public static ConnectPlayerWallet Initialize()
{
var _this = new GameObject("PlayerConnect_AlturaNFT").AddComponent<ConnectPlayerWallet>();
return _this;
}

/// <summary>
/// Action when player successfully connects the wallet returning connected address and connected networkID
/// Action when player successfully connects the wallet, returning connected address and connected networkID.
/// </summary>
/// <returns> Player Wallet Address String </returns>
public ConnectPlayerWallet OnComplete(UnityAction<string,string> action)
public ConnectPlayerWallet OnComplete(UnityAction<string, string> action)
{
this.OnCompleteAction = action;
return this;
}



/// <summary>
/// Use this function on a Button from inside Unity to Connect Account, If a mock wallet is entered It'll be connected only on editor level
/// Use this function on a Button from inside Unity to Connect Account. If a mock wallet is entered, it'll be connected only on editor level.
/// </summary>
public void WebSend_GetAddress()
{
#if UNITY_EDITOR
connectedWalletAddress = MockconnectedWalletAddress;
connectedNetworkID = MockconnectedNetworkID;

User.ConnectedPlayerAddress = connectedWalletAddress;
User.ConnectedPlayerNetworkID = connectedNetworkID;
Debug.Log("Editor Mock Wallet Connected , Address: " + User.ConnectedPlayerAddress + " at Network ID:" + User.ConnectedPlayerNetworkID +" | Access it via User.ConnectedPlayerAddress");
Debug.Log("Editor Mock Wallet Connected, Address: " + User.ConnectedPlayerAddress + " at Network ID:" + User.ConnectedPlayerNetworkID + " | Access it via User.ConnectedPlayerAddress");
GetAddressSuccess();
#endif
}

void Awake()
{

#if UNITY_EDITOR
User.ConnectedPlayerAddress = connectedWalletAddress;
User.ConnectedPlayerNetworkID = connectedNetworkID;
#endif

this.gameObject.name = "PlayerConnect_AlturaNFT";
}

/// <summary>
/// Use this to hook up other wallet connect features to AlturaNFT wallet connect to access User.connectedplayeraddress
/// Use this to hook up other wallet connect features to AlturaNFT wallet connect to access User.connectedplayeraddress.
/// </summary>
/// <param name="walletaddress"></param>
public void ConnectThisToAlturaNFTWalletConnect(string connectedWalletAddress)
{
WebHook_GetAddress(connectedWalletAddress);
}

//called from index - For WebGL
// Called from index - For WebGL
public void WebHook_GetNetworkID(string networkID)
{
User.ConnectedPlayerNetworkID = networkID;
connectedNetworkID = networkID;

}
//called from index - For WebGL
public void WebHook_GetAddress(string recievedaddress)

// Called from index - For WebGL
public void WebHook_GetAddress(string receivedAddress)
{
connectedWalletAddress = recievedaddress;
connectedWalletAddress = receivedAddress;
User.ConnectedPlayerAddress = connectedWalletAddress;
GetAddressSuccess();
}

void GetAddressSuccess()
{
if(OnCompleteAction!=null)
OnCompleteAction.Invoke(connectedWalletAddress,User.ConnectedPlayerNetworkID );

if(afterSuccess!=null)
afterSuccess.Invoke();
OnCompleteAction?.Invoke(connectedWalletAddress, User.ConnectedPlayerNetworkID);
afterSuccess?.Invoke();
}


#if UNITY_WEBGL
[DllImport("__Internal")]
public static extern string SendCallTo_GetAddress();
#else
[DllImport("AlturaNFTConnectUser.jslib")]
public static extern string SendCallTo_GetAddress();
#endif
}
}
}
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "com.alturaweb3.sdk",
"version": "1.0.6",
"version": "1.0.7",
"displayName": "Altura Web3",
"description": "This Web3 Package connects to the Altura APIs to help you authenticate and communicate with the Blockchain from Unity",
"dependencies": {
"com.unity.nuget.newtonsoft-json": "3.0.2"
"com.unity.nuget.newtonsoft-json": "3.2.1"
},
"keywords": [
"web3",
"api",
"nft"
"web3",
"api",
"nft"
],
"author": {
"name": "AlturaNFT",
"email": "team@alturanft.com",
"url": "https://www.alturanft.com"
"name": "AlturaNFT",
"email": "team@alturanft.com",
"url": "https://www.alturanft.com"
},
"samples": [
{
"displayName":"AlturaDemo",
"description": "Altura API Data",
"path": "Altura-Sample~/AlturaDemo"
}
{
"displayName": "AlturaDemo",
"description": "Altura API Data",
"path": "Altura-Sample~/AlturaDemo"
}
],
"type": "tool",
"unity": "2019.4",
"unity": "2022.3",
"hideInEditor": false,
"license": "See LICENSE.md file"
}

0 comments on commit 7bd7622

Please sign in to comment.