Skip to content

Commit 94da850

Browse files
authored
Merge pull request #11 from ethereum-boilerplate/features/webql-unitask
Incorporate support for Unity3D WebGL applications.
2 parents eb41c79 + 2c5d8a7 commit 94da850

File tree

788 files changed

+93482
-267
lines changed

Some content is hidden

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

788 files changed

+93482
-267
lines changed

Assembly-CSharp-Editor.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,18 @@
743743
<Project>{33C7F2A2-4AEA-64FB-8DAF-0F32154145E8}</Project>
744744
<Name>Assembly-CSharp</Name>
745745
</ProjectReference>
746+
<ProjectReference Include="UniTask.TextMeshPro.csproj">
747+
<Project>{DD9FBA50-F34C-8139-B3B5-343F4D69F34A}</Project>
748+
<Name>UniTask.TextMeshPro</Name>
749+
</ProjectReference>
746750
<ProjectReference Include="LeanCommon.csproj">
747751
<Project>{5F33B1B9-9801-72E3-D3B6-0BE732F8089A}</Project>
748752
<Name>LeanCommon</Name>
749753
</ProjectReference>
754+
<ProjectReference Include="UniTask.DOTween.csproj">
755+
<Project>{4DC51B1B-0F5A-CF2E-4B59-76AB2FC4943F}</Project>
756+
<Name>UniTask.DOTween</Name>
757+
</ProjectReference>
750758
<ProjectReference Include="LeanGUI.csproj">
751759
<Project>{1A6356EB-DA13-4D05-E0A2-B4102EFEEE87}</Project>
752760
<Name>LeanGUI</Name>
@@ -755,10 +763,22 @@
755763
<Project>{E15FCF00-000C-B7F6-0240-791AF76D32E0}</Project>
756764
<Name>endel.nativewebsocket</Name>
757765
</ProjectReference>
766+
<ProjectReference Include="UniTask.csproj">
767+
<Project>{476CBF30-A1C6-5E8D-1CA3-CF359CC96538}</Project>
768+
<Name>UniTask</Name>
769+
</ProjectReference>
770+
<ProjectReference Include="UniTask.Addressables.csproj">
771+
<Project>{F5CC6268-57BF-FB81-A497-522C5BACBDF9}</Project>
772+
<Name>UniTask.Addressables</Name>
773+
</ProjectReference>
758774
<ProjectReference Include="LeanTransition.Editor.csproj">
759775
<Project>{2E294EDD-27B9-9A60-ECFB-0CE5E06F28CE}</Project>
760776
<Name>LeanTransition.Editor</Name>
761777
</ProjectReference>
778+
<ProjectReference Include="UniTask.Linq.csproj">
779+
<Project>{8F73A630-12B8-86C2-A4F6-C50A8728D121}</Project>
780+
<Name>UniTask.Linq</Name>
781+
</ProjectReference>
762782
<ProjectReference Include="LeanTransition.csproj">
763783
<Project>{03A0A499-4A5D-BF38-396D-7221417375F7}</Project>
764784
<Name>LeanTransition</Name>

Assembly-CSharp.Player.csproj

Lines changed: 232 additions & 8 deletions
Large diffs are not rendered by default.

Assembly-CSharp.csproj

Lines changed: 229 additions & 5 deletions
Large diffs are not rendered by default.

Assets/MoralisWeb3ApiSdk/Example/Scripts/MainMenuScript.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
* SOFTWARE.
2828
*/
2929
using System.Collections.Generic;
30-
using System.Threading.Tasks;
31-
using Moralis.Platform;
32-
using Moralis.Platform.Objects;
3330
using UnityEngine;
3431
using UnityEngine.SceneManagement;
3532
using UnityEngine.UI;
@@ -38,6 +35,16 @@
3835
using Assets.Scripts;
3936
using Assets;
4037

38+
#if UNITY_WEBGL
39+
using Cysharp.Threading.Tasks;
40+
using Moralis.WebGL.Platform;
41+
using Moralis.WebGL.Platform.Objects;
42+
#else
43+
using System.Threading.Tasks;
44+
using Moralis.Platform;
45+
using Moralis.Platform.Objects;
46+
#endif
47+
4148
/// <summary>
4249
/// Example class that demonstrates a game menu that incorporates Wallet
4350
/// Connect and Moralis Authentication.
@@ -55,7 +62,7 @@ public class MainMenuScript : MonoBehaviour
5562

