using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;

public class NetworkClientUI : MonoBehaviour {

    // Use this for initialization
    static NetworkClient client;

    static string id;

	void Start () {
        client = new NetworkClient();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public bool isConnect()
    {
        return client.isConnected;
    }

    void OnGUI()
    {

        string ipAddress = Network.player.ipAddress;
        GUI.Box(new Rect(10, Screen.height - 50, 100, 50), ipAddress);
        GUI.Label(new Rect(20, Screen.height - 35, 100, 20), "STATUS: " + client.isConnected);

        if(!client.isConnected)
        {
            if(GUI.Button(new Rect(20,20,1000,150),"CONNECT "))
            {
                Connect();
            }
        }
    }

    private void Connect()
    {
       client.Connect("192.168.43.115", 25000);
        StringMessage msg = new StringMessage();
        msg.value = "";
        client.Send(888, msg);
        id = "" + UnityEngine.Random.Range(0, 100).GetHashCode();
    }

    

    public static void SendJoystickInfo(float hDelta,float vDelta)
    {
        if(client.isConnected)
        {

            StringMessage msg = new StringMessage();
            msg.value = id+"|"+ hDelta + "|" + vDelta;
            client.Send(888, msg);
        }
    }
}
