• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UIAtlas.Sprite类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: MarkAsDirty

 /// <summary>
 /// Mark this symbol as dirty, clearing the sprite reference.
 /// </summary>
 public void MarkAsDirty()
 {
     mSprite = null;
 }
开发者ID:NeuroScouting,项目名称:YL,代码行数:7,代码来源:BMSymbol.cs


示例17: Start

 private void Start()
 {
     if (!RPOSInventoryCell._myMaterial)
     {
         Bundling.Load<Material>("content/item/mat/ItemIconShader", out RPOSInventoryCell._myMaterial);
     }
     this._icon.enabled = false;
     if ((int)this.modSprites.Length > 0)
     {
         this.mod_empty = this.modSprites[0].atlas.GetSprite("slot_empty");
         this.mod_full = this.modSprites[0].atlas.GetSprite("slot_full");
     }
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:13,代码来源:RPOSInventoryCell.cs


示例18: OnInspectorGUI

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

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

            if (mAtlas.material != mat)
            {
                RegisterUndo();
                mAtlas.material = 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);

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

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

                if (coords != mAtlas.coordinates)
                {
                    RegisterUndo();
                    mAtlas.coordinates = coords;
                    mConfirmDelete = false;
                }
            }
        }

        if (mAtlas.material != null)
        {
            Color blue = new Color(0f, 0.7f, 1f, 1f);
            Color green = new Color(0.4f, 1f, 0f, 1f);

            if (mSprite == null && mAtlas.sprites.Count > 0)
            {
                mSprite = mAtlas.sprites[0];
            }

            if (mConfirmDelete)
            {
                if (mSprite != null)
                {
                    // Show the confirmation dialog
                    NGUIEditorTools.DrawSeparator();
                    GUILayout.Label("Are you sure you want to delete '" + mSprite.name + "'?");
                    NGUIEditorTools.DrawSeparator();

                    GUILayout.BeginHorizontal();
                    {
                        GUI.backgroundColor = Color.green;
                        if (GUILayout.Button("Cancel")) mConfirmDelete = false;
                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("Delete"))
                        {
                            RegisterUndo();
                            mAtlas.sprites.Remove(mSprite);
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    GUILayout.EndHorizontal();
                }
                else mConfirmDelete = false;
            }
            else
            {
                GUI.backgroundColor = Color.green;

                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PrefixLabel("Add/Delete");

                    if (GUILayout.Button("New Sprite"))
                    {
//.........这里部分代码省略.........
开发者ID:quiker,项目名称:hexagon,代码行数:101,代码来源:UIAtlasInspector.cs


示例19: Update

    /// <summary>
    /// Update the UV coordinates.
    /// </summary>
    public override void Update()
    {
        base.Update();

        if (mChanged || !mSpriteSet)
        {
            mSpriteSet = true;
            mSprite = null;
            mChanged = true;
            UpdateUVs(true);
        }
        else UpdateUVs(false);
    }
开发者ID:Kimsanggu,项目名称:Maze,代码行数:16,代码来源:UISprite.cs


示例20: LoadSpriteData

	/// <summary>
	/// Parse the specified JSon file, loading sprite information for the specified atlas.
	/// </summary>

	public static void LoadSpriteData (UIAtlas atlas, TextAsset asset)
	{
		if (asset == null || atlas == null) return;

		string jsonString = asset.text;
		Hashtable decodedHash = jsonDecode(jsonString) as Hashtable;
		
		if (decodedHash == null)
		{
			Debug.LogWarning("Unable to parse Json file: " + asset.name);
			return;
		}

		atlas.coordinates = UIAtlas.Coordinates.Pixels;
		List<UIAtlas.Sprite> oldSprites = atlas.spriteList;
		atlas.spriteList = new List<UIAtlas.Sprite>();

		Hashtable frames = (Hashtable)decodedHash["frames"];

		foreach (System.Collections.DictionaryEntry item in frames)
		{
			UIAtlas.Sprite newSprite = new UIAtlas.Sprite();
			newSprite.name = item.Key.ToString();

			bool exists = false;

			// Check to see if this sprite exists
			foreach (UIAtlas.Sprite oldSprite in oldSprites)
			{
				if (oldSprite.name.Equals(newSprite.name, StringComparison.OrdinalIgnoreCase))
				{
					exists = true;
					break;
				}
			}

			// Get rid of the extension if the sprite doesn't exist
			// The extension is kept for backwards compatibility so it's still possible to update older atlases.
			if (!exists)
			{
				newSprite.name = newSprite.name.Replace(".png", "");
				newSprite.name = newSprite.name.Replace(".tga", "");
			}

			// Extract the info we need from the TexturePacker json file, mainly uvRect and size
			Hashtable table = (Hashtable)item.Value;
			Hashtable frame = (Hashtable)table["frame"];

			int frameX = int.Parse(frame["x"].ToString());
			int frameY = int.Parse(frame["y"].ToString());
			int frameW = int.Parse(frame["w"].ToString());
			int frameH = int.Parse(frame["h"].ToString());

			// Read the rotation value
			newSprite.rotated = (bool)table["rotated"];

			// Fill in the proper values
			if (newSprite.rotated)
			{
				newSprite.outer = new Rect(frameX, frameY, frameH, frameW);
				newSprite.inner = new Rect(frameX, frameY, frameH, frameW);
			}
			else
			{
				newSprite.outer = new Rect(frameX, frameY, frameW, frameH);
				newSprite.inner = new Rect(frameX, frameY, frameW, frameH);
			}

			// Support for trimmed sprites
			Hashtable sourceSize = (Hashtable)table["sourceSize"];
			Hashtable spriteSize = (Hashtable)table["spriteSourceSize"];

			if (spriteSize != null && sourceSize != null)
			{
				// TODO: Account for rotated sprites
				if (frameW > 0)
				{
					float spriteX = int.Parse(spriteSize["x"].ToString());
					float spriteW = int.Parse(spriteSize["w"].ToString());
					float sourceW = int.Parse(sourceSize["w"].ToString());

					newSprite.paddingLeft = spriteX / frameW;
					newSprite.paddingRight = (sourceW - (spriteX + spriteW)) / frameW;
				}

				if (frameH > 0)
				{
					float spriteY = int.Parse(spriteSize["y"].ToString());
					float spriteH = int.Parse(spriteSize["h"].ToString());
					float sourceH = int.Parse(sourceSize["h"].ToString());

					newSprite.paddingTop = spriteY / frameH;
					newSprite.paddingBottom = (sourceH - (spriteY + spriteH)) / frameH;
				}
			}

//.........这里部分代码省略.........
开发者ID:frizac-b,项目名称:gladiawar,代码行数:101,代码来源:NGUIJson.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UIAutomationClient类代码示例发布时间:2022-05-24
下一篇:
C# UIAtlas类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap