Пример #1
0
        private void DrawNodes()
        {
            if (View.Session == null)
            {
                return;
            }

            var graphEditorNodesField = View.EditorObject.Fields["Nodes"];
            var graphEditorNodes      = graphEditorNodesField.Value as EditorDictionary;

            // Draw Nodes
            foreach (var nodeField in graphEditorNodes.KeyValuePairs)
            {
                var node = nodeField.Value.Value as EditorObject;

                var nodeEditor         = node.Fields["Editor"].Value as EditorObject;
                var nodeType           = node.Fields["Type"].Value as EditorValue;
                var nodeData           = node.Fields["Data"].Value as EditorObject;
                var nodeEditorPosition = nodeEditor.Fields["Position"].Value as EditorObject;

                var nodeRect = new Rect(
                    View.PanPosition.x + (nodeEditorPosition.Fields["x"].Value as EditorValue).GetValue <int>(),
                    View.PanPosition.y + (nodeEditorPosition.Fields["y"].Value as EditorValue).GetValue <int>(),
                    220,
                    1000
                    );

                GUILayout.BeginArea(nodeRect);

                var finalRect = EditorGUILayout.BeginVertical(nodePadding);
                // finalRect.xMax -= 2;
                finalRect.yMax += 4;
                if (currentEvent.type == EventType.Repaint)
                {
                    GUI.skin.window.Draw(finalRect,
                                         false, View.Selection.Contains(nodeField.Key), false, false);
                }

                string nodeTypeString = nodeType.GetValue <string>();
                string nodeHeader     = nodeTypeString?.Substring(nodeTypeString.LastIndexOf(".") + 1) ?? "Unknown";
                EditorGUILayout.LabelField(nodeHeader, EditorStyles.boldLabel);


                float originalLabelWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 115;
                EditorGUI.indentLevel++;
                if (nodeData.Fields != null)
                {
                    foreach (var childField in nodeData.Fields.Values)
                    {
                        RPGCoreEditor.DrawField(childField);
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("There are no fields here");
                }
                EditorGUI.indentLevel--;
                EditorGUIUtility.labelWidth = originalLabelWidth;

                EditorGUILayout.EndVertical();
                GUILayout.EndArea();

                var globalFinalRect = new Rect(
                    nodeRect.x,
                    nodeRect.y,
                    finalRect.width,
                    finalRect.height
                    );

                if (currentEvent.type == EventType.MouseDown)
                {
                    if (globalFinalRect.Contains(currentEvent.mousePosition))
                    {
                        if (currentEvent.button == 1)
                        {
                            var menu = new GenericMenu();

                            menu.AddItem(new GUIContent("Delete"), false, () => { graphEditorNodes.Remove(nodeField.Key); });

                            menu.ShowAsContext();

                            currentEvent.Use();
                        }
                        else
                        {
                            View.Selection.Clear();
                            View.Selection.Add(nodeField.Key);

                            View.CurrentMode = BehaviourEditorView.ControlMode.NodeDragging;
                            GUI.UnfocusWindow();
                            GUI.FocusControl("");

                            currentEvent.Use();
                        }
                    }
                }
            }
        }
Пример #2
0
        private void DrawNodes()
        {
            if (View.Session == null)
            {
                return;
            }
            var graphEditorNodes = View.GraphField["Nodes"];

            // Draw Nodes
            foreach (var node in graphEditorNodes)
            {
                var nodeEditor         = node["Editor"];
                var nodeEditorPosition = nodeEditor["Position"];

                var nodeRect = new Rect(
                    View.PanPosition.x + nodeEditorPosition["x"].GetValue <int>(),
                    View.PanPosition.y + nodeEditorPosition["y"].GetValue <int>(),
                    220,
                    1000
                    );

                GUILayout.BeginArea(nodeRect);

                var finalRect = EditorGUILayout.BeginVertical(NodePadding);
                // finalRect.xMax -= 2;
                finalRect.yMax += 4;
                if (CurrentEvent.type == EventType.Repaint)
                {
                    GUI.skin.window.Draw(finalRect,
                                         false, View.Selection.Contains(node.Name), false, false);
                }

                var    nodeType       = node["Type"];
                string nodeTypeString = nodeType.GetValue <string>();
                string nodeHeader     = nodeTypeString.Substring(nodeTypeString.LastIndexOf(".") + 1);
                EditorGUILayout.LabelField(nodeHeader, EditorStyles.boldLabel);

                var nodeData = node["Data"];

                float originalLabelWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 115;
                EditorGUI.indentLevel++;
                foreach (var childField in nodeData)
                {
                    RPGCoreEditor.DrawField(childField);
                }
                EditorGUI.indentLevel--;
                EditorGUIUtility.labelWidth = originalLabelWidth;

                EditorGUILayout.EndVertical();
                GUILayout.EndArea();

                if (CurrentEvent.type == EventType.MouseDown)
                {
                    var globalFinalRect = new Rect(
                        nodeRect.x,
                        nodeRect.y,
                        finalRect.width,
                        finalRect.height
                        );

                    if (globalFinalRect.Contains(CurrentEvent.mousePosition))
                    {
                        View.Selection.Clear();
                        View.Selection.Add(node.Name);

                        View.CurrentMode = BehaviourEditorView.ControlMode.NodeDragging;
                        GUI.UnfocusWindow();
                        GUI.FocusControl("");

                        CurrentEvent.Use();
                    }
                }
            }
        }