コード例 #1
0
ファイル: AddAttributeNode.cs プロジェクト: pshtif/Dash
        override protected void OnExecuteStart(NodeFlowData p_flowData)
        {
            if (!Model.attributeName.IsNullOrWhitespace() && !Model.expression.IsNullOrWhitespace())
            {
                if (!p_flowData.HasAttribute(Model.attributeName) ||
                    p_flowData.GetAttributeType(Model.attributeName) == Model.attributeType)
                {
                    var value = ExpressionEvaluator.EvaluateTypedExpression(Model.expression, Model.attributeType,
                                                                            ParameterResolver, p_flowData);

                    if (ExpressionEvaluator.hasErrorInEvaluation)
                    {
                        SetError(ExpressionEvaluator.errorMessage);
                        return;
                    }

                    p_flowData.SetAttribute(Model.attributeName, value);
                }
                else
                {
                    Debug.LogWarning("Changing flow data attribute type at runtime not allowed.");
                }
            }

            OnExecuteEnd();
            OnExecuteOutput(0, p_flowData);
        }
コード例 #2
0
        protected bool CheckException(NodeFlowData p_flowData, string p_variableName)
        {
            if (!p_flowData.HasAttribute(p_variableName))
            {
                SetError("Attribute "+p_variableName+" not found during execution of "+this);

                return true;
            }

            return false;
        }
コード例 #3
0
ファイル: DashController.cs プロジェクト: pshtif/Dash
        public void SendEvent(string p_name, NodeFlowData p_flowData)
        {
            if (Graph == null || GetTarget() == null)
            {
                return;
            }

            p_flowData = p_flowData == null?NodeFlowDataFactory.Create(GetTarget()) : p_flowData.Clone();

            if (!p_flowData.HasAttribute(NodeFlowDataReservedAttributes.TARGET))
            {
                p_flowData.SetAttribute(NodeFlowDataReservedAttributes.TARGET, GetTarget());
            }

            p_flowData.SetAttribute(NodeFlowDataReservedAttributes.EVENT, p_name);

            Graph.SendEvent(p_name, p_flowData);
        }
コード例 #4
0
ファイル: RetargetAdvancedNode.cs プロジェクト: pshtif/Dash
        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();
            }
        }
コード例 #5
0
        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);
        }