Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only

/// <summary>
/// Gets the value in a single dimensional array that represents a three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be retrieves.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="x">The x index (0 to width - 1).</param>
/// <param name="y">The y index (0 to height - 1).</param>
/// <param name="z">The z index (0 to depth - 1).</param>
/// <returns>Returns the value stored in the array.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
/// <remarks>
/// <p>This method provides an alternative to working with three dimensional arrays "var value = new int[3,3,3];" by operating 
/// on a single dimensional array using a math formula to determine the index into the array.</p>
/// <p>Think of a multi-layered image. Each image layer consists of a grid of cells defined by width * height.</p>
/// <p>We can use the formula "layer * (width * height)" to get the starting index of the layer in the array. 
/// To get the index in the image we can use the formula "(y * width) + x". 
/// Combining these two formulas we can access any grid cell of any layer in the array like so "(layer * (width * height)) + ((y * width) + x)".</p>
/// <p>This method does not perform range checking and will throw index out of range exceptions if invalid arguments are specified.</p></remarks>
public static T Get3D<T>(this T[] array, int width, int height, int x, int y, int z)
{
    if (width < 1)
    {
        throw new ArgumentOutOfRangeException("width");
    }

    if (height < 1)
    {
        throw new ArgumentOutOfRangeException("height");
    }

    return array[(z * (width * height)) + ((y * width) + x)];
}

Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only

/// <summary>
/// Sets the value in a single dimensional array that represents a three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be set.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="x">The x index (0 to width - 1).</param>
/// <param name="y">The y index (0 to height - 1).</param>
/// <param name="z">The z index (0 to depth - 1).</param>
/// <param name="value">The value to set.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
/// <remarks>
/// <p>This method provides an alternative to working with three dimensional arrays "var value = new int[3,3,3];" by operating
/// on a single dimensional array using a math formula to determine the index into the array.</p>
/// <p>Think of a multi-layered image. Each image layer consists of a grid of cells defined by width * height.</p>
/// <p>We can use the formula "layer * (width * height)" to get the starting index of the layer in the array.
/// To get the index in the image we can use the formula "(y * width) + x".
/// Combining these two formulas we can access any grid cell of any layer in the array like so "(layer * (width * height)) + ((y * width) + x)".</p>
/// <p>This method does not perform range checking and will throw index out of range exceptions if invalid arguments are specified.</p>
/// </remarks>
public static void Set3D<T>(this T[] array, int width, int height, int x, int y, int z, T value)
{
    if (width < 1)
    {
        throw new ArgumentOutOfRangeException("width");
    }

    if (height < 1)
    {
        throw new ArgumentOutOfRangeException("height");
    }

    array[(z * (width * height)) + ((y * width) + x)] = value;
}

If you are writing custom scripts there may be situations where you don’t want the same component added more then once to a game object. For such situations Unity provides the DisallowMultipleComponent attribute that you can specify in your scripts code.


Takes in an array of floats representing pixels ordered left to right top to bottom. Width & height arguments specify the image dimensions.

        /// <summary>
        /// Smoothens out the image.
        /// </summary>
        /// <param name="image">The source image.</param>
        /// <exception cref="ArgumentNullException"><paramref name="getPixel"/> or <paramref name="setPixel"/> is <see langword="null" />.</exception>
        public static void Smoothen(this float[] image, int width, int height, Func<int, int, float> getPixel, Action<int, int, float> setPixel, float smoothinValue = 9f)
        {
            if (getPixel == null)
            {
                throw new ArgumentNullException("getPixel");
            }

            if (setPixel == null)
            {
                throw new ArgumentNullException("setPixel");
            }

            for (var x = 1; x < width - 1; ++x)
            {
                for (var y = 1; y < height - 1; ++y)
                {
                    var total = 0f;
                    for (var u = -1; u <= 1; u++)
                    {
                        for (var v = -1; v <= 1; v++)
                        {
                            total += getPixel(x + u, y + v);
                        }
                    }

                    setPixel(x, y, total / smoothinValue);
                }
            }
        }

It’s not something people think about these days. Back in the 90’s when MS-DOS was king, alerting the user to a problem involved both a visual alert as well as a auditory alert in the form of a “beep”. It’s actually something I miss from those days. Luckily the unity editor has an API to alert the user and wouldn't you know it, it’s called “Beep”!


If you are developing unity editor extensions often it is necessary to know weather or not unity is compiling the projects scripts. To determine if unity is currently compiling you can simply check the EditorApplication.isCompiling flag in your code before deciding what to do. See older related tip and code example here.


ProjectAndHierarchyEnhancements

Unity provides hooks into the Project and Hierarchy windows OnGui event. This allows you to add additional flair to these windows. To learn how to enhance these windows see the fallowing documentation pages

  1. HierarchyWindowChanged
  2. HierarchyWindowItemOnGUI
  3. ProjectWindowItemOnGUI
  4. ProjectWindowChanged

