赞
踩
https://blogs.unity3d.com/cn/2018/09/05/extending-timeline-a-practical-guide/
https://blog.csdn.net/u011643463/article/details/82585846
Timeline已经很常用了,但是项目往往需要自定义timeline来实现一些可选的功能,如自定义景深,如果需要动态直观的的改变,就需要用到自定义timeline。这里是配合postproces v2来做的,unity版本2019.4.4 timeline是v1.2.14
unity提供了一个模板
直接填就好了很方便
\
// DofPlayableBehaviour.cs [System.Serializable] public class DofPlayableAsset : PlayableAsset { public PostProcessProfile VolumeProfile; public float FocusDistance; // Factory method that generates a playable based on this asset public override Playable CreatePlayable(PlayableGraph graph, GameObject go) { var playable = ScriptPlayable<DofPlayableBehaviour>.Create(graph); var dofBehaviour = playable.GetBehaviour(); //dofBehaviour.VolumeProfile = VolumeProfile.Resolve(graph.GetResolver()); dofBehaviour.VolumeProfile = VolumeProfile; dofBehaviour.Distance = FocusDistance; return playable; } }
这个脚本会挂到对应的Asset上
所以在Asset里去关联就好了
// DofPlayableBehaviour.cs public class DofPlayableBehaviour : PlayableBehaviour { public float Distance; public PostProcessProfile VolumeProfile; private DepthOfField m_DepthOfField; // Called when the owning graph starts playing public override void OnGraphStart(Playable playable) { VolumeProfile.TryGetSettings(out m_DepthOfField); } // Called when the owning graph stops playing public override void OnGraphStop(Playable playable) { } // Called when the state of the playable is set to Play public override void OnBehaviourPlay(Playable playable, FrameData info) { } // Called when the state of the playable is set to Paused public override void OnBehaviourPause(Playable playable, FrameData info) { } // Called each frame while the state is set to Play public override void PrepareFrame(Playable playable, FrameData info) { SetFoucusDistance(); } public void SetFoucusDistance() { m_DepthOfField.focusDistance.value = Distance; Debug.Log($"SetFoucusDistance {Distance}"); } }
要用到4个代码 (可见 不混合的方式还是比较简单的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。