当前位置: 首页>>代码示例>>C#>>正文


C# SpriteEntry类代码示例

本文整理汇总了C#中SpriteEntry的典型用法代码示例。如果您正苦于以下问题:C# SpriteEntry类的具体用法?C# SpriteEntry怎么用?C# SpriteEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SpriteEntry类属于命名空间,在下文中一共展示了SpriteEntry类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddSprite

    /// <summary>
    /// Add a new sprite to the atlas, given the texture it's coming from and the packed rect within the atlas.
    /// </summary>
    static UIAtlas.Sprite AddSprite(List<UIAtlas.Sprite> sprites, SpriteEntry se)
    {
        UIAtlas.Sprite sprite = null;

        // See if this sprite already exists
        foreach (UIAtlas.Sprite sp in sprites)
        {
            Debug.Log(se.tex.name + " " + sp.name);
            if (sp.name == se.tex.name)
            {
                sprite = sp;
                break;
            }
        }

        if (sprite != null)
        {
            float x0 = sprite.inner.xMin - sprite.outer.xMin;
            float y0 = sprite.inner.yMin - sprite.outer.yMin;
            float x1 = sprite.outer.xMax - sprite.inner.xMax;
            float y1 = sprite.outer.yMax - sprite.inner.yMax;

            sprite.outer = se.rect;
            sprite.inner = se.rect;

            sprite.inner.xMin = Mathf.Max(sprite.inner.xMin + x0, sprite.outer.xMin);
            sprite.inner.yMin = Mathf.Max(sprite.inner.yMin + y0, sprite.outer.yMin);
            sprite.inner.xMax = Mathf.Min(sprite.inner.xMax - x1, sprite.outer.xMax);
            sprite.inner.yMax = Mathf.Min(sprite.inner.yMax - y1, sprite.outer.yMax);
        }
        else
        {
            sprite = new UIAtlas.Sprite();
            sprite.name = se.tex.name;
            sprite.outer = se.rect;
            sprite.inner = se.rect;
            sprites.Add(sprite);
        }

        float width  = Mathf.Max(1f, sprite.outer.width);
        float height = Mathf.Max(1f, sprite.outer.height);

        // Sprite's padding values are relative to width and height
        sprite.paddingLeft	 = se.minX / width;
        sprite.paddingRight  = se.maxX / width;
        sprite.paddingTop	 = se.maxY / height;
        sprite.paddingBottom = se.minY / height;
        return sprite;
    }
开发者ID:Kaiymu,项目名称:RyS,代码行数:52,代码来源:UIAtlasMaker.cs

示例2: Compare

    /// <summary>
    /// Used to sort the sprites by pixels used
    /// </summary>
    static int Compare(SpriteEntry a, SpriteEntry b)
    {
        // A is null b is not b is greater so put it at the front of the list
        if (a == null && b != null) return 1;

        // A is not null b is null a is greater so put it at the front of the list
        if (a == null && b != null) return -1;

        // Get the total pixels used for each sprite
        int aPixels = a.width * a.height;
        int bPixels = b.width * b.height;

        if (aPixels > bPixels) return -1;
        else if (aPixels < bPixels) return 1;
        return 0;
    }
开发者ID:TomMulvaney,项目名称:JoyGatsby_Runner,代码行数:19,代码来源:UIAtlasMaker.cs

示例3: AddSprite

    /// <summary>
    /// Add a new sprite to the atlas, given the texture it's coming from and the packed rect within the atlas.
    /// </summary>
    static UISpriteData AddSprite(List<UISpriteData> sprites, SpriteEntry se)
    {
        // See if this sprite already exists
        foreach (UISpriteData sp in sprites)
        {
            if (sp.name == se.name)
            {
                sp.CopyFrom(se);
                return sp;
            }
        }

        UISpriteData sprite = new UISpriteData();
        sprite.CopyFrom(se);
        sprites.Add(sprite);
        return sprite;
    }
开发者ID:TomMulvaney,项目名称:JoyGatsby_Runner,代码行数:20,代码来源:UIAtlasMaker.cs

