onflow / UnityFlowSDK

Flow SDK for Unity - build Unity games on the Flow blockchain
https://developers.flow.com/tools/unity-sdk
MIT License
13 stars 4 forks source link

Unity iOS or WebGL support #1

Open yosun opened 1 year ago

yosun commented 1 year ago

Issue to be solved

I notice that the officially supported platforms do not include Unity iOS. This is quite a shame because Unity is single source cross-platform - what works on Android easily works on iOS (on the Unity side)...

Suggest A Solution

There seems to be existing Flow iOS SDKs, so simply wrap it for Unity please - thanks!

What are you currently working on that this is blocking?

Flow Hackathon Mobile

botaohu commented 1 year ago

Currently, SDK has even already supported MacOS. Is there any technical block for iOS?

yosun commented 1 year ago

It seems @Executus just pushed a release a few hours ago, so perhaps he can explain the blocks?

Executus commented 1 year ago

Hi guys, I apologise for the delays in iOS support, there were reasons. I know this doesn't help you for now but iOS support is coming in v2.0, which isn't too far off. WebGL will come a bit later. Yesterday's release (v1.0.2) was to hotfix an issue with the latest version of the emulator.

Executus commented 1 year ago

Actually I think I can push a branch up with iOS support today, to unblock you for the Hackathon. Keep using Windows\MacOS\Android for now and I'll see if I can get that branch up today.

Executus commented 1 year ago

@yosun @botaohu I've tested iOS using one of the samples and it actually works without any changes required to the SDK. You'll just need to set up your provisioning in Unity for your project (Player Settings > Identification). Set the Emulator Endpoint in Flow Control Manager to the correct address that is running the emulator (just like you would for android). Note that we have not done internal testing for iOS, so there may be bugs.

yosun commented 1 year ago

@Executus actually, i am confused how to set the emulator endpoint up since the client will be a device that is not localhost or 127.0.0.1:8888/v1 or the temp IP of the computer running the emulator ... Is there a global endpoint to set the iOS app to? will this only work if we have to hardcode the emulator IP address each time?

Executus commented 1 year ago

@yosun The Emulator Endpoint is used by the Unity app to know which address to connect to the emulator. For Windows and MacOS, this can be left as localhost or 127.0.0.1 because you can run the emulator on the same machine as the Unity app. But for mobile, you will need to run the emulator on a different machine as the emulator doesn't run on mobile devices. You will need to enter the IP address of the machine running your emulator on your network (eg http://192.168.1.1:8888/v1). The emulator is a dev tool, used only by you in a sandbox environment to develop your contracts. It should never be publicly exposed - there is no "global" emulator. If you want to go global then you would use testnet and cease to use the emulator.

Executus commented 1 year ago

Here is an example of initializing the Flow SDK to connect to an emulator using the Emulator Endpoint:

FlowConfig flowConfig = new FlowConfig();
flowConfig.NetworkUrl = FlowControl.Data.EmulatorSettings.emulatorEndpoint;
flowConfig.Protocol = FlowConfig.NetworkProtocol.HTTP;
FlowSDK.Init(flowConfig);

Here is an example of initializing the Flow SDK to connect to testnet (ignores the Emulator Endpoint):

FlowConfig flowConfig = new FlowConfig();
flowConfig.NetworkUrl = "https://rest-testnet.onflow.org/v1";
flowConfig.Protocol = FlowConfig.NetworkProtocol.HTTP;
FlowSDK.Init(flowConfig);
yosun commented 1 year ago

Yes - figured this out - the stack trace was not going deep enough so I had assumed it was just the endpoint.. it turns out that I was just using your emulator sample data for NFTs, not sure how to actually create a NFT using your Unity sdk

https://github.com/onflow/UnityFlowSDK/issues/4