Exemplo n.º 1
0
        public NodeEditor(NodeEditorWindow w)
        {
            backColor = ColorExtensions.From255(59, 62, 74);
            knobColor = ColorExtensions.From255(126, 186, 255);

            guideColor   = Color.gray;
            guideColor.a = 0.3f;

            _gridTex   = TextureLib.GetTexture("Grid");
            _backTex   = TextureLib.GetTexture("Square");
            _circleTex = TextureLib.GetTexture("Circle");

            _window = w;
        }
Exemplo n.º 2
0
        public ActionManager(NodeEditorWindow w)
        {
            _undoStack = new FiniteStack <UndoableAction>(100);
            _redoStack = new Stack <UndoableAction>();

            _window = w;

            // Makes sure that the action cleans up after itself
            // when it is removed from the undo buffer.
            _undoStack.OnRemoveBottomItem += (action) =>
            {
                action.OnDestroy();
            };
        }
        private static bool OpenGraphAsset(int instanceID, int line)
        {
            var graphSelected = EditorUtility.InstanceIDToObject(instanceID) as NodeGraph;

            if (graphSelected != null)
            {
                NodeEditorWindow windowToUse = null;

                // Try to find an editor window without a graph...
                var windows = Resources.FindObjectsOfTypeAll <NodeEditorWindow>();
                foreach (var w in windows)
                {
                    // The canvas is already opened
                    if (w.graph == graphSelected)
                    {
                        return(false);
                    }

                    // Found a window with no active canvas.
                    if (w.graph == null)
                    {
                        windowToUse = w;
                        break;
                    }
                }

                // No windows available...just make a new one.
                if (!windowToUse)
                {
                    windowToUse = EditorWindow.CreateInstance <NodeEditorWindow>();
                    windowToUse.titleContent = new GUIContent("Node Editor");
                    windowToUse.Show();
                }

                windowToUse.SetGraph(graphSelected);
                windowToUse._saveManager.InitState();
                windowToUse.Repaint();

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public SaveManager(NodeEditorWindow w)
        {
            _window = w;

            _saveFSM = new StateMachine <SaveState>();

            var noGraph = new StateMachine <SaveState> .State(SaveState.NoGraph);

            var tempGraph = new StateMachine <SaveState> .State(SaveState.TempGraph);

            var savedGraph = new StateMachine <SaveState> .State(SaveState.SavedGraph);

            _saveFSM.AddState(noGraph);
            _saveFSM.AddState(tempGraph);
            _saveFSM.AddState(savedGraph);

            // Actions to take when starting out on a window with no graph.
            _saveFSM.AddTransition(noGraph, tempGraph, isNewRequested, createNewOnto_Window_WithTempOrEmpty);
            _saveFSM.AddTransition(noGraph, savedGraph, isLoadRequested, loadOnto_EmptyWindow);

            // Actions to take when the window has a temp graph.
            _saveFSM.AddTransition(tempGraph, tempGraph, isNewRequested, createNewOnto_Window_WithTempOrEmpty);
            _saveFSM.AddTransition(tempGraph, savedGraph, isSaveOrSaveAsRequested, saveTempAs);
            _saveFSM.AddTransition(tempGraph, savedGraph, isLoadRequested, loadOnto_Window_WithTempgraph);

            // Actions to take when the window has a valid graph (already saved).
            _saveFSM.AddTransition(savedGraph, savedGraph, isSaveRequested, save);
            _saveFSM.AddTransition(savedGraph, savedGraph, isSaveAsRequested, saveCloneAs);
            _saveFSM.AddTransition(savedGraph, savedGraph, isLoadRequested, loadOnto_Window_WithSavedgraph);
            _saveFSM.AddTransition(savedGraph, tempGraph, isNewRequested, createNewOnto_Window_WithSavedgraph);

            // Consume the save operation even after the transition is made.
            _saveFSM.OnStateChangedEvent += () => { _saveOp = SaveOp.None; };

            InitState();

            NodeConnection.OnConnectionCreated -= saveConnection;
            NodeConnection.OnConnectionCreated += saveConnection;
        }