示例4: ExtractSprites

	/// <summary>
	/// Extract sprites from the atlas, adding them to the list.
	/// </summary>

	static void ExtractSprites (UIAtlas atlas, List<SpriteEntry> sprites)
	{
		// Make the atlas texture readable
		Texture2D atlasTex = NGUIEditorTools.ImportTexture(atlas.texture, true, false);

		if (atlasTex != null)
		{
			atlas.coordinates = UIAtlas.Coordinates.Pixels;

			Color32[] oldPixels = null;
			int oldWidth = atlasTex.width;
			int oldHeight = atlasTex.height;
			List<UIAtlas.Sprite> list = atlas.spriteList;

			foreach (UIAtlas.Sprite asp in list)
			{
				bool found = false;

				foreach (SpriteEntry se in sprites)
				{
					if (asp.name == se.tex.name)
					{
						found = true;
						break;
					}
				}

				if (!found)
				{
					// Read the atlas
					if (oldPixels == null) oldPixels = atlasTex.GetPixels32();

					Rect rect = asp.outer;
					rect.xMin = Mathf.Clamp(rect.xMin, 0f, oldWidth);
					rect.yMin = Mathf.Clamp(rect.yMin, 0f, oldHeight);
					rect.xMax = Mathf.Clamp(rect.xMax, 0f, oldWidth);
					rect.yMax = Mathf.Clamp(rect.yMax, 0f, oldHeight);

					int newWidth = Mathf.RoundToInt(rect.width);
					int newHeight = Mathf.RoundToInt(rect.height);
					if (newWidth == 0 || newHeight == 0) continue;

					Color32[] newPixels = new Color32[newWidth * newHeight];
					int xmin = Mathf.RoundToInt(rect.x);
					int ymin = Mathf.RoundToInt(oldHeight - rect.yMax);

					for (int y = 0; y < newHeight; ++y)
					{
						for (int x = 0; x < newWidth; ++x)
						{
							int newIndex = y * newWidth + x;
							int oldIndex = (ymin + y) * oldWidth + (xmin + x);
							newPixels[newIndex] = oldPixels[oldIndex];
						}
					}

					// Create a new sprite
					SpriteEntry sprite = new SpriteEntry();
					sprite.temporaryTexture = true;
					sprite.tex = new Texture2D(newWidth, newHeight);
					sprite.tex.name = asp.name;
					sprite.rect = new Rect(0f, 0f, newWidth, newHeight);
					sprite.tex.SetPixels32(newPixels);
					sprite.tex.Apply();

					// Min/max coordinates are in pixels
					sprite.minX = Mathf.RoundToInt(asp.paddingLeft * newWidth);
					sprite.maxX = Mathf.RoundToInt(asp.paddingRight * newWidth);
					sprite.minY = Mathf.RoundToInt(asp.paddingBottom * newHeight);
					sprite.maxY = Mathf.RoundToInt(asp.paddingTop * newHeight);

					sprites.Add(sprite);
				}
			}
		}

		// The atlas no longer needs to be readable
		NGUIEditorTools.ImportTexture(atlas.texture, false, false);
	}
开发者ID:btasdoven,项目名称:ScienceWars,代码行数:83,代码来源:UIAtlasMaker.cs

示例5: CreateSprites

	/// <summary>
	/// Create a list of sprites using the specified list of textures.
	/// </summary>

	static List<SpriteEntry> CreateSprites (List<Texture> textures)
	{
		List<SpriteEntry> list = new List<SpriteEntry>();

		foreach (Texture tex in textures)
		{
			Texture2D oldTex = NGUIEditorTools.ImportTexture(tex, true, false);
			if (oldTex == null) continue;

			// If we aren't doing trimming, just use the texture as-is
			if (!NGUISettings.atlasTrimming)
			{
				SpriteEntry sprite = new SpriteEntry();
				sprite.rect = new Rect(0f, 0f, oldTex.width, oldTex.height);
				sprite.tex = oldTex;
				sprite.temporaryTexture = false;
				list.Add(sprite);
				continue;
			}

			// If we want to trim transparent pixels, there is more work to be done
			Color32[] pixels = oldTex.GetPixels32();

			int xmin = oldTex.width;
			int xmax = 0;
			int ymin = oldTex.height;
			int ymax = 0;
			int oldWidth = oldTex.width;
			int oldHeight = oldTex.height;

			// Find solid pixels
			for (int y = 0, yw = oldHeight; y < yw; ++y)
			{
				for (int x = 0, xw = oldWidth; x < xw; ++x)
				{
					Color32 c = pixels[y * xw + x];

					if (c.a != 0)
					{
						if (y < ymin) ymin = y;
						if (y > ymax) ymax = y;
						if (x < xmin) xmin = x;
						if (x > xmax) xmax = x;
					}
				}
			}

			int newWidth  = (xmax - xmin) + 1;
			int newHeight = (ymax - ymin) + 1;

			// If the sprite is empty, don't do anything with it
			if (newWidth > 0 && newHeight > 0)
			{
				SpriteEntry sprite = new SpriteEntry();
				sprite.rect = new Rect(0f, 0f, oldTex.width, oldTex.height);

				// If the dimensions match, then nothing was actually trimmed
				if (newWidth == oldWidth && newHeight == oldHeight)
				{
					sprite.tex = oldTex;
					sprite.temporaryTexture = false;
				}
				else
				{
					// Copy the non-trimmed texture data into a temporary buffer
					Color32[] newPixels = new Color32[newWidth * newHeight];

					for (int y = 0; y < newHeight; ++y)
					{
						for (int x = 0; x < newWidth; ++x)
						{
							int newIndex = y * newWidth + x;
							int oldIndex = (ymin + y) * oldWidth + (xmin + x);
							newPixels[newIndex] = pixels[oldIndex];
						}
					}

					// Create a new texture
					sprite.temporaryTexture = true;
					sprite.tex = new Texture2D(newWidth, newHeight);
					sprite.tex.name = oldTex.name;
					sprite.tex.SetPixels32(newPixels);
					sprite.tex.Apply();

					// Remember the padding offset
					sprite.minX = xmin;
					sprite.maxX = oldWidth - newWidth - xmin;
					sprite.minY = ymin;
					sprite.maxY = oldHeight - newHeight - ymin;
				}
				list.Add(sprite);
			}
		}
		return list;
	}
