Ejemplo n.º 1
0
        protected virtual void TouchEvent()
        {
            if (_CanTouch && TouchManager.Instance.IsTouchValid(0))
            {
                TouchPhaseEnum touchPhase = TouchManager.Instance.GetTouchPhase(0);
                if (touchPhase == TouchPhaseEnum.BEGAN)
                {
                    TouchManager.Instance.GetTouchPos(0, out _StartTouchpos);
                    RaycastHit hit;
                    C_DebugHelper.Log("TouchManager begin..");

                    Ray ray = GetCurrentCamera().ScreenPointToRay(_StartTouchpos);
                    if (Physics.Raycast(ray, out hit, _TouchDistance))
                    {
                        C_DebugHelper.Log("book is touch" + hit.collider.name);

                        if (hit.collider.gameObject == gameObject)
                        {
                            C_DebugHelper.Log("book is touch in:" + hit.collider.name);
                            //播放动画
                            _IsTouch = true;
                            TouchHandle();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
    public byte[] GetClipData()
    {
        if (audio.clip == null)
        {
            C_DebugHelper.Log("GetClipData audio.clip is null");
            return(null);
        }

        float[] samples = new float[audio.clip.samples];

        audio.clip.GetData(samples, 0);


        byte[] outData = new byte[samples.Length * 2];

        int rescaleFactor = 32767;

        for (int i = 0; i < samples.Length; i++)
        {
            short temshort = (short)(samples[i] * rescaleFactor);

            byte[] temdata = System.BitConverter.GetBytes(temshort);

            outData[i * 2]     = temdata[0];
            outData[i * 2 + 1] = temdata[1];
        }
        if (outData == null || outData.Length <= 0)
        {
            C_DebugHelper.Log("GetClipData intData is null");
            return(null);
        }
        return(outData);
    }
Ejemplo n.º 3
0
    public bool IsTalked()
    {
        try
        {
            if (audio.clip == null)
            {
                return(false);
            }
            float[] tempSamples; //临时数据存储
            tempSamples = new float[audio.clip.samples * audio.clip.channels];
            audio.clip.GetData(tempSamples, 0);
            float sourceData = 0.0f;
            sourceData = Array.Find(tempSamples, e => Mathf.Abs(e) > 0.05f);
            if (Mathf.Abs(sourceData) > 0.05f)
            {
                return(true);
            }
            return(false);
        }
        catch (Exception e)
        {
            C_DebugHelper.Log("IsTalked line173:" + e);

            return(false);
        }
        finally
        {
        }
    }
Ejemplo n.º 4
0
        public void InitCutScene(int start, int end)
        {
            InitCutScene();
            GameObject go    = GameObject.FindGameObjectWithTag("CutScene");
            int        count = go.transform.childCount;

            for (int i = 0; i < FileName.Count; i++)
            {
                C_DebugHelper.Log(FileName[i]);
                Transform temp = go.transform.Find(FileName[i]);
                if (temp == null)
                {
                    C_DebugHelper.LogError(FileName[i] + "not find");
                    return;
                }
                Cutscene cut = temp.GetComponent <Cutscene>();
                if (cut == null)
                {
                    C_DebugHelper.LogError(FileName[i] + "not find cutscene");
                    return;
                }
                if (i >= start && i <= end)
                {
                    cutscenes.Add(cut);
                }
            }
        }
Ejemplo n.º 5
0
 protected override void Init()
 {
     string[] ms = Microphone.devices;
     deviceCount = ms.Length;
     if (deviceCount == 0)
     {
         C_DebugHelper.Log("no microphone found");
     }
 }
Ejemplo n.º 6
0
    /// <summary>
    /// 超时 判断 默认 正确
    /// </summary>
    void StopWithStartOverTimeCheck()
    {
        //没网 弹窗tips 不走腾讯云语音识别  等待超时
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            DelayCallback = DOVirtual.DelayedCall(2f, () =>
            {
                ClearEvent();
                DoScoreCallBack("100");
                C_DebugHelper.Log("本轮语音识别无网络,默认正确!");
            });
            Tips.Create("语音识别异常,请切换网络后重试");
            return;
        }

        //等待结果返回,5秒之后如果没有返回结果,则自动返回
        DelayCallback = DOVirtual.DelayedCall(_DelayTime, () =>
        {
            ClearEvent();
            DoScoreCallBack("100");
            C_DebugHelper.Log("当轮语音识别没有拿到结果,默认正确!请确定网络状况是否良好!");
        });
        float time = Time.time;

        //float timeScale = Time.timeScale;
        //DelayCallback.OnUpdate(() =>
        //{
        //    if (Time.timeScale != timeScale)
        //    {
        //        C_DebugHelper.Log("TimeScale:" + Time.timeScale);
        //        timeScale = Time.timeScale;
        //    }
        //    C_DebugHelper.Log("花费时间:" + (Time.time - time));
        //});


        if (_GetTecentWordEvent != null)
        {
            _GetTecentWordEvent.UnregisterEvent();
        }
        _GetTecentWordEvent = null;
        _GetTecentWordEvent = new C_Event();

        _GetTecentWordEvent.RegisterEvent(C_EnumEventChannel.Global, "ResponseRecord", (word) =>
        {
            //停掉超时计算
            //if (DelayCallback != null)
            //{
            //    DelayCallback.Kill();
            //    DelayCallback = null;
            //}
            ClearEvent();
            GetTecentReslut((word == null || word.Length <= 0) ? "" : word[0].ToString());
        });

        _IsRecording = false;
    }
Ejemplo n.º 7
0
        void GenerateCutsceneAsync(int loadSum)
        {
            int sum = loadSum;

            //动态创建5个镜头
            for (int i = _CurrentNeedLoadIndex; i < _CurrentNeedLoadIndex + sum; i++)
            {
                //获取名字,创建cutscene,添加go对象为父节点
                if (i >= FileName.Count)
                {
                    continue;
                }
                bool       loadRes = false;
                GameObject temp    = null;
                if (_CutsceneNode != null)
                {
                    C_DebugHelper.Log("FileName[i]:" + FileName[i]);
                    Transform tran = _CutsceneNode.transform.Find(FileName[i]);
                    if (tran != null)
                    {
                        temp = tran.gameObject;
                    }
                    if (temp == null)
                    {
                        loadRes = true;
                    }
                }
                else
                {
                    loadRes = true;
                }

                if (loadRes)
                {
                    _StringBuilder.Length = 0;
                    _StringBuilder.Append("story/").Append(_ModuleName).Append("/").Append("cutscene/").Append(FileName[i]);
                    C_DebugHelper.Log("_StringBuilder.ToString():" + _StringBuilder.ToString());
                    temp = C_Singleton <GameResMgr> .GetInstance().LoadResource <GameObject>(_StringBuilder.ToString(), true, false);

                    if (temp == null)
                    {
                        continue;
                    }
                }
                temp.transform.SetParent(_CutsceneNode.transform);
                Cutscene cutscene = temp.GetComponent <Cutscene>();
                if (cutscene == null)
                {
                    continue;
                }
                cutscenes.Add(cutscene);
            }
            if (sum > 0)
            {
                _CurrentNeedLoadIndex += sum;
            }
        }
Ejemplo n.º 8
0
    /// <summary>
    /// 评分
    /// </summary>
    /// <param name="result">返回腾讯云的识别结果</param>
    public void GetTecentReslut_old(string result)
    {
        float  score      = 0;
        string resultWord = "0";

        if (!string.IsNullOrEmpty(result))
        {
            WordRespone itemDate = JsonUtility.FromJson <WordRespone>(result);//特殊处理的jason,一般jason类继续使用框架jason
            string      word     = itemDate.inputWords;
            C_DebugHelper.Log("class:RecognizeAudio function:GetTecentReslut  line 59..  word =" + word);
            int resultCode = itemDate.resultCode;
            if (resultCode == 1)
            {
                if (_ResultType == ResultType.PickWord)
                {
                    //解析所有的文字,找到分数最高的文字
                    float           wordMaxScore = 0f;
                    List <WordItem> wordList     = itemDate.words;
                    if (wordList != null)
                    {
                        for (int i = 0; i < wordList.Count; i++)
                        {
                            if (wordList[i] != null)
                            {
                                string wordName = wordList[i].word;
                                float  tmpScore = wordList[i].pronAccuracy * 0.6f + wordList[i].pronFluency * 100f * 0.4f;
                                if (tmpScore >= wordMaxScore || (i == 0))
                                {
                                    wordMaxScore = tmpScore;
                                    resultWord   = wordName;
                                }
                            }
                        }
                    }
                    DoScoreCallBack(resultWord);
                    return;
                }
                else if (_ResultType == ResultType.PickScore)
                {
                    //直接计算分数
                    score = (itemDate.pronAccuracy * 0.6f + itemDate.pronFluency * 100f * 0.4f) * itemDate.pronCompletion;
                }
            }
            if (_ResultCallback != null)
            {
                C_DebugHelper.Log("_ResultCallback ..GetTecentReslut  result =" + result);
                _ResultCallback(score.ToString());
                _ResultCallback = null;
            }
        }
        else
        {
            DoScoreCallBack(score.ToString());
        }
    }
Ejemplo n.º 9
0
 public static void getCutsceneState()
 {
     if (Utility.FindCurrentCutscene().isPaused)
     {
         C_DebugHelper.Log("current cus state: Utility.FindCurrentCutscene().isPaused");
     }
     else
     {
         C_DebugHelper.Log("current cus state: Utility.FindCurrentCutscene().play");
     }
 }
Ejemplo n.º 10
0
 public static void ResumeCurrentCutscene()
 {
     if (_CurrentCutScene != null)
     {
         _CurrentCutScene.Resume();
     }
     else
     {
         C_DebugHelper.Log("_CurrentCutScene is null ,resume fail..");
     }
 }
Ejemplo n.º 11
0
 public static void PauseCurrentCutscene()
 {
     if (_CurrentCutScene != null)
     {
         _CurrentCutScene.Pause();
     }
     else
     {
         C_DebugHelper.Log("_CurrentCutScene is null ,pause fail..");
     }
 }
Ejemplo n.º 12
0
    public void PokeRequestHttp(WWWForm form, string url, Action <string> callback, float timeout = 2.0f)
    {
        form.AddField("app", APP_CONST.PinYin);
        form.AddField("device", GameDataMgr.c_DeviceType);
        form.AddField("deviceid", GameDataMgr.c_DeviceUID);
        form.AddField("udid", GameDataMgr.c_UDID);
        form.AddField("ver", GameConfig.AppVersion);

        C_DebugHelper.Log("NetworkMgr SendHttpPost url = " + url + ", data = " + Encoding.UTF8.GetString(form.data));

        SendHttpPost(url, form.data, callback, timeout);
    }
Ejemplo n.º 13
0
 public static void StopCurrentCutscene()
 {
     if (_CurrentCutScene != null)
     {
         _CurrentCutScene.Stop();
         _CurrentCutScene = null;
     }
     else
     {
         C_DebugHelper.Log("_CurrentCutScene is null ,resume Stop..");
     }
 }
Ejemplo n.º 14
0
 public static bool isPause()
 {
     if (_CurrentCutScene != null)
     {
         return(_CurrentCutScene.isPaused);
     }
     else
     {
         C_DebugHelper.Log("_CurrentCutScene is null ,pause fail..");
     }
     return(false);
 }
Ejemplo n.º 15
0
        public virtual void TouchHandle()
        {
            AudioManager.Instance.PlayEffectSound("public/sound/public_sd_009.ogg");

            mCollider.enabled = false;
            C_DebugHelper.Log(_AudioName);
            if (!string.IsNullOrEmpty(_AudioName))
            {
                AudioManager.Instance.PlayerSound(_AudioName, false, new System.Action(PlaySoundOver));
            }
            if (OnTouch != null)
            {
                OnTouch(mCurrentIndex);
            }
        }
Ejemplo n.º 16
0
    public static Slate.CutsceneSequencePlayer FindCutsceneSequencePlayer()
    {
        GameObject player = GameObject.Find("CutsceneSequencePlayer");

        if (player == null)
        {
            C_DebugHelper.Log("CutsceneSequencePlayer is null..");
            return(null);
        }
        Slate.CutsceneSequencePlayer cutsceneSequencePlayer = player.GetComponent <Slate.CutsceneSequencePlayer>();
        if (cutsceneSequencePlayer == null)
        {
            C_DebugHelper.Log("CutsceneSequencePlayer component is null..");
            return(null);
        }
        return(cutsceneSequencePlayer);
    }
Ejemplo n.º 17
0
    public void PokeRequestHttp(string url, Dictionary <string, string> data, Action <string> callback, float timeout = 2.0f)
    {
        WWWForm form = new WWWForm();

        if (data != null)
        {
            foreach (KeyValuePair <string, string> kv in data)
            {
                form.AddField(kv.Key, kv.Value);
            }
        }
        form.AddField("app", APP_CONST.PinYin);
        form.AddField("device", GameDataMgr.c_DeviceType);
        form.AddField("deviceid", GameDataMgr.c_DeviceUID);
        form.AddField("udid", GameDataMgr.c_UDID);
        form.AddField("ver", GameConfig.AppVersion);

        C_DebugHelper.Log("NetworkMgr SendHttpPost url = " + url + ", data = " + Encoding.UTF8.GetString(form.data));

        SendHttpPost(url, form.data, callback, timeout);
    }
Ejemplo n.º 18
0
    public static IEnumerator SaveScreenShot(Camera shotCamera, Rect rect, string filename, int saveType, bool closeCamera = false)
    {
        yield return(new WaitForEndOfFrame());

        //   shotCamera.gameObject.SetActive(true);
        //  byte[] bytes =  CaptureScreenShot(shotCamera, rect, filename);
        Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGBA32, false);

        texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
        texture.Apply();
        byte[] bytes = texture.EncodeToPNG();
        if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
        {
            try
            {
                string base64String = System.Convert.ToBase64String(bytes);
                C_DebugHelper.Log("获取当前图片base64长度为---" + base64String.Length);
                C_DebugHelper.Log("获取base64String---" + base64String);
            }
            catch (System.Exception e)
            {
                C_DebugHelper.LogError("ImgToBase64String 转换失败:" + e.Message);
            }
        }
        else if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            string base64String = System.Convert.ToBase64String(bytes);
            C_DebugHelper.Log("获取base64String---" + base64String);

            string path = string.Concat(Application.dataPath, "/../capture/");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            File.WriteAllBytes(string.Concat(path, "/", filename), bytes);
        }
    }
Ejemplo n.º 19
0
    void GetTecentReslut(string result)
    {
        float score = 0;

        try
        {
            string resultWord = "0";
            if (!string.IsNullOrEmpty(result))
            {
                //  WordRespone itemDate = JsonUtility.FromJson<WordRespone>(result);//特殊处理的jason,一般jason类继续使用框架jason
                C_DebugHelper.Log("class:RecognizeAudio function:GetTecentReslut  line 59..  result =" + result);

                string word = C_Json.GetJsonKeyString(result, "inputWords");
#if !UNITY_IOS
                int pronCompletion = C_Json.GetJsonKeyInt(result, "pronCompletion");
#else
#endif
                int   resultCode   = C_Json.GetJsonKeyInt(result, "resultCode");
                float pronAccuracy = C_Json.GetJsonKeyFloat(result, "pronAccuracy");
                float pronFluency  = C_Json.GetJsonKeyFloat(result, "pronFluency");
                if (resultCode == 1)
                {
                    if (_ResultType == ResultType.PickWord)
                    {
                        //解析所有的文字,找到分数最高的文字
                        float    wordMaxScore = 0f;
                        JsonData wordList     = C_Json.GetJsonKeyJsonData(result, "words");
                        if (wordList != null)
                        {
                            for (int i = 0; i < wordList.Count; i++)
                            {
                                if (wordList[i] != null)
                                {
                                    string wordName          = C_Json.GetJsonKeyString(wordList[i], "word");
                                    float  pronAccuracy_word = C_Json.GetJsonKeyFloat(wordList[i], "pronAccuracy");
                                    float  pronFluency_word  = C_Json.GetJsonKeyFloat(wordList[i], "pronFluency");
#if !UNITY_IOS
                                    float tmpScore = pronAccuracy_word * 0.6f + pronFluency_word * 100f * 0.4f;
#else
                                    float tmpScore = pronAccuracy_word;
                                    //C_DebugHelper.Log("class:RecognizeAudio function:GetTecentReslut  line 153..  pronFluency_word =" + pronFluency_word);
#endif
                                    if (tmpScore >= wordMaxScore || (i == 0))
                                    {
                                        wordMaxScore = tmpScore;
                                        resultWord   = wordName;
                                    }
                                }
                            }
                        }
                        DoScoreCallBack(resultWord);
                        return;
                    }
                    else if (_ResultType == ResultType.PickScore)
                    {
                        //直接计算分数

#if !UNITY_IOS
                        score = (pronAccuracy * 0.6f + pronFluency * 100f * 0.4f) * pronCompletion;
#else
                        score = (pronAccuracy * 0.6f + pronFluency * 100f * 0.4f);
#endif
                    }
                }
                if (_ResultCallback != null)
                {
                    C_DebugHelper.Log("_ResultCallback ..GetTecentReslut  result =" + result);
                    _ResultCallback(score.ToString());
                    _ResultCallback = null;
                }
            }
            else
            {
                C_DebugHelper.Log("class:RecognizeAudio function:GetTecentReslut  line 169..  result =" + result);

                DoScoreCallBack(score.ToString());
            }
        }
        catch (Exception e)
        {
            DoScoreCallBack(score.ToString());
        }
    }
Ejemplo n.º 20
0
    //private IEnumerator GetRecordVolume(float pitch,System.Action<bool,float> callback, System.Action playOver =null)
    //{
    //    StartCoroutine(EndRecordWithoutSaveData(pitch, callback, playOver));
    //    WaitForEndOfFrame endOfFrame = new WaitForEndOfFrame();
    //    while (IsRecording())
    //    {
    //        yield return endOfFrame;
    //    }
    //}
    private IEnumerator EndRecordWithoutSaveData(float pitch, System.Action <bool, float> callback, Action playOver)
    {
        yield return(new WaitForSeconds(_Duration));

        try
        {
            StopRecord();

            //播放声音结束
            bool result = IsTalked();
            C_DebugHelper.LogErrorFormat("MicphoneSinglton EndRecordWithoutSaveData line287 ...result:" + result);

            if (callback != null)
            {
                callback(result, 1.0f);
            }
#if UNITY_EDITOR
            result = false;
#endif
            SpeechRecognizeSystemEvent.Instance.RemoveGetRecordStatusEvent();
            SpeechRecognizeSystemEvent.Instance.DelayStop = null;
            if (!result)
            {
#if UNITY_EDITOR
                //AudioManager.Instance.PlayerSound("public/sound/common_5.ogg",false,()=> {
                //    AudioManager.Instance.SetPlayerSoundPitch(1.0f);
                //    StopAllCoroutines();
                //    if (playOver != null)
                //    {
                //        playOver();
                //    }
                //});
                SpeechRecognizeSystemEvent.Instance.StartDelayStop(_Duration, () =>
                {
                    AudioManager.Instance.SetPlayerSoundPitch(1.0f);
                    StopAllCoroutines();
                    if (playOver != null)
                    {
                        playOver();
                    }
                });
#else
                AudioManager.Instance.SetPlayerSoundPitch(1.0f);
                StopAllCoroutines();
                if (playOver != null)
                {
                    playOver();
                }
#endif
            }
            else
            {
#if UNITY_EDITOR
                AudioManager.Instance.PlayerSound("public/sound/common_5.ogg", false, () => {
                    AudioManager.Instance.SetPlayerSoundPitch(1.0f);
                    StopAllCoroutines();
                    if (playOver != null)
                    {
                        playOver();
                    }
                });
                //SpeechRecognizeSystemEvent.Instance.StartDelayStop(_Duration, () => {
                //    AudioManager.Instance.SetPlayerSoundPitch(1.0f);
                //    StopAllCoroutines();
                //    if (playOver != null)
                //    {
                //        playOver();
                //    }
                //});
#else
                AudioManager.Instance.PlayerSoundModefyToneByClip(audio.clip, pitch, () => {
                    C_DebugHelper.Log("EndRecordWithoutSaveData line 272: PlayerSoundModefyToneByClip over");
                    AudioManager.Instance.SetPlayerSoundPitch(1.0f);
                    StopAllCoroutines();
                    if (playOver != null)
                    {
                        playOver();
                    }
                });
#endif
            }
        }
        catch (Exception e)
        {
            C_DebugHelper.Log("EndRecordWithoutSaveData line323:" + e);
            AudioManager.Instance.SetPlayerSoundPitch(1.0f);
            StopAllCoroutines();
            if (playOver != null)
            {
                playOver();
            }
        }
        finally
        {
        }
        yield return(null);
    }