/// <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);
        }
示例#2
0
        private void DoToolSceneGUI(ToolBase tool)
        {
            var tileSystem = target as TileSystem;

            // Toggle preview material using control key.
            this.CheckSwitchImmediatePreviewMaterial();

            ToolUtility.CheckToolKeyboardShortcuts();

            // Preserve current state of handles.
            Matrix4x4 originalMatrix     = Handles.matrix;
            Color     restoreHandleColor = Handles.color;

            // Place handles within local space of tile system.
            Handles.matrix = tileSystem.transform.localToWorldMatrix;

            // Tools cannot interact with locked tile systems!
            if (!tileSystem.Locked)
            {
                tool.OnSceneGUI(this.toolEvent, this);
            }
            else
            {
                Vector3 activeCenter = Vector3.zero;
                activeCenter.x += this.toolEvent.MousePointerTileIndex.column * tileSystem.CellSize.x + tileSystem.CellSize.x / 2f;
                activeCenter.y -= this.toolEvent.MousePointerTileIndex.row * tileSystem.CellSize.y + tileSystem.CellSize.y / 2f;

                ToolHandleUtility.DrawWireBox(activeCenter, tileSystem.CellSize);
            }

            // Restore former state of handles.
            Handles.matrix = originalMatrix;
            Handles.color  = restoreHandleColor;
        }
示例#3
0
        /// <summary>
        /// Raised when handling scene view GUI events.
        /// </summary>
        /// <remarks>
        /// <para>The primary purpose of this method is to draw helper objects into
        /// scene views making it easier to interact with tile systems. Custom tool
        /// processing logic should be placed into one of the following methods
        /// where possible:</para>
        /// <list type="bullet">
        ///     <item><see cref="OnRefreshToolEvent"/></item>
        ///     <item><see cref="OnTool"/></item>
        ///     <item><see cref="OnToolInactive"/></item>
        /// </list>
        /// <para>This method will be invoked multiple times when handling different
        /// GUI events within a scene view. This method is called from the context of
        /// the tile system editor (see <a href="http://docs.unity3d.com/Documentation/ScriptReference/Editor.OnSceneGUI.html">Editor.OnSceneGUI</a>).</para>
        /// <para>Here is the default implementation of this method:</para>
        /// <code language="csharp"><![CDATA[
        /// public override void OnSceneGUI(ToolEvent e, IToolContext context)
        /// {
        ///     if (!IsEditorNearestControl) {
        ///         return;
        ///     }
        ///     this.DrawNozzleIndicator(context.TileSystem, e.tileIndex, BrushNozzle.Square, 1);
        /// }
        /// ]]></code>
        /// </remarks>
        /// <param name="e">Event data.</param>
        /// <param name="context">Context of tool usage.</param>
        public virtual void OnSceneGUI(ToolEvent e, IToolContext context)
        {
            if (!IsEditorNearestControl)
            {
                return;
            }

            // Outline plop with wire cube!
            if (ToolUtility.ActivePlop != null)
            {
                ToolHandleUtility.DrawWireBox(ToolUtility.ActivePlop.PlopPoint, context.TileSystem.CellSize);
                return;
            }

            this.DrawNozzleIndicator(context.TileSystem, e.MousePointerTileIndex, BrushNozzle.Square, 1);
        }
        /// <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);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Draw line between two tile indices taking nozzle area into consideration.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <param name="from">Index of first tile.</param>
        /// <param name="to">Index of second tile.</param>
        protected virtual void DrawNozzleLine(TileSystem system, TileIndex from, TileIndex to)
        {
            Vector3 fromPoint = this.PreFilterLocalPoint(system.LocalPositionFromTileIndex(from));
            Vector3 toPoint   = this.PreFilterLocalPoint(system.LocalPositionFromTileIndex(to));

            Vector3 cellSize = system.CellSize;

            if (ToolUtility.BrushNozzle == BrushNozzle.Square && (this.NozzleSize & 0x01) == 0)
            {
                fromPoint.x += cellSize.x;
                fromPoint.y -= cellSize.y;
                toPoint.x   += cellSize.x;
                toPoint.y   -= cellSize.y;
            }

            ToolHandleUtility.DrawLineHandles(fromPoint, toPoint, Color.white);
        }
示例#6
0
        /// <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;
        }