protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { TMP_Text text = p_target.GetComponent <TMP_Text>(); if (CheckException(text, "No TMP_Text component found on target")) { return(null); } text.ForceMeshUpdate(); for (int i = 0; i < text.text.Length; i++) { TextMeshTweenUtils.Scale(text, i, 0); } float time = GetParameterValue(Model.time, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); float characterDelay = GetParameterValue(Model.characterDelay, p_flowData); for (int i = 0; i < text.text.Length; i++) { int index = i; // Rescope variable to avoid modified closure trap DashTween.To(text, 0, 1, time) .OnUpdate(f => TextMeshTweenUtils.Scale(text, index, f)) .SetDelay(index * characterDelay) .SetEase(easeType) .Start(); } return(DashTween.To(p_target, 0, 1, text.text.Length * characterDelay)); }
DashTween ExecuteAs(Image p_target, NodeFlowData p_flowData) { Color startColor = Model.useFrom ? GetParameterValue(Model.fromColor, p_flowData) : p_target.color; Color toColor = GetParameterValue <Color>(Model.toColor, p_flowData); float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); if (Model.storeToAttribute) { string attribute = GetParameterValue(Model.storeAttributeName, p_flowData); p_flowData.SetAttribute <Color>(attribute, p_target.color); } if (time == 0) { UpdateTween(p_target, 1, p_flowData, startColor, toColor); return(null); } else { return(DashTween.To(p_target, 0, 1, time) .OnUpdate(f => UpdateTween(p_target, f, p_flowData, startColor, toColor)) .SetDelay(delay).SetEase(easeType)); } }
override protected void OnExecuteStart(NodeFlowData p_flowData) { if (_activeTweens == null) { _activeTweens = new List <DashTween>(); } float time = GetParameterValue(Model.time, p_flowData); if (time == 0) { OnExecuteEnd(); OnExecuteOutput(0, p_flowData); } else { DashTween tween = DashTween.To(Graph.Controller, 0, 1, time); tween.OnComplete(() => { OnExecuteEnd(); OnExecuteOutput(0, p_flowData); _activeTweens.Remove(tween); }); _activeTweens.Add(tween); tween.Start(); } }
DashTween ExecuteAs(CanvasGroup p_target, NodeFlowData p_flowData) { float startAlpha = Model.useFrom ? Model.isFromRelative ? p_target.alpha + GetParameterValue(Model.fromAlpha, p_flowData) : GetParameterValue(Model.fromAlpha, p_flowData) : p_target.alpha; float toAlpha = GetParameterValue(Model.toAlpha, p_flowData); float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); if (Model.storeToAttribute) { string attribute = GetParameterValue(Model.storeAttributeName, p_flowData); p_flowData.SetAttribute <float>(attribute, p_target.alpha); } if (time == 0) { UpdateTween(p_target, 1, p_flowData, startAlpha, toAlpha, easeType); return(null); } else { return(DashTween.To(p_target, 0, 1, time) .OnUpdate(f => UpdateTween(p_target, f, p_flowData, startAlpha, toAlpha, easeType)) .SetDelay(delay)); } }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { Vector3 fromPosition = GetParameterValue <Vector3>(Model.fromPosition, p_flowData); Vector3 startPosition = Model.useFrom ? Model.isFromRelative ? p_target.position + fromPosition : fromPosition : p_target.position; if (Model.storeToAttribute) { string attribute = GetParameterValue(Model.storeAttributeName, p_flowData); p_flowData.SetAttribute <Vector3>(attribute, p_target.position); } Vector3 finalPosition = GetParameterValue <Vector3>(Model.toPosition, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); if (time == 0) { UpdateTween(p_target, 1, p_flowData, startPosition, finalPosition, easeType); return(null); } return(DashTween.To(p_target, 0, 1, time).SetDelay(delay) .OnUpdate(f => UpdateTween(p_target, f, p_flowData, startPosition, finalPosition, easeType))); }
protected override void ExecuteOnTarget(Transform p_target, NodeFlowData p_flowData) { if (_activeTweens == null) { _activeTweens = new List <DashTween>(); } if (p_target == null) { ExecuteEnd(p_flowData); return; } for (int i = 0; i < p_target.childCount; i++) { NodeFlowData childData = p_flowData.Clone(); childData.SetAttribute("target", p_target.GetChild(Model.inReverse ? p_target.childCount - 1 - i : i)); if (GetParameterValue(Model.onChildDelay, p_flowData) == 0) { OnExecuteOutput(0, childData); } else { float time = GetParameterValue(Model.onChildDelay, p_flowData) * i; DashTween tween = DashTween.To(Graph.Controller, 0, 1, time); tween.OnComplete(() => { _activeTweens.Remove(tween); OnExecuteOutput(0, childData); }); _activeTweens.Add(tween); tween.Start(); } } if (Model.onFinishDelay == 0 && GetParameterValue(Model.onChildDelay, p_flowData) == 0) { ExecuteEnd(p_flowData); } else { float time = Model.onFinishDelay + GetParameterValue(Model.onChildDelay, p_flowData) * p_target.childCount; DashTween tween = DashTween.To(Graph.Controller, 0, 1, time); tween.OnComplete(() => { _activeTweens.Remove(tween); ExecuteEnd(p_flowData); }); _activeTweens.Add(tween); tween.Start(); } }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { Transform targetTransform = p_target.transform; if (CheckException(targetTransform, "No RectTransform component found on target")) { return(null); } // TODO skip this if not using from rotation Vector3 fromRotation = GetParameterValue(Model.fromRotation, p_flowData); fromRotation.x = fromRotation.x > 180 ? fromRotation.x - 360 : fromRotation.x; fromRotation.y = fromRotation.y > 180 ? fromRotation.y - 360 : fromRotation.y; fromRotation.z = fromRotation.z > 180 ? fromRotation.z - 360 : fromRotation.z; Quaternion startRotation = Model.useFrom ? Model.isFromRelative ? targetTransform.rotation * Quaternion.Euler(fromRotation) : Quaternion.Euler(fromRotation) : targetTransform.rotation; if (Model.storeToAttribute) { string attribute = GetParameterValue(Model.storeAttributeName, p_flowData); p_flowData.SetAttribute <Quaternion>(attribute, targetTransform.rotation); } Vector3 toRotation = GetParameterValue <Vector3>(Model.toRotation, p_flowData); float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easing = GetParameterValue(Model.easeType, p_flowData); if (time == 0) { UpdateTween(targetTransform, 1, p_flowData, startRotation, toRotation, easing); return(null); } else { // Virtual tween to update from directly // Tween tween = DOTween // .To((f) => UpdateTween(targetTransform, f, p_flowData, startRotation, toRotation, easing), 0, // 1, time) // .SetDelay(delay) // .SetEase(Ease.Linear); return(DashTween.To(targetTransform, 0, 1, time) .SetDelay(delay) .OnUpdate(f => UpdateTween(targetTransform, f, p_flowData, startRotation, toRotation, easing))); } }
override protected DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); DashTween tween; if (Model.useDashAnimation) { if (Model.source == null) { SetError("Animation source cannot be null"); return(null); } CacheStarts(p_target); // Change time if we are using custom one time = Model.useAnimationTime ? Model.source.Duration : time; // Virtual tween to update from sampler tween = DashTween.To(p_target, 0, Model.source.Duration, time) .OnUpdate(f => UpdateFromAnimation(p_target, f)) .SetDelay(delay) .SetEase(easeType); } else { if (Model.clip == null) { SetError("Animation clip cannot be null"); return(null); } // Change time if we are using custom one time = Model.useAnimationTime ? Model.clip.length : time; // Virtual tween to update from sampler tween = DashTween.To(p_target, 0, Model.clip.length, time) .OnUpdate(f => UpdateFromClip(p_target, f)) .SetDelay(delay) .SetEase(easeType); } return(tween); }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { RectTransform rectTransform = (RectTransform)p_target; if (CheckException(rectTransform, "No RectTransform component found on target")) { return(null); } Transform towards = Model.toTarget.Resolve(Controller); if (CheckException(towards, "Towards not defined in node " + _model.id)) { return(null); } RectTransform rectTowards = towards.GetComponent <RectTransform>(); if (CheckException(rectTowards, "No RectTransform component found on towards")) { return(null); } Vector2 startPosition = rectTransform.anchoredPosition; Quaternion startRotation = rectTransform.localRotation; Vector3 startScale = rectTransform.localScale; float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); if (time == 0) { UpdateTween(rectTransform, 1, p_flowData, startPosition, startRotation, startScale, rectTowards, easeType); return(null); } else { // Virtual tween to update from directly return(DashTween.To(rectTransform, 0, 1, time) .OnUpdate(f => UpdateTween(rectTransform, f, p_flowData, startPosition, startRotation, startScale, rectTowards, easeType)) .SetDelay(delay)); } }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { Transform targetTransform = p_target.transform; if (CheckException(targetTransform, "No RectTransform component found on target")) { return(null); } Vector3 fromScale = GetParameterValue(Model.fromScale, p_flowData); Vector3 startScale = Model.useFrom ? Model.isFromRelative ? targetTransform.localScale + Model.fromScale.GetValue(ParameterResolver, p_flowData) : fromScale : targetTransform.localScale; if (Model.storeToAttribute) { string attribute = GetParameterValue(Model.storeAttributeName, p_flowData); p_flowData.SetAttribute <Vector3>(attribute, targetTransform.localScale); } Vector3 toScale = GetParameterValue(Model.toScale, p_flowData); float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); if (time == 0) { UpdateTween(targetTransform, 1, p_flowData, startScale, toScale, easeType); return(null); } else { // Virtual tween to update from directly return(DashTween.To(targetTransform, 0, 1, time) .OnUpdate(f => UpdateTween(targetTransform, f, p_flowData, startScale, toScale, easeType)) .SetDelay(delay)); } }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { RectTransform rectTransform = p_target.GetComponent <RectTransform>(); if (CheckException(rectTransform, "Target doesn't contain RectTransform")) { return(null); } Vector2 fromSizeDelta = GetParameterValue(Model.fromSizeDelta, p_flowData); Vector2 startSizeDelta = Model.useFrom ? Model.isFromRelative ? rectTransform.sizeDelta + fromSizeDelta : fromSizeDelta : rectTransform.sizeDelta; if (Model.storeToAttribute) { string attribute = GetParameterValue(Model.storeAttributeName, p_flowData); p_flowData.SetAttribute <Vector2>(attribute, rectTransform.sizeDelta); } Vector2 toSizeDelta = GetParameterValue(Model.toSizeDelta, p_flowData); float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); if (time == 0) { UpdateTween(rectTransform, 1, p_flowData, startSizeDelta, toSizeDelta, easeType); return(null); } else { // Virtual tween to update from directly return(DashTween.To(rectTransform, 0, 1, time).SetDelay(delay) .OnUpdate(f => UpdateTween(rectTransform, f, p_flowData, startSizeDelta, toSizeDelta, easeType))); } }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { RectTransform rectTransform = p_target.GetComponent <RectTransform>(); if (CheckException(rectTransform, "No RectTransform component found on target")) { return(null); } Vector2 fromPosition = GetParameterValue <Vector2>(Model.fromPosition, p_flowData); Vector2 startPosition = Model.useFrom ? Model.isFromRelative ? rectTransform.anchoredPosition + fromPosition : fromPosition : rectTransform.anchoredPosition; if (Model.storeToAttribute) { string attribute = GetParameterValue(Model.storeAttributeName, p_flowData); p_flowData.SetAttribute <Vector2>(attribute, rectTransform.anchoredPosition); } Vector2 finalPosition = GetParameterValue <Vector2>(Model.toPosition, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); if (time == 0) { UpdateTween(rectTransform, 1, p_flowData, startPosition, finalPosition, easeType); return(null); } return(DashTween.To(rectTransform, 0, 1, time).SetDelay(delay) .OnUpdate(f => UpdateTween(rectTransform, f, p_flowData, startPosition, finalPosition, easeType))); }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { // Position bool usePosition = GetParameterValue(Model.usePosition, p_flowData); bool useFromPosition = GetParameterValue(Model.useFromPosition, p_flowData); Vector3 fromPosition = GetParameterValue(Model.fromPosition, p_flowData); bool isFromPositionRelative = GetParameterValue(Model.isFromPositionRelative, p_flowData); bool storePositionToAttribute = GetParameterValue(Model.storePositionToAttribute, p_flowData); Vector3 startPosition = useFromPosition ? isFromPositionRelative ? p_target.position + fromPosition : fromPosition : p_target.position; if (storePositionToAttribute) { string attribute = GetParameterValue(Model.storePositionAttributeName, p_flowData); p_flowData.SetAttribute(attribute, p_target.position); } Vector3 finalPosition = GetParameterValue(Model.toPosition, p_flowData); bool isToPositionRelative = GetParameterValue(Model.isToPositionRelative, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); // Rotation bool useRotation = GetParameterValue(Model.useRotation, p_flowData); bool useFromRotation = GetParameterValue(Model.useFromRotation, p_flowData); Vector3 fromRotation = GetParameterValue(Model.fromRotation, p_flowData); fromRotation.x = fromRotation.x > 180 ? fromRotation.x - 360 : fromRotation.x; fromRotation.y = fromRotation.y > 180 ? fromRotation.y - 360 : fromRotation.y; fromRotation.z = fromRotation.z > 180 ? fromRotation.z - 360 : fromRotation.z; bool isFromRotationRelative = GetParameterValue(Model.isFromRotationRelative, p_flowData); Quaternion startRotation = useFromPosition ? isFromPositionRelative ? p_target.rotation * Quaternion.Euler(fromRotation) : Quaternion.Euler(fromRotation) : p_target.rotation; bool storeRotationToAttribute = GetParameterValue(Model.storeRotationToAttribute, p_flowData); if (storeRotationToAttribute) { string attribute = GetParameterValue(Model.storeRotationAttributeName, p_flowData); p_flowData.SetAttribute <Quaternion>(attribute, p_target.rotation); } Vector3 toRotation = GetParameterValue <Vector3>(Model.toRotation, p_flowData); // Scale bool useScale = GetParameterValue(Model.useScale, p_flowData); bool useFromScale = GetParameterValue(Model.useFromScale, p_flowData); Vector3 fromScale = GetParameterValue(Model.fromScale, p_flowData); bool isFromScaleRelative = GetParameterValue(Model.isFromScaleRelative, p_flowData); Vector3 startScale = useFromScale ? isFromScaleRelative ? p_target.localScale + Model.fromScale.GetValue(ParameterResolver, p_flowData) : fromScale : p_target.localScale; bool storeScaleToAttribute = GetParameterValue(Model.storeScaleToAttribute, p_flowData); if (storeScaleToAttribute) { string attribute = GetParameterValue(Model.storeScaleAttributeName, p_flowData); p_flowData.SetAttribute <Vector3>(attribute, p_target.localScale); } Vector3 toScale = GetParameterValue(Model.toScale, p_flowData); bool isToScaleRelative = GetParameterValue(Model.isToScaleRelative, p_flowData); // Animation float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); if (time == 0) { if (usePosition) { UpdatePositionTween(p_target, 1, p_flowData, startPosition, finalPosition, isToPositionRelative, easeType); } if (useRotation) { UpdateRotationTween(p_target, 1, p_flowData, startRotation, toRotation, isToPositionRelative, easeType); } if (useScale) { UpdateScaleTween(p_target, 1, p_flowData, startScale, toScale, isToScaleRelative, easeType); } return(null); } return(DashTween.To(p_target, 0, 1, time).SetDelay(delay) .OnUpdate(f => { if (usePosition) { UpdatePositionTween(p_target, f, p_flowData, startPosition, finalPosition, isToPositionRelative, easeType); } if (useRotation) { UpdateRotationTween(p_target, f, p_flowData, startRotation, toRotation, isToPositionRelative, easeType); } if (useScale) { UpdateScaleTween(p_target, f, p_flowData, startScale, toScale, isToScaleRelative, easeType); } })); }
protected override void OnExecuteStart(NodeFlowData p_flowData) { if (_activeTweens == null) { _activeTweens = new List <DashTween>(); } int firstIndex = GetParameterValue(Model.firstIndex, p_flowData); int lastIndex = GetParameterValue(Model.lastIndex, p_flowData); int length = lastIndex - firstIndex; if (length == 0) { EndLoop(p_flowData); } for (int i = firstIndex; i != lastIndex; i += Math.Abs(length) / length) { NodeFlowData data = p_flowData.Clone(); if (Model.addIndexAttribute) { data.SetAttribute(Model.indexAttribute, i); } if (GetParameterValue(Model.OnIterationDelay, p_flowData) == 0) { OnExecuteOutput(0, data); } else { float time = GetParameterValue(Model.OnIterationDelay, p_flowData) * i; DashTween tween = DashTween.To(Graph.Controller, 0, 1, time); _activeTweens.Add(tween); tween.OnComplete(() => { _activeTweens.Remove(tween); OnExecuteOutput(0, data); }); tween.Start(); } } if (Model.OnFinishedDelay == 0 && GetParameterValue(Model.OnIterationDelay, p_flowData) == 0) { EndLoop(p_flowData); } else { float time = Model.OnFinishedDelay + GetParameterValue(Model.OnIterationDelay, p_flowData) * length; DashTween tween = DashTween.To(Graph.Controller, 0, 1, time); _activeTweens.Add(tween); tween.OnComplete(() => { _activeTweens.Remove(tween); EndLoop(p_flowData); }); tween.Start(); } }
override protected void OnExecuteStart(NodeFlowData p_flowData) { if (_activeTweens == null) { _activeTweens = new List <DashTween>(); } List <Transform> transforms = new List <Transform>(); Transform transform; if (!string.IsNullOrEmpty(Model.target)) { if (!p_flowData.HasAttribute("target") && Model.isChild) { Debug.LogWarning("Cannot retarget to a child of null in node " + _model.id); hasErrorsInExecution = true; OnExecuteEnd(); return; } if (Model.isChild) { if (Model.findAll) { transforms = Controller.transform.DeepFindAll(Model.target); } else { transform = Controller.transform.DeepFind(Model.target); if (transform != null) { transforms.Add(transform); } } } else { if (Model.findAll) { transforms = Controller.transform.root.DeepFindAll(Model.target); } else { transform = Controller.transform.root.DeepFind(Model.target); if (transform != null) { transforms.Add(transform); } } } if (transforms.Count == 0) { Debug.LogWarning("Zero valid retargets found in node " + _model.id); hasErrorsInExecution = true; OnExecuteEnd(); return; } for (int i = 0; i < transforms.Count; i++) { transform = Model.inReverse ? transforms[transforms.Count - i - 1] : transforms[i]; NodeFlowData data = p_flowData.Clone(); data.SetAttribute("target", transform); if (Model.delay.GetValue(ParameterResolver) == 0) { OnExecuteOutput(0, data); } else { float time = Model.delay.GetValue(ParameterResolver) * i; DashTween tween = DashTween.To(Graph.Controller, 0, 1, time); tween.OnComplete(() => { _activeTweens.Remove(tween); OnExecuteOutput(0, data); }); tween.Start(); _activeTweens.Add(tween); } } if (Model.delay.GetValue(ParameterResolver) == 0) { OnExecuteEnd(); } else { float time = Model.delay.GetValue(ParameterResolver) * transforms.Count; DashTween tween = DashTween.To(Graph.Controller, 0, 1, time); tween.OnComplete(() => { _activeTweens.Remove(tween); OnExecuteEnd(); }); tween.Start(); _activeTweens.Add(tween); } } else { Debug.LogWarning("Zero valid retargets found in node " + _model.id); hasErrorsInExecution = true; OnExecuteEnd(); } }
protected override DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData) { bool useRectTransform = GetParameterValue(Model.useRectTransform, p_flowData); Transform targetTransform; if (Model.useToExpression) { var value = ExpressionEvaluator.EvaluateUntypedExpression(Model.targetToExpression, ParameterResolver, p_flowData, false); if (ExpressionEvaluator.hasErrorInEvaluation) { SetError(ExpressionEvaluator.errorMessage); return(null); } targetTransform = value as Transform; if (targetTransform == null && value.GetType() == typeof(GameObject)) { targetTransform = (value as GameObject).transform; } else if (targetTransform == null && value is Component) { targetTransform = (value as Component).transform; } } else { targetTransform = Model.targetTransform.Resolve(Controller); } if (CheckException(targetTransform, "Target transform null.")) { return(null); } Vector2 startPosition = p_target.position; Quaternion startRotation = p_target.localRotation; Vector3 startScale = p_target.localScale; if (useRectTransform) { RectTransform rectTransform = (RectTransform)p_target; if (CheckException(rectTransform, "No RectTransform component found on target.")) { return(null); } RectTransform targetRectTransform = (RectTransform)targetTransform; if (CheckException(targetRectTransform, "No RectTransform component found on target transform.")) { return(null); } startPosition = rectTransform.anchoredPosition; } float time = GetParameterValue(Model.time, p_flowData); float delay = GetParameterValue(Model.delay, p_flowData); EaseType easeType = GetParameterValue(Model.easeType, p_flowData); if (time == 0) { if (useRectTransform) { UpdateRectTransformTween((RectTransform)p_target, 1, p_flowData, startPosition, startRotation, startScale, (RectTransform)targetTransform, easeType); } else { UpdateTransformTween(p_target, 1, p_flowData, startPosition, startRotation, startScale, targetTransform, easeType); } return(null); } else { if (useRectTransform) { return(DashTween.To((RectTransform)p_target, 0, 1, time) .OnUpdate(f => UpdateRectTransformTween((RectTransform)p_target, f, p_flowData, startPosition, startRotation, startScale, (RectTransform)targetTransform, easeType)) .SetDelay(delay)); } else { return(DashTween.To((RectTransform)p_target, 0, 1, time) .OnUpdate(f => UpdateTransformTween(p_target, f, p_flowData, startPosition, startRotation, startScale, targetTransform, easeType)) .SetDelay(delay)); } } }