UIAtlas.Upgrade C# (CSharp) Method

Upgrade() private method

Performs an upgrade from the legacy way of specifying data to the new one.
private Upgrade ( ) : bool
return bool
	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();
				sd.name = old.name;
				
				sd.x = Mathf.RoundToInt(outer.xMin);
				sd.y = Mathf.RoundToInt(outer.yMin);
				sd.width = Mathf.RoundToInt(outer.width);
				sd.height = Mathf.RoundToInt(outer.height);
				
				sd.paddingLeft = Mathf.RoundToInt(old.paddingLeft * outer.width);
				sd.paddingRight = Mathf.RoundToInt(old.paddingRight * outer.width);
				sd.paddingBottom = Mathf.RoundToInt(old.paddingBottom * outer.height);
				sd.paddingTop = Mathf.RoundToInt(old.paddingTop * outer.height);
				
				sd.borderLeft = Mathf.RoundToInt(inner.xMin - outer.xMin);
				sd.borderRight = Mathf.RoundToInt(outer.xMax - inner.xMax);
				sd.borderBottom = Mathf.RoundToInt(outer.yMax - inner.yMax);
				sd.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;
	}
}

Usage Example

Beispiel #1
0
    /// <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);
    }
All Usage Examples Of UIAtlas::Upgrade