public static void AutoAlign(this GameObject tr, UIAlign align = UIAlign.CENTER, UIPluginType uitype = defaultType) { if (uitype == UIPluginType.UGUI) { tr.UGUIAutoAlign(align); } }
public UIImage(string imageVal, UIAlign al = UIAlign.Left) : base(0.0f, 0.0f, -1f, -1f) { this._image = new Sprite(imageVal); this._collisionSize = new Vec2((float)this._image.w, (float)this._image.h); this._image.CenterOrigin(); this.align = al; }
public UIContainer AddContainer(string name, UIAlign anchor) { UIContainer c = gameObject.AddComponent <UIContainer>(); containers.AddLast(c); c.ContainerName = name; c.anchor = anchor; return(c); }
public UIImage(Sprite imageVal, UIAlign al = UIAlign.Left, float s = 1f, float yOff = 0.0f) : base(0.0f, 0.0f, -1f, -1f) { this._image = imageVal; this._collisionSize = new Vec2((float)this._image.w * s, (float)this._image.h * s); this._image.CenterOrigin(); this.scale = new Vec2(s); this.align = al; this.yOffset = yOff; }
public AMenu CreatePopup(UIAlign anchor) { AMenu m = CreateMenu(anchor); popups.AddFirst(m); popups.AssertValid(); // inactivate others var it = popups.Iterator(); it.Next(); while (it.Next()) { it.Value().gameObject.SetActive(false); } return(m); }
public AMenu CreateMenu(UIAlign anchor) { AMenu m = Instantiate(MenuPrefab).GetComponent <AMenu>(); m.main.anchor = anchor; m.Initialize(this); if (menus.Size() > 0) { m.SetLayerOrder(menus.Last().GetLayerOrder() + 1); } else { m.SetLayerOrder(1); } menus.AddLast(m); return(m); }
public static List <GameObject> CreateHorGridScroll(this GameObject gameobject, string masksprite, out GameObject scrollObj, Vector2 viewSize, float delta, GameObject prefab, int cnt, UIAlign align = UIAlign.CENTER, int collimit = -1, int rowlimit = -1, UIPluginType uitype = defaultType) { if (uitype == UIPluginType.UGUI) { GameObject scrollgameobject = gameobject.TryGetGameObject("Scroll"); scrollObj = scrollgameobject; float totalx = 0f; if (prefab != null) { totalx = (prefab.GetComponent <RectTransform>().sizeDelta.x + delta) * cnt; } ScrollViewExpand rect = scrollgameobject.TryAddComponent <ScrollViewExpand>(); rect.vertical = false; rect.horizontal = true; rect.movementType = ScrollRect.MovementType.Elastic; rect.inertia = true; //rect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport; //rect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport; rect.GetComponent <RectTransform>().sizeDelta = viewSize; GameObject viewPortgameobject = scrollgameobject.TryGetGameObject("Viewport"); GameObject Gridgameobject = viewPortgameobject.TryGetGameObject("Grid"); Mask viewmask = viewPortgameobject.TryAddComponent <Mask>(); viewmask.showMaskGraphic = false; ImageExpand viewimage = viewPortgameobject.TryAddComponent <ImageExpand>(); viewimage.raycastTarget = true; viewimage.type = Image.Type.Sliced; viewimage.fillCenter = true; if (SpriteAtlasMgr.mIns != null) { SpriteAtlasMgr.mIns.ChangeSprite(viewimage, masksprite); } GridLayoutGroup group = Gridgameobject.TryAddComponent <GridLayoutGroup>(); group.spacing = new Vector2(delta, 0); group.startCorner = GridLayoutGroup.Corner.UpperLeft; group.startAxis = GridLayoutGroup.Axis.Horizontal; RectTransform grouprect = group.GetComponent <RectTransform>(); grouprect.sizeDelta = new Vector2(totalx, 0); grouprect.anchorMin = new Vector2(0, 1); grouprect.anchorMax = new Vector2(1, 1); grouprect.pivot = new Vector2(0, 1); if (collimit != -1 && collimit >= 0) { group.constraint = GridLayoutGroup.Constraint.FixedColumnCount; group.constraintCount = collimit; } else if (rowlimit != -1 && rowlimit >= 0) { group.constraint = GridLayoutGroup.Constraint.FixedRowCount; group.constraintCount = rowlimit; } if (align == UIAlign.CENTER) { group.childAlignment = TextAnchor.MiddleCenter; } else if (align == UIAlign.CENTER_DOWN) { group.childAlignment = TextAnchor.LowerCenter; } else if (align == UIAlign.CENTER_TOP) { group.childAlignment = TextAnchor.UpperCenter; } else if (align == UIAlign.LEFT_DOWN) { group.childAlignment = TextAnchor.LowerLeft; } else if (align == UIAlign.LEFT_TOP) { group.childAlignment = TextAnchor.UpperLeft; } else if (align == UIAlign.RIGHT_DOWN) { group.childAlignment = TextAnchor.LowerRight; } else if (align == UIAlign.RIGHT_TOP) { group.childAlignment = TextAnchor.UpperRight; } List <GameObject> gameObjectList = null; if (cnt > 0) { gameObjectList = ListPool.TrySpawn <List <GameObject> >(); for (int i = 0; i < cnt; ++i) { GameObject childgameobject = GameObject.Instantiate(prefab); if (i == 0) { RectTransform childrect = childgameobject.GetComponent <RectTransform>(); if (childrect != null) { group.cellSize = childrect.sizeDelta; } } Gridgameobject.AddInstance(childgameobject); gameObjectList.Add(childgameobject); } } RectTransform viewrecttransform = viewPortgameobject.GetComponent <RectTransform>(); viewrecttransform.anchorMin = Vector2.zero; viewrecttransform.anchorMax = new Vector2(1, 1); viewrecttransform.pivot = new Vector2(0, 1); viewrecttransform.sizeDelta = Vector2.zero; rect.content = grouprect; rect.viewport = viewrecttransform; return(gameObjectList); } scrollObj = null; return(null); }
public static void AutoAlign(this Component tr, UIAlign align = UIAlign.CENTER, UIPluginType uitype = defaultType) { tr.gameObject.AutoAlign(align, uitype); }
private static void UGUIAutoAlign(this GameObject target, UIAlign align = UIAlign.CENTER) { Camera camera = null; Canvas canvas = target.GetComponentInParent <Canvas>(); if (canvas == null) { LogMgr.LogErrorFormat("Cant found Canvas :{0}", target); #if UNITY_EDITOR target.PauseGame(); #endif return; } else if (canvas.worldCamera == null && canvas.renderMode != RenderMode.ScreenSpaceOverlay) { LogMgr.LogErrorFormat("Camera is Null:{0", target); return; } RectTransform trans = target.GetComponent <RectTransform>(); if (trans == null) { LogMgr.LogErrorFormat("missing recttransform :{0}", target); return; } camera = canvas.worldCamera; //bool islandscape = FrameWorkConfig.DisplayUIWidth > FrameWorkConfig.DisplayUIHiehgt; //Vector2 size = trans.sizeDelta; //Vector2 screensize = new Vector2(Screen.width,Screen.height); if (align == UIAlign.CENTER) { //if (islandscape) //{ // trans.anchorMin = new Vector2(0,0.5f); // trans.anchorMax = new Vector2(1, 0.5f); // trans.offsetMin = new Vector2(); //} //else //{ // trans.anchorMin = new Vector2(0.5f, 0f); // trans.anchorMax = new Vector2(0.5f, 1f); //} ////trans.anchorMin = new Vector2(0.5f, 0.5f); ////trans.anchorMax = new Vector2(0.5f, 0.5f); //trans.pivot = new Vector2(0.5f, 0.5f); SetUIAlignPos(trans, align, canvas, camera); } else if (align == UIAlign.CENTER_TOP) { //if (islandscape) //{ // trans.anchorMin = new Vector2(0, 0.5f); // trans.anchorMax = new Vector2(1, 0.5f); //} //else //{ // trans.anchorMin = new Vector2(0.5f, 0f); // trans.anchorMax = new Vector2(0.5f, 1f); //} ////trans.anchorMin = new Vector2(0.5f, 1f); ////trans.anchorMax = new Vector2(0.5f, 1f); //trans.pivot = new Vector2(0.5f, 1f); SetUIAlignPos(trans, align, canvas, camera); } else if (align == UIAlign.CENTER_DOWN) { //if (islandscape) //{ // trans.anchorMin = new Vector2(0, 0.5f); // trans.anchorMax = new Vector2(1, 0.5f); //} //else //{ // trans.anchorMin = new Vector2(0.5f, 0f); // trans.anchorMax = new Vector2(0.5f, 1f); //} ////trans.anchorMin = new Vector2(0.5f, 0f); ////trans.anchorMax = new Vector2(0.5f, 0f); //trans.pivot = new Vector2(0.5f, 0f); SetUIAlignPos(trans, align, canvas, camera); } else if (align == UIAlign.LEFT_DOWN) { //if (islandscape) //{ // trans.anchorMin = new Vector2(0, 0.5f); // trans.anchorMax = new Vector2(1, 0.5f); //} //else //{ // trans.anchorMin = new Vector2(0.5f, 0f); // trans.anchorMax = new Vector2(0.5f, 1f); //} ////trans.anchorMin = new Vector2(0f, 0f); ////trans.anchorMax = new Vector2(0f, 0f); //trans.pivot = new Vector2(0f, 0f); SetUIAlignPos(trans, align, canvas, camera); } else if (align == UIAlign.LEFT_TOP) { //if (islandscape) //{ // trans.anchorMin = new Vector2(0, 0.5f); // trans.anchorMax = new Vector2(1, 0.5f); //} //else //{ // trans.anchorMin = new Vector2(0.5f, 0f); // trans.anchorMax = new Vector2(0.5f, 1f); //} ////trans.anchorMin = new Vector2(0f, 1f); ////trans.anchorMax = new Vector2(0f, 1f); //trans.pivot = new Vector2(0f, 1f); SetUIAlignPos(trans, align, canvas, camera); } else if (align == UIAlign.RIGHT_TOP) { //if (islandscape) //{ // trans.anchorMin = new Vector2(0, 0.5f); // trans.anchorMax = new Vector2(1, 0.5f); //} //else //{ // trans.anchorMin = new Vector2(0.5f, 0f); // trans.anchorMax = new Vector2(0.5f, 1f); //} ////trans.anchorMin = new Vector2(1f, 1f); ////trans.anchorMax = new Vector2(1f, 1f); //trans.pivot = new Vector2(1f, 1f); SetUIAlignPos(trans, align, canvas, camera); } else if (align == UIAlign.RIGHT_DOWN) { //if (islandscape) //{ // trans.anchorMin = new Vector2(0, 0.5f); // trans.anchorMax = new Vector2(1, 0.5f); //} //else //{ // trans.anchorMin = new Vector2(0.5f, 0f); // trans.anchorMax = new Vector2(0.5f, 1f); //} ////trans.anchorMin = new Vector2(1f, 0f); ////trans.anchorMax = new Vector2(1f, 0f); //trans.pivot = new Vector2(1f, 0f); SetUIAlignPos(trans, align, canvas, camera); } }
private static void SetUIAlignPos(RectTransform rect, UIAlign align, Canvas canvas, Camera camera) { bool isOverLay = canvas.renderMode == RenderMode.ScreenSpaceOverlay; float ScreenHight = canvas.pixelRect.height; //canvas.pixelRect.height; float ScreenWidth = canvas.pixelRect.width; // canvas.pixelRect.width; //Vector3 WorldPos; Vector2 ScreenPos = Vector2.zero; switch (align) { case UIAlign.CENTER: { ScreenPos = new Vector2(ScreenWidth / 2, ScreenHight / 2); break; } case UIAlign.CENTER_TOP: { ScreenPos = new Vector2(ScreenWidth / 2, ScreenHight); break; } case UIAlign.CENTER_DOWN: { ScreenPos = new Vector2(ScreenWidth / 2, 0); break; } case UIAlign.LEFT_DOWN: { ScreenPos = new Vector2(0, 0); break; } case UIAlign.LEFT_TOP: { ScreenPos = new Vector2(0, ScreenHight); break; } case UIAlign.RIGHT_DOWN: { ScreenPos = new Vector2(ScreenWidth, 0); break; } case UIAlign.RIGHT_TOP: { ScreenPos = new Vector2(ScreenWidth, ScreenHight); break; } } RectTransform canvasrect = canvas.GetComponent <RectTransform>(); Vector3 worldpos; RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasrect, ScreenPos, isOverLay ? null : camera, out worldpos); rect.position = worldpos; //return worldpos; //Vector2 pos; //RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasrect, ScreenPos, isOverLay ? null : camera, out pos); //rect.anchoredPosition = pos; }
public UIModifierMenuItem(UIMenuAction action = null, UIAlign al = UIAlign.Center, Color c = default(Color), bool backButton = false) : base("AAAAAAAAAAAAAAAAAA", action, al, c, backButton) { }
public UICustomLevelMenu(UIMenuAction action = null, UIAlign al = UIAlign.Center, Color c = default(Color), bool backButton = false) : base("AAAAAAAAAAAAAAAAAA", action, al, c, backButton) { }