2D Toolkit Forum

2D Toolkit => Support => Topic started by: JReanne on April 13, 2015, 06:48:26 pm

Title: Making a build with only 1x or 2x graphics?
Post by: JReanne on April 13, 2015, 06:48:26 pm
Hello! I'm working on an Android build of my game, and trying to squeeze out every last bit of memory so I can get the .apk below 50 MB.  Right now every Sprite Collection in my game supports both 1x and 2x platforms (with the "Current Platform" set as 1x).  This means that my builds are including both the 1x and 2x atlases - is it possible to build with just one or the other?

Thanks,
Jenna
Title: Re: Making a build with only 1x or 2x graphics?
Post by: unikronsoftware on April 13, 2015, 07:40:49 pm
Hi,

No it isn't possible out of the box. However, if you want to get your hands dirty - the resources that define the sprite collections to include in the build are in Resources/tk2d/... - if you move the correct tk2d_ prefixed file out of those directories, you should be able to exclude them from the build.
Title: Re: Making a build with only 1x or 2x graphics?
Post by: JReanne on April 13, 2015, 08:37:35 pm
I'll try this out - thank you!
Title: Re: Making a build with only 1x or 2x graphics?
Post by: Finnegan on June 25, 2015, 03:12:15 pm
Put this inside the Editor directory and use "Tools ->Move 2x" menu to get @2x out of your resources. To return @2x into build just drag the temp folder content back (from TempTk2dAssets to Resources/tk2d).

You MUST create TempTk2Assets folder manually or the script will not work.

For Unity 4 use Resources.LoadAssetAtPath instead of AssetDatabase.LoadAssetAtPath.
Code: [Select]
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class Move2x : ScriptableWizard
{

public string filter = "@2x";
public string path =  "Assets/Resources/tk2d";
public string tempPath = "Assets/TempTk2dAssets";

[MenuItem("Tools/Move 2x")]

static void CreateWizard()
{
ScriptableWizard.DisplayWizard <Move2x>("Move 2x", "Move");
}

void OnWizardCreate()
{
string[] assets = AssetDatabase.FindAssets("tk2d", new string[]{path});
List<string> oldPathList = new List<string>();
List<string> newPathList = new List<string>();

for (int i = 0; i < assets.Length; i++)
{
string guid = assets[i];
string oldPath = AssetDatabase.GUIDToAssetPath(guid);
tk2dResource res = AssetDatabase.LoadAssetAtPath<tk2dResource>(oldPath);

if (res != null && res.objectReference != null && res.objectReference.name.Contains(filter))
{
oldPathList.Add(oldPath);
string newPath = oldPath.Replace(path, tempPath);
newPathList.Add(newPath);
AssetDatabase.MoveAsset(oldPath, newPath);
}
}
}
}