本文整理汇总了C#中UIWidget.SetDimensions方法的典型用法代码示例。如果您正苦于以下问题:C# UIWidget.SetDimensions方法的具体用法?C# UIWidget.SetDimensions怎么用?C# UIWidget.SetDimensions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIWidget
的用法示例。
在下文中一共展示了UIWidget.SetDimensions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillWidget
public static void FillWidget(UIWidget widget, MyJson.JsonNode_Object json)
{
widget.color = ComponentTypeConvert.StringToColor(json["w_color"] as MyJson.JsonNode_ValueString);
widget.pivot = (UIWidget.Pivot)Enum.Parse(typeof(UIWidget.Pivot), json["w_pivot"] as MyJson.JsonNode_ValueString);
widget.depth = json["w_depth"] as MyJson.JsonNode_ValueNumber;
widget.keepAspectRatio = (UIWidget.AspectRatioSource)Enum.Parse(typeof(UIWidget.AspectRatioSource), json["w_keepasp"] as MyJson.JsonNode_ValueString);
Vector2 demensions = ComponentTypeConvert.StringToVector2(json["w_dimensions"] as MyJson.JsonNode_ValueString);
widget.SetDimensions((int)demensions.x, (int)demensions.y);
}
示例2: AdjustWidget
//.........这里部分代码省略.........
}
else if (piv.x == 1f && piv.y == 0f)
{
offset.x = rotatedBR.x;
offset.y = rotatedBR.y;
}
else if (piv.x == 0f && piv.y == 0f)
{
offset.x = rotatedBL.x;
offset.y = rotatedBL.y;
}
else if (piv.x == 1f && piv.y == 1f)
{
offset.x = rotatedTR.x;
offset.y = rotatedTR.y;
}
else if (piv.x == 0f && piv.y == 0.5f)
{
offset.x = rotatedL.x + (rotatedT.x + rotatedB.x) * 0.5f;
offset.y = rotatedL.y + (rotatedT.y + rotatedB.y) * 0.5f;
}
else if (piv.x == 1f && piv.y == 0.5f)
{
offset.x = rotatedR.x + (rotatedT.x + rotatedB.x) * 0.5f;
offset.y = rotatedR.y + (rotatedT.y + rotatedB.y) * 0.5f;
}
else if (piv.x == 0.5f && piv.y == 1f)
{
offset.x = rotatedT.x + (rotatedL.x + rotatedR.x) * 0.5f;
offset.y = rotatedT.y + (rotatedL.y + rotatedR.y) * 0.5f;
}
else if (piv.x == 0.5f && piv.y == 0f)
{
offset.x = rotatedB.x + (rotatedL.x + rotatedR.x) * 0.5f;
offset.y = rotatedB.y + (rotatedL.y + rotatedR.y) * 0.5f;
}
else if (piv.x == 0.5f && piv.y == 0.5f)
{
offset.x = (rotatedL.x + rotatedR.x + rotatedT.x + rotatedB.x) * 0.5f;
offset.y = (rotatedT.y + rotatedB.y + rotatedL.y + rotatedR.y) * 0.5f;
}
minWidth = Mathf.Max(minWidth, w.minWidth);
minHeight = Mathf.Max(minHeight, w.minHeight);
// Calculate the widget's width and height after the requested adjustments
int finalWidth = w.width + iRight - iLeft;
int finalHeight = w.height + iTop - iBottom;
// Now it's time to constrain the width and height so that they can't go below min values
Vector3 constraint = Vector3.zero;
int limitWidth = finalWidth;
if (finalWidth < minWidth) limitWidth = minWidth;
else if (finalWidth > maxWidth) limitWidth = maxWidth;
if (finalWidth != limitWidth)
{
if (iLeft != 0) constraint.x -= Mathf.Lerp(limitWidth - finalWidth, 0f, piv.x);
else constraint.x += Mathf.Lerp(0f, limitWidth - finalWidth, piv.x);
finalWidth = limitWidth;
}
int limitHeight = finalHeight;
if (finalHeight < minHeight) limitHeight = minHeight;
else if (finalHeight > maxHeight) limitHeight = maxHeight;
if (finalHeight != limitHeight)
{
if (iBottom != 0) constraint.y -= Mathf.Lerp(limitHeight - finalHeight, 0f, piv.y);
else constraint.y += Mathf.Lerp(0f, limitHeight - finalHeight, piv.y);
finalHeight = limitHeight;
}
// Centered pivot requires power-of-two dimensions
if (piv.x == 0.5f) finalWidth = ((finalWidth >> 1) << 1);
if (piv.y == 0.5f) finalHeight = ((finalHeight >> 1) << 1);
// Update the position, width and height
Vector3 pos = t.localPosition + offset + rot * constraint;
t.localPosition = pos;
w.SetDimensions(finalWidth, finalHeight);
// If the widget is anchored, we should update the anchors as well
if (w.isAnchored)
{
t = t.parent;
float x = pos.x - piv.x * finalWidth;
float y = pos.y - piv.y * finalHeight;
if (w.leftAnchor.target) w.leftAnchor.SetHorizontal(t, x);
if (w.rightAnchor.target) w.rightAnchor.SetHorizontal(t, x + finalWidth);
if (w.bottomAnchor.target) w.bottomAnchor.SetVertical(t, y);
if (w.topAnchor.target) w.topAnchor.SetVertical(t, y + finalHeight);
}
#if UNITY_EDITOR
NGUITools.SetDirty(w);
#endif
}
示例3: CreateUIRoot
//void CreateUGUI()
//{
// var canvasObj = new GameObject("UICanvas");
// UICanvas = canvasObj.AddComponent<Canvas>();
// UICanvas.renderMode = RenderMode.ScreenSpaceOverlay;
// //UICanvas.worldCamera = UiCamera.cachedCamera;
// canvasObj.AddComponent<GraphicRaycaster>();
// var scaler = canvasObj.AddComponent<CanvasScaler>();
// scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; // 屏幕固定大小
// scaler.referenceResolution = new Vector2(1080, 1920);
// var evtSysObj = new GameObject("EventSystem");
// KTool.SetChild(evtSysObj, canvasObj);
// evtSysObj.AddComponent<EventSystem>();
//}
private void CreateUIRoot()
{
GameObject uiRootobj = GameObject.Find("NGUIRoot") ?? new GameObject("NGUIRoot");
UiRoot = uiRootobj.GetComponent<UIRoot>() ?? uiRootobj.AddComponent<UIRoot>();
Debuger.Assert(UiRoot);
UiRoot.scalingStyle = UIRoot.Scaling.FixedSizeOnMobiles;
// 尝试将NGUI转化成跟2dToolkit镜头一致显示
UiRoot.manualHeight = 1080;
//GameDef.ScreenPixelY;//(int)(GameDef.ScreenPixelY / (GameDef.ScreenPixelY / 2f / GameDef.DefaultPixelPerMeters)); // fit width!
//UiRoot.manualWidth = 1920;//GameDef.ScreenPixelX;
// 屏幕中间位置
//UiRoot.transform.localPosition = new Vector3(GameDef.ScreenPixelX / 2f / GameDef.DefaultPixelPerMeters,
// GameDef.ScreenPixelY / 2f / GameDef.DefaultPixelPerMeters, -50);
//var scale = 1 / GameDef.DefaultPixelPerMeters;
//// 覆盖NGUI的Uiroot自动缩放
//UiRoot.transform.localScale = new Vector3(scale, scale, scale);
//UiRoot.enabled = false;
GameObject panelRootObj = new GameObject("PanelRoot");
KTool.SetChild(panelRootObj.transform, uiRootobj.transform);
Transform panelTrans = panelRootObj.transform;
PanelRoot = panelRootObj.AddComponent<UIPanel>();
Debuger.Assert(PanelRoot);
PanelRoot.generateNormals = true;
var uiCamTrans = uiRootobj.transform.Find("UICamera");
GameObject uiCamObj = uiCamTrans != null ? uiCamTrans.gameObject : new GameObject("UICamera");
KTool.SetChild(uiCamObj.transform, UiRoot.transform);
UiCamera = uiCamObj.GetComponent<UICamera>() ?? uiCamObj.AddComponent<UICamera>();
UiCamera.cachedCamera.cullingMask = 1 << (int)UnityLayerDef.UI;
UiCamera.cachedCamera.clearFlags = CameraClearFlags.Depth;
UiCamera.cachedCamera.orthographic = true;
UiCamera.cachedCamera.orthographicSize = GameDef.ScreenPixelY / GameDef.DefaultPixelPerMeters / 2f;
// 9.6,一屏19.2米,跟GameCamera一致
UiCamera.cachedCamera.nearClipPlane = -500;
UiCamera.cachedCamera.farClipPlane = 500;
foreach (UIAnchor.Side side in Enum.GetValues(typeof(UIAnchor.Side)))
{
GameObject anchorObj = new GameObject(side.ToString());
KTool.SetChild(anchorObj.transform, panelTrans);
AnchorSide[side.ToString()] = anchorObj.transform;
}
GameObject nullAnchor = new GameObject("Null");
KTool.SetChild(nullAnchor.transform, panelTrans);
AnchorSide["Null"] = nullAnchor.transform;
AnchorSide[""] = AnchorSide[UIAnchor.Side.Center.ToString()]; // default
NGUITools.SetLayer(uiRootobj, (int)UnityLayerDef.UI);
PressWidget = new GameObject("PressWidget").AddComponent<UIWidget>();
NGUITools.SetLayer(PressWidget.gameObject, (int)UnityLayerDef.UI);
KTool.SetChild(PressWidget.gameObject, panelRootObj);
PressWidget.SetDimensions(2000, 2000);
var col = PressWidget.gameObject.AddComponent<BoxCollider>();
col.size = new Vector3(2000, 2000);
PressWidget.autoResizeBoxCollider = true;
PressWidget.gameObject.SetActive(false);
//UICamera.onDragStart = (go) =>
//{
// if (go != null) // 点击任意NGUI控件,出现阻挡
// PressWidget.gameObject.SetActive(true);
//};
//UICamera.onPress = (go, state) =>
//{
// if (!state) // 点击任意NGUI控件,出现阻挡
// PressWidget.gameObject.SetActive(false);
// //if (go != null)
// //{
// // if (go.GetComponent<UIButton>() == null)
// // {
// // if (go.GetComponent<UIEventListener>() != null && go.GetComponent<UISprite>() != null)
// // {
// // if (Debug.isDebugBuild)
// // {
// // Debug.LogWarning("自动加UIButton和ButtonScale - " + go.name, go);
// // }
// // // 当不包含ButtonScale动画
// // // 并且拥有EventListener和UISprite!
// // // 统一加上ButtonScale!
//.........这里部分代码省略.........
示例4: GetValue
public virtual void GetValue(UIWidget widget)
{
widget.name = Name;
widget.transform.localPosition = Position.GetVector2();
widget.SetDimensions((int)Size.x, (int)Size.y);
}
示例5: AdjustWidget
//.........这里部分代码省略.........
{
zero.x = vector6.x + (vector7.x + vector8.x) * 0.5f;
zero.y = vector6.y + (vector7.y + vector8.y) * 0.5f;
}
else if (pivotOffset.x == 0.5f && pivotOffset.y == 1f)
{
zero.x = vector7.x + (vector5.x + vector6.x) * 0.5f;
zero.y = vector7.y + (vector5.y + vector6.y) * 0.5f;
}
else if (pivotOffset.x == 0.5f && pivotOffset.y == 0f)
{
zero.x = vector8.x + (vector5.x + vector6.x) * 0.5f;
zero.y = vector8.y + (vector5.y + vector6.y) * 0.5f;
}
else if (pivotOffset.x == 0.5f && pivotOffset.y == 0.5f)
{
zero.x = (vector5.x + vector6.x + vector7.x + vector8.x) * 0.5f;
zero.y = (vector7.y + vector8.y + vector5.y + vector6.y) * 0.5f;
}
minWidth = Mathf.Max(minWidth, w.minWidth);
minHeight = Mathf.Max(minHeight, w.minHeight);
int num5 = w.width + num3 - num;
int num6 = w.height + num4 - num2;
Vector3 zero2 = Vector3.zero;
int num7 = num5;
if (num5 < minWidth)
{
num7 = minWidth;
}
else if (num5 > maxWidth)
{
num7 = maxWidth;
}
if (num5 != num7)
{
if (num != 0)
{
zero2.x -= Mathf.Lerp((float)(num7 - num5), 0f, pivotOffset.x);
}
else
{
zero2.x += Mathf.Lerp(0f, (float)(num7 - num5), pivotOffset.x);
}
num5 = num7;
}
int num8 = num6;
if (num6 < minHeight)
{
num8 = minHeight;
}
else if (num6 > maxHeight)
{
num8 = maxHeight;
}
if (num6 != num8)
{
if (num2 != 0)
{
zero2.y -= Mathf.Lerp((float)(num8 - num6), 0f, pivotOffset.y);
}
else
{
zero2.y += Mathf.Lerp(0f, (float)(num8 - num6), pivotOffset.y);
}
num6 = num8;
}
if (pivotOffset.x == 0.5f)
{
num5 = num5 >> 1 << 1;
}
if (pivotOffset.y == 0.5f)
{
num6 = num6 >> 1 << 1;
}
Vector3 localPosition = transform.localPosition + zero + localRotation * zero2;
transform.localPosition = localPosition;
w.SetDimensions(num5, num6);
if (w.isAnchored)
{
transform = transform.parent;
float num9 = localPosition.x - pivotOffset.x * (float)num5;
float num10 = localPosition.y - pivotOffset.y * (float)num6;
if (w.leftAnchor.target)
{
w.leftAnchor.SetHorizontal(transform, num9);
}
if (w.rightAnchor.target)
{
w.rightAnchor.SetHorizontal(transform, num9 + (float)num5);
}
if (w.bottomAnchor.target)
{
w.bottomAnchor.SetVertical(transform, num10);
}
if (w.topAnchor.target)
{
w.topAnchor.SetVertical(transform, num10 + (float)num6);
}
}
}