Hello Guest

Author Topic: Making a build with only 1x or 2x graphics?  (Read 3050 times)

JReanne

  • Newbie
  • *
  • Posts: 8
    • View Profile
Making a build with only 1x or 2x graphics?
« 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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Making a build with only 1x or 2x graphics?
« Reply #1 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.

JReanne

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Making a build with only 1x or 2x graphics?
« Reply #2 on: April 13, 2015, 08:37:35 pm »
I'll try this out - thank you!

Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Making a build with only 1x or 2x graphics?
« Reply #3 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);
}
}
}
}
« Last Edit: June 30, 2015, 07:00:57 pm by Finnegan »