public override void OnInteractivePreviewGUI(Rect region, GUIStyle background) { Array.Resize(ref selected, section.Segments); // Calculate drawing area rect: Vector2 oldCenter = region.center; if (region.width > region.height) { region.width = region.height; } if (region.height > region.width) { region.height = region.width; } region.width -= 10; region.height -= 15; region.center = oldCenter; // Draw background and lines: DrawDrawingArea(region); // Draw the section outline: DrawSectionOutline(region, Color.cyan); // Draw all draggable vertices: for (int i = 0; i < section.Segments; i++) { float x = region.center.x + section.vertices[i].x * region.width * 0.5f; float y = region.center.y + section.vertices[i].y * region.height * 0.5f; Vector2 pos = new Vector2(x, y); bool oldSelection = selected[i]; Vector2 olsPos = pos; selected[i] = DraggableIcon.Draw(selected[i], i, ref pos, Color.cyan); if (selected[i] != oldSelection) { this.Repaint(); } if (pos != olsPos) { pos.x = Mathf.Clamp(CableSection.SnapTo(pos.x - region.center.x, section.snapX, 5) / (region.width * 0.5f), -1, 1); pos.y = Mathf.Clamp(CableSection.SnapTo(pos.y - region.center.y, section.snapY, 5) / (region.height * 0.5f), -1, 1); section.vertices[i] = pos; if (i == 0) { section.vertices[section.Segments] = pos; } EditorUtility.SetDirty(target); } } }
public void OnEnable() { section = (CableSection)target; }