示例#1
0
        public override IEnumerator Run(IGraphRunner graph, IVariableDictionary variables)
        {
            var prefabVariable = Prefab.Resolve(variables);

            if (prefabVariable.TryGetObject(out GameObject prefab))
            {
                GameObject spawned = null;

                var position = Position.Resolve(variables, VariableType.Vector3);
                var rotation = Rotation.Resolve(variables, VariableType.Quaternion);

                if (Positioning == ObjectPositioning.Absolute)
                {
                    spawned = Instantiate(prefab, position.AsVector3, rotation.AsQuaternion);
                }
                else if (Positioning == ObjectPositioning.Relative)
                {
                    if (Object.IsValid)
                    {
                        var obj = Object.Execute <GameObject>(variables);
                        spawned = Instantiate(prefab, obj.transform.position + position.AsVector3, rotation.AsQuaternion);
                    }
                }
                else if (Positioning == ObjectPositioning.Child)
                {
                    if (Parent.IsValid)
                    {
                        var parent = Parent.Execute <GameObject>(variables);
                        spawned = Instantiate(prefab, parent.transform.position + position.AsVector3, rotation.AsQuaternion, parent.transform);
                    }
                }

                if (spawned)
                {
                    var objectName = ObjectName.Resolve(variables, VariableType.String).AsString;

                    if (!string.IsNullOrEmpty(objectName))
                    {
                        spawned.name = objectName;
                    }

                    if (ObjectVariable.IsValid)
                    {
                        ObjectVariable.Assign(variables, Variable.Object(spawned));
                    }
                }
            }

            graph.GoTo(Next, nameof(Next));

            yield break;
        }
        public override IEnumerator Run(IGraphRunner graph, IVariableDictionary variables)
        {
            var type = Type.GetType(ScriptableObjectType, false);
            var obj  = CreateInstance(type);

            if (ObjectVariable.IsValid)
            {
                ObjectVariable.Assign(variables, Variable.Object(obj));
            }

            graph.GoTo(Next, nameof(Next));

            yield break;
        }
示例#3
0
        public override IEnumerator Run(IGraphRunner graph, IVariableDictionary variables)
        {
            var index = 0;

            while (true)
            {
                if (Index.IsValid)
                {
                    Index.Assign(variables, Variable.Int(index++));
                }

                var condition = Condition.Execute(variables, VariableType.Bool);

                if (!condition.AsBool || Loop == null)
                {
                    break;
                }

                yield return(graph.Run(Loop, variables, nameof(Loop)));
            }
        }