// 导出ExportGroupTrack
        private int ExportGroupTrack(GroupTrack groupTrack, JSONObject trackListArr, JSONObject clipListArr)
        {
            JSONObject trackJSON    = GenerateBaseTrack(groupTrack, PlaybaleTrackTypeMap["GroupTrack"]);
            JSONObject childrenJSON = trackJSON.GetField("children");
            IEnumerable <TrackAsset> trackAssetList = groupTrack.GetChildTracks();
            List <int> indexList = ExportTrackList(trackAssetList, trackListArr, clipListArr);

            foreach (int index in indexList)
            {
                childrenJSON.Add(index);
            }
            return(ExportTrack(trackJSON, trackListArr));
        }
Exemplo n.º 2
0
        public static void AddMenuItems(GenericMenu menu, GroupTrack track)
        {
            var state = TimelineWindow.instance.state;

            var trackTypes = TypeUtility.AllTrackTypes();

            foreach (var t in trackTypes)
            {
                if (t == typeof(GroupTrack))
                {
                    continue;
                }

                GenericMenu.MenuFunction2 menuFunc = trackType =>
                {
                    track.SetCollapsed(false);

                    state.GetWindow().AddTrack((System.Type)trackType, track);
                    var uiTrack = FindGUITrack(track);
                    if (uiTrack != null)
                    {
                        TimelineWindow.instance.treeView.data.SetExpanded(uiTrack, true);
                    }
                };

                object lastUserData = t;
                var    category     = TimelineHelpers.GetTrackCategoryName(t);
                if (!string.IsNullOrEmpty(category))
                {
                    category += "/";
                }

                var content = EditorGUIUtility.TrTextContent("Add " + category + TimelineHelpers.GetTrackMenuName(t));
                if (track.lockedInHierarchy)
                {
                    menu.AddDisabledItem(content, false);
                }
                else
                {
                    menu.AddItem(content, false, menuFunc, lastUserData);
                }
            }
        }
Exemplo n.º 3
0
 public static void RunOnTrackIEnumerable(IEnumerable <TrackAsset> tracks, Action <TrackAsset> Action,
                                          bool runOnGroupTracks)
 {
     foreach (TrackAsset track in tracks)
     {
         GroupTrack groupTrack = track as GroupTrack;
         if (groupTrack != null)
         {
             if (runOnGroupTracks)
             {
                 Action.Invoke(track);
             }
             RunOnTrackIEnumerable(groupTrack.GetChildTracks(), Action, runOnGroupTracks);
         }
         else
         {
             Action.Invoke(track);
         }
     }
 }
