/// <summary>
/// Performs an upgrade from the legacy way of specifying data to the new one.
/// </summary>
bool Upgrade()
{
if (mReplacement)
{
return(mReplacement.Upgrade());
}
if (mSprites.Count == 0 && sprites.Count > 0 && material)
{
Texture tex = material.mainTexture;
int width = (tex != null) ? tex.width : 512;
int height = (tex != null) ? tex.height : 512;
for (int i = 0; i < sprites.Count; ++i)
{
Sprite old = sprites[i];
Rect outer = old.outer;
Rect inner = old.inner;
if (mCoordinates == Coordinates.TexCoords)
{
NGUIMath.ConvertToPixels(outer, width, height, true);
NGUIMath.ConvertToPixels(inner, width, height, true);
}
UISpriteData sd = new UISpriteData
{
name = old.name,
x = Mathf.RoundToInt(outer.xMin),
y = Mathf.RoundToInt(outer.yMin),
width = Mathf.RoundToInt(outer.width),
height = Mathf.RoundToInt(outer.height),
paddingLeft = Mathf.RoundToInt(old.paddingLeft * outer.width),
paddingRight = Mathf.RoundToInt(old.paddingRight * outer.width),
paddingBottom = Mathf.RoundToInt(old.paddingBottom * outer.height),
paddingTop = Mathf.RoundToInt(old.paddingTop * outer.height),
borderLeft = Mathf.RoundToInt(inner.xMin - outer.xMin),
borderRight = Mathf.RoundToInt(outer.xMax - inner.xMax),
borderBottom = Mathf.RoundToInt(outer.yMax - inner.yMax),
borderTop = Mathf.RoundToInt(inner.yMin - outer.yMin)
};
mSprites.Add(sd);
}
sprites.Clear();
#if UNITY_EDITOR
NGUITools.SetDirty(this);
UnityEditor.AssetDatabase.SaveAssets();
#endif
return(true);
}
return(false);
}