Beispiel #1
0
        /// <summary>
        /// 获取timeline配置表内容
        /// </summary>
        /// <param name="id"></param>
        /// <param name="timelineConfig"></param>
        /// <returns></returns>
        bool GetTimelineConfig(uint id, out TimelineConfig timelineConfig)
        {
            timelineConfig    = new TimelineConfig();
            timelineConfig.Id = id;

            List <Dictionary <string, string> > dbs = DBManager.Instance.QuerySqliteRow <string>(GlobalConfig.DBFile, "data_timeline", "id", id.ToString());

            if (dbs.Count > 0)
            {
                Dictionary <string, string> db = dbs[0];

                // prefab路径
                string prefabPath = string.Empty;
                string prefabKey  = "prefab_" + LocalPlayerManager.Instance.LocalActorAttribute.Vocation;
                db.TryGetValue(prefabKey, out prefabPath);
                if (string.IsNullOrEmpty(prefabPath) == true)
                {
                    db.TryGetValue("prefab_1", out prefabPath);
                }
                if (string.IsNullOrEmpty(prefabPath) == true)
                {
                    GameDebug.LogError("Get timeline config error, can not find timeline prefab config, id: " + id);
                    return(false);
                }
                timelineConfig.PrefabPath = prefabPath;

                // prefab位置
                string rawStr = string.Empty;
                db.TryGetValue("pos", out rawStr);
                timelineConfig.Pos = DBTextResource.ParseVector3(rawStr);

                // prefab旋转
                rawStr = string.Empty;
                db.TryGetValue("rotation", out rawStr);
                timelineConfig.Rotation = DBTextResource.ParseVector3(rawStr);

                // 播放完毕后是否需要镜头融合
                db.TryGetValue("need_camera_follow_interpolation_when_finished", out rawStr);
                if (string.IsNullOrEmpty(rawStr) == true || rawStr.Equals("0"))
                {
                    timelineConfig.NeedCameraFollowInterpolationWhenFinished = false;
                }
                else
                {
                    timelineConfig.NeedCameraFollowInterpolationWhenFinished = true;
                }

                // 播放时是否显示主角
                db.TryGetValue("show_local_player", out rawStr);
                if (string.IsNullOrEmpty(rawStr) == true || rawStr.Equals("0"))
                {
                    timelineConfig.ShowLocalPlayer = false;
                }
                else
                {
                    timelineConfig.ShowLocalPlayer = true;
                }

                // 播放时是否不停止主角行为
                db.TryGetValue("no_stop_local_player", out rawStr);
                if (string.IsNullOrEmpty(rawStr) == true || rawStr.Equals("0"))
                {
                    timelineConfig.NoStopLocalPlayer = false;
                }
                else
                {
                    timelineConfig.NoStopLocalPlayer = true;
                }

                // 播放时是否显示ui
                db.TryGetValue("show_ui", out rawStr);
                if (string.IsNullOrEmpty(rawStr) == true || rawStr.Equals("0"))
                {
                    timelineConfig.ShowUI = false;
                }
                else
                {
                    timelineConfig.ShowUI = true;
                }

                // 播放的最低内存要求
                db.TryGetValue("min_memory", out rawStr);
                if (string.IsNullOrEmpty(rawStr) == true || rawStr.Equals("0"))
                {
                    timelineConfig.MinMemory = 0;
                }
                else
                {
                    uint.TryParse(rawStr, out timelineConfig.MinMemory);
                }

                // 播放时是否显示ui
                db.TryGetValue("pause_music", out rawStr);
                if (string.IsNullOrEmpty(rawStr) == true || rawStr.Equals("0"))
                {
                    timelineConfig.PauseMusic = false;
                }
                else
                {
                    timelineConfig.PauseMusic = true;
                }

                // 关联prefab的路径
                db.TryGetValue("related_prefab", out rawStr);
                timelineConfig.RelatedPrefabPath = rawStr;

                // 关联prefab的位置
                db.TryGetValue("related_prefab_pos", out rawStr);
                timelineConfig.RelatedPrefabPos = DBTextResource.ParseVector3(rawStr);

                // 绑定的lua脚本
                db.TryGetValue("behavior_script", out timelineConfig.BehaviorScript);

                // 播放完毕后是否要触发gc
                db.TryGetValue("need_gc", out rawStr);
                if (string.IsNullOrEmpty(rawStr) == true || rawStr.Equals("0"))
                {
                    timelineConfig.NeedGC = false;
                }
                else
                {
                    timelineConfig.NeedGC = true;
                }

                return(true);
            }
            else
            {
                GameDebug.LogError("Get timeline config error, can not find timeline id: " + id);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 播放Timeline动画
        /// </summary>
        /// <param name="id">剧情配置表里面的id</param>
        /// <param name="finishCallback">播放结束回调</param>
        public void Play(uint id, System.Action finishCallback = null, AvatarProperty avatarProperty = null)
        {
            //GameDebug.LogError("TimelineManager.Play: " + id);
            //GameDebug.Log("TimelineManager.Play: " + id);

            TimelineConfig timelineConfig = null;

            if (GetTimelineConfig(id, out timelineConfig) == false)
            {
                if (finishCallback != null)
                {
                    finishCallback();
                }

                GameDebug.LogError("Play timeline error, can not find timeline id: " + id);
                return;
            }

            if (QualitySetting.SkipTimeline(timelineConfig.MinMemory) == true)
            {
                // 野外场景中记住正在寻路的任务
                uint navigatingTaskId = 0;
                if (SceneHelp.Instance.IsInWildInstance() == true)
                {
                    Task navigatingTask = TaskManager.Instance.NavigatingTask;
                    if (navigatingTask != null)
                    {
                        navigatingTaskId = navigatingTask.Define.Id;
                    }
                }
                bool isAutoFighting = InstanceManager.Instance.IsAutoFighting;

                if (finishCallback != null)
                {
                    finishCallback();
                }

                // 恢复自动战斗和任务寻路
                InstanceManager.Instance.IsAutoFighting = isAutoFighting;
                if (navigatingTaskId > 0)
                {
                    TaskHelper.TaskGuide(navigatingTaskId);
                }

                return;
            }

            mPlayedTimelineIds.Add(id);

            if (mLoadingTimelineIdList.Contains(id) == false)
            {
                mLoadingTimelineIdList.Add(id);
            }

            // 停止并禁止玩家操作
            if (timelineConfig.NoStopLocalPlayer == false)
            {
                Actor localPlayer = Game.Instance.GetLocalPlayer();
                if (localPlayer != null)
                {
                    localPlayer.Stop();
                    localPlayer.MoveCtrl.TryWalkAlongStop();
                }
            }
            GameInput.Instance.EnableInput(false, true);

            Coroutine coroutine = SGameEngine.ResourceLoader.Instance.StartCoroutine(LoadPrefabCoroutine(timelineConfig, finishCallback, avatarProperty));

            mLoadPrefabCoroutines.Add(coroutine);
        }
Beispiel #3
0
        /// <summary>
        /// 预加载资源
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Preload(uint id, System.Action finishCallback = null)
        {
            TimelineConfig timelineConfig = null;

            if (GetTimelineConfig(id, out timelineConfig) == false)
            {
                if (finishCallback != null)
                {
                    finishCallback();
                    finishCallback = null;
                }
                GameDebug.LogError("Preload timeline error, can not find timeline id: " + id);
                return(false);
            }

            if (QualitySetting.SkipTimeline(timelineConfig.MinMemory) == true)
            {
                if (finishCallback != null)
                {
                    finishCallback();
                    finishCallback = null;
                }
                return(false);
            }

            string prefabPath = timelineConfig.PrefabPath;
            bool   needCameraFollowInterpolationWhenFinished = timelineConfig.NeedCameraFollowInterpolationWhenFinished;

            // 是否已经预加载过
            if (mPreloadedTimelineReses.ContainsKey(id) == true)
            {
                if (finishCallback != null)
                {
                    finishCallback();
                    finishCallback = null;
                }
                //GameDebug.LogError("Preload timeline error, this timeline have been preloaded, id:" + id);
                return(false);
            }

            // 加载前放一个空值进去,防止多次预加载
            mPreloadedTimelineReses.Add(id, null);

            if (mPreloadingTimelines.Contains(id) == false)
            {
                mPreloadingTimelines.Add(id);
            }

            SGameEngine.ResourceLoader.Instance.LoadAssetAsync(string.Format("Assets/Res{0}.prefab", prefabPath), (ar) =>
            {
                if (ar != null)
                {
                    mPreloadedTimelineReses[id] = ar;

                    if (mPreloadingTimelines.Contains(id) == true)
                    {
                        mPreloadingTimelines.Remove(id);
                    }
                }

                if (finishCallback != null)
                {
                    finishCallback();
                    finishCallback = null;
                }
            });

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// 加载timeline prefab协程
        /// </summary>
        /// <param name="id"></param>
        /// <param name="prefabPath"></param>
        /// <param name="finishCallback"></param>
        /// <param name="pos"></param>
        /// <param name="needCameraFollowInterpolationWhenFinished"></param>
        /// <param name="showLocalPlayer"></param>
        /// <returns></returns>
        IEnumerator LoadPrefabCoroutine(TimelineConfig config, System.Action finishCallback, AvatarProperty avatarProperty)
        {
            uint    id         = config.Id;
            string  prefabPath = config.PrefabPath;
            Vector3 pos        = config.Pos;
            Vector3 rotation   = config.Rotation;
            bool    needCameraFollowInterpolationWhenFinished = config.NeedCameraFollowInterpolationWhenFinished;
            bool    showLocalPlayer   = config.ShowLocalPlayer;
            bool    noStopLocalPlayer = config.NoStopLocalPlayer;
            bool    showUI            = config.ShowUI;
            bool    pauseMusic        = config.PauseMusic;
            bool    needGC            = config.NeedGC;

            SGameEngine.PrefabResource pr = new SGameEngine.PrefabResource();
            yield return(SGameEngine.ResourceLoader.Instance.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_prefab(string.Format("Assets/Res{0}.prefab", prefabPath), pr)));

            // 延迟资源的加载,测试用
            //yield return new WaitForSeconds(5f);

            // 恢复玩家操作
            GameInput.Instance.EnableInput(true, true);

            GameObject obj = pr.obj_;

            if (obj == null)
            {
                if (finishCallback != null)
                {
                    finishCallback();
                }

                if (mLoadingTimelineIdList.Contains(id) == true)
                {
                    mLoadingTimelineIdList.Remove(id);
                }

                GameDebug.LogError("Play timeline " + prefabPath + " error, can not load prefab!");
                yield break;
            }

            PlayableDirector playableDirector = obj.GetComponent <PlayableDirector>();

            if (playableDirector == null)
            {
                GameObject.DestroyImmediate(obj);

                if (finishCallback != null)
                {
                    finishCallback();
                }

                if (mLoadingTimelineIdList.Contains(id) == true)
                {
                    mLoadingTimelineIdList.Remove(id);
                }

                GameDebug.LogError("Play timeline " + prefabPath + " error, can not find PlayableDirector component!");
                yield break;
            }

            string relatedPrefabPath = config.RelatedPrefabPath;

            SGameEngine.PrefabResource relatedPrefabPr = null;
            if (string.IsNullOrEmpty(relatedPrefabPath) == false)
            {
                relatedPrefabPr = new SGameEngine.PrefabResource();
                yield return(SGameEngine.ResourceLoader.Instance.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_prefab(string.Format("Assets/Res{0}.prefab", relatedPrefabPath), relatedPrefabPr)));
            }

            obj.SetActive(false);
            obj.transform.position         = pos;
            obj.transform.localScale       = Vector3.one;
            obj.transform.localEulerAngles = rotation;

            TimelineInfo timelineInfo = new TimelineInfo();

            playableDirector.time         = 0;
            timelineInfo.Id               = id;
            timelineInfo.PlayableDirector = playableDirector;
            timelineInfo.FinishCallback   = finishCallback;
            timelineInfo.AvatarProperty   = avatarProperty;
            timelineInfo.NeedCameraFollowInterpolationWhenFinished = needCameraFollowInterpolationWhenFinished;
            timelineInfo.ShowLocalPlayer   = showLocalPlayer;
            timelineInfo.NoStopLocalPlayer = noStopLocalPlayer;
            timelineInfo.ShowUI            = showUI;
            timelineInfo.PauseMusic        = pauseMusic;
            timelineInfo.NeedGC            = needGC;

            // 关联GameObject
            timelineInfo.RelatedGameObject = null;
            if (relatedPrefabPr != null)
            {
                if (relatedPrefabPr.obj_ != null)
                {
                    timelineInfo.RelatedGameObject = relatedPrefabPr.obj_;
                    timelineInfo.RelatedGameObject.SetActive(false);
                    timelineInfo.RelatedGameObject.transform.position         = config.RelatedPrefabPos;
                    timelineInfo.RelatedGameObject.transform.localScale       = Vector3.one;
                    timelineInfo.RelatedGameObject.transform.localEulerAngles = Vector3.zero;
                }
                else
                {
                    GameDebug.LogError("Play timeline " + id + " error, can not load related prefab " + relatedPrefabPath);
                }
            }

            // lua脚本
            if (string.IsNullOrEmpty(config.BehaviorScript) == false)
            {
                if (LuaScriptMgr.Instance != null && LuaScriptMgr.Instance.IsLuaScriptExist(config.BehaviorScript))
                {
                    LuaMonoBehaviour com = obj.AddComponent <LuaMonoBehaviour>();
                    com.Init(config.BehaviorScript);
                }
                else
                {
                    System.Type t = System.Type.GetType(config.BehaviorScript);
                    if (t != null)
                    {
                        obj.AddComponent(t);
                    }
                }
            }

            // 延迟资源的加载,测试用
            //yield return new WaitForSeconds(10f);

            if (mPlayingTimeline != null)
            {
                mCacheTimelineList.Enqueue(timelineInfo);
            }
            else
            {
                PlayImpl(timelineInfo);
            }

            if (mLoadingTimelineIdList.Contains(id) == true)
            {
                mLoadingTimelineIdList.Remove(id);
            }

            //GameDebug.LogError("TimelineManager.LoadPrefabCoroutine: " + id);
        }