If you want an example project to work off of and learn from there is an open source project called “UnityEditorEnhancements” that you can download as a zip file or you can fork the Mercurial repository.


SteelSeries 7H Final Review

Published 4/13/2015 by createdbyx in News | Reviews
Tags: ,

I don't like to write reviews immediately after receiving an item, I'd much rather wait a good long time before posting. I purchased these headphones back in Oct 25, 2010 and am only posting this now because the headphones are still for sale on ncix and else where.

Ultimately they worked great for about 2 years of infrequent use, but considering that they are a mid range (price wise) headset and I paid $130 after tax & shipping, I expected them to last a lot longer.

After the first few months the glue partly separated on one side of the top padding. (See link to picture below)

Then the cord had a line break at the point at which the cable merges with the micro usb style end (the end that plugs into the left ear muff). I fully admit this was most likely my fault with the cord break. 2-3 times I had my headphones on and while sitting in my desk chair I bent over to pick something off the ground and yanked on the cord. Not enough to pull them off my head but enough for me to curse at my own stupidity. :P  Even though they did not break after being yanked they did eventually stop working and I needed to bend and twist the cable to get the sound working.

I finally contacted SteelSeries support and was able to purchase a replacement cable for just $5 through PayPal. I bought 2 cables just in case it broke again and I would not have to go through the replacement process another time.

Over the last year the right ear muff would periodically stop working. I would only have to twist the headphones on my head slightly to get them to work. I suspected at the time that it was a connection issue at the point where the top head piece clips into the right ear muff piece. There are 4 springy pins in the ear muffs that make the connection with the top piece. I thought there was just a lack of solid connection but the problem got a bit worse even after a bit of polishing/cleaning.

They finally died this last week when the right ear muff stopped working completely. I broke down and decided to take the right ear muff piece apart. I inspected the cable where the ear muff passes through the hinge that allows the muff to rotate 90 degrees and there did not seem to be any issues with frayed/pinched wiring etc. Before putting them back together I did adjust the wire routing slightly to give it more slack but it did not fix the issue.

Next I took apart the top piece. There were 3 screws holding either the connection points at both ends of the top piece and there did not appear to be any issues there. Then I peeled back the padding and tried taking off the plastic panel via 4 screws but there is 2 plastic weld points that prevented me from removing the panel. I suspect that the problems are hidden behind the panel but I can't get access to it without destroying the panel in the process.

Here is a picture showing the breaks in the plastic, glue separation, and stress points. 7H Problems Screenshot

The glue separation is due to a combination of the heat from my head and the flex in the top part of the head band and never came apart more then what you see in the picture.

I rated this two stars because a 5 star headset is perfect, every part works until it has been used for a few years, and can take a beating. Based on my experience these are not able to take much of a beating in day to day use. I only ever used them periodically at night when other people were sleeping otherwise I prefer to use my 5.1 surround sound speakers. I used them a few times when traveling and kept them in a laptop backpack but always took care to ensure there safety.

All in all when they did work they worked great, but ultimately I won't be buying another SteelSeries headset product. I have nothing against SteelSeries but I am the type of person that expects more out of the products I buy. I'm sure others have had great experiences with there 7H's but I feel my experience was lacking. Buying headphones off the internet is always a crap shoot as you can only rely on on line reviews, and each person has different hearing and tastes.

I have since purchased a Logitech G430 as a replacement based on the reviews, specs, and the fact it has a 3 year warranty.


Work Delegation

Published 4/8/2015 by createdbyx in News
Tags:

I came across a YouTube video related to delegating your work and thought I would try and break it down more as it video did not quite make sense to me at first.

https://www.youtube.com/watch?v=6dIuA69p6dY&t=3m45s

Me                   
==========           
5 day work week       
8hrs day           
$25hr wage           
$200 a day           
$1000 week income   

Assistant
==========
1 day work week
8hrs day
$30hr wage
$240 day
$240 week income

(me) $1000 a week – (assistant) $240 a week = (me) $760 at end of week

I earned $760 adjusted weekly income and I worked 5 days a week

I work 5 days a week and spend $240 a week for someone to work one day means I technically put in a 6 day work week but personally earned $760 if I used an assistant to work that extra day. Normally I would have had to work a 6 day a week job but hiring the assistant means I can work a regular 5 day a week job.

In reality if I personally worked for 5 days a week without an assistant I would earn $1000 a week. At 4 days a week at $25hr I make $800 week Monday to Thursday. I hire an assistant at $30hr to work on Friday and they get my $200 a day wage for taking my place and working on Friday. Then on Friday I give them an extra $40 for working on Friday so they earn there $30hr/$240 a day wage.

