Пример #1
0
    void RenderDecaledNode(int id, PWNode node)
    {
        //node grid snapping when pressing cmd/crtl
        if (node.isDragged && e.command)
        {
            Vector2 pos = node.rect.position;
            //aproximative grid cell size
            float snapPixels = 25.6f;

            pos.x = Mathf.RoundToInt(Mathf.RoundToInt(pos.x / snapPixels) * snapPixels);
            pos.y = Mathf.RoundToInt(Mathf.RoundToInt(pos.y / snapPixels) * snapPixels);
            node.rect.position = pos;
        }

        //move the node if panPosition changed:
        node.rect = PWUtils.DecalRect(node.rect, graph.panPosition);
        Rect decaledRect = GUILayout.Window(id, node.rect, node.OnWindowGUI, node.name, (node.isSelected) ? nodeSelectedStyle : nodeStyle, GUILayout.Height(node.viewHeight));

        node.visualRect = decaledRect;
        node.rect       = PWUtils.DecalRect(decaledRect, -graph.panPosition);

        //draw node header:
        //Draw the node header using the color scheme:
        if (e.type == EventType.Repaint)
        {
            float h = nodeStyle.border.top;
            float w = decaledRect.width - nodeStyle.border.right - nodeStyle.border.left;
            GUI.color = PWColorTheme.GetNodeColor(node.colorSchemeName);
            // GUI.DrawTexture(new Rect(0, 0, w, h), nodeHeaderStyle.normal.background);
            nodeHeaderStyle.Draw(new Rect(decaledRect.x, decaledRect.y, w, h), false, false, false, false);
            GUI.color = Color.white;
        }

        if (node.debug)
        {
            Rect debugRect = decaledRect;
            debugRect.y -= 20;
            EditorGUI.LabelField(debugRect, "id: " + node.id);
            debugRect.y -= 20;
            EditorGUI.LabelField(debugRect, "comp order: " + node.computeOrder + " | can work: " + node.canWork);
        }
    }