/// <summary> /// Raised by <see cref="OnTool"/> to perform painting upon pressing left or right mouse button. /// </summary> /// <param name="e">Tool event data.</param> /// <param name="context">Context that tool is being used in.</param> protected virtual void OnPaint(ToolEvent e, IToolContext context) { var brush = e.IsLeftButtonPressed ? ToolUtility.SelectedBrush : ToolUtility.SelectedBrushSecondary; // Like with the regular paint tool, null brush is the eraser! if (brush != null && !PlopUtility.CanPlopWithBrush(brush)) { return; } if (brush == null) { if (ToolUtility.ActivePlop != null) { PlopUtility.ErasePlop(ToolUtility.ActivePlop); ToolUtility.ActivePlop = null; } } else { if (!this.allowOverpaint && ToolUtility.ActivePlop != null) { // Cycle to next variation if replacing plop with same brush. int nextVariation = ToolUtility.ActivePlop.VariationIndex; if (brush == ToolUtility.ActivePlop.Brush) { ++nextVariation; } ToolUtility.ActivePlop = PlopUtility.CyclePlop(context.TileSystem, ToolUtility.ActivePlop, brush, ToolUtility.Rotation, nextVariation); } else { var args = this.GetPaintingArgs(brush); if (args.variation == Brush.RANDOM_VARIATION) { args.variation = this.PreRandomizeVariation(brush, 0); this.RandomizeVariationShift(); } int nextVariation = args.ResolveVariation(0); var plop = PlopUtility.PaintPlop(context.TileSystem, this.ApplySnapping(this.localMousePoint), brush, ToolUtility.Rotation, nextVariation); ToolUtility.ActivePlop = plop; ToolUtility.PreviouslyPlopped = plop; } } }
/// <inheritdoc/> public override void OnDrawGizmos(TileSystem system) { // We need to populate properties of `IBrushContext` for preview generation. var brush = (PreviousToolEvent != null && PreviousToolEvent.IsRightButtonPressed) ? ToolUtility.SelectedBrushSecondary : ToolUtility.SelectedBrush; if (!PlopUtility.CanPlopWithBrush(brush)) { return; } // Do not draw immediate preview when mouse is positioned over a plop // unless overpainting is permitted. if (!this.allowOverpaint && ToolUtility.ActivePlop != null) { return; } // Offset preview against mouse position. Vector3 placementPoint = PlopUtility.PositionFromPlopPoint(system, this.ApplySnapping(this.localMousePoint)); ImmediatePreviewUtility.Matrix = system.transform.localToWorldMatrix * MathUtility.TranslationMatrix(placementPoint); this._fakeContext.TileSystem = system; this._fakeContext.Brush = brush; // Pretend to paint tile so that we can see its data beforehand! var previewTile = ImmediatePreviewUtility.GetPreviewTileData(this._fakeContext, brush, ToolUtility.Rotation); // Plop tool does not support orientations. previewTile.orientationMask = 0; var args = GetPaintingArgs(brush); if (args.variation == Brush.RANDOM_VARIATION) { args.variation = this.PreRandomizeVariation(brush, 0); } previewTile.variationIndex = (byte)args.ResolveVariation(0); brush.OnDrawImmediatePreview(this._fakeContext, previewTile, ImmediatePreviewUtility.PreviewMaterial, brush); }
/// <inheritdoc/> public override void OnSceneGUI(ToolEvent e, IToolContext context) { if (!IsEditorNearestControl) { return; } // "Hide wireframe outline" if (this.HideWireframeOutline) { bool willErase = (ToolUtility.SelectedBrush == null && ToolUtility.ActivePlop != null); bool willCycle = (!this.allowOverpaint && ToolUtility.ActivePlop != null && PlopUtility.CanPlopWithBrush(ToolUtility.SelectedBrush)); bool disableImmediatePreview = (ToolUtility.SelectedBrush != null && ToolUtility.SelectedBrush.disableImmediatePreview); if (!willErase && !willCycle && !disableImmediatePreview) { return; } } // Outline plop with wire cube! Vector3 wirePoint = (!this.allowOverpaint && ToolUtility.ActivePlop != null) ? ToolUtility.ActivePlop.PlopPoint : this.ApplySnapping(this.localMousePoint); Vector3 snapCellSize = context.TileSystem.CellSize; snapCellSize.x = this.SnapAxisX.Resolve(snapCellSize.x); snapCellSize.y = this.SnapAxisY.Resolve(snapCellSize.y); ToolHandleUtility.DrawWireBox(wirePoint, snapCellSize); }