开发者ID:btasdoven,项目名称:ScienceWars,代码行数:99,代码来源:UIAtlasMaker.cs

示例6: AddOrUpdate

	/// <summary>
	/// Add the specified texture to the atlas, or update an existing one.
	/// </summary>

	static public void AddOrUpdate (UIAtlas atlas, SpriteEntry se)
	{
		if (atlas != null && se != null)
		{
			List<SpriteEntry> sprites = new List<SpriteEntry>();
			sprites.Add(se);
			ExtractSprites(atlas, sprites);
			UpdateAtlas(atlas, sprites);
		}
	}
开发者ID:ElectrikSheep,项目名称:E_Project,代码行数:14,代码来源:UIAtlasMaker.cs

示例7: ExtractSprite

	/// <summary>
	/// Extract the specified sprite from the atlas texture.
	/// </summary>

	static SpriteEntry ExtractSprite (UISpriteData es, Color32[] oldPixels, int oldWidth, int oldHeight)
	{
		int xmin = Mathf.Clamp(es.x, 0, oldWidth);
		int ymin = Mathf.Clamp(es.y, 0, oldHeight);
		int xmax = Mathf.Min(xmin + es.width, oldWidth - 1);
		int ymax = Mathf.Min(ymin + es.height, oldHeight - 1);
		int newWidth = Mathf.Clamp(es.width, 0, oldWidth);
		int newHeight = Mathf.Clamp(es.height, 0, oldHeight);

		if (newWidth == 0 || newHeight == 0) return null;

		Color32[] newPixels = new Color32[newWidth * newHeight];

		for (int y = 0; y < newHeight; ++y)
		{
			int cy = ymin + y;
			if (cy > ymax) cy = ymax;

			for (int x = 0; x < newWidth; ++x)
			{
				int cx = xmin + x;
				if (cx > xmax) cx = xmax;

				int newIndex = (newHeight - 1 - y) * newWidth + x;
				int oldIndex = (oldHeight - 1 - cy) * oldWidth + cx;

				newPixels[newIndex] = oldPixels[oldIndex];
			}
		}

		// Create a new sprite
		SpriteEntry sprite = new SpriteEntry();
		sprite.CopyFrom(es);
		sprite.SetRect(0, 0, newWidth, newHeight);
		sprite.temporaryTexture = true;
		sprite.tex = new Texture2D(newWidth, newHeight);
		sprite.tex.SetPixels32(newPixels);
		sprite.tex.Apply();
		return sprite;
	}
开发者ID:ElectrikSheep,项目名称:E_Project,代码行数:44,代码来源:UIAtlasMaker.cs

