Implementing Custom Platforms

Documentation and discussion for Draconus Icon Manager available in the Unity Asset Store.
snlehton
Crew
Crew
Posts: 16
Joined: Tue Nov 04, 2014 1:59 pm

Implementing Custom Platforms

Postby snlehton » Thu Jan 15, 2015 12:24 pm

At the moment DIM supports Standalone, iOS and Android builds out of the box. However, it is possible to add your own or other Unity platforms in the tool as well. It only requires a little bit of scripting.

Reason why not all of the Unity platforms are supported is that we haven't had chance to properly test and verify them yet. If your project is on some other platform (such as BlackBerry, PS3, PS4, XBox360, XBoxOne) and need support for it or have implemented support for it, contact us (support@draconus.com, @snlehton or @draconusltd on Twitter). We aim to add all the feasible platforms to DIM in the future (not all of them have icons, though).

To add a custom platform in DIM, you simply need to implement an interface called DIMTargetPlatform:

Code: Select all

public interface DIMTargetPlatform
{   
    // Platform identifier, used for identifying the platform settings
    // (should be something like "BlackBerry" or "Ouya"
    string GetId();
   
        // Name of the platform, displayed to the user ("BlackBerry", "Ouya", "XBox One" or so)
    string GetPlatformName();
   
    // A small texture to be displayed on the platform selector in DIM window
    Texture2D GetPlatformIcon();
       
    // Get information of the icons for this platform
    IList<DIMIconDefinition> GetIconDefinitions();
   
    // Store all generated icons
    void SetIconsForTargetPlatform(IList<DIMGeneratedIcon> icons);
}


As an example, let's implement support for BlackBerry platform. The way this script is going to be implemented is actually the same way how the internally supported platforms work (Standalone, iOS and Android). The script goes into a file named Editor/BlackBerryTargetPlatform.cs (it's an editor only script)

First thing we do is define the id and the platform name:

Code: Select all

public class BlackBerryTargetPlatform : DIMTargetPlatform
{
    public string GetId()
    {
         return "MyCustomTargetPlatform";
    }
   
    public string GetPlatformName()
    {
        return "BlackBerry";
    }
}


Next, let's return an icon for the platform. We're going to use the built-in BlackBerry icon in Unity editor, but you can easily create your own icons as well (the size should be 16x16).

Code: Select all

    public Texture2D GetPlatformIcon()
    {
        return EditorGUIUtility.Load("icons/BuildSettings.BlackBerry.Small.png") as Texture2D;
        // or
       // return AssetDatabase.LoadAsset("MyPlatform.png", typeof(Texture2D)) as Texture2D;
    }


Next, we define all the icons we want to have generated for the platform. We can also return the existing icons for the platform so that DIM can view them. Note that if you're using PlayerSettings.GetIconSizesForTargetGroup and GetIconsForTargetGroup, the arrays may not match in size or order if Unity adds new icons to the platform (which happened recently when they added new iOS and Android icons). Therefore it's better to get the sizes and then find textures of correct size in the texture array:

Code: Select all

    public IList<DIMIconDefinition> GetIconDefinitions()
    {
        // get the icon sizes and textures for BlackBerry
        int[] iconsSizes = PlayerSettings.GetIconSizesForTargetGroup(BuildTargetGroup.BlackBerry);
        List<Texture2D> icons = new List<Texture2D>(PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.BlackBerry));
        // list all icons with textures (if any)
        var list = new List<DIMIconDefinition>();
        for (int i = 0; i < iconsSizes.Length; i++)
        {
            int size = iconsSizes[i];
            Texture2D icon = icons.Find(o => { return o != null && o.width == size; });
            list.Add(new DIMIconDefinition() { textureInPlayerSettings = icon, width = size, height = size });
        }
        return list;
    }


Finally we need to implement support for storing the generated icons:

Code: Select all

    public void SetIconsForTargetPlatform(IList<DIMGeneratedIcon> icons)
    {
        Texture2D[] iconArray = new Texture2D[icons.Count];
        for (int i = 0; i < icons.Count; i++)
            iconArray[i] = icons[i].texture;

        PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.BlackBerry, iconArray);
    }


And that's it!

After compiling the script, you should be able to see the new platform in the DIM window:

customplatform_blackbery.png
customplatform_blackbery.png (32.12 KiB) Viewed 1042 times


You can download the BlackBerry extension here:

tools.draconus.com/dim/DIMTargetPlatform_BlackBerry.cs

Place the extension under an Editor folder such as Assets/Editor or Assets/DIM/Editor.

There is also an extended version of iOS platform which generates iOS Settings and Spotlight icons. Those icons are not currently supported by Unity, but you can manually copy the generated icons to the xcode project (working on a PostProcessBuild extension for this)

tools.draconus.com/dim/DIMTargetPlatform_iOSExtended.cs

Return to “DIM - Draconus Icon Manager”

Who is online

Users browsing this forum: No registered users and 1 guest