コード例 #1
0
        /// <summary>
        /// 生成动画
        /// </summary>
        private void GenerateAnim()
        {
            string abPath = string.Format("{0}/{1}", PlatformUtility.GetResStreamingAssets(), "AssetBundle/facerecviewanim.assetbundle");

            //面部检测
            _scannerSpriteAnimator = _imgScanner.gameObject.AddComponent <SpriteAnimator>();

            _scannerSpriteAnimator.FPS = 12;

            _scannerSpriteAnimator.Loop = true;

            for (int i = 0; i < 48; i++)
            {
                string assetName = string.Format("HeadScanner_{0}", i);

                _scannerSpriteAnimator?.LoadSpriteFrames(AssetBundleLoader?.GetAsset <Sprite>(abPath, assetName));
            }

            //面部分析
            if (_recImageArr != null && _recImageArr.Length >= 3)
            {
                _recSpriteAnimators = new SpriteAnimator[_recImageArr.Length];

                for (int i = 0; i < _recImageArr.Length; i++)
                {
                    _recSpriteAnimators[i] = _recImageArr[i]?.gameObject.AddComponent <SpriteAnimator>();
                }

                //眼睛
                SpriteAnimator eye = _recSpriteAnimators[0];

                eye.FPS = 12;

                for (int i = 0; i < 32; i++)
                {
                    string assetName = string.Format("EyeAnalyze_{0}", i);

                    eye?.LoadSpriteFrames(AssetBundleLoader?.GetAsset <Sprite>(abPath, assetName));
                }

                //鼻子
                SpriteAnimator nose = _recSpriteAnimators[1];

                nose.FPS = 12;

                for (int i = 0; i < 28; i++)
                {
                    string assetName = string.Format("NoseAnalyze_{0}", i);

                    nose?.LoadSpriteFrames(AssetBundleLoader?.GetAsset <Sprite>(abPath, assetName));
                }

                //嘴巴
                SpriteAnimator mouth = _recSpriteAnimators[2];

                mouth.FPS = 12;

                for (int i = 0; i < 32; i++)
                {
                    string assetName = string.Format("MouthAnalyze_{0}", i);

                    mouth?.LoadSpriteFrames(AssetBundleLoader?.GetAsset <Sprite>(abPath, assetName));
                }
            }
        }