示例8: ExtractSprites

	/// <summary>
	/// Extract sprites from the atlas, adding them to the list.
	/// </summary>

	static public void ExtractSprites (UIAtlas atlas, List<SpriteEntry> finalSprites)
	{
		// Make the atlas texture readable
		Texture2D atlasTex = NGUIEditorTools.ImportTexture(atlas.texture, true, false, !atlas.premultipliedAlpha);

		if (atlasTex != null)
		{
			Color32[] oldPixels = null;
			int oldWidth = atlasTex.width;
			int oldHeight = atlasTex.height;
			List<UISpriteData> existingSprites = atlas.spriteList;

			foreach (UISpriteData es in existingSprites)
			{
				bool found = false;

				foreach (SpriteEntry fs in finalSprites)
				{
					if (es.name == fs.name)
					{
						fs.CopyBorderFrom(es);
						found = true;
						break;
					}
				}

				if (!found)
				{
					// Read the atlas
					if (oldPixels == null) oldPixels = atlasTex.GetPixels32();

					int xmin = Mathf.Clamp(es.x, 0, oldWidth);
					int ymin = Mathf.Clamp(es.y, 0, oldHeight);
					int xmax = Mathf.Min(xmin + es.width, oldWidth - 1);
					int ymax = Mathf.Min(ymin + es.height, oldHeight - 1);
					int newWidth = Mathf.Clamp(es.width, 0, oldWidth);
					int newHeight = Mathf.Clamp(es.height, 0, oldHeight);

					if (newWidth == 0 || newHeight == 0) continue;

					Color32[] newPixels = new Color32[newWidth * newHeight];

					for (int y = 0; y < newHeight; ++y)
					{
						int cy = ymin + y;
						if (cy > ymax) cy = ymax;

						for (int x = 0; x < newWidth; ++x)
						{
							int cx = xmin + x;
							if (cx > xmax) cx = xmax;

							int newIndex = (newHeight - 1 - y) * newWidth + x;
							int oldIndex = (oldHeight - 1 - cy) * oldWidth + cx;

							newPixels[newIndex] = oldPixels[oldIndex];
						}
					}

					// Create a new sprite
					SpriteEntry sprite = new SpriteEntry();
					sprite.CopyFrom(es);
					sprite.SetRect(0, 0, newWidth, newHeight);
					sprite.temporaryTexture = true;
					sprite.tex = new Texture2D(newWidth, newHeight);
					sprite.tex.SetPixels32(newPixels);
					sprite.tex.Apply();
					finalSprites.Add(sprite);
				}
			}
		}

		// The atlas no longer needs to be readable
		NGUIEditorTools.ImportTexture(atlas.texture, false, false, !atlas.premultipliedAlpha);
	}
开发者ID:SNY-GROUP,项目名称:EMProject,代码行数:79,代码来源:UIAtlasMaker.cs

示例9: CreateSprites

    /// <summary>
    /// Create a list of sprites using the specified list of textures.
    /// </summary>
    static List<SpriteEntry> CreateSprites(List<Texture> textures)
    {
        List<SpriteEntry> list = new List<SpriteEntry>();

        foreach (Texture tex in textures)
        {
            Texture2D oldTex = NGUIEditorTools.ImportTexture(tex, true, false);
            if (oldTex == null) continue;

            Color32[] pixels = oldTex.GetPixels32();

            int xmin = oldTex.width;
            int xmax = 0;
            int ymin = oldTex.height;
            int ymax = 0;
            int oldWidth = oldTex.width;
            int oldHeight = oldTex.height;

            for (int y = 0, yw = oldHeight; y < yw; ++y)
            {
                for (int x = 0, xw = oldWidth; x < xw; ++x)
                {
                    Color32 c = pixels[y * xw + x];

                    if (c.a != 0)
                    {
                        if (y < ymin) ymin = y;
                        if (y > ymax) ymax = y;
                        if (x < xmin) xmin = x;
                        if (x > xmax) xmax = x;
                    }
                }
            }

            int newWidth  = (xmax - xmin) + 1;
            int newHeight = (ymax - ymin) + 1;

            if (newWidth > 0 && newHeight > 0)
            {
                SpriteEntry sprite = new SpriteEntry();
                sprite.rect = new Rect(0f, 0f, oldTex.width, oldTex.height);

                if (newWidth == oldWidth && newHeight == oldHeight)
                {
                    sprite.tex = oldTex;
                    sprite.temporaryTexture = false;
                }
                else
                {
                    Color32[] newPixels = new Color32[newWidth * newHeight];

                    for (int y = 0; y < newHeight; ++y)
                    {
                        for (int x = 0; x < newWidth; ++x)
                        {
                            int newIndex = y * newWidth + x;
                            int oldIndex = (ymin + y) * oldWidth + (xmin + x);
                            newPixels[newIndex] = pixels[oldIndex];
                        }
                    }

                    // Create a new texture
                    sprite.temporaryTexture = true;
                    sprite.tex = new Texture2D(newWidth, newHeight);
                    sprite.tex.name = oldTex.name;
                    sprite.tex.SetPixels32(newPixels);
                    sprite.tex.Apply();

                    // Remember the padding offset
                    sprite.minX = xmin;
                    sprite.maxX = oldWidth - newWidth - xmin;
                    sprite.minY = ymin;
                    sprite.maxY = oldHeight - newHeight - ymin;
                }
                list.Add(sprite);
            }
        }
        return list;
    }
