|
|
- 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.Connect(serverAddress, port);
- }
-
- public void Stop()
- {
- client.Disconnect();
- }
-
- public void UpdatePlayerDetails(string DisplayName, Color PlayerColor)
- {
- this.DisplayName = DisplayName;
- this.PlayerColor = PlayerColor;
- }
-
- }
-
- }
|