/// <summary>Tweens a RectTransform's anchoredPosition to the given value, while also applying a jump effect along the Y axis. /// Returns a Sequence instead of a Tweener. /// Also stores the RectTransform as the tween's target so it can be used for filtered operations</summary> /// <param name="endValue">The end value to reach</param> /// <param name="jumpPower">Power of the jump (the max height of the jump is represented by this plus the final Y offset)</param> /// <param name="numJumps">Total number of jumps</param> /// <param name="duration">The duration of the tween</param> /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param> public static Sequence DOJumpAnchorPos(this RectTransform target, Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) { if (numJumps < 1) { numJumps = 1; } float startPosY = 0; float offsetY = -1; bool offsetYSet = false; // Separate Y Tween so we can elaborate elapsedPercentage on that insted of on the Sequence // (in case users add a delay or other elements to the Sequence) Sequence s = DOTween.Sequence(); Tween yTween = DOTween.To(() => target.anchoredPosition, x => target.anchoredPosition = x, new Vector2(0, jumpPower), duration / (numJumps * 2)) .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative() .SetLoops(numJumps * 2, LoopType.Yoyo) .OnStart(() => startPosY = target.anchoredPosition.y); s.Append(DOTween.To(() => target.anchoredPosition, x => target.anchoredPosition = x, new Vector2(endValue.x, 0), duration) .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) ).Join(yTween) .SetTarget(target).SetEase(DOTween.defaultEaseType); s.OnUpdate(() => { if (!offsetYSet) { offsetYSet = true; offsetY = s.isRelative ? endValue.y : endValue.y - startPosY; } Vector2 pos = target.anchoredPosition; pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad); target.anchoredPosition = pos; }); return(s); }
public static Sequence DOLocalJump(this Transform target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) { if (numJumps < 1) { numJumps = 1; } float offsetY = endValue.y - target.localPosition.y; Sequence s = DOTween.Sequence().Append(DOTween.To(() => target.localPosition, delegate(Vector3 x) { target.localPosition = x; }, new Vector3(endValue.x, 0f, 0f), duration).SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)).Join(DOTween.To(() => target.localPosition, delegate(Vector3 x) { target.localPosition = x; }, new Vector3(0f, 0f, endValue.z), duration).SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear)).Join(DOTween.To(() => target.localPosition, delegate(Vector3 x) { target.localPosition = x; }, new Vector3(0f, jumpPower, 0f), duration / (float)(numJumps * 2)).SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetLoops(numJumps * 2, LoopType.Yoyo)).SetTarget(target).SetEase(DOTween.defaultEaseType); s.OnUpdate(delegate { Vector3 localPosition = target.localPosition; localPosition.y += DOVirtual.EasedValue(0f, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad); target.localPosition = localPosition; }); return(s); }
static int OnUpdate(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); DG.Tweening.Sequence obj = (DG.Tweening.Sequence)ToLua.CheckObject(L, 1, typeof(DG.Tweening.Sequence)); DG.Tweening.TweenCallback arg0 = null; LuaTypes funcType2 = LuaDLL.lua_type(L, 2); if (funcType2 != LuaTypes.LUA_TFUNCTION) { arg0 = (DG.Tweening.TweenCallback)ToLua.CheckObject(L, 2, typeof(DG.Tweening.TweenCallback)); } else { LuaFunction func = ToLua.ToLuaFunction(L, 2); arg0 = DelegateFactory.CreateDelegate(typeof(DG.Tweening.TweenCallback), func) as DG.Tweening.TweenCallback; } DG.Tweening.Tween o = obj.OnUpdate(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public static Sequence DOJumpAnchorPos(this RectTransform target, Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) { if (numJumps < 1) { numJumps = 1; } float startPosY = target.anchoredPosition.y; float offsetY = -1f; bool offsetYSet = false; Sequence s = DOTween.Sequence().Append(DOTween.To(() => target.anchoredPosition, delegate(Vector2 x) { target.anchoredPosition = x; }, new Vector2(endValue.x, 0f), duration).SetOptions(AxisConstraint.X, snapping).SetEase <Tweener>(Ease.Linear)).Join(DOTween.To(() => target.anchoredPosition, delegate(Vector2 x) { target.anchoredPosition = x; }, new Vector2(0f, jumpPower), duration / ((float)(numJumps * 2))).SetOptions(AxisConstraint.Y, snapping).SetEase <Tweener>(Ease.OutQuad).SetLoops <Tweener>((numJumps * 2), LoopType.Yoyo).SetRelative <Tweener>()).SetTarget <Sequence>(target).SetEase <Sequence>(DOTween.defaultEaseType); s.OnUpdate <Sequence>(delegate { if (!offsetYSet) { offsetYSet = true; offsetY = s.isRelative ? endValue.y : (endValue.y - startPosY); } Vector2 anchoredPosition = target.anchoredPosition; anchoredPosition.y += DOVirtual.EasedValue(0f, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad); target.anchoredPosition = anchoredPosition; }); return(s); }
static int QPYX_OnUpdate_YXQP(IntPtr L_YXQP) { try { ToLua.CheckArgsCount(L_YXQP, 2); DG.Tweening.Sequence QPYX_obj_YXQP = (DG.Tweening.Sequence)ToLua.CheckObject(L_YXQP, 1, typeof(DG.Tweening.Sequence)); DG.Tweening.TweenCallback QPYX_arg0_YXQP = (DG.Tweening.TweenCallback)ToLua.CheckDelegate <DG.Tweening.TweenCallback>(L_YXQP, 2); DG.Tweening.Tween QPYX_o_YXQP = QPYX_obj_YXQP.OnUpdate(QPYX_arg0_YXQP); ToLua.PushObject(L_YXQP, QPYX_o_YXQP); return(1); } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static int OnUpdate(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); DG.Tweening.Sequence obj = (DG.Tweening.Sequence)ToLua.CheckObject(L, 1, typeof(DG.Tweening.Sequence)); DG.Tweening.TweenCallback arg0 = (DG.Tweening.TweenCallback)ToLua.CheckDelegate <DG.Tweening.TweenCallback>(L, 2); DG.Tweening.Tween o = obj.OnUpdate(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int _m_OnUpdate(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); DG.Tweening.Sequence __cl_gen_to_be_invoked = (DG.Tweening.Sequence)translator.FastGetCSObj(L, 1); try { { DG.Tweening.TweenCallback action = translator.GetDelegate <DG.Tweening.TweenCallback>(L, 2); DG.Tweening.Tween __cl_gen_ret = __cl_gen_to_be_invoked.OnUpdate(action); translator.Push(L, __cl_gen_ret); return(1); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } }
void Start() { _initialized = true; _isRadioButton = _toggleGroupid != ""; List<IHOtk2dBase> childrenSprites = null; bool hasChildrenToTween = false; bool hasTextMeshesToTween = false; if (_tweenChildren && _tweenColorOn != ButtonActionType.None) { Component[] children = gameObject.GetComponentsInChildren(typeof(IHOtk2dBase)); childrenSprites = new List<IHOtk2dBase>(); foreach (Component child in children) { if (child == sprite) continue; childrenSprites.Add(child as IHOtk2dBase); IHOtk2dTextMesh txtMesh = child as IHOtk2dTextMesh; if (txtMesh != null) _txtMeshesToUpdate.Add(txtMesh); } hasChildrenToTween = childrenSprites.Count > 0; hasTextMeshesToTween = _txtMeshesToUpdate.Count > 0; } // Hide eventual tooltip if (_tooltip != null) { _tooltip.SetActive(false); _showTooltip = true; } // Create tweens if (hasRollover) { _rolloutTween = DOTween.Sequence().SetUpdate(true).SetAutoKill(false) .OnKill(() =>_rolloutTween = null) .Pause(); if (hasTextMeshesToTween) _rolloutTween.OnUpdate(UpdateTextMeshes); if (_tweenScaleOn == ButtonActionType.OnRollover) _rolloutTween.Insert(0, trans.DOScale(trans.localScale * _tweenScaleMultiplier, _TweenDuration).From()); if (_tweenColorOn == ButtonActionType.OnRollover) { _rolloutTween.Insert(0, DOTween.To(() => sprite.color, x => sprite.color = x, _tweenColor, _TweenDuration).From()); if (hasChildrenToTween) { foreach (IHOtk2dBase childSprite in childrenSprites) { IHOtk2dBase s = childSprite; _rolloutTween.Insert(0, DOTween.To(() => s.color, x => s.color = x, _tweenColor, _TweenDuration).From()); } } } _rolloutTween.Complete(); } if (_tweenColorOn == ButtonActionType.OnPress || _tweenScaleOn == ButtonActionType.OnPress) { _unpressTween = DOTween.Sequence().SetUpdate(true).SetAutoKill(false) .OnKill(() => _unpressTween = null) .Pause(); if (hasTextMeshesToTween) _unpressTween.OnUpdate(UpdateTextMeshes); if (_tweenScaleOn == ButtonActionType.OnPress) _unpressTween.Insert(0, trans.DOScale(trans.localScale * _tweenScaleMultiplier, _TweenDuration).From()); if (_tweenColorOn == ButtonActionType.OnPress) { _unpressTween.Insert(0, DOTween.To(() => sprite.color, x => sprite.color = x, _tweenColor, _TweenDuration).From()); if (hasChildrenToTween) { foreach (IHOtk2dBase childSprite in childrenSprites) { IHOtk2dBase s = childSprite; _rolloutTween.Insert(0, DOTween.To(() => s.color, x => s.color = x, _tweenColor, _TweenDuration).From()); } } } _unpressTween.Complete(); } if (_tweenColorOn == ButtonActionType.OnClick || _tweenScaleOn == ButtonActionType.OnClick) { _unclickTween = DOTween.Sequence().SetUpdate(true).SetAutoKill(false) .OnKill(() => _unclickTween = null) .Pause(); if (hasTextMeshesToTween) _unclickTween.OnUpdate(UpdateTextMeshes); if (_tweenScaleOn == ButtonActionType.OnClick) _unclickTween.Insert(0.15f, trans.DOScale(trans.localScale * _tweenScaleMultiplier, _TweenDuration).From()); if (_tweenColorOn == ButtonActionType.OnClick) { _unclickTween.Insert(0.15f, DOTween.To(() => sprite.color, x => sprite.color = x, _tweenColor, _TweenDuration).From()); if (hasChildrenToTween) { foreach (IHOtk2dBase childSprite in childrenSprites) { IHOtk2dBase s = childSprite; _rolloutTween.Insert(0, DOTween.To(() => s.color, x => s.color = x, _tweenColor, _TweenDuration).From()); } } } _unclickTween.Complete(); } // Execute eventual cued actions if (_preinitActionsQueue != null) { foreach (PreinitActionType visualActionType in _preinitActionsQueue) { switch (visualActionType) { case PreinitActionType.ToggleOn: ToggleOn(); break; case PreinitActionType.ToggleOnWithoutEventDispatching: ToggleOn(false); break; case PreinitActionType.ToggleOff: ToggleOff(); break; case PreinitActionType.ToggleOffWithoutEventDispatching: ToggleOff(false); break; } } } }