网站建设首页包括什么,印度域名注册网站,100深夜看黄禁用免费,建设政务网站报告1、命名法
Tweener#xff08;补间器#xff09;#xff1a;一种控制某个值并对其进行动画处理的补间。 Sequence#xff08;序列#xff09;#xff1a;一种特殊的补间#xff0c;它不直接控制某个值#xff0c;而是控制其他补间并将它们作为一个组进行动画处理。 Tw…1、命名法
Tweener补间器一种控制某个值并对其进行动画处理的补间。 Sequence序列一种特殊的补间它不直接控制某个值而是控制其他补间并将它们作为一个组进行动画处理。 Tween补间一个通用术语既指代 Tweener 也指代 Sequence。 Nested tween嵌套补间包含在 Sequence 中的补间。 前缀 前缀对于充分利用 IntelliSense 非常重要所以尽量记住这些 DO 前缀用于所有补间快捷方式可以从已知对象如变换或材质直接启动的操作。
transform.DOMoveX(100, 1);
transform.DORestart();
DOTween.Play();
Set所有可以链接到补间的设置除了 From因为它作为设置应用但并不真正属于设置的前缀。
myTween.SetLoops(4, LoopType.Yoyo).SetSpeedBased();
On 用于所有可以链接到补间的回调函数。
myTween.OnStart(myStartFunction).OnComplete(myCompleteFunction);
2、DOTween.Init 首次创建补间时DOTween 会使用默认值自动初始化自身。如果你希望手动初始化它推荐请在创建任何补间之前调用一次此方法之后调用将不会有任何效果。请注意你仍然可以通过 DOTween 的全局设置随时更改所有初始化设置。另外你可以将 SetCapacity 方法链接到 Init 方法上这允许设置 Tweeners/Sequences 的初始容量这与稍后调用 DOTween.SetTweensCapacity 是相同的。 public static IDOTweenInit Init(bool? recycleAllByDefault null, bool? useSafeMode null, LogBehaviour? logBehaviour null); 初始化 DOTween。调用时不带任何参数以使用你在 DOTween 的工具面板中设置的首选项否则这些首选项将被传递的任何参数覆盖。 recycleAllByDefault如果为 TRUE则所有新的补间都将被设置为可回收这意味着当它们被销毁时不会真正销毁而是会被放入池中并重用而不是创建新的补间。此选项允许你通过重用补间来避免垃圾回收分配但你需要小心处理补间引用因为即使补间已被销毁它们也可能依然活跃因为它们可能已经被重新生成并作为完全不同的补间在使用。 如果你希望在补间被销毁时自动将其引用设置为 NULL可以使用 OnKill 回调如下所示 // 使用 OnKill 回调自动将补间引用设置为 NULL
myTween.OnKill(() myTween null);
你可以随时通过更改静态属性 DOTween.defaultRecyclable 来修改此设置或者你可以使用 SetRecyclable 为每个补间单独设置回收行为。 useSafeMode如果设置为 TRUE补间会稍微慢一些但更安全允许 DOTween 自动处理诸如在补间运行时目标被销毁的情况。 警告在 iOS 上safeMode 仅在剥离级别设置为 Strip Assemblies 或脚本调用优化设置为 Slow and Safe 时有效而在 Windows 10 WSA 上如果选择了 Master Configuration 和 .NET则不会生效。 logBehaviour根据所选模式DOTween 将记录仅错误、错误和警告或所有信息加上附加信息。
// 示例 A使用 DOTween 的工具面板中设置的首选项进行初始化
DOTween.Init();
// 示例 B使用自定义设置进行初始化并立即设置容量
DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10);
3、创建一个Tweener
截至目前DOTween可以补间这些类型的值 floatdoubleintuintlongulongVector2 / 3/4QuaternionRectRectOffsetColorstring 其中一些值可以通过特殊方式进行补间 此外您可以创建自定义DOTween插件以补间自定义值类型。
有3种方法来创建一个Tweener在通用的方式快捷方式和更多的通用方式。
A. 通用方式
这是最灵活的补间方式允许你几乎任何值公共或私有静态或动态 只是你知道快捷方式实际上在后台使用通用方式。
与快捷方式一样通用方式具有FROM备用版本。只需将From链接到Tweener使补间表现为FROM补间而不是TO补间。
static DOTween.Togettersettertofloat duration
B. 快捷方式
DOTween包含一些已知Unity对象的快捷方式如TransformRigidbody和Material。您可以直接从对这些对象的引用启动补间这也将自动将对象本身设置为补间目标如 transform.DOMove(new Vector3(2,3,4), 1);rigidbody.DOMove(new Vector3(2,3,4), 1);material.DOColor(Color.green, 1);
除非另有说明否则这些快捷方式中的每一个都具有FROM备用版本。只需将From链接到Tweener使补间表现为FROM补间而不是TO补间。
重要提示当您将一个FROM分配给补间时目标将立即跳转到FROM位置就像“编写该行代码的那一刻”而不是“补间开始的那一刻”。 transform.DOMove(new Vector3(2,3,4), 1).From();rigidbody.DOMove(new Vector3(2,3,4), 1).From();material.DOColor(Color.green, 1).From();
AudioSource
DOFade(float to, float duration) DOPitch(float to, float duration)
Camera
DOAspect(float to, float duration) DOColor(Color to, float duration) DOFarClipPlane(float to, float duration) DOFieldOfView(float to, float duration) DONearClipPlane(float to, float duration) DOOrthoSize(float to, float duration) DOPixelRect(Rect to, float duration) DORect(Rect to, float duration) DOShakePosition(float duration, float/Vector3 strength, int vibrato, bool fadeOut) DOShakeRotation(float duration, float/Vector3 strength, int vibrato, float randomness bool fadeOut)
Light
DOColor(Color to, float duration) DOIntensity(float to, float duration) DOShadowStrength(float to, float duration) 可混合的补间 DOBlendableColor(Color to, float duration)
LineRenderer DOColor(Color2 startValue, Color2 endValue, float duration)
Material
DOColor(Color to, float duration) DOColor(Color to, string property, float duration) DOFade(float to, float duration) DOFade(float to, string property, float duration) DOFloat(float to, string property, float duration) DOGradientColor(Gradient to, float duration) DOGradientColor(Gradient to, string property, float duration) DOOffset(Vector2 to, float duration) DOOffset(Vector2 to, string property, float duration) DOTiling(Vector2 to, float duration) DOTiling(Vector2 to, string property, float duration) DOVector(Vector4 to, string property, float duration) 可混合的补间 DOBlendableColor(Color to, float duration) DOBlendableColor(Color to, string property, float duration)
Rigidbody这些快捷方式在后台使用刚体的MovePosition / MoveRotation方法以正确设置与物理对象相关的内容。
DOMoveVector3 tofloat durationbool snapping DOMoveX / DOMoveY / DOMoveZfloat tofloat durationbool snapping DOJumpVector3 endValuefloat jumpPowerint numJumpsfloat durationbool snapping DORotate(Vector3 to, float duration, RotateMode mode) DOLookAt(Vector3 towards, float duration, AxisConstraint axisConstraint AxisConstraint.None, Vector3 up Vector3.up) PRO ONLY ➨ Spiral – no FROM DOSpiral(float duration, Vector3 axis null, SpiralMode mode SpiralMode.Expand, float speed 1, float frequency 10, float depth 0, bool snapping false)
SpriteRenderer
DOColor(Color to, float duration) DOFade(float to, float duration) DOGradientColor(Gradient to, float duration)
C. 其他通用方法
这些是允许以特定方式补间值的其他通用方法。这些也有FROM备用版本除非另有说明。只需将From链接到Tweener使补间表现为FROM补间而不是TO补间。
static DOTween.Punch(getter, setter, Vector3 direction, float duration, int vibrato, float elasticity)
static DOTween.Shake(getter, setter, float duration, float/Vector3 strength, int vibrato, float randomness, bool ignoreZAxis)
static DOTween.ToAlpha(getter, setter, float to, float duration)
static DOTween.ToArray(getter, setter, float to, float duration)
static DOTween.ToAxis(getter, setter, float to, float duration, AxisConstraint axis)
4、创建序列
序列类似于Tweeners但它们不是动画属性或值而是将其他Tweeners或Sequences作为一组动画。序列可以包含在其他序列中而不限制层次结构的深度。排序的补间不必一个接一个。您可以使用Insert方法重叠补间。
补间序列或Tweener只能嵌套在单个其他序列中这意味着您不能在多个序列中重用相同的补间。此外主序列将控制其所有嵌套元素并且您将无法单独控制嵌套补间将序列视为电影时间轴一旦它第一次启动就会变为固定。
重要提示不要使用空序列。
1.获取要使用的新序列并将其存储为引用 static DOTween.Sequence
2.将补间间隔和回调添加到序列
请注意所有这些方法都需要在序列开始之前应用通常是在创建它之后的下一帧除非它已暂停否则它们将没有任何效果。另请注意任何嵌套的Tweener / Sequence都需要在将其添加到Sequence之前完全创建因为之后它将被锁定。 Append(Tween tween)AppendCallback(TweenCallback callback)AppendInterval(float interval)Insert(float atPosition, Tween tween)InsertCallback(float atPosition, TweenCallback callback)Join(Tween tween)Prepend(Tween tween)PrependCallback(TweenCallback callback)PrependInterval(float interval) // 创建一个 Sequence
Sequence mySequence DOTween.Sequence();// 在 Sequence 的开头添加一个 1 秒的延迟
mySequence.PrependInterval(1);// 在 Sequence 的末尾添加一个移动 Tween物体将在 X 轴上移动到 45耗时 1 秒
mySequence.Append(transform.DOMoveX(45, 1));// 在移动 Tween 完成后添加一个旋转 Tween物体将旋转到 (0, 180, 0) 的角度耗时 1 秒
mySequence.Append(transform.DORotate(new Vector3(0, 180, 0), 1));// 在 Sequence 的 0 秒处插入一个缩放 Tween物体将缩放到 (3, 3, 3) 的大小持续整个 Sequence 的时长
mySequence.Insert(0, transform.DOScale(new Vector3(3, 3, 3), mySequence.Duration()));动画流程
延迟 1 秒Sequence 开始前会等待 1 秒。
移动动画物体在 X 轴上从当前位置移动到 45耗时 1 秒。
旋转动画物体旋转到 (0, 180, 0) 的角度耗时 1 秒。
缩放动画物体从 Sequence 开始时就逐渐缩放到 (3, 3, 3) 的大小持续整个 Sequence 的时长。Sequence mySequence DOTween.Sequence();mySequence.Append(transform.DOMoveX(45, 1)).Append(transform.DORotate(new Vector3(0,180,0), 1)).PrependInterval(1).Insert(0, transform.DOScale(new Vector3(3,3,3), mySequence.Duration()));
5、设置选项和回调
在将设置应用于补间时DOTween使用链接方法。或者您可以更改将应用于所有新创建的补间的全局默认选项。
全局设置 static LogBehaviour DOTween.logBehaviourstatic bool DOTween.maxSmoothUnscaledTimestatic bool DOTween.showUnityEditorReportstatic float DOTween.timeScalestatic bool DOTween.useSafeModestatic bool DOTween.useSmoothDeltaTimestatic DOTween.SetTweensCapacity(int maxTweeners, int maxSequences)
应用于所有新创建的补间的设置 static bool DOTween.defaultAutoKillstatic AutoPlay DOTween.defaultAutoPlaystatic float DOTween.defaultEaseOvershootOrAmplitudestatic float DOTween.defaultEasePeriodstatic Ease DOTween.defaultEaseTypestatic LoopType DOTween.defaultLoopTypestatic bool DOTween.defaultRecyclablestatic bool DOTween.defaultTimeScaleIndependentstatic UpdateType DOTween.defaultUpdateType
Tweener 和 Sequence 设置 SetAs(Tween tween \ TweenParams tweenParams)SetAutoKill(bool autoKillOnCompletion true)SetEase(Ease easeType \ AnimationCurve animCurve \ EaseFunction customEase)SetId(object id)SetLoops(int loops, LoopType loopType LoopType.Restart)SetRecyclable(bool recyclable)SetRelative(bool isRelative true)SetUpdate(UpdateType updateType, bool isIndependentUpdate false) OnComplete(TweenCallback callback)OnKill(TweenCallback callback)OnPlay(TweenCallback callback)OnPause(TweenCallback callback)OnRewind(TweenCallback callback)OnStart(TweenCallback callback)OnStepComplete(TweenCallback callback)OnUpdate(TweenCallback callback)OnWaypointChange(TweenCallbackint callback)
特定于Tweener的设置和选项
这些设置特定于Tweeners对序列没有影响。 除了SetEase在补间运行时链接这些设置将不起作用。 From(bool isRelative false)SetDelay(float delay)SetSpeedBased(bool isSpeedBased true)
需要记住的重要一点是虽然所有其他设置可以按任何顺序链接在一起但SetOptions 必须在补间创建功能之后立即链接否则它将不再可用。
DOPath特定选项 Path tween ➨ SetOptions(bool closePath, AxisConstraint lockPosition AxisConstraint.None, AxisConstraint lockRotation AxisConstraint.None)Path tween ➨ SetLookAt(Vector3 lookAtPosition/lookAtTarget/lookAhead, Vector3 forwardDirection, Vector3 up Vector3.up)
6、路径动画 API
1. 路径动画概述
路径动画允许物体沿着指定的路径移动。Dotween 提供了两种主要的路径动画方式 使用 DOPath 物体沿着路径移动但不会调整自身方向。 使用 DOLocalPath 物体沿着局部路径移动。 使用 DOPath 和 PathType.CatmullRom 使用 Catmull-Rom 样条曲线生成平滑路径。
2.解析
2.1 transform.DOPath
让物体沿着指定的路径点移动。
参数 path (Vector3[]): 路径点的数组。 duration (float): 动画持续时间。 pathType (PathType): 路径类型默认为直线路径PathType.Linear。 pathMode (PathMode): 路径模式默认为 3D 路径PathMode.Full3D。 resolution (int): 路径分辨率默认为 10。 gizmoColor (Color): 在 Scene 视图中绘制路径的颜色。
// 定义路径点
Vector3[] pathPoints new Vector3[] {new Vector3(0, 0, 0),new Vector3(5, 5, 0),new Vector3(10, 0, 0)
};// 让物体沿着路径移动耗时 3 秒
transform.DOPath(pathPoints, 3, PathType.CatmullRom).SetEase(Ease.Linear).OnComplete(() Debug.Log(路径动画完成));
2.2 transform.DOLocalPath
让物体沿着局部坐标系下的路径移动。
参数 与 DOPath 相同。
// 定义局部路径点
Vector3[] localPathPoints new Vector3[] {new Vector3(0, 0, 0),new Vector3(2, 2, 0),new Vector3(4, 0, 0)
};// 让物体沿着局部路径移动耗时 2 秒
transform.DOLocalPath(localPathPoints, 2, PathType.CatmullRom).SetEase(Ease.Linear);
2.3 transform.DOPath 的 LookAt 功能
让物体在移动时始终朝向路径方向。
参数 lookAhead (float): 向前看的位置偏移量默认为 0.01。 forwardDirection (Vector3): 物体的前方方向默认为 Vector3.forward。 up (Vector3): 物体的上方方向默认为 Vector3.up。
// 让物体沿着路径移动并始终朝向路径方向
transform.DOPath(pathPoints, 3, PathType.CatmullRom).SetLookAt(0.01f) // 朝向路径方向.SetEase(Ease.Linear);
2.4 tween.PathLength
计算路径的长度。
2.5t ween.PathGetPoint
参数 t (float): 时间点0 到 1 之间。 void Test_06(){Vector3[] pathPoints new[] {new Vector3(0,1,0),new Vector3(0,2,0),new Vector3(0,3,0),new Vector3(0,4,0)};Tween tween transform.DOPath(pathPoints, 3, PathType.Linear);tween.ForceInit();float pathLength tween.PathLength();Debug.Log(路径长度: pathLength);// 获取路径上 50% 时间点的位置Vector3 point tween.PathGetPoint(0.5f);Debug.Log(路径中点位置: point);}
3. 路径动画的高级功能
3.1 自定义路径缓动
可以通过 SetEase 方法设置路径动画的缓动函数。
// 使用缓动函数
transform.DOPath(pathPoints, 3, PathType.CatmullRom).SetEase(Ease.InOutSine);
3.2 路径动画的循环
可以通过 SetLoops 方法设置路径动画的循环次数。
// 让路径动画循环 3 次
transform.DOPath(pathPoints, 3, PathType.CatmullRom).SetLoops(3, LoopType.Restart);
3.3 路径动画的回调
可以通过 OnComplete、OnStart、OnUpdate 等方法设置路径动画的回调。
// 设置路径动画的回调
transform.DOPath(pathPoints, 3, PathType.CatmullRom).OnStart(() Debug.Log(路径动画开始)).OnUpdate(() Debug.Log(路径动画进行中)).OnComplete(() Debug.Log(路径动画完成));
文章转载自: http://www.morning.jftl.cn.gov.cn.jftl.cn http://www.morning.mngh.cn.gov.cn.mngh.cn http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn http://www.morning.mbzlg.cn.gov.cn.mbzlg.cn http://www.morning.ywpcs.cn.gov.cn.ywpcs.cn http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.qjdqj.cn.gov.cn.qjdqj.cn http://www.morning.ryznd.cn.gov.cn.ryznd.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.rshkh.cn.gov.cn.rshkh.cn http://www.morning.gbxxh.cn.gov.cn.gbxxh.cn http://www.morning.xgzwj.cn.gov.cn.xgzwj.cn http://www.morning.dnpft.cn.gov.cn.dnpft.cn http://www.morning.tnjff.cn.gov.cn.tnjff.cn http://www.morning.txnqh.cn.gov.cn.txnqh.cn http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn http://www.morning.rhjhy.cn.gov.cn.rhjhy.cn http://www.morning.ptqbt.cn.gov.cn.ptqbt.cn http://www.morning.saastob.com.gov.cn.saastob.com http://www.morning.wfbs.cn.gov.cn.wfbs.cn http://www.morning.ymqrc.cn.gov.cn.ymqrc.cn http://www.morning.alive-8.com.gov.cn.alive-8.com http://www.morning.rfgc.cn.gov.cn.rfgc.cn http://www.morning.lfmwt.cn.gov.cn.lfmwt.cn http://www.morning.nrzbq.cn.gov.cn.nrzbq.cn http://www.morning.klyyd.cn.gov.cn.klyyd.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.yhwxn.cn.gov.cn.yhwxn.cn http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.kfwrq.cn.gov.cn.kfwrq.cn http://www.morning.lsgjf.cn.gov.cn.lsgjf.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn http://www.morning.qyqmj.cn.gov.cn.qyqmj.cn http://www.morning.gjsjt.cn.gov.cn.gjsjt.cn http://www.morning.mwjwy.cn.gov.cn.mwjwy.cn http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn http://www.morning.zsgbt.cn.gov.cn.zsgbt.cn http://www.morning.dzrcj.cn.gov.cn.dzrcj.cn http://www.morning.fbjnr.cn.gov.cn.fbjnr.cn http://www.morning.hnrdtz.com.gov.cn.hnrdtz.com http://www.morning.hwxxh.cn.gov.cn.hwxxh.cn http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn http://www.morning.gydth.cn.gov.cn.gydth.cn http://www.morning.qpsdq.cn.gov.cn.qpsdq.cn http://www.morning.wklmj.cn.gov.cn.wklmj.cn http://www.morning.smmby.cn.gov.cn.smmby.cn http://www.morning.lswgs.cn.gov.cn.lswgs.cn http://www.morning.drrt.cn.gov.cn.drrt.cn http://www.morning.pbknh.cn.gov.cn.pbknh.cn http://www.morning.ttryd.cn.gov.cn.ttryd.cn http://www.morning.smpmn.cn.gov.cn.smpmn.cn http://www.morning.glxdk.cn.gov.cn.glxdk.cn http://www.morning.clzly.cn.gov.cn.clzly.cn http://www.morning.yongkangyiyuan-pfk.com.gov.cn.yongkangyiyuan-pfk.com http://www.morning.alwpc.cn.gov.cn.alwpc.cn http://www.morning.jkcpl.cn.gov.cn.jkcpl.cn http://www.morning.nzhzt.cn.gov.cn.nzhzt.cn http://www.morning.dbqcw.com.gov.cn.dbqcw.com http://www.morning.bpmnl.cn.gov.cn.bpmnl.cn http://www.morning.klzt.cn.gov.cn.klzt.cn http://www.morning.jghty.cn.gov.cn.jghty.cn http://www.morning.gcqkb.cn.gov.cn.gcqkb.cn http://www.morning.qzdxy.cn.gov.cn.qzdxy.cn http://www.morning.fwcnx.cn.gov.cn.fwcnx.cn http://www.morning.hwlmy.cn.gov.cn.hwlmy.cn http://www.morning.wplbs.cn.gov.cn.wplbs.cn http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.btlmb.cn.gov.cn.btlmb.cn http://www.morning.gpnfg.cn.gov.cn.gpnfg.cn http://www.morning.kgcss.cn.gov.cn.kgcss.cn http://www.morning.pqbkk.cn.gov.cn.pqbkk.cn http://www.morning.gcxfh.cn.gov.cn.gcxfh.cn http://www.morning.tkzqw.cn.gov.cn.tkzqw.cn http://www.morning.ghpld.cn.gov.cn.ghpld.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.tlnkz.cn.gov.cn.tlnkz.cn http://www.morning.rxkl.cn.gov.cn.rxkl.cn http://www.morning.lywys.cn.gov.cn.lywys.cn http://www.morning.0dirty.cn.gov.cn.0dirty.cn http://www.morning.dtzxf.cn.gov.cn.dtzxf.cn