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


C# UIAtlas.Sprite类代码示例

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


UIAtlas.Sprite类属于命名空间,在下文中一共展示了UIAtlas.Sprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Validate

	/// <summary>
	/// Validate this symbol, given the specified atlas.
	/// </summary>

	public bool Validate (UIAtlas atlas)
	{
		if (atlas == null) return false;

#if UNITY_EDITOR
		if (!Application.isPlaying || !mIsValid)
#else
		if (!mIsValid)
#endif
		{
			if (string.IsNullOrEmpty(spriteName)) return false;

			mSprite = (atlas != null) ? atlas.GetSprite(spriteName) : null;

			if (mSprite != null)
			{
				Texture tex = atlas.texture;

				if (tex == null)
				{
					mSprite = null;
				}
				else
				{
					Rect outer = mSprite.outer;
					mUV = outer;

					if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
					{
						mUV = NGUIMath.ConvertToTexCoords(mUV, tex.width, tex.height);
					}
					else
					{
						outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);
					}

					mOffsetX = Mathf.RoundToInt(mSprite.paddingLeft * outer.width);
					mOffsetY = Mathf.RoundToInt(mSprite.paddingTop * outer.width);
					mWidth = Mathf.RoundToInt(outer.width);
					mHeight = Mathf.RoundToInt(outer.height);
					mAdvance = Mathf.RoundToInt(outer.width + (mSprite.paddingRight + mSprite.paddingLeft) * outer.width);
					mIsValid = true;
				}
			}
		}
		return (mSprite != null);
	}
开发者ID:lbddk,项目名称:ahzs-client,代码行数:51,代码来源:BMSymbol.cs

示例3: MarkAsDirty

	/// <summary>
	/// Refresh all labels that use this font.
	/// </summary>

	public void MarkAsDirty ()
	{
#if UNITY_EDITOR
		UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
		if (mReplacement != null) mReplacement.MarkAsDirty();

		mSprite = null;
		UILabel[] labels = NGUITools.FindActive<UILabel>();

		for (int i = 0, imax = labels.Length; i < imax; ++i)
		{
			UILabel lbl = labels[i];
			
			if (lbl.enabled && NGUITools.GetActive(lbl.gameObject) && CheckIfRelated(this, lbl.font))
			{
				UIFont fnt = lbl.font;
				lbl.font = null;
				lbl.font = fnt;
			}
		}

		// Clear all symbols
		for (int i = 0, imax = mSymbols.Count; i < imax; ++i)
			symbols[i].MarkAsDirty();
	}
开发者ID:NeuroScouting,项目名称:YL,代码行数:30,代码来源:UIFont.cs

示例4: OnUpdate

    /// <summary>
    /// Update the UV coordinates.
    /// </summary>

    override public bool OnUpdate()
    {
        if (mChanged || !mSpriteSet)
        {
            mSpriteSet = true;
            mSprite = null;
            mChanged = true;
            UpdateUVs(true);
            return true;
        }
        UpdateUVs(false);
        return false;
    }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:17,代码来源:UISprite.cs

示例5: MarkAsDirty

    /// <summary>
    /// Refresh all labels that use this font.
    /// </summary>
    public void MarkAsDirty()
    {
        mSprite = null;
        UILabel[] labels = NGUITools.FindActive<UILabel>();

        foreach (UILabel lbl in labels)
        {
            if (lbl.enabled && lbl.gameObject.active && CheckIfRelated(this, lbl.font))
            {
                UIFont fnt = lbl.font;
                lbl.font = null;
                lbl.font = fnt;
            }
        }
    }
开发者ID:shinobushiva,项目名称:Perfume-Unity,代码行数:18,代码来源:UIFont.cs

