Beispiel #1
0
        private void DrawNodeWindow(int id)
        {
            if (Event.current.type == EventType.Layout)
            {
                return;
            }

            BehaviourNode node = targetGraph.AllNodes[id];

            if (EventType.MouseDown == currentEvent.type || EventType.MouseUp == currentEvent.type ||
                EventType.MouseDrag == currentEvent.type || EventType.MouseMove == currentEvent.type)
            {
                selectedWindow = id;
                EditorUtility.SetDirty(node);
            }

            if (!node.LastRect.Overlaps(screenRect))
            {
                return;
            }

            Rect settingsRect = new Rect(node.LastRect.width - 20, 5, 20, 20);
            Rect iconRect     = new Rect(0, 0, 18, 18);

            if (GUI.Button(settingsRect, "", BehaviourGUIStyles.Instance.settingsStyle))
            {
                rightClickedNode = node;
                BasicNodeMenu.ShowAsContext();
            }

            Color originalColour = GUI.color;

            GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.65f);
            EditorGUI.LabelField(iconRect, new GUIContent(AssetPreview.GetMiniThumbnail(node)));
            GUI.color = originalColour;

            if (currentEvent.type == EventType.MouseDown)
            {
                if (iconRect.Contains(currentEvent.mousePosition))
                {
                    if (currentEvent.button == 0)
                    {
                        if (currentEvent.clickCount == 1)
                        {
                            rightClickedNode = node;
                            PingSourceCallback();
                        }
                        else
                        {
                            rightClickedNode = node;
                            OpenScriptCallback();
                        }
                        currentEvent.Use();
                    }
                }
            }

            SerializedObject serializedObject = SerializedObjectPool.Grab(node);

            //Undo.RecordObject (node, "Edit Node");

            float originalLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = node.LastRect.width / 2;

            serializedObject.FindProperty("Position").vector2Value = node.Position;

            //EditorGUI.BeginChangeCheck ();
            //string newName = EditorGUILayout.DelayedTextField (node.name);
            //if (EditorGUI.EndChangeCheck ())
            //{
            //	RenameAction (node, newName);
            //}

            Rect contentRect = BehaviourGraphResources.Instance.NodeStyle.padding.Remove(node.LastRect);

            node.DrawGUI(serializedObject, new Rect(contentRect.x - node.Position.x - dragging_Position.x,
                                                    contentRect.y - node.Position.y - dragging_Position.y,
                                                    contentRect.width, contentRect.height));

            serializedObject.ApplyModifiedProperties();

            if (currentEvent.type == EventType.MouseDown)
            {
                if (currentEvent.button == 1)
                {
                    rightClickedNode = node;
                    BasicNodeMenu.ShowAsContext();
                }
            }

            EditorGUIUtility.labelWidth = originalLabelWidth;

#if HOVER_EFFECTS
            if (connection_Start == null && connection_End == null)
            {
                EditorGUIUtility.AddCursorRect(new Rect(node.LastRect.x - node.Position.x - dragging_Position.x,
                                                        node.LastRect.y - node.Position.y - dragging_Position.y,
                                                        node.LastRect.width, node.LastRect.height), MouseCursor.MoveArrow);
            }
#endif

            if (currentEvent.button != 2)
            {
                GUI.DragWindow();
            }
        }