Example #1
0
    void Start()
    {
        nManager = gameObject.GetComponent <NetworkManager>();
        hud      = gameObject.GetComponent <NetworkManagerHUD>();
        errorLog.AddLogLine("");

        //errorLog.AddLogLine("" + Network.player.ipAddress);
        errorLog.AddLogLine("" + IPManager.GetIPv4());
        errorLog.AddLogLine("" + Application.persistentDataPath);
        errorLog.AddLogLine("streamingAssetsPath: " + Application.streamingAssetsPath);
    }
Example #2
0
    public void StartServer()
    {
        uServer = gameObject.AddComponent <UNetServerLite>();

        Dictionary <short, NetworkMessageDelegate> handlers = new Dictionary <short, NetworkMessageDelegate>();

        handlers.Add((short)MessageCommand.CMD_TO_SERVER, ServerMsg);
        handlers.Add((short)MessageCommand.TEST_MSG, OnReceiveClientMsg);

        uServer.StartServer(handlers);
        UNetTestSataic.isReady  = true;
        UNetTestSataic.isServer = true;

        uServer.uLog("" + IPManager.GetIPv4());
        uServer.uLog("" + IPManager.GetIPv6());
    }
Example #3
0
 // Use this for initialization
 void Start()
 {
     //serverIp.text = Network.ip
     serverIp.text = "IP: " + IPManager.GetIPv4();
 }
Example #4
0
    private void OnGUI()
    {
        if (UNetTestSataic.isReady)
        {
            if (UNetTestSataic.isServer)
            {
                if (GUI.Button(new Rect(100, 100, 150, 100), "Server test"))
                {
                    MsgTest msg = new MsgTest();
                    msg.msg = "test msg";

                    uServer.SendMessageToAllClients((short)MessageCommand.CMD_TO_CLIENT, msg, UNetBase.RELIABLE);
                }

                if (GUI.Button(new Rect(300, 100, 150, 100), "Show Server IP address."))
                {
                    //System.Diagnostics.Process.Start("E:/Projects/HenryTool/Build/Network/PC/PC.exe");
                    uServer.uLog(IPManager.GetIPv4());
                }

                if (GUI.Button(new Rect(500, 100, 150, 100), "Clear"))
                {
                    DebugLogMain.logManager.ClearLog();
                }
            }
            else
            {
                if (GUI.Button(new Rect(100, 100, 150, 100), "Client test"))
                {
                    UNetMessage msg = new UNetMessage();
                    //msg.msg = "test server msg";
                    int        length = Random.Range(1, 5);
                    MsgStrct[] al     = new MsgStrct[length];
                    for (int i = 0; i < length; i++)
                    {
                        MsgStrct us;
                        us.id   = (uint)i;
                        us.name = "N" + i.ToString();
                        //us.position = new Vector3(Random.Range(1, 50), Random.Range(1, 50), Random.Range(1, 50));
                        us.position = new Vector3(aRandomFloat, aRandomFloat, aRandomFloat);
                        al[i]       = us;
                    }

                    msg.msgs = al;

                    uClient.SendMessageToServer((short)MessageCommand.CMD_TO_SERVER, msg, UNetBase.RELIABLE);
                }

                if (GUI.Button(new Rect(300, 100, 150, 100), "Client value"))
                {
                    MsgLite msg = new MsgLite();
                    msg.value = (int)aRandomFloat;
                    uClient.SendMessageToServer((short)MessageCommand.TEST_MSG, msg, UNetBase.RELIABLE);
                }

                if (GUI.Button(new Rect(500, 100, 150, 100), "Clear"))
                {
                    DebugLogMain.logManager.ClearLog();
                }
            }
        }
    }