Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        if (this.avatar == null)
        {
            Debug.LogError("The 'avatar' object has not been specified");
            Debug.Break();
        }

        if (this.body == null)
        {
            Debug.LogError("The 'body' object has not been specified");
            Debug.Break();
        }

        this.gazescript    = this.body.GetComponent <EyeHeadGazeController>();
        this.ttsController = this.body.GetComponent <MaryTTSController>();
        this.facialExpressionsController = this.body.GetComponent <FacialExpressionsController>();
        this.locomotionController        = this.avatar.GetComponent <LocomotionController>();


        // Look at the target
        if (this.gazeTarget != null)
        {
            this.gazescript.LookAtObject(this.gazeTarget.name);
        }
    }
Esempio n. 2
0
    void Awake()
    {
        // Execute only if we are running on WebGL
        if (Application.platform != RuntimePlatform.WebGLPlayer)
        {
            return;
        }

        Assert.IsNotNull(this.avatarMesh);
        Assert.IsNotNull(this.mainCamera);

        //
        // Get the reference to the object's components.
        _animationController = this.avatarMesh.GetComponentInParent <AnimationController>();
        Assert.IsNotNull(_animationController);
        _maryTTSController = this.avatarMesh.GetComponent <MaryTTSController> ();
        Assert.IsNotNull(_maryTTSController);
        _facialExpressionController = this.avatarMesh.GetComponent <FacialExpressionsController> ();
        Assert.IsNotNull(_facialExpressionController);
        _eyeGazeController = this.avatarMesh.GetComponent <EyeHeadGazeController> ();
        Assert.IsNotNull(_eyeGazeController);

        //New?
        _cameraController = this.mainCamera.GetComponent <CameraCinemaControl> ();
        Assert.IsNotNull(_cameraController);

        //
        // Set the callbacks
        Debug.Log("Setting anim callbacks");
        set_anim_callbacks(napi_PlayAnimationClip, napi_IsAnimationClipPlaying, napi_GetPlayingAnimationClip,
                           napi_ListAvailableAnimationClips, napi_EnableAmbientAnimation, napi_DisableAmbientAnimation);

        Debug.Log("Setting MaryTTS callbacks");
        set_marytts_callbacks(napi_MaryTTSspeak, napi_IsMaryTTSspeaking);

        Debug.Log("Setting Facial Expression callbacks");
        set_facial_expression_callbacks(napi_SetCurrentFacialExpression, napi_GetCurrentFacialExpression,
                                        napi_ClearFacialExpression, napi_ListFacialExpressions,
                                        napi_SetExpressionTransitionTime, napi_GetExpressionTransitionTime);

        Debug.Log("Setting Eye Gaze callbacks");
        set_eyegaze_callbacks(napi_LookAtPoint, napi_LookAtObject);

        Debug.Log("Setting Camera Movement callbacks");
        set_camera_callbacks(napi_GoToNextShot, napi_GoToPreviousShot,
                             napi_GetCurrentShot, napi_SetCurrentShot,
                             napi_SetShotFineTunePercentage, napi_GetShotFineTunePercentage,
                             napi_ListCameraShots);

        Debug.Log("Callbacks all set");
    }
Esempio n. 3
0
    // Start is called before the first frame update
    void Start()
    {
        //
        // Lookup for the components to speak and animate the character

        this._ttsController = gameObject.GetComponentInChildren <MaryTTSController>();
        Debug.Assert(this._ttsController != null, "Couldn't find the TTSController (text to speech) in the avatar.");

        this._animController = gameObject.GetComponent <AnimationController>();
        Debug.Assert(this._animController != null, "Couldn't find the AnimationController in the avatar.");

        this._facialExprController = gameObject.GetComponentInChildren <FacialExpressionsController>();
        Debug.Assert(this._facialExprController != null, "Couldn't find the FacialAnimationController in the avatar.");

        this._eyeGazeController = gameObject.GetComponentInChildren <EyeHeadGazeController>();
        Debug.Assert(this._eyeGazeController != null, "Couldn't find the EyeHeadGazeController in the avatar.");

        //
        // Now initialize the WebSocket

        // It is important to have the trailing slash!
        String serverURL = "ws://" + this.ServerAddress + ":" + this.ServerPort + "/";

        Debug.Log("WebSocket Server URL is '" + serverURL + "'.");

        _webSock = new WebSocket(serverURL);

        _webSock.OnMessage += (bytes) =>
        {
            // Reading a plain text message
            var message = System.Text.Encoding.UTF8.GetString(bytes);
            // Debug.Log("WebSocket Got message: " + message);
            _HandleMessage(message);
        };

        _webSock.OnError += (msg) =>
        {
            // Reading a plain text message
            //var message = System.Text.Encoding.UTF8.GetString(bytes);
            Debug.Log("WebSocket Error: " + msg);
        };

        _webSock.OnClose += (msg) =>
        {
            Debug.Log("WebSocket Connection closed: " + msg);
        };


        // BEWARE!!! In UnityEditor `Connect` is blocking!
        // It will unlock only when the socket closes.
        //await _webSock.Connect();

        // Can only use the await form. Explicit use of Task hangs the system

        /*Task t = _webSock.Connect();
         * t.Wait();
         * Debug.Log(t.Status);
         * if (t.IsFaulted)
         * {
         *  Debug.Log(t.Exception);
         * }
         * Debug.Log("Connected.");
         */

        Debug.Log("WebSocket State: " + _webSock.State);


        // Instantiate the listener
        this._ttsListener = new MaryTTSCallback(this._webSock);
        this._ttsController.AddListener(this._ttsListener);
    }
Esempio n. 4
0
 void Awake()
 {
     this.tts_controller = GetComponent <MaryTTSController>();
 }