5663
Image menuBackground;
5764

58-
void Start()
65+
async void Start()
5966
{
6067
menuBackground = (Image)gameObject.GetComponent(typeof(Image));
6168

@@ -74,7 +81,7 @@ void Start()
7481
joystick.SetActive(true);
7582
#endif
7683

77-
MoralisInterface.Initialize(MoralisApplicationId, MoralisServerURI, hostManifestData);
84+
await MoralisInterface.Initialize(MoralisApplicationId, MoralisServerURI, hostManifestData);
7885

7986
if (MoralisInterface.IsLoggedIn())
8087
{
@@ -106,7 +113,7 @@ public async void Play()
106113
Debug.Log("User is already logged in to Moralis.");
107114

108115
// Transition to main game scene
109-
SceneManager.LoadScene(SceneMap.GAME_VIEW);
116+
//SceneManager.LoadScene(SceneMap.GAME_VIEW);
110117
}
111118
// User is not logged in, depending on build target, begin wallect connection.
112119
else
@@ -196,7 +203,8 @@ public async void Quit()
196203
/// <summary>
197204
/// Display Moralis connector login page
198205
/// </summary>
199-
private async Task LoginViaConnectionPage()
206+
#if UNITY_WEBGL
207+
private async UniTask LoginViaConnectionPage()
200208
{
201209
// Use Moralis Connect page for authentication as we work to make the Wallet
202210
// Connect experience better.
@@ -213,7 +221,25 @@ private async Task LoginViaConnectionPage()
213221
AuthenticationButtonOn();
214222
}
215223
}
224+
#else
225+
private async Task LoginViaConnectionPage()
226+
{
227+
// Use Moralis Connect page for authentication as we work to make the Wallet
228+
// Connect experience better.
229+
MoralisUser user = await MobileLogin.LogIn(MoralisServerURI, MoralisApplicationId);
216230

231+
if (user != null)
232+
{
233+
// User is not null so login was successful, show first game scene.
234+
//SceneManager.LoadScene(SceneMap.GAME_VIEW);
235+
AuthenticationButtonOff();
236+
}
237+
else
238+
{
239+
AuthenticationButtonOn();
240+
}
241+
}
242+
#endif
217243
private void AuthenticationButtonOff()
218244
{
219245
AuthenticationButton.SetActive(false);

Assets/MoralisWeb3ApiSdk/Example/Scripts/MainMenuScript.cs.bak.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/MoralisWeb3ApiSdk/Example/Scripts/MoralisSetup.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
* SOFTWARE.
2828
*/
29+
#if UNITY_WEBGL
30+
using Moralis.WebGL.Platform;
31+
using System.Collections.Generic;
32+
#else
2933
using Moralis.Platform;
34+
using System.Collections.Generic;
35+
#endif
3036
using UnityEngine;
3137

3238
public class MoralisSetup : MonoBehaviour
@@ -36,7 +42,7 @@ public class MoralisSetup : MonoBehaviour
3642
public string ApplicationName;
3743
public string Version;
3844

39-
void Start()
45+
async void Start()
4046
{
4147
HostManifestData hostManifestData = new HostManifestData()
4248
{
@@ -46,6 +52,9 @@ void Start()
4652
ShortVersion = Version
4753
};
4854

49-
MoralisInterface.Initialize(MoralisApplicationId, MoralisServerURI, hostManifestData);
55+
await MoralisInterface.Initialize(MoralisApplicationId, MoralisServerURI, hostManifestData);
56+
57+
var authData = new Dictionary<string, object> { { "id", "0x26841E928b5b89BB257CCCeC06d8d63951f2507b".ToLower() }, { "signature", "0x7589245bd712ccdcaa9f946c1052b169569fecaf5beed44d916acc0361be16b63f9ad8fb8526c276a1869a314ca7f9a0becee334aadca2e62ccd656cd1379c041b" }, { "data", "Moralis Authentication" } };
58+
await MoralisInterface.GetClient().LogInAsync(authData);
5059
}
5160
}

Assets/MoralisWeb3ApiSdk/Example/Scripts/PlayerController.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,21 @@ private void Start()
6969
#endif
7070
}
7171

