本文整理汇总了C#中UIAtlas.GetSprite方法的典型用法代码示例。如果您正苦于以下问题:C# UIAtlas.GetSprite方法的具体用法?C# UIAtlas.GetSprite怎么用?C# UIAtlas.GetSprite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIAtlas
的用法示例。
在下文中一共展示了UIAtlas.GetSprite方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public bool Validate(UIAtlas atlas)
{
if (atlas == null)
{
return false;
}
if (!this.mIsValid)
{
if (string.IsNullOrEmpty(this.spriteName))
{
return false;
}
this.mSprite = (atlas == null) ? null : atlas.GetSprite(this.spriteName);
if (this.mSprite != null)
{
Texture texture = atlas.texture;
if (texture == null)
{
this.mSprite = null;
}
else
{
this.mUV = new Rect((float) this.mSprite.x, (float) this.mSprite.y, (float) this.mSprite.width, (float) this.mSprite.height);
this.mUV = NGUIMath.ConvertToTexCoords(this.mUV, texture.width, texture.height);
this.mOffsetX = this.mSprite.paddingLeft;
this.mOffsetY = this.mSprite.paddingTop;
this.mWidth = this.mSprite.width;
this.mHeight = this.mSprite.height;
this.mAdvance = this.mSprite.width + (this.mSprite.paddingLeft + this.mSprite.paddingRight);
this.mIsValid = true;
}
}
}
return (this.mSprite != null);
}
示例2: Add
/// <summary>
/// Add a sprite appropriate for the specified atlas sprite.
/// It will be a UISlicedSprite if the sprite has an inner rect, and a regular sprite otherwise.
/// </summary>
public static UISprite Add(GameObject go, UIAtlas atlas, string spriteName)
{
UIAtlas.Sprite sp = (atlas != null) ? atlas.GetSprite(spriteName) : null;
UISprite sprite = (sp == null || sp.inner == sp.outer) ? NGUITools.AddWidget<UISprite>(go) : (UISprite)NGUITools.AddWidget<UISlicedSprite>(go);
sprite.atlas = atlas;
sprite.spriteName = spriteName;
return sprite;
}
示例3: 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);
}
示例4: 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
{
mUV = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
mUV = NGUIMath.ConvertToTexCoords(mUV, tex.width, tex.height);
mOffsetX = mSprite.paddingLeft;
mOffsetY = mSprite.paddingTop;
mWidth = mSprite.width;
mHeight = mSprite.height;
mAdvance = mSprite.width + (mSprite.paddingLeft + mSprite.paddingRight);
mIsValid = true;
}
}
}
return (mSprite != null);
}
示例5: OnInspectorGUI
/// <summary>
/// Draw the inspector widget.
/// </summary>
public override void OnInspectorGUI ()
{
NGUIEditorTools.SetLabelWidth(80f);
mAtlas = target as UIAtlas;
UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;
GUILayout.Space(6f);
if (mAtlas.replacement != null)
{
mType = AtlasType.Reference;
mReplacement = mAtlas.replacement;
}
GUILayout.BeginHorizontal();
AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);
GUILayout.Space(18f);
GUILayout.EndHorizontal();
if (mType != after)
{
if (after == AtlasType.Normal)
{
mType = AtlasType.Normal;
OnSelectAtlas(null);
}
else
{
mType = AtlasType.Reference;
}
}
if (mType == AtlasType.Reference)
{
ComponentSelector.Draw<UIAtlas>(mAtlas.replacement, OnSelectAtlas, true);
GUILayout.Space(6f);
EditorGUILayout.HelpBox("You can have one atlas simply point to " +
"another one. This is useful if you want to be " +
"able to quickly replace the contents of one " +
"atlas with another one, for example for " +
"swapping an SD atlas with an HD one, or " +
"replacing an English atlas with a Chinese " +
"one. All the sprites referencing this atlas " +
"will update their references to the new one.", MessageType.Info);
if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
{
NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
mAtlas.replacement = mReplacement;
NGUITools.SetDirty(mAtlas);
}
return;
}
//GUILayout.Space(6f);
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.premultipliedAlpha);
mAtlas.MarkAsChanged();
}
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, !mAtlas.premultipliedAlpha);
NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
NGUIJson.LoadSpriteData(mAtlas, ta);
if (sprite != null) sprite = mAtlas.GetSprite(sprite.name);
mAtlas.MarkAsChanged();
}
float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));
if (pixelSize != mAtlas.pixelSize)
{
NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
mAtlas.pixelSize = pixelSize;
}
}
if (mAtlas.spriteMaterial != null)
{
//.........这里部分代码省略.........
示例6: ExtractSprite
/// <summary>
/// Extract the specified sprite from the atlas.
/// </summary>
static public SpriteEntry ExtractSprite (UIAtlas atlas, string spriteName)
{
if (atlas.texture == null) return null;
UISpriteData sd = atlas.GetSprite(spriteName);
if (sd == null) return null;
Texture2D tex = NGUIEditorTools.ImportTexture(atlas.texture, true, true, false);
SpriteEntry se = ExtractSprite(sd, tex);
NGUIEditorTools.ImportTexture(atlas.texture, false, false, !atlas.premultipliedAlpha);
return se;
}
示例7: DuplicateSprite
/// <summary>
/// Duplicate the specified sprite.
/// </summary>
static public SpriteEntry DuplicateSprite (UIAtlas atlas, string spriteName)
{
if (atlas == null || atlas.texture == null) return null;
UISpriteData sd = atlas.GetSprite(spriteName);
if (sd == null) return null;
Texture2D tex = NGUIEditorTools.ImportTexture(atlas.texture, true, true, false);
SpriteEntry se = ExtractSprite(sd, tex);
if (se != null)
{
se.name = se.name + " (Copy)";
List<UIAtlasMaker.SpriteEntry> sprites = new List<UIAtlasMaker.SpriteEntry>();
UIAtlasMaker.ExtractSprites(atlas, sprites);
sprites.Add(se);
UIAtlasMaker.UpdateAtlas(atlas, sprites);
if (se.temporaryTexture) DestroyImmediate(se.tex);
}
else NGUIEditorTools.ImportTexture(atlas.texture, false, false, !atlas.premultipliedAlpha);
return se;
}
示例8: buildAnImage
private NvUIImage buildAnImage( UIAtlas atlas, string spriteName )
{
if ( atlas != null )
{
UIAtlas.Sprite sprite = atlas.GetSprite( spriteName );
if ( sprite != null )
{
Rect rc = sprite.outer;
GameObject obj = new GameObject("ImageSlot (" + spriteName + ")");
obj.transform.parent = transform;
obj.transform.localPosition = Vector3.zero;
obj.transform.localRotation = Quaternion.identity;
obj.transform.localScale = new Vector3( rc.width, rc.height, 1.0f );
obj.layer = gameObject.layer;
UISprite spr = obj.AddComponent<UISprite>();
spr.atlas = atlas;
NvUIImage image = obj.AddComponent<NvUIImage>();
image.spriteName = spriteName;
return image;
}
}
return null;
}
示例9: OnInspectorGUI
/// <summary>
/// Draw the inspector widget.
/// </summary>
public override void OnInspectorGUI ()
{
EditorGUIUtility.LookLikeControls(80f);
mAtlas = target as UIAtlas;
UIAtlas.Sprite sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;
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();
EditorGUILayout.HelpBox("You can have one atlas simply point to " +
"another one. This is useful if you want to be " +
"able to quickly replace the contents of one " +
"atlas with another one, for example for " +
"swapping an SD atlas with an HD one, or " +
"replacing an English atlas with a Chinese " +
"one. All the sprites referencing this atlas " +
"will update their references to the new one.", MessageType.Info);
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 (sprite != null) sprite = mAtlas.GetSprite(sprite.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)
//.........这里部分代码省略.........
示例10: 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;
//.........这里部分代码省略.........
示例11: 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);
}
示例12: 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"))
{
//.........这里部分代码省略.........