Exemplo n.º 4
0
        public ITrack CreateTimeline()
        {
            var root = new GroupTrack {
                Name = "root"
            };

            // root直下のenabledなTrack
            var enabledMotion = new MotionTrack {
                Name = "enabled motion track"
            };

            root.Add(enabledMotion);

            // root直下のdisabledなTrack
            var disabledMotion = new MotionTrack {
                Name = "disabled motion track", IsEnabled = false
            };

            root.Add(disabledMotion);

            // rootの下のGroupTrack
            var group = new GroupTrack {
                Name = "group"
            };

            root.Add(group);

            var groupMotion_1 = new MotionTrack {
                Name = "motion track in group 1"
            };

            group.Add(groupMotion_1);

            var groupMotion_2 = new MotionTrack {
                Name = "motion track in group 2"
            };

            group.Add(groupMotion_2);

            return(root);
        }
    private void Create()
    {
        //---タイムラインアセット作成---
        TimelineAsset timelineAsset = ScriptableObject.CreateInstance <TimelineAsset>();
        string        savePath      = exportPath + "/" + timelineAssetName + ".playable";

        //                                                ↓C:\xxx\xxxの部分を消す処理
        AssetDatabase.CreateAsset(timelineAsset, savePath.Replace(Application.dataPath, "Assets"));

        //---RecorderTrackをまとめるグループを作成---
        GroupTrack groupTrack = timelineAsset.CreateTrack <GroupTrack>(null, "RecorderGroup");

        foreach (ClipInfo clipInfo in clipInfos)
        {
            //---RecorderClip専用のトラックを作成---
            RecorderTrack recorderTrack = timelineAsset.CreateTrack <RecorderTrack>(groupTrack, clipInfo.name + "_track");

            //---RecorderClipの作成---
            TimelineClip timelineClip = recorderTrack.CreateClip <RecorderClip>();
            timelineClip.displayName = clipInfo.name + "_clip";

            //---RecorderSetting---
            RecorderClip recorderClip = timelineClip.asset as RecorderClip;
            SetRecorderSettings(clipInfo.type, ref recorderClip.settings);
            recorderClip.settings.name = clipInfo.name + "_asset";

            //---Presetを使用---
            if (clipInfo.isUsePreset)
            {
                presets[(int)clipInfo.type].ApplyTo(recorderClip.settings);
            }

            //---TimelineAssetにsettings(ScriptableObject)を追加---
            //                              追加しないと保持されない!
            AssetDatabase.AddObjectToAsset(recorderClip.settings, timelineAsset);
        }

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
        static public List <TrackAsset> GetTrackList(GroupTrack groupTrack)
        {
            var bf             = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField;
            var type           = groupTrack.GetType().BaseType;
            var fieldInfo      = type.GetField("m_Children", bf);
            var clips          = fieldInfo.GetValue(groupTrack);
            var trackAssetList = clips as List <TrackAsset>;

            if (trackAssetList != null)
            {
                return(trackAssetList);  // 2017.1 tracks
            }
            // later version.
            var scriptableObjectList = clips as List <ScriptableObject>;
            var ret = new List <TrackAsset>();

            foreach (var asset in scriptableObjectList)
            {
                ret.Add(asset as TrackAsset);
            }
            return(ret);
        }
        public static void Show(TrackDrawer drawer, TrackAsset track, Vector2 mousePosition)
        {
            GenericMenu genericMenu = new GenericMenu();

            TimelineAction.AddToMenu(genericMenu, TimelineWindow.instance.state);
            genericMenu.AddSeparator("");
            TrackAction.AddToMenu(genericMenu, TimelineWindow.instance.state);
            GroupTrack groupTrack = track as GroupTrack;

            if (groupTrack == null)
            {
                if (drawer != null)
                {
                    genericMenu.AddSeparator("");
                    drawer.OnBuildTrackContextMenu(genericMenu, track, TimelineWindow.instance.state);
                }
            }
            else
            {
                genericMenu.AddSeparator("");
                TimelineGroupGUI.AddMenuItems(genericMenu, groupTrack);
            }
            genericMenu.ShowAsContext();
        }
        public static void AddMenuItems(GenericMenu menu, GroupTrack track)
        {
            var state = TimelineWindow.instance.state;

            var trackTypes = TypeUtility.AllTrackTypes();

            foreach (var t in trackTypes)
            {
                if (t == typeof(GroupTrack))
                {
                    continue;
                }

                GenericMenu.MenuFunction2 menuFunc = trackType =>
                {
                    TimelineHelpers.CreateTrack((System.Type)trackType, track);
                };

                object lastUserData = t;
                var    category     = TimelineHelpers.GetTrackCategoryName(t);
                if (!string.IsNullOrEmpty(category))
                {
                    category += "/";
                }

                var content = EditorGUIUtility.TrTextContent("Add " + category + TimelineHelpers.GetTrackMenuName(t));
                if (track.lockedInHierarchy || state.editSequence.isReadOnly)
                {
                    menu.AddDisabledItem(content, false);
                }
                else
                {
                    menu.AddItem(content, false, menuFunc, lastUserData);
                }
            }
        }
    public void Awake()
    {
        if (SceneHelp.Instance.IsInWeddingInstance == true) // 婚宴副本外面使用第二套模型
        {
            mModelIds = GameConstHelper.GetUintList("GAME_WEDDING_DRAMA_TIMELINE_COUPLE_MODEL_IDS");
        }
        else
        {
            mModelIds = GameConstHelper.GetUintList("GAME_WEDDING_DRAMA_TIMELINE_COUPLE_MODEL_IDS_2");
        }

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

        if (playableDirector != null)
        {
            uint rid1 = 0;
            uint rid2 = 0;
            MarryHelper.GetWeddingCoupleJobs(out rid1, out rid2);

            TimelineAsset asset = playableDirector.playableAsset as TimelineAsset;
            foreach (TrackAsset track in asset.GetOutputTracks())
            {
                GroupTrack group = track.GetGroup();
                if (group != null)
                {
                    if (group.name.Equals("Mate") == true)
                    {
                        foreach (PlayableBinding output in track.outputs)
                        {
                            if (output.sourceObject != null)
                            {
                                Object binding = playableDirector.GetGenericBinding(output.sourceObject);
                                if (binding == null)
                                {
                                    GameDebug.LogError("Player wedding chapel timeline " + this.name + " error!!! " + output.sourceObject.name + " 's binding object is null!!!");
                                    continue;
                                }
                                GameObject bindingObj = binding as GameObject;

                                // 根据职业显示主角的模型
                                if (bindingObj != null)
                                {
                                    if (bindingObj.name.Equals("Mate_R") == true)
                                    {
                                        if (rid1 > 0)
                                        {
                                            bindingObj.SetActive(false);
                                            ReplaceActorModel(playableDirector, output, bindingObj, rid1, bindingObj.name);
                                        }
                                    }
                                    if (bindingObj.name.Equals("Mate_L") == true)
                                    {
                                        if (rid2 > 0)
                                        {
                                            bindingObj.SetActive(false);
                                            ReplaceActorModel(playableDirector, output, bindingObj, rid2, bindingObj.name);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        // 跳过按钮
        Transform skipButtonTrans = gameObject.transform.Find("UI/Canvas/SkipButton");

        if (skipButtonTrans != null)
        {
            Button skipButton = skipButtonTrans.GetComponent <Button>();
            if (skipButton != null)
            {
                skipButton.onClick.RemoveAllListeners();
                skipButton.onClick.AddListener(() =>
                {
                    TimelineManager.Instance.StopAll();
                });
            }
        }

        GameInput.Instance.EnableInput(true, true);
    }
Exemplo n.º 10
0
        public static void AddTrackToTimelineAsset(TimelineAsset asset, TrackAsset track, GroupTrack parent)
        {
            MethodInfo addTrackMethod = typeof(TimelineAsset).GetMethod("AddTrackInternal", BindingFlags.NonPublic | BindingFlags.Instance);

            // ReSharper disable once PossibleNullReferenceException as if this is no longer a method I want to know about it!
            addTrackMethod.Invoke(asset, new object[] { track });
            if (parent != null)
            {
                track.SetGroup(parent);
            }
            RefreshTimelineState();
        }
Exemplo n.º 11
0
        /// <summary>
        /// 开始播放剧情
        /// </summary>
        /// <param name="timelineInfo"></param>
        void PlayImpl(TimelineInfo timelineInfo)
        {
            //GameDebug.LogError("TimelineManager.PlayImpl: " + timelineInfo.Id);

            mPlayingTimeline = timelineInfo;

            PlayableDirector playableDirector = timelineInfo.PlayableDirector;

            if (playableDirector == null)
            {
                if (timelineInfo.FinishCallback != null)
                {
                    timelineInfo.FinishCallback();
                }

                if (timelineInfo.RelatedGameObject != null)
                {
                    GameObject.DestroyImmediate(timelineInfo.RelatedGameObject);
                }

                return;
            }

            if (playableDirector.playableAsset == null)
            {
                if (timelineInfo.FinishCallback != null)
                {
                    timelineInfo.FinishCallback();
                }

                GameDebug.LogError("Play timeline " + playableDirector.gameObject.name + " error, playable asset is null!");

                mPlayingTimeline = null;
                GameObject.DestroyImmediate(playableDirector.gameObject);
                if (timelineInfo.RelatedGameObject != null)
                {
                    GameObject.DestroyImmediate(timelineInfo.RelatedGameObject);
                }
                return;
            }

            if (Game.Instance.MainCamera == null)
            {
                if (timelineInfo.FinishCallback != null)
                {
                    timelineInfo.FinishCallback();
                }

                GameDebug.LogError("Play timeline " + playableDirector.gameObject.name + " error, main camera is null!");

                mPlayingTimeline = null;
                GameObject.DestroyImmediate(playableDirector.gameObject);
                if (timelineInfo.RelatedGameObject != null)
                {
                    GameObject.DestroyImmediate(timelineInfo.RelatedGameObject);
                }
                return;
            }

            Cinemachine.CinemachineBrain cinemachineBrain = Game.Instance.MainCamera.GetComponent <Cinemachine.CinemachineBrain>();
            if (cinemachineBrain == null)
            {
                cinemachineBrain = Game.Instance.MainCamera.gameObject.AddComponent <Cinemachine.CinemachineBrain>();
            }
            if (cinemachineBrain != null)
            {
                cinemachineBrain.enabled = true;
            }
            else
            {
                GameDebug.LogError("Play timeline " + playableDirector.gameObject.name + " error, can not find CinemachineBrain component in main camera!");

                mPlayingTimeline = null;
                GameObject.DestroyImmediate(playableDirector.gameObject);
                if (timelineInfo.RelatedGameObject != null)
                {
                    GameObject.DestroyImmediate(timelineInfo.RelatedGameObject);
                }

                if (timelineInfo.FinishCallback != null)
                {
                    timelineInfo.FinishCallback();
                }

                return;
            }

            // 隐藏所有角色
            SetAllActorsVisible(false, timelineInfo.ShowLocalPlayer);

            // 野外场景中记住正在寻路的任务
            if (SceneHelp.Instance.IsInWildInstance() == true)
            {
                Task navigatingTask = TaskManager.Instance.NavigatingTask;
                if (navigatingTask != null)
                {
                    mNavigatingTaskIdBeforePlay = navigatingTask.Define.Id;
                }
            }

            Actor localPlayer = Game.Instance.GetLocalPlayer();

            TimelineAsset asset = playableDirector.playableAsset as TimelineAsset;

            foreach (TrackAsset track in asset.GetOutputTracks())
            {
                GroupTrack group = track.GetGroup();
                if (group != null)
                {
                    // 绑定主摄像机
                    if (group.name.StartsWith("Camera") == true)
                    {
                        Camera mainCamera = Game.Instance.MainCamera;
                        if (mainCamera != null)
                        {
                            foreach (PlayableBinding output in track.outputs)
                            {
                                if (output.sourceObject != null)
                                {
                                    playableDirector.SetGenericBinding(output.sourceObject, mainCamera.gameObject);
                                }
                            }
                        }
                    }

                    if (group.name.StartsWith("Hero") == true)
                    {
                        if (localPlayer != null)
                        {
                            foreach (PlayableBinding output in track.outputs)
                            {
                                GameObject actorModel = null;
                                if (output.sourceObject != null)
                                {
                                    Object binding = playableDirector.GetGenericBinding(output.sourceObject);
                                    if (binding == null)
                                    {
                                        GameDebug.LogError("Player timeline " + timelineInfo.PlayableDirector.name + " error!!! " + output.sourceObject.name + " 's binding object is null!!!");
                                        continue;
                                    }
                                    GameObject bindingObj = binding as GameObject;
                                    if (bindingObj != null)
                                    {
                                        bindingObj.SetActive(false);
                                    }

                                    // 根据职业显示主角的模型
                                    if (bindingObj != null && bindingObj.name.StartsWith("Hero_") == true)
                                    {
                                        uint vocation = uint.Parse(bindingObj.name.Substring(5));
                                        if (vocation == LocalPlayerManager.Instance.LocalActorAttribute.Vocation)
                                        {
                                            //playableDirector.SetGenericBinding(output.sourceObject, localPlayer.gameObject);
                                            CommonTool.SetActive(bindingObj, true);
                                            actorModel = bindingObj;
                                        }
                                        else
                                        {
                                            CommonTool.SetActive(bindingObj, false);
                                        }
                                    }
                                }
                                if (actorModel != null && changeSkin)
                                {
                                    //changeSkin = false;
                                    if (timelineInfo.AvatarProperty != null)
                                    {
                                        ResourceLoader.Instance.StartCoroutine(AvatarUtils.ChangeModel(actorModel, timelineInfo.AvatarProperty));
                                    }
                                    else
                                    {
                                        AvatarProperty avatarProperty;
                                        if (localPlayer.mAvatarCtrl != null && localPlayer.mAvatarCtrl.GetLatestAvatartProperty() != null)
                                        {
                                            avatarProperty = localPlayer.mAvatarCtrl.GetLatestAvatartProperty();
                                        }
                                        else
                                        {
                                            avatarProperty = mPlayerLastSceneAvatarProperty;
                                        }
                                        ResourceLoader.Instance.StartCoroutine(AvatarUtils.ChangeModel(actorModel, avatarProperty));
                                    }
                                }
                            }
                        }
                    }
                }

                // 音效是否静音
                AudioTrack audioTrack = track as AudioTrack;
                if (audioTrack != null)
                {
                    audioTrack.muted = GlobalSettings.Instance.SFXMute;
                }
            }

            if (Game.Instance.CameraControl != null)
            {
                Game.Instance.CameraControl.Target = null;
            }

            // 记住当前状态并暂停主角的自动战斗
            mIsAutoFightingWhenPlaying = InstanceManager.Instance.IsAutoFighting;
            InstanceManager.Instance.IsAutoFighting = false;

            // 停止主角的寻路
            if (timelineInfo.NoStopLocalPlayer == false)
            {
                TargetPathManager.Instance.StopPlayerAndReset();
            }

            mCameraRotationBeforePlay = Game.Instance.MainCamera.transform.rotation;
            mCameraFOVBeforePlay      = Game.Instance.MainCamera.fieldOfView;

            bool setUI = true;

            if (timelineInfo.ShowUI == true)
            {
                setUI = false;
            }
            GameInput.Instance.EnableInput(false, setUI);

            // 暂停CullManager的Update
            CullManager.Instance.IsEnabled = false;

            // 隐藏UI
            if (timelineInfo.ShowUI == false)
            {
                xc.ui.ugui.UIManager.Instance.CloseAllWindow();
            }

            if (!GlobalSettings.Instance.MusicMute && timelineInfo.PauseMusic)
            {
                AudioManager.Instance.PauseMusic(true);
            }

            playableDirector.gameObject.SetActive(true);

            if (timelineInfo.RelatedGameObject != null)
            {
                timelineInfo.RelatedGameObject.SetActive(true);
            }

            playableDirector.Play();

            ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TIMELINE_START, new CEventBaseArgs(timelineInfo.Id));
        }