Beispiel #1
0
 public override void DrawDragAndDropPreview()
 {
     if (DragAndDropUtility.Is <FlowMacro>())
     {
         GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, DragAndDropUtility.Get <FlowMacro>().name, typeof(FlowMacro).Icon());
     }
     else if (DragAndDropUtility.Is <StateMacro>())
     {
         GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, DragAndDropUtility.Get <StateMacro>().name, typeof(StateMacro).Icon());
     }
 }
Beispiel #2
0
 public override void PerformDragAndDrop()
 {
     if (DragAndDropUtility.Is <FlowMacro>())
     {
         var flowMacro = DragAndDropUtility.Get <FlowMacro>();
         var flowState = new FlowState(flowMacro);
         AddState(flowState, DragAndDropUtility.position);
     }
     else if (DragAndDropUtility.Is <StateMacro>())
     {
         var asset      = DragAndDropUtility.Get <StateMacro>();
         var superState = new SuperState(asset);
         AddState(superState, DragAndDropUtility.position);
     }
 }
        public override void DrawDragAndDropPreview()
        {
            if (DragAndDropUtility.Is <FlowMacro>())
            {
                GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, DragAndDropUtility.Get <FlowMacro>().name, typeof(FlowMacro).Icon());
            }
            else if (DragAndDropUtility.Is <GameObject>())
            {
                var gameObject = DragAndDropUtility.Get <GameObject>();
                GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, gameObject.name + "...", gameObject.Icon());
            }
            else if (DragAndDropUtility.Is <UnityObject>())
            {
                var obj  = DragAndDropUtility.Get <UnityObject>();
                var type = obj.GetType();
                GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, type.HumanName() + "...", type.Icon());
            }
            else if (EditorVariablesUtility.isDraggingVariable)
            {
                var kind = EditorVariablesUtility.kind;
                var name = EditorVariablesUtility.declaration.name;

                string label;

                if (e.alt)
                {
                    label = $"Set {name}";
                }
                else if (e.shift)
                {
                    label = $"Check if {name} is defined";
                }
                else
                {
                    label = $"Get {name}";
                }

                GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, label, BoltCore.Icons.VariableKind(kind));
            }
        }
Beispiel #4
0
 public override bool AcceptsDragAndDrop()
 {
     return(DragAndDropUtility.Is <StateMacro>());
 }
 public override bool AcceptsDragAndDrop()
 {
     return(DragAndDropUtility.Is <StateGraphAsset>());
 }
Beispiel #6
0
 public bool AcceptsDragAndDrop()
 {
     return(DragAndDropUtility.Is <FlowMacro>());
 }
        public override void PerformDragAndDrop()
        {
            if (DragAndDropUtility.Is <FlowMacro>())
            {
                var flowMacro = DragAndDropUtility.Get <FlowMacro>();
                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 <Self>(new Self()));
                    }

                    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 Self();
                                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);
            }
        }
 public override bool AcceptsDragAndDrop()
 {
     return(DragAndDropUtility.Is <FlowMacro>() ||
            (DragAndDropUtility.Is <UnityObject>() && !DragAndDropUtility.Is <IMacro>() && CanDetermineDraggedInput(DragAndDropUtility.Get <UnityObject>())) ||
            EditorVariablesUtility.isDraggingVariable);
 }