So at the end of the week I make $800 - $40 = $760 income for a 5 day work week even though I only actually worked 4 days. You earn $760 take home at the end of the week after having paid $40 to not work on Friday. The benefit to me is that for $40 a week expense I can work 4 days a week and have someone else do my job on Friday.

For the assistant they are getting paid more money then I do at $30hr plus I am paying them an additional $40 for that day of work. So the assistant doing my job for one day actually gets paid $5hr more than I would have earned.

Just because I paid someone to work one extra day for me what benefit does that get me? I still work 4 days a week and I have to spend money to hire an assistant to work 1 extra day but in reality where does that get me?

Essentially what I am getting from hiring an assistant is 24hrs of free time and it only costs me $40. And having 24hrs of free time allows me to get other things done. This is of course totally dependent on how valuable the work my assistant does and weather or not they are properly trained and capable of performing the assigned tasks. From the assistants perspective they are making $5hr more then I do but are under more pressure to perform in order to keep the job in order to justify the $30hr wage.


The fallowing script allows you to control fog settings on a per camera basis, allowing you to use say green fog for one camera but red fog for another camera.

Unity 5 package demo is available here CameraFog.unitypackage (46.66 kb)

Camera Fog Screen Shot

CameraFog.cs script

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CameraFog.cs" company="Codefarts">
//   Copyright (c) 2012 Codefarts
//   All rights reserved.
//   contact@codefarts.com
//   http://www.codefarts.com
// </copyright>   
// --------------------------------------------------------------------------------------------------------------------

// Per-camera fog
// This is a simple class that, when added to a GameObject with a camera, allows you to control the fog settings for that camera separately from the global ones. 
// I'd love to hear from you if you do anything cool with this or have any suggestions :)
// Original author: http://wiki.unity3d.com/index.php/User:Tenebrous
// Author website as of 2015: www.tenebrous.co.uk
// Source: http://wiki.unity3d.com/index.php/CameraFog

namespace Codefarts.GeneralTools.Scripts.Camera
{
    using UnityEngine;

    /// <summary>
    /// Modifies a camera to allows you to control the fog settings for that camera separately from the global scene fog or other cameras. 
    /// </summary>
    [RequireComponent(typeof(Camera))]
    [ExecuteInEditMode]
    public class CameraFog : MonoBehaviour
    {
        /// <summary>
        /// The enabled state weather or not fog will be visible.
        /// </summary>
        public bool Enabled;

        /// <summary>
        /// The start distance from the camera where the fog will be drawn.
        /// </summary>
        public float StartDistance;

        /// <summary>
        /// The end distance from the camera where the fog will be drawn.
        /// </summary>
        public float EndDistance;

        /// <summary>
        /// The fog mode that controls how the fog is rendered.
        /// </summary>
        public FogMode Mode;

        /// <summary>
        /// The density of the fog that is rendered.
        /// </summary>
        public float Density;

        /// <summary>
        /// The fog color.
        /// </summary>
        public Color Color;

        /// <summary>
        /// Stores the pre-render state of the start distance.
        /// </summary>
        private float _startDistance;

        /// <summary>
        /// Stores the pre-render state of the end  distance.
        /// </summary>
        private float _endDistance;

        /// <summary>
        /// Stores the pre-render state of the fog mode.
        /// </summary>
        private FogMode _mode;

        /// <summary>
        /// Stores the pre-render state of the density.
        /// </summary>
        private float _density;

        /// <summary>
        /// Stores the pre-render state of the fog color.
        /// </summary>
        private Color _color;
        
        /// <summary>
        /// Stores the pre-render state wheather or not the fog is enabled.
        /// </summary>
        private bool _enabled;

        /// <summary>
        /// Event that is fired before any camera starts rendering.
        /// </summary>
        private void OnPreRender()
        {
            this._startDistance = RenderSettings.fogStartDistance;
            this._endDistance = RenderSettings.fogEndDistance;
            this._mode = RenderSettings.fogMode;
            this._density = RenderSettings.fogDensity;
            this._color = RenderSettings.fogColor;
            this._enabled = RenderSettings.fog;

            RenderSettings.fog = this.Enabled;
            RenderSettings.fogStartDistance = this.StartDistance;
            RenderSettings.fogEndDistance = this.EndDistance;
            RenderSettings.fogMode = this.Mode;
            RenderSettings.fogDensity = this.Density;
            RenderSettings.fogColor = this.Color;
        }

        /// <summary>
        /// Event that is fired after any camera finishes rendering.
        /// </summary>
        private void OnPostRender()
        {
            RenderSettings.fog = this._enabled;
            RenderSettings.fogStartDistance = this._startDistance;
            RenderSettings.fogEndDistance = this._endDistance;
            RenderSettings.fogMode = this._mode;
            RenderSettings.fogDensity = this._density;
            RenderSettings.fogColor = this._color;
        }
    }
}

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