com.xmobitea.changx.protonnet
v1.0.0
Published
XmobiTea Unity package
Downloads
4
Maintainers
Readme
ProtonNet Server
ProtonNet UnityClientSdk
Supports Unity platforms:
Android
iOS
WebGL
Standalone
- and more...
I. Introduction
ProtonNet Unity Client Sdk
is the ProtonNet Client support for Unity project.
II. How to import
- import via
Unity Package
file Release - import via
Unity Package Manager
- Open
Package Manager
byWindow/PackageManager
- Press
+
->Add package from git URL...
- Type
https://github.com/XmobiTea-Family/ProtonNet.Solution.UnityClientSdk
then pressAdd
- Open
III. How to use
Create a MonoBehaviour Script
Create a new MonoBehaviour
script in Unity with the following content:
using UnityEngine;
using XmobiTea.Data;
using XmobiTea.Logging;
using XmobiTea.Logging.Unity;
using XmobiTea.ProtonNet.Client;
using XmobiTea.ProtonNet.Client.Socket;
using XmobiTea.ProtonNet.Networking;
using XmobiTea.ProtonNet.Networking.Extensions;
public class ProtonNetworkBehaviour : MonoBehaviour {
IClientPeerFactory clientPeerFactory;
ISocketClientPeer socketClientPeer;
void Start()
{
LogManager.SetLoggerFactory(UnityLoggerFactory.Instance);
clientPeerFactory = UnityClientPeerFactory.NewBuilder()
.SetAutoCallService(true)
.Build();
socketClientPeer = clientPeerFactory.NewSocketClientPeer("http://127.0.0.1:32202", XmobiTea.ProtonNet.Client.Socket.Types.TransportProtocol.Tcp);
socketClientPeer.Connect(true, (connectionId, serverSessionId) =>
{
Debug.Log("OnConnected");
Debug.LogError(connectionId + " " + serverSessionId);
}, (reason, message) =>
{
Debug.Log("OnDisconnected");
Debug.LogError(reason + " " + message);
});
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
socketClientPeer.Send(new OperationRequest()
.SetOperationCode("login")
.SetParameters(GNHashtable.NewBuilder()
.Add("username", "admin")
.Add("password", "123456")
.Build()), response =>
{
Debug.Log("Received from Server: " + response.ReturnCode + ", DebugMessage: " + response.DebugMessage);
}, new SendParameters()
{
Encrypted = false,
});
}
}
}
- Attach this script to a
GameObject
in Unity and run the project. When you see theOnConnected
log, pressSpace
to send the login request.
IV. Support
If you encounter issues or have any questions, feel free to share them on ProtonNet Discussions to get help from the community, or contact directly via email at [email protected].
Enjoy your development with ProtonNet!