Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

The DrawGizmo attribute allows you to setup your gizmo drawing code some place other then with your MonoBehavior class. The code below shows an example of the DrawGizmo attribute used on a method within a Editor class.

    /// <summary>
    /// Provides a editor for the <see cref="TileMap"/> component
    /// </summary>
    [CustomEditor(typeof(TileMap))]
    public class TileMapEditor : Editor
    {
        /// The RenderMapGizmo method will be called if the map is selected. 
        [DrawGizmo(GizmoType.Selected | GizmoType.Active)]
        static void RenderMapGizmo(TileMap map, GizmoType gizmoType)
        {
            // store map width, height and position
            var mapWidth = map.Columns * map.CellWidth;
            var mapHeight = map.Rows * map.CellHeight;
            var position = map.transform.position;
            var activelayerHeight = map.ActiveLayer * map.Depth;

            if (map.drawGridLines)
            {
                // draw layer border
                Gizmos.color = Color.white;
                Gizmos.DrawLine(
                    position + new Vector3(0, activelayerHeight, 0), position + new Vector3(mapWidth, activelayerHeight, 0));
                Gizmos.DrawLine(
                    position + new Vector3(0, activelayerHeight, 0), position + new Vector3(0, activelayerHeight, mapHeight));
                Gizmos.DrawLine(
                    position + new Vector3(mapWidth, activelayerHeight, 0),
                    position + new Vector3(mapWidth, activelayerHeight, mapHeight));
                Gizmos.DrawLine(
                    position + new Vector3(0, activelayerHeight, mapHeight),
                    position + new Vector3(mapWidth, activelayerHeight, mapHeight));
 
                // more draw logic here
        }
    }

The alternative is that you can have a method in your MonoBehavior called OnDrawGizmosSelected

    /// <summary>
    /// Provides a component for tile mapping.
    /// </summary>
    public class TileMap : MonoBehaviour
    {
 
        /// <summary>
        /// When the game object is selected this will draw the gizmos
        /// </summary>
        /// <remarks>Only called when in the Unity editor.</remarks>
        private void OnDrawGizmosSelected()
        {
            // gizmo draw code goes here            
        }
    }

… But since gizmo drawing logic is typically for use within the unity editor the DrawGizmo attribute allows you to place the draw logic in a more appropriate location.


I have made a few minor changes to my Tile material Creation Window.

  • Provided a download link to the second release of the tool.
  • Added inset field to tweak the selection rectangle by a small amount to help clip off any unwanted pixels bleeding over from adjacent tiles.
  • Fixed a small bug where selection rectangles were not being drawn exactly where they should be

I have created a tool to assit in creating materials from tiles in a tile set. See the Tile Material Creation Window page for *.unitypackage download and more information.


If you have private fields that are wrapped with a public property but you want the value of those private fields to be saved with your scene you can use the SerializeField attribute.


Did you know with the release of Unity 4 MonoBehaviours can now be inside namespaces! Finally we can better organize our codez!


Did you know you can customize the look of the mouse cursor in your game by calling Cursor.SetCursor?


This is not so much a unity specific tip but more of a C# language tip. if you are trying to port or adapt your game code from one platform to another like for example from XNA over to unity implicit operators may come in handy for automatically casting types and making you code much more readable and easier to port.

Link to MSDN Documentation here

Often times we programmers can fall into bad programming habits and we can forget or overlook language and API features that would otherwise make our lives easier. :P


I recently purchased the $40 windows 8 pro upgrade deal. I already had windows 7 and was in the process of upgrading my computer to 32gb ram and a ssd so decided to take advantage of the offer.

I got the Windows 8 pro install utility to generate a iso for me and then made a usb boot stick and proceeded to install windows 8 as a clean install so I could start from scratch.

The problem came when I tried to activate windows and it said I could not. Even though windows 8 allowed me to perform a clean install the activation said I could not activate because I used the windows 8 upgrade to do the clean install?

After some searching I came across this article and it allowed me to activate my windows 8 installation.

http://www.ghacks.net/2012/10/27/windows-8-upgrade-clean-install-possible/

  • Open regedit by pressing Windows-q, entering regedit and selecting the result from the list of hits.
  • Navigate to HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Setup/OOBE/
  • Change MediaBootInstall from 1 to 0
  • Go back to the start screen and enter cmd there.
  • Right-click Command Prompt and select to run it as administrator.
  • Type slmgr /rearm on the command line and hit enter.
  • Reboot Windows now.
  • Run the activation utility afterwards, enter your product key to activate Windows. (I didn’t have to do this step it was already activated)

I'm running out of tips from the unity docs so I will be posting small code snips that you can use

The first code snip is for object billboarding. Just drop the script onto the object and it will automatically face the camera.


You can specify the RequireComponent attribute on a class that inherits from MonoBehavior and Unity will add the specified component if it is not already present when you add the script to the game object.

[RequireComponent(typeof(RigidBody))]
public class SomeBehaviorScript : MonoBehaviour
{
}

Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume