Пример #1
0
        public CHMessage FromImageCue(CHImageCue cue)
        {
            Cue parsedCue;

            parsedCue.mediaDomain = MediaDomain.image;
            parsedCue.cueNumber   = cue.cueNumber;
            parsedCue.cueAction   = CueAction.play;
            parsedCue.targetTags  = new List <string>();
            parsedCue.targetTags.Add("all");

            return(cueToCHMessage(parsedCue));
        }
Пример #2
0
        /*
         *   Cohort handlers
         */

        void OnCohortMessageReceived(CHMessage msg)
        {
            if (msg.id > 0)
            {
                PlayerPrefs.SetInt("lastReceivedCohortMessageId", msg.id);
            }

            Debug.Log("current grouping: " + grouping);
            if (!msg.targetTags.Contains(grouping) && !msg.targetTags.Contains("all"))
            {
                Debug.Log("cohort message is for another grouping (not " + grouping + "), not processing it");
                return;
            }

            // DO STUFF
            switch (msg.mediaDomain)
            {
            case MediaDomain.sound:
                CHSoundCue soundCue = soundCues.Find((CHSoundCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001);
                if (soundCue != null)
                {
                    audioPlayer.clip = soundCue.audioClip;
                }

                // looped cues
                //if(Math.Abs(msg.cueNumber - 4) < Mathf.Epsilon) {
                //  if(msg.cueAction == CueAction.play) {
                //    audioPlayer.loop = true;
                //  } else {
                //    audioPlayer.loop = false;
                //  }
                //}

                switch (msg.cueAction)
                {
                case CueAction.play:
                    audioPlayer.Play();
                    break;

                case CueAction.pause:
                    audioPlayer.Pause();
                    break;

                case CueAction.restart:
                    audioPlayer.Pause();
                    audioPlayer.time = 0;
                    audioPlayer.Play();
                    break;

                case CueAction.stop:
                    audioPlayer.Stop();
                    audioPlayer.clip = null;
                    break;
                }
                break;

            case MediaDomain.video:
                CHVideoCue videoCue = videoCues.Find((CHVideoCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001);
                if (videoCue != null)
                {
                    if (videoPlayer.clip != videoCue.videoClip)
                    {
                        videoPlayer.Pause();
                        videoPlayer.clip = videoCue.videoClip;
                    }

                    switch (msg.cueAction)
                    {
                    case CueAction.play:
                        videoPlayer.Play();
                        break;

                    case CueAction.pause:
                        videoPlayer.Pause();
                        break;

                    case CueAction.restart:
                        videoPlayer.Pause();
                        videoPlayer.time = 0;
                        videoPlayer.Play();
                        break;

                    case CueAction.stop:
                        videoPlayer.Stop();
                        videoPlayer.clip = nullVideo;
                        videoPlayer.Play();
                        break;

                    default:
                        Debug.Log("Error: cue action not implemented");
                        break;
                    }
                    break;
                }
                else
                {
                    Debug.Log("Error: cue number not valid");
                }
                break;

            case MediaDomain.image:
                CHImageCue imageCue = imageCues.Find((CHImageCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001);
                if (imageCue != null)
                {
                    switch (msg.cueAction)
                    {
                    case CueAction.play:
                        Debug.Log("got image cue");
                        imageCueSurface.sprite = imageCue.image;
                        imageCueSurface.gameObject.SetActive(true);
                        break;

                    case CueAction.stop:
                        imageCueSurface.gameObject.SetActive(false);
                        imageCueSurface.sprite = null;
                        break;

                    default:
                        Debug.Log("Error: cue action not implemented");
                        break;
                    }
                }
                else
                {
                    Debug.Log("Error: cue number not valid");
                }
                break;

            case MediaDomain.text:
                CHTextCue textCue = textCues.Find((CHTextCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001);
                if (textCue == null && msg.cueContent == null)
                {
                    return;
                }
                string textOfCue;
                if (msg.cueContent != null)
                {
                    textOfCue = msg.cueContent;
                }
                else if (textCue.text != null)
                {
                    textOfCue = textCue.text;
                }
                else
                {
                    Debug.Log("Error: Failed to find text for text cue in onboard text cues or in remote cue");
                    return;
                }

                switch (msg.cueAction)
                {
                case CueAction.play:
                    UnityEngine.Handheld.Vibrate();
                    onTextCue(CueAction.play, textOfCue);
                    break;

                case CueAction.pause:
                    Debug.Log("action 'pause' is not defined for text cues");
                    break;

                case CueAction.restart:
                    Debug.Log("action 'restart' is not defined for text cues");
                    break;

                case CueAction.stop:
                    onTextCue(CueAction.stop, textOfCue);
                    break;
                }
                break;

            //case MediaDomain.light:
            //  switch(msg.cueAction) {
            //    case CueAction.play:
            //      flashlightController.TurnOn();
            //      break;
            //    case CueAction.stop:
            //      flashlightController.TurnOff();
            //      break;
            //    case CueAction.pause:
            //      flashlightController.TurnOff();
            //      break;
            //    case CueAction.restart:
            //      Debug.Log("action 'restart' is not defined for light cues");
            //      break;
            //  }
            //  break;

            case MediaDomain.haptic:
                UnityEngine.Handheld.Vibrate();
                break;
            }
        }