Beispiel #1
0
    // 在空格处放上表情动画
    private GameObject ReplaceEmojiWithPicture(string faceName)
    {
        GameObject        sprite;
        UISprite          spFace;
        UISpriteAnimation spaFace;
        AnimationVO       aniConfig = GameConst.GetAnimationConfigByIndex(faceName);

        sprite  = GameObject.Instantiate(faceTemplate);
        spFace  = sprite.GetComponent <UISprite>();
        spaFace = sprite.GetComponent <UISpriteAnimation>();

        spFace.GetComponent <UIWidget>().width  = (int)(cellLength * aniConfig.spaceNum * 0.5f);
        spFace.GetComponent <UIWidget>().height = (int)cellLength * aniConfig.rowNum;

        sprite.transform.parent = emojiContainer;
        spFace.spriteName       = faceName + "_1";
        spaFace.namePrefix      = faceName + "_";

        if (aniConfig != null)
        {
            if (aniConfig.isNotPlay)
            {
                StopAudioAnimation(spaFace);
                if (aniConfig.isAudio)
                {
                    RegistUIButton(gameObject, (go) => {
                        if (chatData == null || chatData.voiceData == null)
                        {
                            return;
                        }
                        Byte[] wavData = SevenZipCompress.Decompress(chatData.voiceData);
                        _microPhoneInput.PlayClipData(wavData);
                        spaFace.Play();
                        Director.GetInstance().scheduler.SetTimeOut(chatData.time, () => {
                            StopAudioAnimation(spaFace);
                        });
                    });
                }
            }
            spaFace.framesPerSecond = aniConfig.rate;
        }
        if (!aniConfig.isAudio)
        {
            sprite.GetComponent <Collider>().enabled = false;
        }
        Vector3 tmpPos;

        sprite.transform.localScale = Vector3.one;
        tmpPos   = picIndex;
        tmpPos.y = picIndex.y + cellLength * (aniConfig.rowNum - 1);

        sprite.transform.localPosition = tmpPos;
        sprite.name = faceName;
        sprite.SetActive(true);
        spFace.ResizeCollider();

        return(sprite);
    }
Beispiel #2
0
    public Byte[] GetClipData()
    {
        if (_audio.clip == null)
        {
            return(null);
        }

        float[] samples = new float[_audio.clip.samples];
        _audio.clip.GetData(samples, 0);

        float[] compressSamples = null;
        bool    isRecord        = false;

        for (int i = samples.Length - 1; i >= 0; i--)
        {
            if (isRecord)
            {
                compressSamples[i] = samples[i];
            }
            else
            {
                if (samples[i] == 0 && !isRecord)
                {
                    continue;
                }
                else
                {
                    isRecord           = true;
                    compressSamples    = new float[i + 1];
                    compressSamples[i] = samples[i];
                }
            }
        }
        samples = null;
        samples = compressSamples;

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

        for (int i = 0; i < samples.Length; i++)
        {
            Int16  temshort = (Int16)(samples[i] * INT16_SCALE);
            Byte[] temdata  = BitConverter.GetBytes(temshort);
            outData[i * 2]     = temdata[0];
            outData[i * 2 + 1] = temdata[1];
        }

        if (outData == null || outData.Length <= 0)
        {
            return(null);
        }
        Debug.Log("out data:" + outData.Length);
        Byte[] compressData = SevenZipCompress.Compress(outData);
        Debug.Log("compress data" + compressData.Length);
        return(compressData);
    }