本文整理汇总了C#中UIWidget.Pivot类的典型用法代码示例。如果您正苦于以下问题:C# UIWidget.Pivot类的具体用法?C# UIWidget.Pivot怎么用?C# UIWidget.Pivot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UIWidget.Pivot类属于命名空间,在下文中一共展示了UIWidget.Pivot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
static void Load ()
{
mLoaded = true;
mPartial = EditorPrefs.GetString("NGUI Partial");
mFontName = EditorPrefs.GetString("NGUI Font Name");
mAtlasName = EditorPrefs.GetString("NGUI Atlas Name");
mFontData = GetObject("NGUI Font Asset") as TextAsset;
mFontTexture = GetObject("NGUI Font Texture") as Texture2D;
mFont = GetObject("NGUI Font") as UIFont;
mAtlas = GetObject("NGUI Atlas") as UIAtlas;
mAtlasPadding = EditorPrefs.GetInt("NGUI Atlas Padding", 1);
mAtlasTrimming = EditorPrefs.GetBool("NGUI Atlas Trimming", true);
mAtlasPMA = EditorPrefs.GetBool("NGUI Atlas PMA", true);
mUnityPacking = EditorPrefs.GetBool("NGUI Unity Packing", true);
mForceSquare = EditorPrefs.GetBool("NGUI Force Square Atlas", true);
mPivot = (UIWidget.Pivot)EditorPrefs.GetInt("NGUI Pivot", (int)mPivot);
mLayer = EditorPrefs.GetInt("NGUI Layer", -1);
mDynFont = GetObject("NGUI DynFont") as Font;
mDynFontSize = EditorPrefs.GetInt("NGUI DynFontSize", 16);
mDynFontStyle = (FontStyle)EditorPrefs.GetInt("NGUI DynFontStyle", (int)FontStyle.Normal);
if (mLayer < 0 || string.IsNullOrEmpty(LayerMask.LayerToName(mLayer))) mLayer = -1;
if (mLayer == -1) mLayer = LayerMask.NameToLayer("UI");
if (mLayer == -1) mLayer = LayerMask.NameToLayer("GUI");
if (mLayer == -1) mLayer = 5;
EditorPrefs.SetInt("UI Layer", mLayer);
LoadColor();
}
示例2: Init
protected void Init()
{
if (this.mDoInit && (this.label != null))
{
this.mDoInit = false;
this.mDefaultText = this.label.text;
this.mDefaultColor = this.label.color;
this.label.supportEncoding = false;
this.mPivot = this.label.pivot;
this.mPosition = this.label.cachedTransform.localPosition.x;
this.UpdateLabel();
}
}
示例3: Load
static void Load ()
{
mLoaded = true;
mPartial = EditorPrefs.GetString("NGUI Partial");
mFontName = EditorPrefs.GetString("NGUI Font Name");
mAtlasName = EditorPrefs.GetString("NGUI Atlas Name");
mFontData = GetObject("NGUI Font Asset") as TextAsset;
mFontTexture = GetObject("NGUI Font Texture") as Texture2D;
mFont = GetObject("NGUI Font") as UIFont;
mAtlas = GetObject("NGUI Atlas") as UIAtlas;
mAtlasPadding = EditorPrefs.GetInt("NGUI Atlas Padding", 1);
mAtlasTrimming = EditorPrefs.GetBool("NGUI Atlas Trimming", true);
mUnityPacking = EditorPrefs.GetBool("NGUI Unity Packing", true);
mPivot = (UIWidget.Pivot)EditorPrefs.GetInt("NGUI Pivot", (int)mPivot);
}
示例4: Load
static void Load ()
{
int l = LayerMask.NameToLayer("HotUI");//UI->HotUI Jerrylai_2014-12-11 13:13:24
if (l == -1) l = LayerMask.NameToLayer("GUI");
mLoaded = true;
mPartial = EditorPrefs.GetString("NGUI Partial");
mFontName = EditorPrefs.GetString("NGUI Font Name");
mAtlasName = EditorPrefs.GetString("NGUI Atlas Name");
mFontData = GetObject("NGUI Font Asset") as TextAsset;
mFontTexture = GetObject("NGUI Font Texture") as Texture2D;
mFont = GetObject("NGUI Font") as UIFont;
mAtlas = GetObject("NGUI Atlas") as UIAtlas;
mAtlasPadding = EditorPrefs.GetInt("NGUI Atlas Padding", 1);
mAtlasTrimming = EditorPrefs.GetBool("NGUI Atlas Trimming", true);
mUnityPacking = EditorPrefs.GetBool("NGUI Unity Packing", true);
mForceSquare = EditorPrefs.GetBool("NGUI Force Square Atlas", true);
mPivot = (UIWidget.Pivot)EditorPrefs.GetInt("NGUI Pivot", (int)mPivot);
mLayer = EditorPrefs.GetInt("NGUI Layer", l);
LoadColor();
}
示例5: Init
/// <summary>
/// Labels used for input shouldn't support rich text.
/// </summary>
protected void Init ()
{
if (mDoInit && label != null)
{
mDoInit = false;
mDefaultText = label.text;
mDefaultColor = label.color;
label.supportEncoding = false;
mPivot = label.pivot;
mPosition = label.cachedTransform.localPosition.x;
UpdateLabel();
}
}
示例6: OnSceneGUI
/// <summary>
/// Handles & interaction.
/// </summary>
public void OnSceneGUI ()
{
NGUIEditorTools.HideMoveTool(true);
if (!UIWidget.showHandles) return;
Event e = Event.current;
int id = GUIUtility.GetControlID(s_Hash, FocusType.Passive);
EventType type = e.GetTypeForControl(id);
Transform t = mPanel.cachedTransform;
Vector3[] handles = UIWidgetInspector.GetHandles(mPanel.worldCorners);
// Time to figure out what kind of action is underneath the mouse
UIWidgetInspector.Action actionUnderMouse = mAction;
Color handlesColor = new Color(0.5f, 0f, 0.5f);
NGUIHandles.DrawShadowedLine(handles, handles[0], handles[1], handlesColor);
NGUIHandles.DrawShadowedLine(handles, handles[1], handles[2], handlesColor);
NGUIHandles.DrawShadowedLine(handles, handles[2], handles[3], handlesColor);
NGUIHandles.DrawShadowedLine(handles, handles[0], handles[3], handlesColor);
if (mPanel.isAnchored)
{
UIWidgetInspector.DrawAnchorHandle(mPanel.leftAnchor, mPanel.cachedTransform, handles, 0, id);
UIWidgetInspector.DrawAnchorHandle(mPanel.topAnchor, mPanel.cachedTransform, handles, 1, id);
UIWidgetInspector.DrawAnchorHandle(mPanel.rightAnchor, mPanel.cachedTransform, handles, 2, id);
UIWidgetInspector.DrawAnchorHandle(mPanel.bottomAnchor, mPanel.cachedTransform, handles, 3, id);
}
if (type == EventType.Repaint)
{
bool showDetails = (mAction == UIWidgetInspector.Action.Scale) || NGUISettings.drawGuides;
if (mAction == UIWidgetInspector.Action.None && e.modifiers == EventModifiers.Control) showDetails = true;
if (NGUITools.GetActive(mPanel) && mPanel.parent == null) showDetails = true;
if (showDetails) NGUIHandles.DrawSize(handles, Mathf.RoundToInt(mPanel.width), Mathf.RoundToInt(mPanel.height));
}
bool canResize = (mPanel.clipping != UIDrawCall.Clipping.None);
// NOTE: Remove this part when it's possible to neatly resize rotated anchored panels.
if (canResize && mPanel.isAnchored)
{
Quaternion rot = mPanel.cachedTransform.localRotation;
if (Quaternion.Angle(rot, Quaternion.identity) > 0.01f) canResize = false;
}
bool[] resizable = new bool[8];
resizable[4] = canResize; // left
resizable[5] = canResize; // top
resizable[6] = canResize; // right
resizable[7] = canResize; // bottom
resizable[0] = resizable[7] && resizable[4]; // bottom-left
resizable[1] = resizable[5] && resizable[4]; // top-left
resizable[2] = resizable[5] && resizable[6]; // top-right
resizable[3] = resizable[7] && resizable[6]; // bottom-right
UIWidget.Pivot pivotUnderMouse = UIWidgetInspector.GetPivotUnderMouse(handles, e, resizable, true, ref actionUnderMouse);
switch (type)
{
case EventType.Repaint:
{
Vector3 v0 = HandleUtility.WorldToGUIPoint(handles[0]);
Vector3 v2 = HandleUtility.WorldToGUIPoint(handles[2]);
if ((v2 - v0).magnitude > 60f)
{
Vector3 v1 = HandleUtility.WorldToGUIPoint(handles[1]);
Vector3 v3 = HandleUtility.WorldToGUIPoint(handles[3]);
Handles.BeginGUI();
{
for (int i = 0; i < 4; ++i)
DrawKnob(handles[i], id, resizable[i]);
if (Mathf.Abs(v1.y - v0.y) > 80f)
{
if (mPanel.leftAnchor.target == null || mPanel.leftAnchor.absolute != 0)
DrawKnob(handles[4], id, resizable[4]);
if (mPanel.rightAnchor.target == null || mPanel.rightAnchor.absolute != 0)
DrawKnob(handles[6], id, resizable[6]);
}
if (Mathf.Abs(v3.x - v0.x) > 80f)
{
if (mPanel.topAnchor.target == null || mPanel.topAnchor.absolute != 0)
DrawKnob(handles[5], id, resizable[5]);
if (mPanel.bottomAnchor.target == null || mPanel.bottomAnchor.absolute != 0)
DrawKnob(handles[7], id, resizable[7]);
}
}
Handles.EndGUI();
//.........这里部分代码省略.........
示例7: OnSceneGUI
/// <summary>
/// Draw the on-screen selection, knobs, and handle all interaction logic.
/// </summary>
public void OnSceneGUI ()
{
NGUIEditorTools.HideMoveTool(true);
if (!UIWidget.showHandles) return;
mWidget = target as UIWidget;
Transform t = mWidget.cachedTransform;
Event e = Event.current;
int id = GUIUtility.GetControlID(s_Hash, FocusType.Passive);
EventType type = e.GetTypeForControl(id);
Action actionUnderMouse = mAction;
Vector3[] handles = GetHandles(mWidget.worldCorners);
NGUIHandles.DrawShadowedLine(handles, handles[0], handles[1], handlesColor);
NGUIHandles.DrawShadowedLine(handles, handles[1], handles[2], handlesColor);
NGUIHandles.DrawShadowedLine(handles, handles[2], handles[3], handlesColor);
NGUIHandles.DrawShadowedLine(handles, handles[0], handles[3], handlesColor);
// If the widget is anchored, draw the anchors
if (mWidget.isAnchored)
{
DrawAnchorHandle(mWidget.leftAnchor, mWidget.cachedTransform, handles, 0, id);
DrawAnchorHandle(mWidget.topAnchor, mWidget.cachedTransform, handles, 1, id);
DrawAnchorHandle(mWidget.rightAnchor, mWidget.cachedTransform, handles, 2, id);
DrawAnchorHandle(mWidget.bottomAnchor, mWidget.cachedTransform, handles, 3, id);
}
if (type == EventType.Repaint)
{
bool showDetails = (mAction == UIWidgetInspector.Action.Scale) || NGUISettings.drawGuides;
if (mAction == UIWidgetInspector.Action.None && e.modifiers == EventModifiers.Control) showDetails = true;
if (NGUITools.GetActive(mWidget) && mWidget.parent == null) showDetails = true;
if (showDetails) NGUIHandles.DrawSize(handles, mWidget.width, mWidget.height);
}
// Presence of the legacy stretch component prevents resizing
bool canResize = (mWidget.GetComponent<UIStretch>() == null);
bool[] resizable = new bool[8];
resizable[4] = canResize; // left
resizable[5] = canResize; // top
resizable[6] = canResize; // right
resizable[7] = canResize; // bottom
UILabel lbl = mWidget as UILabel;
if (lbl != null)
{
if (lbl.overflowMethod == UILabel.Overflow.ResizeFreely)
{
resizable[4] = false; // left
resizable[5] = false; // top
resizable[6] = false; // right
resizable[7] = false; // bottom
}
else if (lbl.overflowMethod == UILabel.Overflow.ResizeHeight)
{
resizable[5] = false; // top
resizable[7] = false; // bottom
}
}
if (mWidget.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnHeight)
{
resizable[4] = false;
resizable[6] = false;
}
else if (mWidget.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnWidth)
{
resizable[5] = false;
resizable[7] = false;
}
resizable[0] = resizable[7] && resizable[4]; // bottom-left
resizable[1] = resizable[5] && resizable[4]; // top-left
resizable[2] = resizable[5] && resizable[6]; // top-right
resizable[3] = resizable[7] && resizable[6]; // bottom-right
UIWidget.Pivot pivotUnderMouse = GetPivotUnderMouse(handles, e, resizable, true, ref actionUnderMouse);
switch (type)
{
case EventType.Repaint:
{
Vector3 v0 = HandleUtility.WorldToGUIPoint(handles[0]);
Vector3 v2 = HandleUtility.WorldToGUIPoint(handles[2]);
if ((v2 - v0).magnitude > 60f)
{
Vector3 v1 = HandleUtility.WorldToGUIPoint(handles[1]);
Vector3 v3 = HandleUtility.WorldToGUIPoint(handles[3]);
Handles.BeginGUI();
//.........这里部分代码省略.........
示例8: OnSceneGUI
/// <summary>
/// Draw the on-screen selection, knobs, and handle all interaction logic.
/// </summary>
public void OnSceneGUI()
{
NGUIEditorTools.HideMoveTool(true);
if (!UIWidget.showHandles) return;
mWidget = target as UIWidget;
Transform t = mWidget.cachedTransform;
Event e = Event.current;
int id = GUIUtility.GetControlID(s_Hash, FocusType.Passive);
EventType type = e.GetTypeForControl(id);
Vector3[] corners = mWidget.worldCorners;
Handles.color = handlesColor;
Handles.DrawLine(corners[0], corners[1]);
Handles.DrawLine(corners[1], corners[2]);
Handles.DrawLine(corners[2], corners[3]);
Handles.DrawLine(corners[0], corners[3]);
Vector3[] worldPos = new Vector3[8];
worldPos[0] = corners[0];
worldPos[1] = corners[1];
worldPos[2] = corners[2];
worldPos[3] = corners[3];
worldPos[4] = (corners[0] + corners[1]) * 0.5f;
worldPos[5] = (corners[1] + corners[2]) * 0.5f;
worldPos[6] = (corners[2] + corners[3]) * 0.5f;
worldPos[7] = (corners[0] + corners[3]) * 0.5f;
// Time to figure out what kind of action is underneath the mouse
Action actionUnderMouse = mAction;
UIWidget.Pivot pivotUnderMouse = UIWidget.Pivot.Center;
if (actionUnderMouse == Action.None)
{
int index = 0;
float dist = GetScreenDistance(worldPos, e.mousePosition, out index);
if (mWidget.canResize && dist < 10f)
{
pivotUnderMouse = mPivots[index];
actionUnderMouse = Action.Scale;
}
else if (e.modifiers == 0 && NGUIEditorTools.SceneViewDistanceToRectangle(corners, e.mousePosition) == 0f)
{
actionUnderMouse = Action.Move;
}
else if (dist < 30f)
{
actionUnderMouse = Action.Rotate;
}
}
// Change the mouse cursor to a more appropriate one
#if !UNITY_3_5
{
Vector2[] screenPos = new Vector2[8];
for (int i = 0; i < 8; ++i) screenPos[i] = HandleUtility.WorldToGUIPoint(worldPos[i]);
Bounds b = new Bounds(screenPos[0], Vector3.zero);
for (int i = 1; i < 8; ++i) b.Encapsulate(screenPos[i]);
Vector2 min = b.min;
Vector2 max = b.max;
min.x -= 30f;
max.x += 30f;
min.y -= 30f;
max.y += 30f;
Rect rect = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
if (actionUnderMouse == Action.Rotate)
{
SetCursorRect(rect, MouseCursor.RotateArrow);
}
else if (actionUnderMouse == Action.Move)
{
SetCursorRect(rect, MouseCursor.MoveArrow);
}
else if (actionUnderMouse == Action.Scale)
{
SetCursorRect(rect, MouseCursor.ScaleArrow);
}
else SetCursorRect(rect, MouseCursor.Arrow);
}
#endif
switch (type)
{
case EventType.Repaint:
{
Handles.BeginGUI();
//.........这里部分代码省略.........
示例9: Init
/// <summary>
/// Labels used for input shouldn't support color encoding.
/// </summary>
protected void Init ()
{
if (mDoInit)
{
mDoInit = false;
if (label == null) label = GetComponentInChildren<UILabel>();
if (label != null)
{
if (useLabelTextAtStart) mText = label.text;
mDefaultText = label.text;
mDefaultColor = label.color;
label.supportEncoding = false;
label.password = isPassword;
label.maxLineCount = 1;
mPivot = label.pivot;
mPosition = label.cachedTransform.localPosition.x;
}
else enabled = false;
}
}
示例10: Awake
//.........这里部分代码省略.........
GameObject Front = Instantiate<GameObject>(Resources.Load ("BG") as GameObject);
Front.transform.name = "BG";
Front.transform.parent = transform;
Front.transform.localScale = new Vector3(1,1,1);
}
BenchmarkSize = 720f;
if(CoverFlowCount>4){
if(CoverFlowCount == 5){
BenchmarkSize = 800f;
}else{
BenchmarkSize = 800f + (((float)CoverFlowCount-5f)*220f);
}
}
transform.FindChild("BG").localPosition = new Vector3((Size.x*(CoverFlowCount-1))*0.5f,((MaxSize.y-200)*0.5f)+20f);
transform.FindChild("BG").GetComponent<BoxCollider2D>().size = new Vector2((Size.x*CoverFlowCount)+((360-(Size.x*0.5f))*2f),MaxSize.y);
transform.FindChild("BG").GetComponent<BoxCollider2D>().offset = new Vector2(0,0);
transform.FindChild("BG").GetComponent<UITexture>().SetRect((Size.x*CoverFlowCount)+((360-(Size.x*0.5f))*2f),MaxSize.y);
transform.parent.FindChild("Benchmark").GetComponent<BoxCollider2D>().size = new Vector2(BenchmarkSize,Size.y);
transform.parent.FindChild("Benchmark").GetComponent<CoverFlowOndrag>().BenchmarkSize = BenchmarkSize;
transform.parent.FindChild("Benchmark").GetComponent<CoverFlowOndrag>().DefaultSize = DefaultSize;
transform.parent.FindChild("Benchmark").GetComponent<CoverFlowOndrag>().MaxSize = MaxSize;
transform.parent.FindChild("Benchmark").GetComponent<CoverFlowOndrag>().Size = Size;
transform.parent.FindChild("Benchmark").GetComponent<CoverFlowOndrag>().Gap = Gap;
for(int i = 0; i<CoverFlowCount;i++){
//Debug.Log(CoverFlowCount);
GameObject Temp = (GameObject)Instantiate(CoverFlowItem);
Temp.transform.FindChild("CoverFlowItem").tag = "item";
Temp.transform.name = "Item " + i.ToString();
Temp.transform.parent = transform;
Temp.transform.localScale = new Vector3(1,1,1);
Temp.transform.localPosition = new Vector3(Size.x*i,((MaxSize.y-200)*0.5f)+20f);
Temp.transform.FindChild("CoverFlowItem").GetComponent<UITexture>().SetRect(DefaultSize.x,DefaultSize.y);
if(Temp.transform.FindChild("CoverFlowItem").GetComponent<UIDragScrollView>()==null){
Temp.transform.FindChild("CoverFlowItem").gameObject.AddComponent<UIDragScrollView>();
}
if(Temp.transform.FindChild("CoverFlowItem").GetComponent<BoxCollider2D>()==null){
Temp.transform.FindChild("CoverFlowItem").gameObject.AddComponent<BoxCollider2D>();
}
Temp.transform.FindChild("CoverFlowItem").GetComponent<BoxCollider2D>().size = DefaultSize;
Temp.transform.FindChild("CoverFlowItem").GetComponent<UITexture>().SetRect(DefaultSize.x,DefaultSize.y);
Temp.transform.GetComponent<UIPanel>().SetRect(DefaultSize.x,DefaultSize.y);
Temp.transform.FindChild("CoverFlowItem").FindChild("BG").GetComponent<UISprite>().SetRect(DefaultSize.x,DefaultSize.y);
if(i>=CoverFlowCount-(int)Mathf.Round((float)(CoverFlowCount-3)*0.5f)){
int num = CoverFlowCount-(int)Mathf.Round((float)(CoverFlowCount-3)*0.5f);
Temp.transform.name = "Item " + (num-(i+1)).ToString();
Temp.transform.localPosition = new Vector3(Size.x*(num-(i+1)),((MaxSize.y-200)*0.5f)+20f);
}
}
}
}
mTrans = transform;
mPanel = GetComponent<UIPanel>();
if (mPanel.clipping == UIDrawCall.Clipping.None)
mPanel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
// Auto-upgrade
if (movement != Movement.Custom && scale.sqrMagnitude > 0.001f)
{
if (scale.x == 1f && scale.y == 0f)
{
movement = Movement.Horizontal;
}
else if (scale.x == 0f && scale.y == 1f)
{
movement = Movement.Vertical;
}
else if (scale.x == 1f && scale.y == 1f)
{
movement = Movement.Unrestricted;
}
else
{
movement = Movement.Custom;
customMovement.x = scale.x;
customMovement.y = scale.y;
}
scale = Vector3.zero;
#if UNITY_EDITOR
NGUITools.SetDirty(this);
#endif
}
// Auto-upgrade
if (contentPivot == UIWidget.Pivot.TopLeft && relativePositionOnReset != Vector2.zero)
{
contentPivot = NGUIMath.GetPivot(new Vector2(relativePositionOnReset.x, 1f - relativePositionOnReset.y));
relativePositionOnReset = Vector2.zero;
#if UNITY_EDITOR
NGUITools.SetDirty(this);
#endif
}
}
示例11: Load
static void Load()
{
int l = LayerMask.NameToLayer("UI");
if (l == -1) l = LayerMask.NameToLayer("GUI");
if (l == -1) l = 31;
mLoaded = true;
mPartial = EditorPrefs.GetString("NGUI Partial");
mFontName = EditorPrefs.GetString("NGUI Font Name");
mAtlasName = EditorPrefs.GetString("NGUI Atlas Name");
mFontData = GetObject("NGUI Font Asset") as TextAsset;
mFontTexture = GetObject("NGUI Font Texture") as Texture2D;
mFont = GetObject("NGUI Font") as UIFont;
mAtlas = GetObject("NGUI Atlas") as UIAtlas;
mAtlasPadding = EditorPrefs.GetInt("NGUI Atlas Padding", 1);
mAtlasTrimming = EditorPrefs.GetBool("NGUI Atlas Trimming", true);
mUnityPacking = EditorPrefs.GetBool("NGUI Unity Packing", true);
mForceSquare = EditorPrefs.GetBool("NGUI Force Square Atlas", true);
mPivot = (UIWidget.Pivot)EditorPrefs.GetInt("NGUI Pivot", (int)mPivot);
mLayer = EditorPrefs.GetInt("NGUI Layer", l);
mDynFont = GetObject("NGUI DynFont") as Font;
mDynFontSize = EditorPrefs.GetInt("NGUI DynFontSize", 16);
mDynFontStyle = (FontStyle)EditorPrefs.GetInt("NGUI DynFontStyle", (int)FontStyle.Normal);
LoadColor();
}
示例12: Awake
private void Awake()
{
this.mTrans = base.transform;
this.mPanel = base.GetComponent<UIPanel>();
if (this.mPanel.clipping == UIDrawCall.Clipping.None)
{
this.mPanel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
}
if (this.movement != UIScrollView.Movement.Custom && this.scale.sqrMagnitude > 0.001f)
{
if (this.scale.x == 1f && this.scale.y == 0f)
{
this.movement = UIScrollView.Movement.Horizontal;
}
else if (this.scale.x == 0f && this.scale.y == 1f)
{
this.movement = UIScrollView.Movement.Vertical;
}
else if (this.scale.x == 1f && this.scale.y == 1f)
{
this.movement = UIScrollView.Movement.Unrestricted;
}
else
{
this.movement = UIScrollView.Movement.Custom;
this.customMovement.x = this.scale.x;
this.customMovement.y = this.scale.y;
}
this.scale = Vector3.zero;
}
if (this.contentPivot == UIWidget.Pivot.TopLeft && this.relativePositionOnReset != Vector2.zero)
{
this.contentPivot = NGUIMath.GetPivot(new Vector2(this.relativePositionOnReset.x, 1f - this.relativePositionOnReset.y));
this.relativePositionOnReset = Vector2.zero;
}
}
示例13: ShowMenuBar
/// <summary>
/// Special case version of Show() designed for menu bars. This not only ondoes
/// HideMenuBar(), it also will, if necessary, build the entire menu hierarchy,
/// though it will avoid doing so if it can. For non-menu bar menus this is
/// a no-op. Normally you would not need to call this unless you have hidden
/// the menu bar yourself, as it will be called at startup automatically.
/// </summary>
public void ShowMenuBar()
{
if (menuBar)
{
CtxHelper.SetActive(gameObject, true);
// Avoid rebuilding the menu bar if it's already created.
if (menuRoot != null)
{
if (panel == null)
panel = NGUITools.FindInParents<UIPanel>(gameObject);
if (panel != null)
Refresh();
}
else
{
// Menu bars use their own positioning logic. It is assumed that the menu bar
// will choose an edge of the screen based on the specified pivot. Horizontal
// menu bars will prefer the top or bottom, while vertical menu bars will prefer
// the left or right edge. It is also assumed that the menu bar is under a
// UIAnchor that has an appropriate Side setting, which is why the menu bar
// position is always 0,0,0.
if (style == Style.Horizontal)
{
switch (pivot)
{
default:
case UIWidget.Pivot.Top:
pivot = UIWidget.Pivot.TopLeft;
break;
case UIWidget.Pivot.Bottom:
case UIWidget.Pivot.BottomLeft:
case UIWidget.Pivot.BottomRight:
pivot = UIWidget.Pivot.BottomLeft;
break;
}
Show(Vector3.zero);
}
else if (style == Style.Vertical)
{
switch (pivot)
{
default:
case UIWidget.Pivot.Left:
case UIWidget.Pivot.TopLeft:
case UIWidget.Pivot.BottomLeft:
pivot = UIWidget.Pivot.TopLeft;
break;
case UIWidget.Pivot.Right:
case UIWidget.Pivot.TopRight:
case UIWidget.Pivot.BottomRight:
pivot = UIWidget.Pivot.TopRight;
break;
}
Show(Vector3.zero);
}
}
}
}
示例14: Init
protected void Init()
{
if (this.mDoInit && this.label != null)
{
this.mDoInit = false;
this.mDefaultText = this.label.text;
this.mDefaultColor = this.label.color;
this.label.supportEncoding = false;
if (this.label.alignment == NGUIText.Alignment.Justified)
{
this.label.alignment = NGUIText.Alignment.Left;
global::Debug.LogWarning(new object[]
{
"Input fields using labels with justified alignment are not supported at this time",
this
});
}
this.mPivot = this.label.pivot;
this.mPosition = this.label.cachedTransform.localPosition.x;
this.UpdateLabel();
}
}
示例15: OnSceneGUI
/// <summary>
/// Draw the on-screen selection, knobs, and handle all interaction logic.
/// Lets the Editor handle an event in the scene view.
/// </summary>
public void OnSceneGUI()
{
//Tools.current = Tool.View;
mWidget = target as UIWidget;
Handles.color = mOutlineColor;
Transform t = mWidget.cachedTransform;
Event e = Event.current;
int id = GUIUtility.GetControlID(s_Hash, FocusType.Passive);//此GUI控件,不会有键盘聚焦事件
EventType type = e.GetTypeForControl(id);
//绘制控件的四条边
Vector3[] corners = NGUIMath.CalculateWidgetCorners(mWidget);
Handles.DrawLine(corners[0], corners[1]);
Handles.DrawLine(corners[1], corners[2]);
Handles.DrawLine(corners[2], corners[3]);
Handles.DrawLine(corners[0], corners[3]);
Vector3[] worldPos = new Vector3[8];
worldPos[0] = corners[0];
worldPos[1] = corners[1];
worldPos[2] = corners[2];
worldPos[3] = corners[3];
worldPos[4] = (corners[0] + corners[1]) * 0.5f;
worldPos[5] = (corners[1] + corners[2]) * 0.5f;
worldPos[6] = (corners[2] + corners[3]) * 0.5f;
worldPos[7] = (corners[0] + corners[3]) * 0.5f;
Vector2[] screenPos = new Vector2[8];
for (int i = 0; i < 8; ++i) screenPos[i] = HandleUtility.WorldToGUIPoint(worldPos[i]);
//Represents an axis aligned bounding box.这个box与坐标轴平行,不会因target而rotate
//Vector3.zero 表示这个Bounds的Size为(0,0,0)
Bounds b = new Bounds(screenPos[0], Vector3.zero);
//Grow the bounds to encapsulate the bounds.慢慢将各点纳入bounds
for (int i = 1; i < 8; ++i) b.Encapsulate(screenPos[i]);
// Time to figure out what kind of action is underneath the mouse
Action actionUnderMouse = mAction;
UIWidget.Pivot pivotUnderMouse = UIWidget.Pivot.Center;
if (actionUnderMouse == Action.None)
{
int index = 0;
float dist = GetScreenDistance(worldPos, e.mousePosition, out index);
//缩放
if (dist < 10f)
{
pivotUnderMouse = mPivots[index];
actionUnderMouse = Action.Scale;
}
//移动,modifier【调节器;<语>修饰语】这里表示组合键,比如旋转的alt键
else if (e.modifiers == 0 && NGUIEditorTools.DistanceToRectangle(corners, e.mousePosition) == 0f)
{
if (Tools.current != Tool.Rotate && Tools.current != Tool.Scale)
{
actionUnderMouse = Action.Move;
}
}
//旋转
else if (dist < 30f)
{
actionUnderMouse = Action.Rotate;
}
}
// Change the mouse cursor to a more appropriate one
#if !UNITY_3_5
{
Vector2 min = b.min;
Vector2 max = b.max;
min.x -= 30f;
max.x += 30f;
min.y -= 30f;
max.y += 30f;
Rect rect = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
if (actionUnderMouse == Action.Rotate)
{
SetCursorRect(rect, MouseCursor.RotateArrow);
}
else if (actionUnderMouse == Action.Move)
{
SetCursorRect(rect, MouseCursor.MoveArrow);
}
else if (actionUnderMouse == Action.Scale)
{
SetCursorRect(rect, MouseCursor.ScaleArrow);
}
//.........这里部分代码省略.........