示例#1
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;
        }
        /// <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);
        }
示例#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);
        }