예제 #1
0
    public void Initialize(string id)
    {
        LNSClientParameters clientParameters = new LNSClientParameters(id, System.Environment.UserName);


        LNSConnectSettings settings = new LNSConnectSettings();

        settings.gameKey     = "com.hybriona.multiplayertest";
        settings.gameVersion = Application.version;
        if (connectToLocalServer)
        {
            settings.serverIp = "127.0.0.1";
        }
        else
        {
            settings.serverIp = "45.55.33.88";
        }
        settings.serverPort        = 10002;
        settings.serverSecurityKey = serverKey;

        //settings.serverIp = "192.168.0.100";
        connector = new LNSConnector(clientParameters, settings, this);

        if (writer == null)
        {
            writer = new LNSWriter();
        }
        writer.Reset();

        connector.onPlayerConnected      = OnPlayerConnected;
        connector.onPlayerDisconnected   = OnPlayerDisconnected;
        connector.onMasterClientUpdated += (LNSClient client) => {
            Debug.Log("Masterclient changed to " + client.id);
        };
    }
예제 #2
0
    private void Update()
    {
        if (connector != null && connector.isConnected && connector.isInActiveRoom)
        {
            if (Time.time - lastTimeDataSent > 0.05f)
            {
                lastTimeDataSent = Time.time;
                Vector3 playerPos = player.localPosition;
                writer.Reset();
                writer.Put(playerPos);
                connector.RaiseEventOnNearby(0, new Vector2(playerPos.x, playerPos.z), searchExtends, writer, DeliveryMethod.Sequenced);
            }
            //connector.RaiseEventOnAll(0, writer, DeliveryMethod.Sequenced);
        }
        if (Vector3.Distance(player.localPosition, playerTarget) > 0.5f)
        {
            player.localPosition = Vector3.MoveTowards(player.localPosition, playerTarget, Time.deltaTime * 15f);
        }

        foreach (var element in remoteClones)
        {
            if (Vector3.Distance(player.localPosition, element.Value.transform.localPosition) > searchExtends)
            {
                element.Value.transform.localPosition = new Vector3(0, -50, 0);
            }
        }
    }
예제 #3
0
 public void SendData()
 {
     writer.Reset();
     writer.Put("Message from " + id + " at " + Time.fixedTime);
     connector.RaiseEventOnAll(0, writer, DeliveryMethod.ReliableOrdered);
 }