Saturday, August 23, 2014

Making GalleryView items clickable with FancyBox

I am currently making use of the GalleryView jQuery plugin which feels great but it lacks a functionality that I needed: clicking on the images to show them in a modal dialog.

I therefore integrated a separate plugin called FancyBox that handles modal functionality beautifully.

To do this, I first did a minor change to jquery.galleryview.js, where I added the following underneath var img = $('<img />');:
img.attr('class', 'clickable');
img.attr('alt', gvImage.attrs.title);

This is so that I can access the images in the GalleryView image gallery whenever an image is clicked, and I reference them with a class clickable. I also fetch the description of the image and store it in the alt tag.

Then I simply hook to those images and open fancy box with the current image that's displayed on the slideshow:
$('.clickable').live('click', function(e){ 
    var img = $(this);
    var imgSrc = img.attr('src');
    var imgDesc = img.attr('alt');
    $[ { href : imgSrc, title : imgDesc } ], { padding : 0 });

And here's a demo.

Monday, July 21, 2014

A workaround for allowing multiple callbacks to Application.RegisterLogCallback

Unity only supports a single delegate to be registered with Application.RegisterLogCallback, which is unfortunate because it means that two independent plugins can't make separate use of it.

A bug was filed for this issue last year:

To get around this, I wrote a class to allow for multiple callbacks to be registered. Make sure let only this class make the call to Application.RegisterLogCallback.
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Unity only handles a single delegate registered with Application.RegisterLogCallback
/// This class is used to work around that by allowing multiple delegates to hook to the log callback.
/// </summary>
public static class LogCallbackHandler
    private static readonly List<Application.LogCallback> callbacks;

    static LogCallbackHandler()
        callbacks = new List<Application.LogCallback>();


    /// <summary>
    /// Register a delegate to be called on log messages.
    /// </summary>
    /// <param name="logCallback"></param>
    public static void RegisterLogCallback(Application.LogCallback logCallback)

    private static void HandleLog(string condition, string stackTrace, LogType type)
        for (var i = 0; i < callbacks.Count; i++)
            callbacks[i](condition, stackTrace, type);

Thursday, June 26, 2014

Getting rid of the pesky "Uncaught exception in async net callback" Unity message

After some Unity update a couple of months back, an annoying error started showing in the console unexpectedly:

Uncaught exception in async net callback: Object reference not set to an instance of an object
UnityEditor.AsyncHTTPClient:Done(State, Int32)

  at UnityEngine.GUISkin.GetStyle (System.String styleName) [0x00010] in C:\BuildAgent\work\aeedb04a1292f85a\artifacts\EditorGenerated\GUISkinBindings.cs:268 
  at UnityEngine.GUIStyle.op_Implicit (System.String str) [0x00020] in C:\BuildAgent\work\aeedb04a1292f85a\artifacts\EditorGenerated\GUIStyleBindings.cs:833 
  at UnityEditor.ProjectBrowser.InitSearchMenu () [0x00014] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\ProjectBrowser.cs:460 
  at UnityEditor.ProjectBrowser.AssetStoreSearchEndedCallback () [0x00000] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\ProjectBrowser.cs:488 
  at UnityEditor.ObjectListArea+c__AnonStorey10.<>m__19 (UnityEditor.AssetStoreSearchResults results) [0x00356] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\ObjectListArea.cs:407 
  at UnityEditor.AssetStoreResultBase`1[Derived].Parse (UnityEditor.AssetStoreResponse response) [0x000fc] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\AssetStore\AssetStoreClient.cs:89 
  at UnityEditor.AssetStoreClient+c__AnonStorey2E.<>m__53 (UnityEditor.AssetStoreResponse ar) [0x00000] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\AssetStore\AssetStoreClient.cs:751 
  at UnityEditor.AssetStoreClient+c__AnonStorey2D.<>m__51 (UnityEditor.AsyncHTTPClient job) [0x00012] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\AssetStore\AssetStoreClient.cs:624 
UnityEditor.AsyncHTTPClient:Done(State, Int32)

Long story short, this is how you get rid of it:

Thursday, February 13, 2014

Failed to start a Riak cluster after changing the -name parameter in vm.args

I am currently in the process of setting up a Riak cluster and I encountered a problem where my cluster would not start if I change the -name parameter in the vm.args file.

After some searching, I found this official link with this notice:

Following the first option to delete the contents of the ring directory (I built from the source, so my ring directory was at /riak-1.4.7/rel/riak/data/ring/), I then managed to successfully restart the cluster with ./riak start.

Wednesday, January 15, 2014

Changing Unity's default MonoBehaviour and Shader templates

If you find yourself having to delete those default // Use this for initialization and // Update is called once per frame comments every time you create a script file, then it's probably best you modify Unity's default source file template.

From Unity 4, assuming a default installation directory these templates are found in: C:\Program Files (x86)\Unity\Editor\Data\Resources\ScriptTemplates

In there, you'll find the JavaScript, C# and Boo script templates along with the shader and compute shader templates.

Here's the C# one:
using UnityEngine;
using System.Collections;

public class #SCRIPTNAME# : MonoBehaviour {

 // Use this for initialization
 void Start () {
 // Update is called once per frame
 void Update () {