コード例 #1
0
 public void PerformDragAndDrop()
 {
     UndoUtility.RecordEditedObject("Drag & Drop Macro");
     state.nest.source = GraphSource.Macro;
     state.nest.macro  = DragAndDropUtility.Get <StateGraphAsset>();
     state.nest.embed  = null;
     GUI.changed       = true;
 }
コード例 #2
0
 public void PerformDragAndDrop()
 {
     UndoUtility.RecordEditedObject("Drag & Drop Macro");
     unit.nest.source = GraphSource.Macro;
     unit.nest.macro  = DragAndDropUtility.Get <ScriptGraphAsset>();
     unit.nest.embed  = null;
     unit.Define();
     GUI.changed = true;
 }
コード例 #3
0
 public override void PerformDragAndDrop()
 {
     if (DragAndDropUtility.Is <ScriptGraphAsset>())
     {
         var flowMacro = DragAndDropUtility.Get <ScriptGraphAsset>();
         var flowState = new FlowState(flowMacro);
         AddState(flowState, DragAndDropUtility.position);
     }
     else if (DragAndDropUtility.Is <StateGraphAsset>())
     {
         var asset      = DragAndDropUtility.Get <StateGraphAsset>();
         var superState = new SuperState(asset);
         AddState(superState, DragAndDropUtility.position);
     }
 }
コード例 #4
0
        public override void DrawDragAndDropPreview()
        {
            if (DragAndDropUtility.Is <ScriptGraphAsset>())
            {
                GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, DragAndDropUtility.Get <ScriptGraphAsset>().name, typeof(ScriptGraphAsset).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));
            }
        }
コード例 #5
0
 public void DrawDragAndDropPreview()
 {
     GraphGUI.DrawDragAndDropPreviewLabel(new Vector2(edgePosition.x, outerPosition.yMax), "Replace with: " + DragAndDropUtility.Get <StateGraphAsset>().name, typeof(StateGraphAsset).Icon());
 }
コード例 #6
0
 public override void DrawDragAndDropPreview()
 {
     if (DragAndDropUtility.Is <ScriptGraphAsset>())
     {
         GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, DragAndDropUtility.Get <ScriptGraphAsset>().name, typeof(ScriptGraphAsset).Icon());
     }
     else if (DragAndDropUtility.Is <StateGraphAsset>())
     {
         GraphGUI.DrawDragAndDropPreviewLabel(DragAndDropUtility.offsetedPosition, DragAndDropUtility.Get <StateGraphAsset>().name, typeof(StateGraphAsset).Icon());
     }
 }
コード例 #7
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);
            }
        }
コード例 #8
0
 public override bool AcceptsDragAndDrop()
 {
     return(DragAndDropUtility.Is <ScriptGraphAsset>() ||
            (DragAndDropUtility.Is <UnityObject>() && !DragAndDropUtility.Is <IMacro>() && CanDetermineDraggedInput(DragAndDropUtility.Get <UnityObject>())) ||
            EditorVariablesUtility.isDraggingVariable);
 }