72-
private void Update()
72+
private async void Update()
7373
{
7474
// Update character address if it has not been set
75-
if (!isAuthenticated && MoralisInterface.GetUser() != null)
75+
if (!isAuthenticated)
7676
{
77-
string addr = MoralisInterface.GetUser().authData["moralisEth"]["id"].ToString();
77+
var user = await MoralisInterface.GetUserAsync();
7878

79-
addressText.text = string.Format("{0}...{1}", addr.Substring(0, 6), addr.Substring(addr.Length - 3, 3));
79+
if (user != null)
80+
{
81+
string addr = user.authData["moralisEth"]["id"].ToString();
82+
83+
addressText.text = string.Format("{0}...{1}", addr.Substring(0, 6), addr.Substring(addr.Length - 3, 3));
8084

81-
isAuthenticated = true;
85+
isAuthenticated = true;
86+
}
8287
}
8388

8489
Move();
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Module: ResourceData.cs
3+
* Descriptiontion: Define a set of objects that represent a known response from
4+
* a Moralis Cloud function used to load remote resources and so
5+
* by-pass CORS issues when loading resources from remote servers.
6+
* NOTE: This was designed spoecifically to retrieve image files for the
7+
* sample TokenListController. Other resource may require modification.
8+
* Author: Moralis Web3 Technology AB, 559307-5988 - David B. Goodrich
9+
*
10+
* Sample Moralis Cloud Function used to retrieve remote resources
11+
* =================================================================
12+
Moralis.Cloud.define("loadResource", async (request) => {
13+
const logger = Moralis.Cloud.getLogger();
14+
15+
return await Moralis.Cloud.httpRequest({
16+
url: request.params.url
17+
}).then(function(httpResponse) {
18+
let resp = {status: httpResponse.status, headers: httpResponse.headers, data: JSON.stringify(httpResponse.buffer)};
19+
return resp;
20+
},function(httpResponse) {
21+
// Error occurred
22+
logger.error('Request failed with response code ' + httpResponse.status);
23+
return httpResponse;
24+
});
25+
}, {
26+
fields : ["url"]
27+
});
28+
*
29+
*
30+
* MIT License
31+
*
32+
* Copyright (c) 2021 Moralis Web3 Technology AB, 559307-5988
33+
*
34+
* Permission is hereby granted, free of charge, to any person obtaining a copy
35+
* of this software and associated documentation files (the "Software"), to deal
36+
* in the Software without restriction, including without limitation the rights
37+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38+
* copies of the Software, and to permit persons to whom the Software is
39+
* furnished to do so, subject to the following conditions:
40+
*
41+
* The above copyright notice and this permission notice shall be included in all
42+
* copies or substantial portions of the Software.
43+
*
44+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50+
* SOFTWARE.
51+
*/
52+
53+
using System.Collections.Generic;
54+
using Newtonsoft.Json;
55+
56+
/// <summary>
57+
/// Define a set of objects that represent a known response from
58+
/// a Moralis Cloud function used to load remote resources and so
59+
/// by-pass CORS issues when loading resources from remote servers.
60+
/// NOTE: This was designed spoecifically to retrieve image files for the
61+
/// sample TokenListController. Other resource may require modification.
62+
/// </summary>
63+
namespace Assets.MoralisWeb3ApiSdk.Example.Scripts
64+
{
65+
/// <summary>
66+
/// Raw data element of the resource loaded.
67+
/// </summary>
68+
public class ResourceData
69+
{
70+
public string type;
71+
public byte[] data;
72+
}
73+
74+
/// <summary>
75+
/// Response body from the Cloud Function.
76+
/// </summary>
77+
public class ResourceResponse
78+
{
79+
public int status;
80+
public Dictionary<string, string> headers;
81+
public string data;
82+
83+
public ResourceData resourceData
84+
{
85+
get
86+
{
87+
return JsonConvert.DeserializeObject<ResourceData>(data);
88+
}
89+
}
90+
}
91+
92+
/// <summary>
93+
/// Result wrapper added by the server after the fact.
94+
/// </summary>
95+
public class ResourceRequestResult
96+
{
97+
public ResourceResponse result;
98+
}
99+
}

Assets/MoralisWeb3ApiSdk/Example/Scripts/ResourceRequestResult.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.

0 commit comments

Comments
 (0)