开发者ID:shinobushiva,项目名称:Perfume-Unity,代码行数:82,代码来源:UIAtlasMaker.cs

示例10: ExtractSprites

    /// <summary>
    /// Extract sprites from the atlas, adding them to the list.
    /// </summary>
    static void ExtractSprites(UIAtlas atlas, List<SpriteEntry> sprites)
    {
        // Make the atlas texture readable
        Texture2D atlasTex = NGUIEditorTools.ImportTexture(atlas.texture, true, false, !atlas.premultipliedAlpha);

        if (atlasTex != null)
        {
            Color32[] oldPixels = null;
            int oldWidth = atlasTex.width;
            int oldHeight = atlasTex.height;
            List<UISpriteData> list = atlas.spriteList;

            foreach (UISpriteData asp in list)
            {
                bool found = false;

                foreach (SpriteEntry se in sprites)
                {
                    if (asp.name == se.name)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    // Read the atlas
                    if (oldPixels == null) oldPixels = atlasTex.GetPixels32();

                    int xmin = Mathf.Clamp(asp.x, 0, oldWidth);
                    int ymin = Mathf.Clamp(asp.y, 0, oldHeight);
                    int newWidth = Mathf.Clamp(asp.width, 0, oldWidth);
                    int newHeight = Mathf.Clamp(asp.height, 0, oldHeight);
                    if (newWidth == 0 || newHeight == 0) continue;

                    Color32[] newPixels = new Color32[newWidth * newHeight];

                    for (int y = 0; y < newHeight; ++y)
                    {
                        for (int x = 0; x < newWidth; ++x)
                        {
                            int newIndex = (newHeight - 1 - y) * newWidth + x;
                            int oldIndex = (oldHeight - 1 - (ymin + y)) * oldWidth + (xmin + x);
                            newPixels[newIndex] = oldPixels[oldIndex];
                        }
                    }

                    // Create a new sprite
                    SpriteEntry sprite = new SpriteEntry();
                    sprite.CopyFrom(asp);
                    sprite.SetRect(0, 0, newWidth, newHeight);
                    sprite.temporaryTexture = true;
                    sprite.tex = new Texture2D(newWidth, newHeight);
                    sprite.tex.SetPixels32(newPixels);
                    sprite.tex.Apply();
                    sprites.Add(sprite);
                }
            }
        }

        // The atlas no longer needs to be readable
        NGUIEditorTools.ImportTexture(atlas.texture, false, false, !atlas.premultipliedAlpha);
    }
开发者ID:jennydvr,项目名称:Speedrun,代码行数:67,代码来源:UIAtlasMaker.cs

示例11: AddSprite

		static UIAtlas.Sprite AddSprite(ICollection<UIAtlas.Sprite> sprites, SpriteEntry se)
		{
			UIAtlas.Sprite sprite = sprites.FirstOrDefault(sp => sp.name == se.Tex.name);

			// See if this sprite already exists

			if (sprite != null)
			{
				float x0 = sprite.inner.xMin - sprite.outer.xMin;
				float y0 = sprite.inner.yMin - sprite.outer.yMin;
				float x1 = sprite.outer.xMax - sprite.inner.xMax;
				float y1 = sprite.outer.yMax - sprite.inner.yMax;

				sprite.outer = se.Rect;
				sprite.inner = se.Rect;

				sprite.inner.xMin = Mathf.Max(sprite.inner.xMin + x0, sprite.outer.xMin);
				sprite.inner.yMin = Mathf.Max(sprite.inner.yMin + y0, sprite.outer.yMin);
				sprite.inner.xMax = Mathf.Min(sprite.inner.xMax - x1, sprite.outer.xMax);
				sprite.inner.yMax = Mathf.Min(sprite.inner.yMax - y1, sprite.outer.yMax);
			}
			else
			{
				sprite = new UIAtlas.Sprite {name = se.Tex.name, outer = se.Rect, inner = se.Rect};
				sprites.Add(sprite);
			}

			float width = Mathf.Max(1f, sprite.outer.width);
			float height = Mathf.Max(1f, sprite.outer.height);

			// Sprite's padding values are relative to width and height
			sprite.paddingLeft = se.MinX / width;
			sprite.paddingRight = se.MaxX / width;
			sprite.paddingTop = se.MaxY / height;
			sprite.paddingBottom = se.MinY / height;
			return sprite;
		}
开发者ID:CptDefault,项目名称:spriterdapi-unity-ngui,代码行数:37,代码来源:SpriterDataNGUI.cs


注:本文中的SpriteEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。