Exemplo n.º 1
0
        void OnSelectionChange()
        {
            DirectedGraphConfig config = Selection.activeObject as DirectedGraphConfig;

            if (config == null || config != _config)
            {
                OnDisable();
                Show(config);
            }
        }
Exemplo n.º 2
0
 void OnDisable()
 {
     EditorApplication.update -= UpdateGraphEditorWindow;
     _config?.CleanupEditor(_object);
     _object?.ApplyModifiedProperties();
     _config           = null;
     _object           = null;
     _graph            = null;
     titleContent.text = "Graph Editor";
     Repaint();
 }
Exemplo n.º 3
0
        public static GraphEditorWindow Show(DirectedGraphConfig config)
        {
            string            title  = (config == null ? "" : (config.name + " | ")) + "Graph Editor";
            GraphEditorWindow window = GetWindow <GraphEditorWindow>(title, true, typeof(UnityEditor.SceneView));

            window.SetObject(config);
            EditorApplication.update -= window.UpdateGraphEditorWindow;
            if (config != null)
            {
                EditorApplication.update += window.UpdateGraphEditorWindow;
            }
            return(window);
        }
Exemplo n.º 4
0
        private void SetObject(DirectedGraphConfig config)
        {
            if (config == null || _config == config)
            {
                _object?.Update();
                return;
            }
            _config = config;
            _object = new SerializedObject(_config);
            _object.Update();
            _graph = _object.FindProperty(_config.GraphProperty);
            if (_graph == null)
            {
                _object = null;
                _config = null;
                return;
            }

            Vector2 adjust;
            Rect    rect = new Rect(0f, 0f, NODE_WIDTH, NODE_HEIGHT);

            _config.InitializeEditor(_object);
            _scrollRect = rect;
            _nodes      = _graph.FindPropertyRelative("Nodes");
            _links      = _graph.FindPropertyRelative("Links");
            _linkData   = _graph.FindPropertyRelative("LinkData");
            _positions  = _object.FindProperty("_Positions");

            if ((_nodes?.arraySize ?? 0) == 0)
            {
                CreateNewNode(Vector2.zero);
            }
            _positions.arraySize = _nodes.arraySize;
            adjust = _positions.GetArrayElementAtIndex(0).vector2Value;

            for (int i = _positions.arraySize - 1; i >= 0; i--)
            {
                rect.center = _positions.GetArrayElementAtIndex(i).vector2Value -= adjust;
                AdjustScrollRect(rect, SCROLL_PADDING);
            }

            _object.ApplyModifiedProperties();
            _selectedNodes = new List <int>();
            _selectedLinks = new List <int>();
            _linking       = -1;

            _scroll = new Vector2((position.width - _scrollRect.xMin) * .5f, -position.height - _scrollRect.yMin * .5f);
            Repaint();
        }