/// <summary> /// 设置人物动画轨道,相机轨道 /// </summary> /// <param name="director">播放器</param> /// <param name="animator">人物动画</param> /// <param name="brain">主相机</param> /// <param name="cameras">机位列表</param> private void SetCinemachineTrack(PlayableDirector director, CinemachineBrain brain, params CinemachineVirtualCameraBase[] cameras) { bool cinemachineFinded = false; bool animatorFinded = false; foreach (PlayableBinding binding in director.playableAsset.outputs) { if (binding.streamName.Equals("CinemachineTrack")) { director.SetGenericBinding(binding.sourceObject, brain); int index = 0; CinemachineTrack track = (CinemachineTrack)binding.sourceObject; foreach (TimelineClip clip in track.GetClips()) { CinemachineShot cameraShot = clip.asset as CinemachineShot; director.SetReferenceValue(cameraShot.VirtualCamera.exposedName, cameras != null && index < cameras.Length ? cameras[index] : null); index++; } cinemachineFinded = true; } if (cinemachineFinded && animatorFinded) { break; } } }
void Start() { fdirector = fabulaTimeline.GetComponent <PlayableDirector>(); fdirector.initialTime = 0f; dc = DiscourseContainer.Load(Path.Combine(Application.dataPath, "Scripts//CinemachineTimelineCode//FileIO_xml//discourse.xml")); timeline = (TimelineAsset)ScriptableObject.CreateInstance("TimelineAsset"); director = GetComponent <PlayableDirector>(); main_camera_object = GameObject.Find("Main Camera"); ftrack = timeline.CreateTrack <CinemachineTrack>(null, "film_track"); ctrack = timeline.CreateTrack <ControlTrack>(null, "control_track"); ntrack = timeline.CreateTrack <PlayableTrack>(null, "nav_track"); ptrack = timeline.CreateTrack <PlayableTrack>(null, "timetravel_track"); pos_track = timeline.CreateTrack <ControlTrack>(null, "pos_track"); foreach (DiscourseClip clip in dc.Clips) { if (clip.Type.Equals("cam_custom")) { populateCustom(clip); } else if (clip.Type.Equals("nav_cam")) { populateNavCam(clip); } else if (clip.Type.Equals("nav_virtual")) { populateNavVirtual(clip); } // cam_timeline cannot time travel else if (clip.Type.Equals("cam_timeline")) { populateCamObject(clip); } else if (clip.Type.Equals("cntrl_timeline")) { populateCtrlObject(clip); if (clip.fabulaStart >= 0f) { addTimeTravel(clip); } } else { Debug.Log("What TYPE of discourse clip is this?"); } } director.SetGenericBinding(ftrack, main_camera_object); director.Play(timeline); }
// triggered when the generated button is clicked public void OnGenerateClicked() { storyCreator.storyManager.CreateNewBranch("new", 0.0); storyCreator.storyManager.DoChoice(0); storyCreator.timelineManager.AddTrack(new AnimationTrack(), storyCreator.actor); CinemachineTrack cameraTrack = storyCreator.timelineManager.AddTrack(new CinemachineTrack(), "Camera") as CinemachineTrack; CinemachineShot cameraClip = storyCreator.timelineManager.AddCustomClipWithInitialTime(cameraTrack, 0) as CinemachineShot; storyCreator.ResetActioPosition(); for (int i = 0; i < operationPanel.childCount - 2; i++) { int option = operationPanel.GetChild(i).GetComponent <Dropdown>().value; if (animationList[option] != "None") { storyCreator.timelineManager.AddAnimationClip(TSEiAResourceManager.GetAnimation(animationList[option]), storyCreator.actor, -0.1, false); } } storyCreator.timelineManager.StartTimeline(); }
public void BindToPlayableDirector(PlayableDirector playableDirector) { foreach (var output in playableDirector.playableAsset.outputs) { Binding binding = null; if (output.sourceObject is CinemachineTrack) { CinemachineTrack cinemachineTrack = output.sourceObject as CinemachineTrack; if (bindingMap.TryGetValue(cinemachineTrack.name, out binding)) { playableDirector.SetGenericBinding(cinemachineTrack, binding.cinemachineBrain); } foreach (var clip in cinemachineTrack.GetClips()) { if (bindingMap.TryGetValue(clip.displayName, out binding)) { var cinemachineShot = clip.asset as CinemachineShot; playableDirector.SetReferenceValue(cinemachineShot.VirtualCamera.exposedName, binding.cinemachineVCam); } } } else if (output.sourceObject is AnimationTrack) { AnimationTrack animationTrack = output.sourceObject as AnimationTrack; if (bindingMap.TryGetValue(animationTrack.name, out binding)) { playableDirector.SetGenericBinding(animationTrack, binding.animator); } } else if (output.sourceObject != null) { if (bindingMap.TryGetValue(output.sourceObject.name, out binding)) { playableDirector.SetGenericBinding(output.sourceObject, binding.gameObject); } } } }
bool Process(TimelineInfo timelineInfo) { var timelineState = EntityManager.GetComponentData <TimelineState>(timelineInfo.Owner); bool isCanInterrupt = timelineState.InterruptStatus == TimelineState.InterruptState.Allow; if (!isCanInterrupt) { return(false); } ResourceManager.GetInstance().LoadAsset <PlayableAsset>(timelineInfo.ResPath, delegate(UnityEngine.Object[] objs) { if (objs == null || objs.Length <= 0) { return; } var entity = timelineInfo.Owner; var playerDirector = EntityManager.GetComponentObject <PlayableDirector>(entity); playerDirector.Stop(); playerDirector.playableAsset = objs[0] as PlayableAsset; var looksInfo = EntityManager.GetComponentData <LooksInfo>(entity); if (looksInfo.CurState != LooksInfo.State.Loaded) { return; } var looksEntity = looksInfo.LooksEntity; var animator = EntityManager.GetComponentObject <Animator>(looksEntity); foreach (var at in playerDirector.playableAsset.outputs) { if (at.sourceObject.GetType() == typeof(AnimationTrack)) { playerDirector.SetGenericBinding(at.sourceObject, animator); } else if (at.sourceObject.GetType() == typeof(CinemachineTrack)) { CinemachineBrain mainCamBrian = SceneMgr.Instance.MainCameraTrans.GetComponent <Cinemachine.CinemachineBrain>();//将主摄像机传入 playerDirector.SetGenericBinding(at.sourceObject, mainCamBrian); CinemachineTrack cinemachineTrack = (CinemachineTrack)at.sourceObject; int idx = 0; try { foreach (var c in cinemachineTrack.GetClips()) { CinemachineShot shot = (CinemachineShot)c.asset; // playerDirector.SetReferenceValue(shot.VirtualCamera.exposedName, vCams[idx++]); } } catch (Exception) { Debug.LogError("Clip Num InEqual Cam Num"); } } else if (at.streamName.StartsWith("ParticleTrack")) { var nameParts = at.streamName.Split('_'); var hangPointName = "root"; if (nameParts.Length > 1) { hangPointName = nameParts[1]; } var ct = at.sourceObject as ControlTrack; var looksTrans = EntityManager.GetComponentObject <Transform>(looksEntity); var particleParent = looksTrans.Find(hangPointName); foreach (var info in ct.GetClips()) { var cpa = info.asset as ControlPlayableAsset; playerDirector.SetReferenceValue(cpa.sourceGameObject.exposedName, particleParent.gameObject); } } // Debug.Log("timelineInfo.Param != null : "+(timelineInfo.Param != null).ToString()); if (timelineInfo.Param != null) { var nameParts = at.streamName.Split('_'); // Debug.Log("nameParts : "+nameParts[0]); if (timelineInfo.Param.ContainsKey(nameParts[0])) { var ta = at.sourceObject as TrackAsset; foreach (var info in ta.GetClips()) { // var cpa = info.asset as ScriptPlayable<>; var cpa = info.asset as ParamPlayableAsset; Debug.Log("cpa != null : " + (cpa != null).ToString()); if (cpa != null) { cpa.Param = timelineInfo.Param[nameParts[0]]; } else { Debug.LogError("error : trying to set param with no param playable asset name : " + at.streamName); } } } } } playerDirector.Play(); }); return(true); }