Example #1
0
        public IAniPlayer Build()
        {
            if (mIsDestroy)
            {
                return(this);
            }
            var go_player = new GameObject(mName, new Type[]
            {
                typeof(AniDirector),
                //typeof(PlayableDirector)
            });

            mPlayerBaseGo = go_player;
            mPlayerBaseGo.transform.position = mPosition;

            mAniDirector = mPlayerBaseGo.GetComponent <AniDirector>();


            //初始化Director
            mAniDirector.InitAni(mAsset);
            //事件注册
            mAniDirector.OnFinish(() =>
            {
                mCallback_OnPlayFinish?.Invoke(this);
            });


            //stage
            if (mStagePrefab != null)
            {
                mStageGameObject = UnityEngine.Object.Instantiate(mStagePrefab, mPlayerBaseGo.transform);
                var stageObj = mStageGameObject.GetComponent <AniStage>();
                if (stageObj == null)
                {
                    Debug.LogError("can not found \" AniStage\" component your stage prefab ");
                }
                mAniDirector.mAniStage = stageObj;
            }


            //如果需要的话,在player内部执行stage的对象替换
            if (mAniDirector.mAniStage != null)
            {
                this.mCallback_OnReady_private += ((player, trackInfo) =>
                {
                    if (!string.IsNullOrEmpty(trackInfo.TransformPath))
                    {
                        //Debug.Log("尝试在stage中寻找:" + trackInfo.TransformPath);
                        //尝试在stage中寻找对应路径的Object
                        var trans = mStageGameObject.transform.Find(trackInfo.TransformPath);
                        if (trans != null)
                        {
                            //Debug.Log("    找到了", trans);
                            //Debug.Log("        寻找类型:" + trackInfo.TrackType);
                            //Debug.Log("尝试获取类型");
                            var type = typen(trackInfo.TrackType);
                            if (type != null)
                            {
                                var obj = trans.GetComponent(type);
                                if (obj != null)
                                {
                                    player.SetBinding(trackInfo.TrackName, obj);
                                }
                            }
                            else
                            {
                                Debug.LogWarning("[AniCat] AniPlayer解析JSON辅助文件时获取类型失败:" + trackInfo.TrackType);
                            }
                        }
                    }
                });
            }


            //触发Ready方法
            if (mTimelineModel != null)
            {
                foreach (var item in mTimelineModel.Tracks)
                {
                    mCallback_OnReady_private?.Invoke(this, item);
                    mCallback_OnReady1?.Invoke(this, item);
                    mCallback_OnReady2?.Invoke(this, item.GameObjectName, item.TransformPath, item.TrackName, item.TrackType);
                }
            }


            return(this);
        }