Exemplo n.º 1
0
        protected override void OnExecuteStart(NodeFlowData p_flowData)
        {
            Transform target = p_flowData.GetAttribute <Transform>(NodeFlowDataReservedAttributes.TARGET);

            if (Model.prefab == null)
            {
                OnExecuteEnd();
                OnExecuteOutput(0, p_flowData);
                return;
            }

            RectTransform spawned = null;

            if (Model.usePooling)
            {
                if (_prefabPool == null)
                {
                    _prefabPool = DashCore.Instance.GetOrCreatePrefabPool(GetParameterValue(Model.poolId, p_flowData), Model.prefab);
                }
                spawned = _prefabPool.Get() as RectTransform;

                if (spawned == null)
                {
                    SetError("Prefab instance is not a RectTransform");
                }
            }
            else
            {
                spawned = GameObject.Instantiate(Model.prefab);
            }

            if (Model.setTargetAsParent)
            {
                spawned.transform.SetParent(target, false);
            }

            spawned.anchoredPosition = GetParameterValue(Model.position, p_flowData);

            if (Model.retargetToSpawned)
            {
                p_flowData.SetAttribute(NodeFlowDataReservedAttributes.TARGET, spawned.transform);
            }
            else if (Model.createSpawnedAttribute)
            {
                if (string.IsNullOrEmpty(Model.spawnedAttributeName))
                {
                    SetError("Attribute name cannot be empty");
                }

                p_flowData.SetAttribute <Transform>(Model.spawnedAttributeName, spawned);
            }

            OnExecuteEnd();
            OnExecuteOutput(0, p_flowData);
        }
Exemplo n.º 2
0
        public void Execute(NodeFlowData p_flowData)
        {
            ExecutionCount++;
            
#if UNITY_EDITOR
            if (!_hasDebugOverride)
            {
                DashEditorDebug.Debug(new NodeDebugItem(NodeDebugItem.NodeDebugItemType.EXECUTE, Graph.Controller, Graph.GraphPath, _model.id,
                    p_flowData.GetAttribute<Transform>("target")));
            }
            
            executeTime = 1;
#endif

            OnExecuteStart(p_flowData == null ? new NodeFlowData() : p_flowData.Clone());
        }
Exemplo n.º 3
0
        protected override void OnExecuteStart(NodeFlowData p_flowData)
        {
            Transform target = p_flowData.GetAttribute <Transform>(NodeFlowDataReservedAttributes.TARGET);

            GameObject spawned = new GameObject();

            spawned.name = Model.spawnedName;
            if (Model.setTargetAsParent)
            {
                spawned.transform.SetParent(target, false);
            }

            Image image = spawned.AddComponent <Image>();

            image.sprite = GetParameterValue(Model.sprite, p_flowData);
            RectTransform rectTransform = image.GetComponent <RectTransform>();

            rectTransform.anchoredPosition = GetParameterValue(Model.position, p_flowData);

            if (GetParameterValue(Model.setNativeSize, p_flowData))
            {
                image.SetNativeSize();
            }

            image.maskable      = GetParameterValue(Model.isMaskable, p_flowData);
            image.raycastTarget = GetParameterValue(Model.isRaycastTarget, p_flowData);

            if (Model.retargetToSpawned)
            {
                p_flowData.SetAttribute(NodeFlowDataReservedAttributes.TARGET, spawned.transform);
            }
            else if (Model.createSpawnedAttribute)
            {
                if (string.IsNullOrEmpty(Model.spawnedAttributeName))
                {
                    SetError("Attribute name cannot be empty");
                }

                p_flowData.SetAttribute <Transform>(Model.spawnedAttributeName, rectTransform);
            }

            OnExecuteEnd();
            OnExecuteOutput(0, p_flowData);
        }
Exemplo n.º 4
0
        protected override void ExecuteOnTarget(Transform p_target, NodeFlowData p_flowData)
        {
            Dictionary <Transform, TransformStorageData> storage = null;

            switch (Model.storageType)
            {
            case StorageType.VARIABLE:
                if (Graph.variables.HasVariable(Model.storageName))
                {
                    storage = Graph.variables
                              .GetVariable <Dictionary <Transform, TransformStorageData> >(Model.storageName)
                              .value;
                }
                else
                {
                    SetError("Storage variable " + Model.storageName + " not found.");
                    return;
                }
                break;

            case StorageType.ATTRIBUTE:
                storage = p_flowData.GetAttribute(Model.storageName) as Dictionary <Transform, TransformStorageData>;
                if (storage == null)
                {
                    SetError("Storage attribute " + Model.storageName + " not found.");
                    return;
                }
                break;
            }

            foreach (var pair in storage)
            {
                pair.Value.Restore(pair.Key);
            }

            OnExecuteEnd();
            OnExecuteOutput(0, p_flowData);
        }
Exemplo n.º 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);
        }