Esempio n. 1
0
        public GraphViewEditor(GraphViewWindow window)
        {
            _window         = window;
            _graphProvider  = ScriptableObject.CreateInstance <GraphProvider>();
            _objectProvider = ScriptableObject.CreateInstance <ObjectProvider>();

            this.AddStyleSheet(Stylesheet);
            AddToClassList(UssClassName);

            CreateToolbar();

            // this has to be here because Unity doesn't allow EditorPrefs access in a static constructor
            Graph.IsDebugBreakEnabled   = _breakpointsEnabled.Value;
            Graph.IsDebugLoggingEnabled = _loggingEnabled.Value;
        }
Esempio n. 2
0
        public GraphView(GraphViewWindow window, Graph graph)
        {
            Graph = graph;

            _window        = window;
            _nodeProvider  = ScriptableObject.CreateInstance <GraphViewNodeProvider>();
            _nodeConnector = new GraphViewConnector(_nodeProvider);

            _inputs  = this.Query <GraphViewInputPort>().Build();
            _outputs = this.Query <GraphViewOutputPort>().Build();

            AddToClassList(UssClassName);
            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            SetupNodeProvider();
            SetupNodes();
            SetupConnections();
            RegisterCallback <KeyDownEvent>(OnKeyDown);
            RegisterCallback <GeometryChangedEvent>(evt => ShowAll());            // Use this event because the layout isn't build right away so ShowAll won't work immediately

            nodeCreationRequest    = OnShowCreateNode;
            graphViewChanged       = OnGraphChanged;
            canPasteSerializedData = data => canPaste;
            serializeGraphElements = OnCopy;
            unserializeAndPaste    = OnPaste;

            this.AddManipulator(new ContentDragger());
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());
            this.AddManipulator(new ClickSelector());

            Undo.undoRedoPerformed += Rebuild;
            EditorApplication.playModeStateChanged += PlayStateChanged;

            if (Application.isPlaying)             // Make sure the callback still gets set if the window was opened during play mode
            {
                PlayStateChanged(PlayModeStateChange.EnteredPlayMode);
                FrameChanged(null);
            }
        }