本文整理汇总了C#中UISprite.GetAtlasSprite方法的典型用法代码示例。如果您正苦于以下问题:C# UISprite.GetAtlasSprite方法的具体用法?C# UISprite.GetAtlasSprite怎么用?C# UISprite.GetAtlasSprite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UISprite
的用法示例。
在下文中一共展示了UISprite.GetAtlasSprite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Show
/// <summary>
/// Show the popup list dialog.
/// </summary>
public void Show ()
{
if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
{
mLabelList.Clear();
StopCoroutine("CloseIfUnselected");
// Ensure the popup's source has the selection
UICamera.selectedObject = (UICamera.hoveredObject ?? gameObject);
mSelection = UICamera.selectedObject;
source = UICamera.selectedObject;
if (source == null)
{
Debug.LogError("Popup list needs a source object...");
return;
}
mOpenFrame = Time.frameCount;
// Automatically locate the panel responsible for this object
if (mPanel == null)
{
mPanel = UIPanel.Find(transform);
if (mPanel == null) return;
}
// Calculate the dimensions of the object triggering the popup list so we can position it below it
Vector3 min;
Vector3 max;
// Create the root object for the list
mChild = new GameObject("Drop-down List");
mChild.layer = gameObject.layer;
current = this;
Transform t = mChild.transform;
t.parent = mPanel.cachedTransform;
Vector3 pos;
// Manually triggered popup list on some other game object
if (openOn == OpenOn.Manual && mSelection != gameObject)
{
pos = UICamera.lastEventPosition;
min = mPanel.cachedTransform.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(pos));
max = min;
t.localPosition = min;
pos = t.position;
}
else
{
Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, transform, false, false);
min = bounds.min;
max = bounds.max;
t.localPosition = min;
pos = t.position;
}
StartCoroutine("CloseIfUnselected");
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
// Add a sprite for the background
mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
mBackground.pivot = UIWidget.Pivot.TopLeft;
mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
mBackground.color = backgroundColor;
// We need to know the size of the background sprite for padding purposes
Vector4 bgPadding = mBackground.border;
mBgBorder = bgPadding.y;
mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);
// Add a sprite used for the selection
mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite);
mHighlight.pivot = UIWidget.Pivot.TopLeft;
mHighlight.color = highlightColor;
UISpriteData hlsp = mHighlight.GetAtlasSprite();
if (hlsp == null) return;
float hlspHeight = hlsp.borderTop;
float fontHeight = activeFontSize;
float dynScale = activeFontScale;
float labelHeight = fontHeight * dynScale;
float x = 0f, y = -padding.y;
List<UILabel> labels = new List<UILabel>();
// Clear the selection if it's no longer present
if (!items.Contains(mSelectedItem))
mSelectedItem = null;
// Run through all items and create labels for each one
for (int i = 0, imax = items.Count; i < imax; ++i)
{
//.........这里部分代码省略.........
示例2: Show
/// <summary>
/// Show the popup list dialog.
/// </summary>
public void Show ()
{
if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
{
mLabelList.Clear();
// Automatically locate the panel responsible for this object
if (mPanel == null)
{
mPanel = UIPanel.Find(transform);
if (mPanel == null) return;
}
// Disable the navigation script
handleEvents = true;
// Calculate the dimensions of the object triggering the popup list so we can position it below it
Transform myTrans = transform;
Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);
// Create the root object for the list
mChild = new GameObject("Drop-down List");
mChild.layer = gameObject.layer;
Transform t = mChild.transform;
t.parent = myTrans.parent;
t.localPosition = bounds.min;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
// Add a sprite for the background
mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
mBackground.pivot = UIWidget.Pivot.TopLeft;
mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
mBackground.color = backgroundColor;
// We need to know the size of the background sprite for padding purposes
Vector4 bgPadding = mBackground.border;
mBgBorder = bgPadding.y;
mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);
// Add a sprite used for the selection
mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite);
mHighlight.pivot = UIWidget.Pivot.TopLeft;
mHighlight.color = highlightColor;
UISpriteData hlsp = mHighlight.GetAtlasSprite();
if (hlsp == null) return;
float hlspHeight = hlsp.borderTop;
float fontHeight = activeFontSize;
float dynScale = activeFontScale;
float labelHeight = fontHeight * dynScale;
float x = 0f, y = -padding.y;
int labelFontSize = (bitmapFont != null) ? bitmapFont.defaultSize : fontSize;
List<UILabel> labels = new List<UILabel>();
// Clear the selection if it's no longer present
if (!items.Contains(mSelectedItem))
mSelectedItem = null;
// Run through all items and create labels for each one
for (int i = 0, imax = items.Count; i < imax; ++i)
{
string s = items[i];
UILabel lbl = NGUITools.AddWidget<UILabel>(mChild);
lbl.name = i.ToString();
lbl.pivot = UIWidget.Pivot.TopLeft;
lbl.bitmapFont = bitmapFont;
lbl.trueTypeFont = trueTypeFont;
lbl.fontSize = labelFontSize;
lbl.fontStyle = fontStyle;
lbl.text = isLocalized ? Localization.Get(s) : s;
lbl.color = textColor;
lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -1f);
lbl.overflowMethod = UILabel.Overflow.ResizeFreely;
lbl.alignment = alignment;
lbl.MakePixelPerfect();
if (dynScale != 1f) lbl.cachedTransform.localScale = Vector3.one * dynScale;
labels.Add(lbl);
y -= labelHeight;
y -= padding.y;
x = Mathf.Max(x, lbl.printedSize.x);
// Add an event listener
UIEventListener listener = UIEventListener.Get(lbl.gameObject);
listener.onHover = OnItemHover;
listener.onPress = OnItemPress;
listener.onClick = OnItemClick;
listener.parameter = s;
// Move the selection here if this is the right label
if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
Highlight(lbl, true);
//.........这里部分代码省略.........
示例3: OnClick
/// <summary>
/// Display the drop-down list when the game object gets clicked on.
/// </summary>
void OnClick()
{
if (mChild == null && atlas != null && font != null && items.Count > 0)
{
mLabelList.Clear();
// Disable the navigation script
handleEvents = true;
// Automatically locate the panel responsible for this object
if (mPanel == null) mPanel = UIPanel.Find(transform, true);
// Calculate the dimensions of the object triggering the popup list so we can position it below it
Transform myTrans = transform;
Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);
// Create the root object for the list
mChild = new GameObject("Drop-down List");
mChild.layer = gameObject.layer;
Transform t = mChild.transform;
t.parent = myTrans.parent;
t.localPosition = bounds.min;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
// Add a sprite for the background
mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
mBackground.pivot = UIWidget.Pivot.TopLeft;
mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
mBackground.color = backgroundColor;
// We need to know the size of the background sprite for padding purposes
Vector4 bgPadding = mBackground.border;
mBgBorder = bgPadding.y;
mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);
// Add a sprite used for the selection
mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite);
mHighlight.pivot = UIWidget.Pivot.TopLeft;
mHighlight.color = highlightColor;
UIAtlas.Sprite hlsp = mHighlight.GetAtlasSprite();
if (hlsp == null) return;
float hlspHeight = hlsp.inner.yMin - hlsp.outer.yMin;
float fontScale = font.size * font.pixelSize * textScale;
float x = 0f, y = -padding.y;
List<UILabel> labels = new List<UILabel>();
// Run through all items and create labels for each one
for (int i = 0, imax = items.Count; i < imax; ++i)
{
string s = items[i];
UILabel lbl = NGUITools.AddWidget<UILabel>(mChild);
lbl.pivot = UIWidget.Pivot.TopLeft;
lbl.font = font;
lbl.text = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s;
lbl.color = textColor;
lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -0.01f);
lbl.MakePixelPerfect();
if (textScale != 1f)
{
Vector3 scale = lbl.cachedTransform.localScale;
lbl.cachedTransform.localScale = scale * textScale;
}
labels.Add(lbl);
y -= fontScale;
y -= padding.y;
x = Mathf.Max(x, lbl.relativeSize.x * fontScale);
// Add an event listener
UIEventListener listener = UIEventListener.Get(lbl.gameObject);
listener.onHover = OnItemHover;
listener.onPress = OnItemPress;
listener.parameter = s;
// Move the selection here if this is the right label
if (mSelectedItem == s) Highlight(lbl, true);
// Add this label to the list
mLabelList.Add(lbl);
}
// The triggering widget's width should be the minimum allowed width
x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f);
Vector3 bcCenter = new Vector3((x * 0.5f) / fontScale, -0.5f, 0f);
Vector3 bcSize = new Vector3(x / fontScale, (fontScale + padding.y) / fontScale, 1f);
// Run through all labels and add colliders
for (int i = 0, imax = labels.Count; i < imax; ++i)
{
//.........这里部分代码省略.........