You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
1.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace Networking.Client
{
[CreateAssetMenu(menuName = "Major Project/Networking/ClientObject", order = 150)]
public class ClientObject : ScriptableObject
{
#region Inspector Fields
[Header("Connection Settings")]
[SerializeField]
[Tooltip("Server Address to Connect to")]
private string ServerIP;
[SerializeField]
[Tooltip("Port to connect on")]
private int Port;
[Header("Player Settings")]
[SerializeField]
[Tooltip("Player Name")]
private string DisplayName;
[SerializeField]
[Tooltip("Player Color")]
private Color PlayerColor;
#endregion Inspector Fields
#region ReadOnly Variables
public NetworkClient client { get; private set; }
public bool isConnected { get { return client != null && client.isConnected; } }
#endregion ReadOnly Variables
public void Connect(string serverAddress,int port)
{
Debug.Log("Connecting to server: " + serverAddress + ", " + port);
this.ServerIP = serverAddress;
this.Port = port;
client = new NetworkClient();
client.Configure(TransportConfigure.CreateConfigure(), 1);
client.Connect(serverAddress, port);
}
public void Stop()
{
client.Disconnect();
}
public void UpdatePlayerDetails(string DisplayName, Color PlayerColor)
{
this.DisplayName = DisplayName;
this.PlayerColor = PlayerColor;
}
}
}