I have been working on getting Unity working with the Lidgren networking library.
So far I have a simple Chat client where you can connect either with a web player or windows / Mac client to the server and send messages back and forth.
I will be creating a full blown tutorial with a demo level as well as releasing the server + source for the server.
Demo Will include:
Connecting to server
Logging in to server
Sending / Receiving Chat Messages
Sending / Receiving Transform
Sending / Receiving Functions
Instancing of Other Player prefabs
3RD person and First Person camera modes
Multiple Spawn Points
Planned features also will be zones, db access from the server etc for player stats, position, etc.
This Demo won’t be any GameType specific just a networking demo.
I’m wondering if $25 is a good price for this Demo.
Here is an example of the ChatClient without the gui etc.
This is just my debug version and not the finished tutorial code that is using some code from the lidgren samples etc.
using UnityEngine;
using System.Collections;
using Lidgren.Network;
using System.Threading;
public class ChatMessage
{
public string Sender;
public string Text;
}
public class ClientApp : MonoBehaviour {
public NetClient client;
public NetPeerConfiguration config;
private static bool s_keepGoing = true;
// Use this for initialization
void Start () {
// create a client with a default configuration
config = new NetPeerConfiguration("Chat");
client = new NetClient(config);
client.Start();
client.Connect("localhost", 14242);
// Wait half a second to allow server to start up if run via Visual Studio
Thread.Sleep(500);
// Send chat message
//SendMessages("test")
}
// Update is called once per frame
void Update () {
// create a buffer to read data into
NetIncomingMessage inc;
RBSChatController rbsCC = GetComponent<RBSChatController>();
// check if any messages has been received
while ((inc = client.ReadMessage()) != null)
{
switch (inc.MessageType)
{
//case NetIncomingMessageType.ServerDiscovered:
//case NetIncomingMessageType.ConnectionRejected:
//Console.WriteLine("Rejected: " + buffer.ReadString());
//break;
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.VerboseDebugMessage:
//Console.WriteLine(buffer.ReadString());
break;
case NetIncomingMessageType.StatusChanged:
string statusMessage = inc.ReadString();
NetConnectionStatus newStatus = (NetConnectionStatus)inc.ReadByte();
//rbsCC.AddChatMessage(newStatus.ToString());
//Console.WriteLine("New status: " + newStatus + " (" + statusMessage + ")");
break;
case NetIncomingMessageType.Data:
// The server sent this data!
ChatMessage cm = new ChatMessage();
inc.ReadAllFields(cm);
//Console.WriteLine(msg);
rbsCC.AddChatMessage("Received from " + cm.Sender + ": " + cm.Text);
break;
}
}
}
public void SendMessages(string input){
// Send chat message
ChatMessage cm = new ChatMessage();
cm.Sender = client.UniqueIdentifier.ToString();
cm.Text = input;
NetOutgoingMessage om = client.CreateMessage();
om.WriteAllFields(cm);
client.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 8);
}
}
[/list]