Exemple #1
0
        void RemovingNodes(int id)
        {
            Ray pointer = HandleUtility.GUIPointToWorldRay(e.mousePosition);

            // draws brush
            var p = pointer.origin + pointer.direction * 5f;

            Handles.color = Color.yellow;
            Handles.CircleHandleCap(id, p, Quaternion.LookRotation(pointer.direction), graph.m_brushRadius, EventType.Repaint);

            var nodes = graph.GetNodes();

            Handles.color = Color.red;
            for (int ni = 0; ni < nodes.Count; ni++)
            {
                var screenNodePos = HandleUtility.WorldToGUIPoint(nodes[ni].Position);
                var mousePos      = e.mousePosition;

                var distance = Vector2.Distance(new Vector2(screenNodePos.x, screenNodePos.y), mousePos);
                //Handles.Label(nodes[ni].Position, $"Distance: {distance}");
                if (distance <= graph.m_brushRadius * 100)
                {
                    Handles.CubeHandleCap(0, nodes[ni].Position, Quaternion.identity, graph.m_nodeSize, EventType.Repaint);
                }
            }

            if (Event.current.type == EventType.MouseDown)
            {
                for (int ni = 0; ni < nodes.Count; ni++)
                {
                    var screenNodePos = HandleUtility.WorldToGUIPoint(nodes[ni].Position);
                    var mousePos      = e.mousePosition;

                    var distance = Vector2.Distance(new Vector2(screenNodePos.x, screenNodePos.y), mousePos);
                    if (distance <= graph.m_brushRadius * 100)
                    {
                        graph.RemoveNode(ni);
                    }
                }
            }

            if (autoRebuild.boolValue)
            {
                graph.RebuildNodegraph();
            }
        }