private void Start()
    {
        keywords.Add("rechts", () =>
        {
            Debug.Log("Voice: rechts");
            voiceMovement  = true;
            voiceDirection = VoiceDirection.RIGHT;
        });
        keywords.Add("links", () => {
            Debug.Log("Voice: links");
            voiceMovement  = true;
            voiceDirection = VoiceDirection.LEFT;
        });
        keywords.Add("hoch", () => {
            Debug.Log("Voice: hoch");
            voiceMovement  = true;
            voiceDirection = VoiceDirection.FORWARD;
        });
        keywords.Add("runter", () => {
            Debug.Log("Voice: runter");
            voiceMovement  = true;
            voiceDirection = VoiceDirection.BACKWARD;
        });

        keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
        keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
        keywordRecognizer.Start();
    }
Exemplo n.º 2
0
    public void Speak(VoiceDirection direction)
    {
        if (!will_notify.isOn)
        {
            voice.Stop();
            return;
        }

        if (voice.isPlaying == false)
        {
            AudioClip clipToPlay = direction == VoiceDirection.Left ? left : right;

            voice.clip = clipToPlay;

            voice.Play();
        }
    }
    private void HandleMovement()
    {
        float h = CrossPlatformInputManager.GetAxis("Horizontal");
        float v = CrossPlatformInputManager.GetAxis("Vertical");

        if (h != 0 || v != 0 || voiceMovement)
        {
            var forwardVectorToMatch = currentModule.transform.forward;
            var camForward           = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
            var correctiveRotation   = Helper.Azimuth(forwardVectorToMatch) - Helper.Azimuth(camForward);
            Debug.Log("RotationTile: " + forwardVectorToMatch + ", Rotation Cam: " + Camera.main.transform.forward + ",Correction: " + correctiveRotation);
            ModuleConnector agentDestinationModuleConnector = null;

            switch (Convert.ToInt32(correctiveRotation))
            {
            case 0:
                Debug.Log("Rotation 0 Case");
                if (h < 0 || voiceDirection == VoiceDirection.LEFT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "left");
                }
                else if (h > 0 || voiceDirection == VoiceDirection.RIGHT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "right");
                }
                else if (v < 0 || voiceDirection == VoiceDirection.BACKWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "back");
                }
                else if (v > 0 || voiceDirection == VoiceDirection.FORWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "front");
                }
                break;

            case 90:
                Debug.Log("Rotation 90 Case");
                if (h < 0 || voiceDirection == VoiceDirection.LEFT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "back");
                }
                else if (h > 0 || voiceDirection == VoiceDirection.RIGHT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "front");
                }
                else if (v < 0 || voiceDirection == VoiceDirection.BACKWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "right");
                }
                else if (v > 0 || voiceDirection == VoiceDirection.FORWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "left");
                }
                break;

            case -90:
                Debug.Log("Rotation -90 Case");
                if (h < 0 || voiceDirection == VoiceDirection.LEFT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "front");
                }
                else if (h > 0 || voiceDirection == VoiceDirection.RIGHT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "back");
                }
                else if (v < 0 || voiceDirection == VoiceDirection.BACKWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "left");
                }
                else if (v > 0 || voiceDirection == VoiceDirection.FORWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "right");
                }
                break;

            case 180:
                Debug.Log("Rotation 180 Case");
                if (h < 0 || voiceDirection == VoiceDirection.LEFT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "right");
                }
                else if (h > 0 || voiceDirection == VoiceDirection.RIGHT)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "left");
                }
                else if (v < 0 || voiceDirection == VoiceDirection.BACKWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "front");
                }
                else if (v > 0 || voiceDirection == VoiceDirection.FORWARD)
                {
                    agentDestinationModuleConnector = Helper.FindComponentInChildWithTag <ModuleConnector>(currentModule.gameObject, "back");
                }
                break;

            default:
                Debug.Log("no matching rotation for movement: " + Convert.ToInt32(correctiveRotation));
                break;
            }
            if (agentDestinationModuleConnector != null && agentDestinationModuleConnector.getOtherSide() != null || voiceMovement)
            {
                voiceMovement  = false;
                voiceDirection = VoiceDirection.NONE;
                agent.SetTarget(Helper.FindComponentInChildWithTag <Transform>(agentDestinationModuleConnector.getOtherSide().GetComponentInParent <Module>().gameObject, "movePoint").transform);
            }
        }
    }