示例6: OnInspectorGUI

	/// <summary>
	/// Draw the inspector widget.
	/// </summary>

	public override void OnInspectorGUI ()
	{
		EditorGUIUtility.LookLikeControls(80f);
		mAtlas = target as UIAtlas;

		NGUIEditorTools.DrawSeparator();

		if (mAtlas.replacement != null)
		{
			mType = AtlasType.Reference;
			mReplacement = mAtlas.replacement;
		}

		AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

		if (mType != after)
		{
			if (after == AtlasType.Normal)
			{
				OnSelectAtlas(null);
			}
			else
			{
				mType = AtlasType.Reference;
			}
		}

		if (mType == AtlasType.Reference)
		{
			ComponentSelector.Draw<UIAtlas>(mAtlas.replacement, OnSelectAtlas);

			NGUIEditorTools.DrawSeparator();
			GUILayout.Label("You can have one atlas simply point to\n" +
				"another one. This is useful if you want to be\n" +
				"able to quickly replace the contents of one\n" +
				"atlas with another one, for example for\n" +
				"swapping an SD atlas with an HD one, or\n" +
				"replacing an English atlas with a Chinese\n" +
				"one. All the sprites referencing this atlas\n" +
				"will update their references to the new one.");

			if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
			{
				NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
				mAtlas.replacement = mReplacement;
				UnityEditor.EditorUtility.SetDirty(mAtlas);
			}
			return;
		}

		if (!mConfirmDelete)
		{
			NGUIEditorTools.DrawSeparator();
			Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

			if (mAtlas.spriteMaterial != mat)
			{
				NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
				mAtlas.spriteMaterial = mat;

				// Ensure that this atlas has valid import settings
				if (mAtlas.texture != null) NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);

				mAtlas.MarkAsDirty();
				mConfirmDelete = false;
			}

			if (mat != null)
			{
				TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

				if (ta != null)
				{
					// Ensure that this atlas has valid import settings
					if (mAtlas.texture != null) NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);

					NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
					NGUIJson.LoadSpriteData(mAtlas, ta);
					if (mSprite != null) mSprite = mAtlas.GetSprite(mSprite.name);
					mAtlas.MarkAsDirty();
				}
				
				UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates);

				if (coords != mAtlas.coordinates)
				{
					NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
					mAtlas.coordinates = coords;
					mConfirmDelete = false;
				}

				float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

				if (pixelSize != mAtlas.pixelSize)
				{
					NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
//.........这里部分代码省略.........
开发者ID:unigame,项目名称:Unity3Dtetris,代码行数:101,代码来源:UIAtlasInspector.cs

示例7: OnInspectorGUI

    /// <summary>
    /// Draw the inspector widget.
    /// </summary>
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        mAtlas = target as UIAtlas;

        NGUIEditorTools.DrawSeparator();

        if (mAtlas.replacement != null)
        {
            mType = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw<UIAtlas>(mAtlas.replacement, OnSelectAtlas);

            NGUIEditorTools.DrawSeparator();
            GUILayout.Label("You can have one atlas simply point to\n" +
                "another one. This is useful if you want to be\n" +
                "able to quickly replace the contents of one\n" +
                "atlas with another one, for example for\n" +
                "swapping an SD atlas with an HD one, or\n" +
                "replacing an English atlas with a Chinese\n" +
                "one. All the sprites referencing this atlas\n" +
                "will update their references to the new one.");

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mAtlas);
            }
            return;
        }

        if (!mConfirmDelete)
        {
            NGUIEditorTools.DrawSeparator();
            Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

            if (mAtlas.spriteMaterial != mat)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.spriteMaterial = mat;

                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null) NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);

                mAtlas.MarkAsDirty();
                mConfirmDelete = false;
            }

            if (mat != null)
            {
                TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

                if (ta != null)
                {
                    // Ensure that this atlas has valid import settings
                    if (mAtlas.texture != null) NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);

                    NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                    NGUIJson.LoadSpriteData(mAtlas, ta);
                    if (mSprite != null) mSprite = mAtlas.GetSprite(mSprite.name);
                    mAtlas.MarkAsDirty();
                }

                UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates);

                if (coords != mAtlas.coordinates)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.coordinates = coords;
                    mConfirmDelete = false;
                }

                float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize);

                if (pixelSize != mAtlas.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.pixelSize = pixelSize;
//.........这里部分代码省略.........
开发者ID:BisuUk,项目名称:unity-mtd,代码行数:101,代码来源:UIAtlasInspector.cs

示例8: 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

示例9: SelectSprite

	/// <summary>
	/// Sprite selection callback.
	/// </summary>

	void SelectSprite (string spriteName)
	{
		mSprite = mAtlas.GetSprite(spriteName);
		EditorPrefs.SetString("NGUI Selected Sprite", spriteName);
		Repaint();
	}
开发者ID:unigame,项目名称:Unity3Dtetris,代码行数:10,代码来源:UIAtlasInspector.cs

示例10: GetAtlasSprite

    /// <summary>
    /// Retrieve the atlas sprite referenced by the spriteName field.
    /// </summary>
    public UIAtlas.Sprite GetAtlasSprite()
    {
        if (!mSpriteSet) mSprite = null;

        if (mSprite == null && mAtlas != null)
        {
            if (!string.IsNullOrEmpty(mSpriteName))
            {
                UIAtlas.Sprite sp = mAtlas.GetSprite(mSpriteName);
                if (sp == null) return null;
                SetAtlasSprite(sp);
            }

            if (mSprite == null && mAtlas.spriteList.Count > 0)
            {
                UIAtlas.Sprite sp = mAtlas.spriteList[0];
                if (sp == null) return null;
                SetAtlasSprite(sp);

                if (mSprite == null)
                {
                    Debug.LogError(mAtlas.name + " seems to have a null sprite!");
                    return null;
                }
                mSpriteName = mSprite.name;
            }

            // If the sprite has been set, update the UVs
            if (mSprite != null) UpdateUVs(true);
        }
        return mSprite;
    }
开发者ID:Kimsanggu,项目名称:Maze,代码行数:35,代码来源:UISprite.cs

示例11: SetAtlasSprite

    /// <summary>
    /// Set the atlas sprite directly.
    /// </summary>
    protected void SetAtlasSprite(UIAtlas.Sprite sp)
    {
        mChanged = true;
        mSpriteSet = true;

        if (sp != null)
        {
            mSprite = sp;
            mSpriteName = mSprite.name;
        }
        else
        {
            mSpriteName = (mSprite != null) ? mSprite.name : "";
            mSprite = sp;
        }
    }
开发者ID:Kimsanggu,项目名称:Maze,代码行数:19,代码来源:UISprite.cs

示例12: OnUpdate

 public override bool OnUpdate()
 {
     if (this.mLastName == this.mSpriteName)
     {
         this.UpdateUVs(false);
         return false;
     }
     this.mSprite = null;
     base.ChangedAuto();
     this.mLastName = this.mSpriteName;
     this.UpdateUVs(false);
     return true;
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:13,代码来源:UISprite.cs

示例13: Init

 /// <summary>
 /// Ensure that the sprite has been initialized properly.
 /// This is necessary because the order of execution is unreliable.
 /// Sometimes the sprite's functions may be called prior to Start().
 /// </summary>
 protected void Init()
 {
     if (mAtlas != null)
     {
         if (material == null) material = mAtlas.spriteMaterial;
         if (sprite == null) sprite = string.IsNullOrEmpty(mSpriteName) ? null : mAtlas.GetSprite(mSpriteName);
     }
 }
开发者ID:eonaranas,项目名称:piggiesgame,代码行数:13,代码来源:UISprite.cs

示例14: CreateAtlas

        /// <summary>
        /// Create a UIAtlas on runtime from a list of Texture2Ds
        /// </summary>
        public static UIAtlas CreateAtlas(string atlasName, GameObject parent, List<Texture2D> textures, List<string> names)
        {
            Logger.Debug(TAG, "Generating UIAtlas: {0}", atlasName);

            // Pack textures
            int maxSize = SystemInfo.maxTextureSize;
            Texture2D atlasTexture = new Texture2D(maxSize, maxSize);
            Rect[] rects = atlasTexture.PackTextures(textures.ToArray(), 0, maxSize);

            // Create new empty GameObject with UIAtlas component
            UIAtlas atlas = NGUITools.AddChild<UIAtlas>(parent);
            atlas.name = atlasName;

            // Set material
            atlas.coordinates = UIAtlas.Coordinates.TexCoords;
            atlas.spriteMaterial = new Material(Shader.Find("Unlit/Transparent Colored"));
            atlas.spriteMaterial.mainTexture = atlasTexture;

            // Add sprites
            for (int i = 0; i < rects.Length; i++) {
                UIAtlas.Sprite sprite = new UIAtlas.Sprite();
                sprite.inner = rects[i];
                sprite.outer = rects[i];
                sprite.name = names[i];
                atlas.spriteList.Add(sprite);
            }

            // Return reference to the UIAtlas script
            return atlas;
        }
开发者ID:hjrhjr,项目名称:Beats2,代码行数:33,代码来源:UITools.cs

示例15: Validate

    /// <summary>
    /// Validate this symbol, given the specified atlas.
    /// </summary>
    public bool Validate(UIAtlas atlas)
    {
        if (atlas == null) return false;

        #if UNITY_EDITOR
        if (!Application.isPlaying || mSprite == null)
        #else
        if (mSprite == null)
        #endif
        {
            if (string.IsNullOrEmpty(spriteName)) return false;

            mSprite = (atlas != null) ? atlas.GetSprite(spriteName) : null;

            if (mSprite != null)
            {
                Texture tex = atlas.texture;

                if (tex == null)
                {
                    mSprite = null;
                }
                else
                {
                    Rect inner = mSprite.inner;
                    Rect outer = mSprite.outer;
                    mUV = outer;

                    if (atlas.coordinates == UIAtlas.Coordinates.Pixels)
                    {
                        mUV = NGUIMath.ConvertToTexCoords(mUV, tex.width, tex.height);
                    }
                    else
                    {
                        inner = NGUIMath.ConvertToPixels(inner, tex.width, tex.height, true);
                        outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);
                    }

                    mOffsetX = Mathf.RoundToInt(outer.x - inner.x);
                    mOffsetY = Mathf.RoundToInt(outer.y - inner.y);
                    mOuterWidth = Mathf.RoundToInt(outer.width);
                    mOuterHeight = Mathf.RoundToInt(outer.height);
                    mInnerWidth = Mathf.RoundToInt(inner.width);
                }
            }
        }
        return (mSprite != null);
    }
开发者ID:NeuroScouting,项目名称:YL,代码行数:51,代码来源:BMSymbol.cs


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