Exemple #1
0
    void OnMessage(MessageResponse resp, string customData)
    {
        if (resp != null && (resp.intents.Length > 0 || resp.entities.Length > 0))
        {
            string intent = resp.intents[0].intent;
            Debug.Log("Intent: " + intent);
            string currentMat   = null;
            string currentScale = null;
            if (intent == "create")
            {
                bool createdObject = false;
                foreach (EntityResponse entity in resp.entities)
                {
                    Debug.Log("entityType: " + entity.entity + " , value: " + entity.value);
                    if (entity.entity == "material")
                    {
                        currentMat = entity.value;
                    }
                    if (entity.entity == "scale")
                    {
                        currentScale = entity.value;
                    }
                    else if (entity.entity == "object")
                    {
                        gameManager.CreateObject(entity.value, currentMat, currentScale);
                        createdObject = true;
                        currentMat    = null;
                        currentScale  = null;
                    }
                }

                if (!createdObject)
                {
                    gameManager.PlayError(sorryClip);
                }
            }
            else if (intent == "destroy")
            {
                gameManager.DestroyAtRight();
                gameManager.DestroyAtLeft();
            }
            else if (intent == "help")
            {
                if (helpClips.Count > 0)
                {
                    gameManager.PlayClip(helpClips[Random.Range(0, helpClips.Count)]);
                }
            }
            else if (intent == "screenshot")
            {
                //Assumes is attached to the [CameraRig]
                Camera camera = transform.parent.FindChild("Camera (eye)").GetComponent <Camera>();
                DemoScreen.takeScreenshot(camera);
            }
        }
        else
        {
            Debug.Log("Failed to invoke OnMessage();");
        }
    }
    void OnMessage(object resp, Dictionary <string, object> customData)
    {
        //  Convert resp to fsdata

        fsData   fsdata = null;
        fsResult r      = _serializer.TrySerialize(resp.GetType(), resp, out fsdata);

        if (!r.Succeeded)
        {
            throw new WatsonException(r.FormattedMessages);
        }

        //  Convert fsdata to MessageResponse
        MessageResponse messageResponse = new MessageResponse();
        object          obj             = messageResponse;

        r = _serializer.TryDeserialize(fsdata, obj.GetType(), ref obj);
        if (!r.Succeeded)
        {
            throw new WatsonException(r.FormattedMessages);
        }

        if (resp != null && (messageResponse.intents.Length > 0 || messageResponse.entities.Length > 0))
        {
            string intent = messageResponse.intents[0].intent;
            Debug.Log("Intent: " + intent);
            string currentMat   = null;
            string currentScale = null;
            if (intent == "create")
            {
                bool createdObject = false;
                foreach (RuntimeEntity entity in messageResponse.entities)
                {
                    Debug.Log("entityType: " + entity.entity + " , value: " + entity.value);
                    if (entity.entity == "material")
                    {
                        currentMat = entity.value;
                    }
                    if (entity.entity == "scale")
                    {
                        currentScale = entity.value;
                    }
                    else if (entity.entity == "object")
                    {
                        gameManager.CreateObject(entity.value, currentMat, currentScale);
                        createdObject = true;
                        currentMat    = null;
                        currentScale  = null;
                    }
                }

                if (!createdObject)
                {
                    gameManager.PlayError(sorryClip);
                }
            }
            else if (intent == "destroy")
            {
                gameManager.DestroyAtRight();
                gameManager.DestroyAtLeft();
            }
            else if (intent == "help")
            {
                if (helpClips.Count > 0)
                {
                    gameManager.PlayClip(helpClips[Random.Range(0, helpClips.Count)]);
                }
            }
            else if (intent == "screenshot")
            {
                //Assumes is attached to the [CameraRig]
                Camera camera = transform.parent.Find("Camera (eye)").GetComponent <Camera>();
                DemoScreen.takeScreenshot(camera);
            }
        }
        else
        {
            Debug.Log("Failed to invoke OnMessage();");
        }
    }