/// <summary> /// Draw nozzle indicator to match specified radius. /// </summary> /// <param name="position">Position to draw indicator (in local space of tile system).</param> /// <param name="nozzle">Type of brush nozzle.</param> /// <param name="radius">Radius of nozzle (in local space of tile system).</param> /// <param name="faceColor">Color of shaded face.</param> /// <param name="outlineColor">Color of wire outline.</param> public static void DrawNozzleIndicatorSmoothRadius(Vector3 position, BrushNozzle nozzle, float radius, Color faceColor, Color outlineColor) { if (nozzle == BrushNozzle.Round) { Handles.color = faceColor; Handles.DrawSolidDisc(position, Vector3.forward, radius); Handles.color = outlineColor; Handles.DrawWireDisc(position, Vector3.forward, radius); } else { Handles.color = Color.white; s_SquareNozzleVerts[0] = new Vector3(position.x - radius, position.y + radius, 0); s_SquareNozzleVerts[1] = new Vector3(position.x + radius, position.y + radius, 0); s_SquareNozzleVerts[2] = new Vector3(position.x + radius, position.y - radius, 0); s_SquareNozzleVerts[3] = new Vector3(position.x - radius, position.y - radius, 0); Handles.DrawSolidRectangleWithOutline(s_SquareNozzleVerts, faceColor, outlineColor); } }
/// <summary> /// Draw nozzle indicator to match specified radius using shading and wireframe /// color from user preferences. /// </summary> /// <inheritdoc cref="DrawNozzleIndicatorSmoothRadius(Vector3, BrushNozzle, float, Color, Color)"/> public static void DrawNozzleIndicatorSmoothRadius(Vector3 position, BrushNozzle nozzle, float radius) { DrawNozzleIndicatorSmoothRadius(position, nozzle, radius, RtsPreferences.ToolShadedColor, RtsPreferences.ToolWireframeColor); }
/// <inheritdoc/> protected override NozzleIndicator GetNozzleIndicator(TileSystem system, TileIndex index, BrushNozzle nozzle) { NozzleIndicator mode = RtsPreferences.ToolPreferredNozzleIndicator; if (mode == NozzleIndicator.Automatic) { mode = NozzleIndicator.Flat; // Determine based upon active tile. var tile = system.GetTile(index); if (tile != null && tile.brush != null && tile.brush.UseWireIndicatorInEditor) { mode = NozzleIndicator.Wireframe; } } return(mode); }
/// <summary> /// Draw nozzle indicator to provide user with feedback by indicating position /// of active tile in scene view. /// </summary> /// <remarks> /// <para>The default implementation of this function honors preferred nozzle /// indicator where possible. Flat indicator is drawn to represent larger areas of /// tiles when a radius larger than zero is specified regardless of the preferred /// nozzle indicator.</para> /// <para>This function is typically invoked automatically when processing scene /// GUI events (unless of course <see cref="OnSceneGUI"/> has been overridden).</para> /// </remarks> /// <param name="system">Tile system.</param> /// <param name="index">Index of tile.</param> /// <param name="nozzle">Type of brush nozzle.</param> /// <param name="nozzleSize">Size of nozzle where <c>1</c> is a single tile.</param> /// <seealso cref="GetNozzleIndicator"/> protected virtual void DrawNozzleIndicator(TileSystem system, TileIndex index, BrushNozzle nozzle, int nozzleSize) { nozzleSize = Mathf.Max(1, nozzleSize); // Temporarily scale handles matrix by cell size of tile system. Matrix4x4 restoreMatrix = Handles.matrix; Matrix4x4 tempMatrix = restoreMatrix; MathUtility.MultiplyMatrixByScale(ref tempMatrix, system.CellSize); Handles.matrix = tempMatrix; // Calculate position to draw indicator (in local space of tile system). Vector3 position = new Vector3(index.column + 0.5f, -index.row - 0.5f); // Always use flat indicator for larger nozzle sizes. NozzleIndicator mode = (nozzleSize > 1) ? NozzleIndicator.Flat : this.GetNozzleIndicator(system, index, nozzle); if (mode == NozzleIndicator.Flat) { // Always use square nozzle indicator when radius only permits a single // tile to be painted! if (nozzleSize == 1) { nozzle = BrushNozzle.Square; } --nozzleSize; float indicatorRadius; switch (nozzle) { default: case BrushNozzle.Round: indicatorRadius = (float)(nozzleSize / 2) + 0.5f; break; case BrushNozzle.Square: indicatorRadius = (float)nozzleSize / 2f + 0.5f; // Offset indicator for odd sizes. if ((nozzleSize & ~1) != nozzleSize) { position.x += 0.5f; position.y -= 0.5f; } break; } // Illustrate size of brush radius. ToolHandleUtility.DrawNozzleIndicatorSmoothRadius(position, nozzle, indicatorRadius); } else { // Simple 3D wire cube. ToolHandleUtility.DrawWireCube(position); } Handles.matrix = restoreMatrix; }
/// <summary> /// Gets indicator that should be drawn to represent tool nozzle. /// </summary> /// <remarks> /// <para>This method is called by <see cref="DrawNozzleIndicator"/> to determine /// which nozzle indicator should be used for the given context. For example, the /// wireframe indicator is sometimes more appropriate for 3D tiles whilst the flat /// indicator is better for 2D tiles.</para> /// <para>The outcome of this method can be customized by providing a specialized /// implementation. This can be useful to dynamically choose the indicator most /// relevant for an existing tile.</para> /// </remarks> /// <example> /// <para>The following example demonstrates how to pick an indicator based upon /// an existing tile. The method begins by assuming the user preferred nozzle /// indicator and proceeds to automatically pick between flat and wireframe when /// specified based upon the brush that was used to paint the existing tile.</para> /// <code language="csharp"><![CDATA[ /// protected override NozzleIndicator GetNozzleIndicator(TileSystem system, int row, int column, BrushNozzle nozzle) /// { /// NozzleIndicator mode = PreferredNozzleIndicator; /// /// // Would user prefer tool to automatically pick indicator? /// if (mode == NozzleIndicator.Automatic) { /// mode = NozzleIndicator.Flat; /// /// // Lookup the existing tile and switch to wireframe mode if /// // associated brush indicates to do so. /// TileData tile = system.GetTile(row, column); /// if (tile != null && tile.brush != null && tile.brush.UseWireIndicatorInEditor) { /// mode = NozzleIndicator.Wireframe; /// } /// } /// /// return mode; /// } /// ]]></code> /// </example> /// <param name="system">Tile system.</param> /// <param name="index">Index of tile.</param> /// <param name="nozzle">Type of brush nozzle.</param> protected virtual NozzleIndicator GetNozzleIndicator(TileSystem system, TileIndex index, BrushNozzle nozzle) { NozzleIndicator mode = RtsPreferences.ToolPreferredNozzleIndicator; if (mode == NozzleIndicator.Automatic) { mode = NozzleIndicator.Flat; if (ToolUtility.SelectedBrush != null) { if (ToolUtility.SelectedBrush.UseWireIndicatorInEditor) { mode = NozzleIndicator.Wireframe; } } else { // Determine based upon active tile (i.e. when using eraser). var tile = system.GetTile(index); if (tile != null && tile.brush != null && tile.brush.UseWireIndicatorInEditor) { mode = NozzleIndicator.Wireframe; } } } return(mode); }
/// <inheritdoc/> protected override void DrawNozzleIndicator(TileSystem system, TileIndex index, BrushNozzle nozzle, int radius) { base.DrawNozzleIndicator(system, index, BrushNozzle.Square, 1); if (system == this.anchorSystem) { if (ToolUtility.FillCenter) { ToolHandleUtility.DrawRectangle(system, this.anchorIndex, index, this.IsTargetPointConstrained); } else { ToolHandleUtility.DrawRectangleBorder(system, this.anchorIndex, index, this.IsTargetPointConstrained); } } }