async private void RunTestSubscribePublish()
    {
        await ubiiClient.WaitForConnection();

        string topic   = "/" + ubiiClient.GetID() + "/unity3D_client/test/subcribe_publish_simple";
        bool   success = false;

        Action <TopicDataRecord> callback = (TopicDataRecord record) =>
        {
            success = record.Bool;
        };

        await ubiiClient.Subscribe(topic, callback);

        ubiiClient.Publish(new Ubii.TopicData.TopicData {
            TopicDataRecord = new Ubii.TopicData.TopicDataRecord {
                Topic = topic, Bool = true
            }
        });

        await Task.Delay(1000).ContinueWith(async(Task t) =>
        {
            await ubiiClient.Unsubscribe(topic, callback);

            if (success)
            {
                Debug.Log("RunTestSubscribePublish SUCCESS!");
            }
            else
            {
                Debug.LogError("RunTestSubscribePublish FAILURE!");
            }
        });
    }
    // Update is called once per frame
    void Update()
    {
        targetObject.transform.position = testPosition;

        float tNow = Time.time;

        if (testRunning && tNow > tLastPublish + 1)
        {
            Vector3 randomPosition = Random.insideUnitSphere;
            ubiiClient.Publish(
                new Ubii.TopicData.TopicData
            {
                TopicDataRecord = new Ubii.TopicData.TopicDataRecord
                {
                    Topic   = topicTestPublishSubscribe,
                    Vector3 = new Ubii.DataStructure.Vector3 {
                        X = randomPosition.x, Y = randomPosition.y, Z = randomPosition.z
                    }
                }
            });
            tLastPublish = tNow;
        }
    }
Example #3
0
    //private async void reconnect()
    //{
    //    if (connected) CancelInvoke();
    //    await client.InitializeClient();
    //    Debug.Log("connected");
    //    connected = true;
    //    CancelInvoke();
    //}


    public void send_texture(Texture2D texture, string filename)
    {
        if (!connected)
        {
            return;
        }
        //send filename
        client.Publish(UbiiParser.UnityToProto("image name", filename));
        //send size
        client.Publish(UbiiParser.UnityToProto("image size", new Vector2(texture.width, texture.height)));
        //send format
        int index = 0;

        for (; index < texture_formats.Length; index++)
        {
            if (texture_formats[index] == texture.format)
            {
                break;
            }
        }
        ;
        client.Publish(UbiiParser.UnityToProto("image format", index + 1));   // added +1 to not send empty data
        client.Publish(UbiiParser.UnityToProto("image", Convert.ToBase64String(texture.GetRawTextureData())));

        Debug.Log("Sent texture");
    }