void DrawNodeDragOverlay(Rect bounds) { var cursorWorld = camera.ScreenToWorld(lastMousePosition); var ringTexture = rendererContext.Resources.GetResource <Texture2D>(DungeonEditorResources.TEXTURE_CURSOR_RING_SOLID); int sx = Mathf.RoundToInt(cursorWorld.x / SCBaseDomainNode.TileSize); int sy = Mathf.RoundToInt(cursorWorld.y / SCBaseDomainNode.TileSize); int drawNodeRangeRadius = 4; float drawPixelRangeRadius = drawNodeRangeRadius * SCBaseDomainNode.TileSize; float maxCursorSize = 20; for (int x = sx - drawNodeRangeRadius; x <= sx + drawNodeRangeRadius; x++) { for (int y = sy - drawNodeRangeRadius; y <= sy + drawNodeRangeRadius; y++) { for (int ox = 0; ox < 2; ox++) { for (int oy = 0; oy < 2; oy++) { var offset = new Vector2(ox, oy) * 0.5f; var pos = (new Vector2(x, y) + offset) * SCBaseDomainNode.TileSize; var distanceToCursor = (pos - cursorWorld).magnitude; var cursorScale = Mathf.Clamp(1 - distanceToCursor / drawPixelRangeRadius, 0.0f, 1.0f); // Ease the size { cursorScale = Mathf.Pow(cursorScale, 3); } float cursorSize = maxCursorSize * cursorScale; var size = new Vector2(cursorSize, cursorSize); pos -= size / 2.0f; pos = camera.WorldToScreen(pos); size /= camera.ZoomLevel; var ringBounds = new Rect(pos, size); var color = new Color(1, 0.3f, 0, cursorScale / 2.0f); GUI.DrawTexture(ringBounds, ringTexture, ScaleMode.ScaleToFit, true, 1.0f, color, 0, 0); } } } } var selectedNodes = GetSelectedNodes(); foreach (var node in selectedNodes) { var start = node.Bounds.center; var end = SCBaseDomainNode.GetSnapPosition(start); start = camera.WorldToScreen(start); end = camera.WorldToScreen(end); Handles.color = new Color(0, 0, 0, 0.5f); Handles.DrawLine(start, end); } }
Color GetNodeColor(SCBaseDomainNode node) { var color = node.GetColor(); if (!node.IsSnapped) { color = Color.red; } color.a = node.Selected ? 1.0f : 0.33f; return(color); }
private void OnNodeDragged_Event(object sender, GraphNodeEventArgs e) { foreach (var node in e.Nodes) { if (node is SCBaseDomainNode) { var baseNode = node as SCBaseDomainNode; var snappedCenter = SCBaseDomainNode.GetSnapPosition(baseNode.Bounds.center); bool bCannotBeSnapped = baseNode.ContainsOtherNodeAt(snappedCenter); baseNode.IsSnapped = !bCannotBeSnapped; } } }