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 void ExecuteOnTarget(Transform p_target, NodeFlowData p_flowData) { if (p_target == null) { return; } if (Model.usePooling) { var poolId = GetParameterValue(Model.poolId, p_flowData); var pool = DashCore.Instance.GetPrefabPool(poolId); if (pool == null) { SetError("Prefab pool with id " + Model.poolId + " not found target not destroyed."); } else { pool.Return(p_target); } } else { if (p_target.gameObject != null) { if (Model.immediate || !Application.isPlaying) { GameObject.DestroyImmediate(p_target.gameObject); } else { GameObject.Destroy(p_target.gameObject); } } } OnExecuteEnd(); OnExecuteOutput(0, p_flowData); }
protected void UpdateTween(RectTransform p_target, float p_delta, NodeFlowData p_flowData, Vector2 p_startSizeDelta, Vector2 p_toSizeDelta, EaseType p_easeType) { if (p_target == null) { if (Model.killOnNullEncounter) { Stop_Internal(); } return; } if (Model.isToRelative) { p_target.sizeDelta = p_startSizeDelta + new Vector2(DashTween.EaseValue(0, p_toSizeDelta.x, p_delta, p_easeType), DashTween.EaseValue(0, p_toSizeDelta.y, p_delta, p_easeType)); } else { p_target.sizeDelta = new Vector2(DashTween.EaseValue(p_startSizeDelta.x, p_toSizeDelta.x, p_delta, p_easeType), DashTween.EaseValue(p_startSizeDelta.y, p_toSizeDelta.y, p_delta, p_easeType)); } }
protected void UpdateTween(RectTransform p_target, float p_delta, NodeFlowData p_flowData, Vector2 p_startPosition, Vector2 p_finalPosition, EaseType p_easeType) { if (p_target == null) { if (Model.killOnNullEncounter) { Stop_Internal(); } return; } if (Model.isToRelative) { p_target.anchoredPosition = p_startPosition + new Vector2(DashTween.EaseValue(0, p_finalPosition.x, p_delta, p_easeType), DashTween.EaseValue(0, p_finalPosition.y, p_delta, p_easeType)); } else { p_target.anchoredPosition = new Vector2(DashTween.EaseValue(p_startPosition.x, p_finalPosition.x, p_delta, p_easeType), DashTween.EaseValue(p_startPosition.y, p_finalPosition.y, p_delta, p_easeType)); } }
protected override void ExecuteOnTarget(Transform p_target, NodeFlowData p_flowData) { if (p_target != null) { bool maskable = GetParameterValue(Model.maskable, p_flowData); if (GetParameterValue(Model.wholeHierarchy, p_flowData)) { var graphics = p_target.GetComponentsInChildren <MaskableGraphic>(); graphics.ForEach(g => g.maskable = maskable); } else { var graphics = p_target.GetComponent <MaskableGraphic>(); if (graphics != null) { graphics.maskable = maskable; } } } OnExecuteEnd(); OnExecuteOutput(0, p_flowData); }
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(); } }
void ExecuteEnd(NodeFlowData p_flowData) { OnExecuteEnd(); OnExecuteOutput(0, p_flowData); }
protected override void OnExecuteStart(NodeFlowData p_flowData) { OnExecuteEnd(); ((IInternalGraphAccess)Graph).OutputExecuted(this, p_flowData); }
void EndLoop(NodeFlowData p_flowData) { OnExecuteEnd(); OnExecuteOutput(1, p_flowData); }
protected void UpdateRectTransformTween(RectTransform p_target, float p_delta, NodeFlowData p_flowData, Vector2 p_startPosition, Quaternion p_startRotation, Vector3 p_startScale, RectTransform p_towards, EaseType p_easeType) { if (p_target == null) { if (Model.killOnNullEncounter) { Stop_Internal(); } return; } if (GetParameterValue(Model.useToPosition, p_flowData)) { Vector2 towardsPosition = TransformExtensions.FromToRectTransform(p_towards, p_target); towardsPosition = new Vector2(DashTween.EaseValue(p_startPosition.x, towardsPosition.x, p_delta, p_easeType), DashTween.EaseValue(p_startPosition.y, towardsPosition.y, p_delta, p_easeType)); p_target.anchoredPosition = towardsPosition; } if (GetParameterValue(Model.useToRotation, p_flowData)) { p_target.localRotation = Quaternion.Lerp(p_startRotation, p_towards.localRotation, p_delta); } if (GetParameterValue(Model.useToScale, p_flowData)) { p_target.localScale = Vector3.Lerp(p_startScale, p_towards.localScale, p_delta); } }
override protected void OnExecuteStart(NodeFlowData p_flowData) { Transform target = null; if (!p_flowData.HasAttribute("target") && Model.isChild) { Debug.LogWarning("Cannot retarget to a child of null in node " + _model.id); hasErrorsInExecution = true; return; } target = p_flowData.GetAttribute <Transform>("target"); // Handle retargeting if (Model.retarget) { if (Model.useReference) { if (Model.useExpression) { // var value = ExpressionEvaluator.EvaluateTypedExpression(Model.targetExpression, typeof(Transform), // ParameterResolver, p_flowData); var value = ExpressionEvaluator.EvaluateUntypedExpression(Model.targetExpression, ParameterResolver, p_flowData, false); if (ExpressionEvaluator.hasErrorInEvaluation) { SetError(ExpressionEvaluator.errorMessage); return; } target = value as Transform; if (target == null && value.GetType() == typeof(GameObject)) { target = (value as GameObject).transform; } else if (target == null && value is Component) { target = (value as Component).transform; } } else { target = Model.targetReference.Resolve(Controller); } } else { if (target != null) { if (Model.isChild) { string find = GetParameterValue(Model.target, p_flowData); target = target.Find(find, true); } else { string find = GetParameterValue(Model.target, p_flowData); GameObject go = GameObject.Find(find); target = go == null ? null : go.transform; } } } } #if UNITY_EDITOR DashEditorDebug.Debug(new NodeDebugItem(NodeDebugItem.NodeDebugItemType.EXECUTE, Graph.Controller, Graph.GraphPath, _model.id, target)); #endif if (CheckException(target, "No valid target found")) { return; } ExecuteOnTarget(target, p_flowData); }
protected abstract void ExecuteOnTarget(Transform p_target, NodeFlowData p_flowData);
protected override void ExecuteOnTarget(Transform p_target, NodeFlowData p_flowData) { p_flowData.SetAttribute("target", p_target); ExecuteEnd(p_flowData); }
public DashTween Execute(Transform p_transform, IParameterResolver p_resolver, NodeFlowData p_flowData) { // RectTransform rect = p_transform as RectTransform; // // Vector2 startPosition = rect.anchoredPosition; // // Sequence sequence = DOTween.Sequence(); // // for (int i = 0; i < shakeCount; i++) // { // float f = fade ? ((shakeCount - i) / (float)shakeCount) : 1; // Tween tween1 = DOTween // .To(() => rect.anchoredPosition-startPosition, v2 => rect.anchoredPosition = startPosition+v2, // new Vector2(Random.Range(-shakeStrength*f, shakeStrength*f), Random.Range(-shakeStrength*f, shakeStrength*f)), // p_duration / (shakeCount * 2)) // .SetEase(Ease.OutQuad); // sequence.Append(tween1); // // Tween tween2 = DOTween // .To(() => rect.anchoredPosition-startPosition, v2 => rect.anchoredPosition = startPosition+v2, // Vector2.zero, p_duration / (shakeCount * 2)) // .SetEase(Ease.InQuad); // sequence.Append(tween2); // } // // return sequence; // TODO DashTween implementation return(null); }
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)); } } }
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(); } }
protected abstract DashTween AnimateOnTarget(Transform p_target, NodeFlowData p_flowData);
override protected void OnExecuteStart(NodeFlowData p_flowData) { if (!Model.variableName.IsNullOrWhitespace() && Model.variableType != null && !Model.expression.IsNullOrWhitespace()) { var value = ExpressionEvaluator.EvaluateTypedExpression(Model.expression, Model.variableType, ParameterResolver, p_flowData); if (ExpressionEvaluator.hasErrorInEvaluation) { SetError(ExpressionEvaluator.errorMessage); return; } if (Model.isGlobal) { if (DashCore.Instance.GlobalVariables == null) { SetError("Global variables not found!"); } else if (DashCore.Instance.GlobalVariables.HasVariable(Model.variableName)) { Variable variable = DashCore.Instance.GlobalVariables.GetVariable(Model.variableName); if (variable.GetVariableType() != Model.variableType || (variable.GetVariableType() != value.GetType() && !variable.GetVariableType() .IsImplicitlyAssignableFrom(value.GetType()))) { Debug.Log(variable.GetVariableType().IsImplicitlyAssignableFrom(value.GetType())); SetError("Cannot set existing variable of different type! Expecting " + variable.GetVariableType() + " got " + Model.variableType); return; } variable.value = value; } else { if (Model.enableCreate) { DashCore.Instance.GlobalVariables.AddVariableByType(Model.variableType, Model.variableName, value); } else { SetError("Variable " + Model.variableName + " doesn't exist, if you want to create enable it."); } } } else { if (Graph.variables.HasVariable(Model.variableName)) { var variable = Graph.variables.GetVariable(Model.variableName); if (variable.GetVariableType() != Model.variableType || (variable.GetVariableType() != value.GetType() && !variable.GetVariableType() .IsImplicitlyAssignableFrom(value.GetType()))) { Debug.Log(variable.GetVariableType().IsImplicitlyAssignableFrom(value.GetType())); SetError("Cannot set existing variable of different type! Expecting " + variable.GetVariableType() + " got " + Model.variableType); return; } variable.value = value; } else { if (Model.enableCreate) { Graph.variables.AddVariable(Model.variableName, value); } else { SetError("Variable " + Model.variableName + " doesn't exist, if you want to create enable it."); } } } } OnExecuteEnd(); OnExecuteOutput(0, p_flowData); }
protected abstract void OnExecuteStart(NodeFlowData p_flowData);
// #if UNITY_EDITOR // protected override Color NodeBackgroundColor => new Color(0.8f, 0.6f, 0f); // protected override Color TitleBackgroundColor => new Color(0.8f, 0.5f, 0f); // // protected override Color TitleTextColor => new Color(1f, 0.8f, 0); // #endif protected override void OnExecuteStart(NodeFlowData p_flowData) { OnExecuteEnd(); OnExecuteOutput(0, p_flowData); }
public void ExecuteNodeOutputs(NodeBase p_node, int p_index, NodeFlowData p_flowData) { _connections.FindAll(c => c.active && c.outputNode == p_node && c.outputIndex == p_index) .ForEach(c => c.Execute(p_flowData)); }
public void Invoke(NodeFlowData p_flowData) { Callback?.Invoke(p_flowData); }
void IInternalGraphAccess.OutputExecuted(OutputNode p_node, NodeFlowData p_flowData) { OnOutput?.Invoke(p_node, p_flowData); }
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 void ExecuteEnd(int p_outputIndex, NodeFlowData p_flowData) { Debug.Log("EEND: " + p_outputIndex); OnExecuteEnd(); OnExecuteOutput(p_outputIndex, p_flowData); }