示例#1
0
        public static SuperUnit WithStartUpdate()
        {
            var superUnit = new SuperUnit();

            superUnit.nest.source = GraphSource.Embed;
            superUnit.nest.embed  = FlowGraph.WithStartUpdate();
            return(superUnit);
        }
示例#2
0
        public static SuperUnit WithInputOutput()
        {
            var superUnit = new SuperUnit();

            superUnit.nest.source = GraphSource.Embed;
            superUnit.nest.embed  = FlowGraph.WithInputOutput();
            return(superUnit);
        }
示例#3
0
        public override void PerformDragAndDrop()
        {
            if (DragAndDropUtility.Is <ScriptGraphAsset>())
            {
                var flowMacro = DragAndDropUtility.Get <ScriptGraphAsset>();
                var superUnit = new SuperUnit(flowMacro);
                AddUnit(superUnit, DragAndDropUtility.position);
            }
            else if (DragAndDropUtility.Is <UnityObject>())
            {
                var uo     = DragAndDropUtility.Get <UnityObject>();
                var type   = uo.GetType();
                var filter = UnitOptionFilter.Any;
                filter.Literals = false;
                filter.Expose   = false;
                var options = GetNewUnitOptions(filter);

                var root = new List <object>();

                if (!uo.IsSceneBound() || reference.serializedObject.IsSceneBound())
                {
                    if (uo == reference.self)
                    {
                        root.Add(new UnitOption <This>(new This()));
                    }

                    root.Add(new LiteralOption(new Literal(type, uo)));
                }

                if (uo is MonoScript script)
                {
                    var scriptType = script.GetClass();

                    if (scriptType != null)
                    {
                        root.Add(scriptType);
                    }
                }
                else
                {
                    root.Add(type);
                }

                if (uo is GameObject)
                {
                    root.AddRange(uo.GetComponents <Component>().Select(c => c.GetType()));
                }

                options.rootOverride = root.ToArray();

                NewUnit(DragAndDropUtility.position, options, (unit) =>
                {
                    // Try to assign a correct input
                    var compatibleInput = unit.CompatibleValueInput(type);

                    if (compatibleInput == null)
                    {
                        return;
                    }

                    if (uo.IsSceneBound())
                    {
                        if (reference.self == uo.GameObject())
                        {
                            // The component is owned by the same game object as the graph.

                            if (compatibleInput.nullMeansSelf)
                            {
                                compatibleInput.SetDefaultValue(null);
                            }
                            else
                            {
                                var self      = new This();
                                self.position = unit.position + new Vector2(-150, 19);
                                graph.units.Add(self);
                                self.self.ConnectToValid(compatibleInput);
                            }
                        }
                        else if (reference.serializedObject.IsSceneBound())
                        {
                            // The component is from another object from the same scene
                            compatibleInput.SetDefaultValue(uo.ConvertTo(compatibleInput.type));
                        }
                        else
                        {
                            throw new NotSupportedException("Cannot determine compatible input from dragged Unity object.");
                        }
                    }
                    else
                    {
                        compatibleInput.SetDefaultValue(uo.ConvertTo(compatibleInput.type));
                    }
                });
            }
            else if (EditorVariablesUtility.isDraggingVariable)
            {
                var kind        = EditorVariablesUtility.kind;
                var declaration = EditorVariablesUtility.declaration;

                UnifiedVariableUnit unit;

                if (e.alt)
                {
                    unit = new SetVariable();
                }
                else if (e.shift)
                {
                    unit = new IsVariableDefined();
                }
                else
                {
                    unit = new GetVariable();
                }

                unit.kind = kind;
                AddUnit(unit, DragAndDropUtility.position);
                unit.name.SetDefaultValue(declaration.name);
            }
        }
示例#4
0
        private static IEnumerable <IUnitOption> GetStaticOptions()
        {
            // Standalones

            foreach (var unit in Codebase.ludiqRuntimeTypes.Where(t => typeof(IUnit).IsAssignableFrom(t) &&
                                                                  t.IsConcrete() &&
                                                                  t.GetDefaultConstructor() != null &&
                                                                  !t.HasAttribute <SpecialUnitAttribute>() &&
                                                                  (EditorPlatformUtility.allowJit || !t.HasAttribute <AotIncompatibleAttribute>()) &&
                                                                  t.GetDefaultConstructor() != null)
                     .Select(t => (IUnit)t.Instantiate()))
            {
                yield return(unit.Option());
            }

            // Self

            yield return(new This().Option());

            // Types

            foreach (var type in codebase.types)
            {
                foreach (var typeOption in GetTypeOptions(type))
                {
                    yield return(typeOption);
                }
            }

            // Members

            foreach (var member in codebase.members)
            {
                foreach (var memberOption in GetMemberOptions(member))
                {
                    yield return(memberOption);
                }
            }

            // Events

            foreach (var eventType in Codebase.ludiqRuntimeTypes.Where(t => typeof(IEventUnit).IsAssignableFrom(t) && t.IsConcrete()))
            {
                yield return(((IEventUnit)eventType.Instantiate()).Option());
            }

            // Blank Variables

            yield return(new GetVariableOption(VariableKind.Flow));

            yield return(new GetVariableOption(VariableKind.Graph));

            yield return(new GetVariableOption(VariableKind.Object));

            yield return(new GetVariableOption(VariableKind.Scene));

            yield return(new GetVariableOption(VariableKind.Application));

            yield return(new GetVariableOption(VariableKind.Saved));

            yield return(new SetVariableOption(VariableKind.Flow));

            yield return(new SetVariableOption(VariableKind.Graph));

            yield return(new SetVariableOption(VariableKind.Object));

            yield return(new SetVariableOption(VariableKind.Scene));

            yield return(new SetVariableOption(VariableKind.Application));

            yield return(new SetVariableOption(VariableKind.Saved));

            yield return(new IsVariableDefinedOption(VariableKind.Flow));

            yield return(new IsVariableDefinedOption(VariableKind.Graph));

            yield return(new IsVariableDefinedOption(VariableKind.Object));

            yield return(new IsVariableDefinedOption(VariableKind.Scene));

            yield return(new IsVariableDefinedOption(VariableKind.Application));

            yield return(new IsVariableDefinedOption(VariableKind.Saved));

            // Blank Super Unit

            yield return(SuperUnit.WithInputOutput().Option());

            // Extensions

            foreach (var staticUnitsExtension in staticUnitsExtensions)
            {
                foreach (var extensionStaticUnit in staticUnitsExtension())
                {
                    yield return(extensionStaticUnit);
                }
            }
        }