private void ApplySprite(Sprite sprite) { if (sprite == null) { return; } if (_Image == null) { _Image = GetComponent <Image>(); } if (_Image != null) { _Image.overrideSprite = sprite; if (UseNativeSize) { _Image.SetNativeSize(); } } else { Debug.LogError("This node doesnt have an Image on it! " + GNewUITools.PrintScenePath(transform)); } }
protected override void OnDestroy() { #if UNITY_EDITOR if (!_IsQuiting && (_ModelT != null || (_PlatformT != null && _PlatformT.childCount > 0))) { Debug.LogError("CUIMODEL destroy was not called ! " + GNewUITools.PrintScenePath(rectTransform)); LuaScriptMgr.Instance.CallOnTraceBack(); } #endif Release(); base.OnDestroy(); _IsDestroyed = true; }
public static int SetGroupToggleOn(IntPtr L) { int count = LuaDLL.lua_gettop(L); const int nRet = 0; if ((count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(GameObject), typeof(int)))) { var groupObj = LuaScriptMgr.GetUnityObject <GameObject>(L, 1); if (groupObj == null) { HobaDebuger.LogWarning("SetGroupToggleOn: param 1 must be GameObject"); return(GameUtilWrap.CheckReturnNum(L, count, nRet)); } var group = groupObj.GetComponent <ToggleGroup>(); if (group == null) { HobaDebuger.LogWarning("SetGroupToggleOn: param 1 must have ToggleGroup component " + GNewUITools.PrintScenePath(groupObj.transform, 5)); return(GameUtilWrap.CheckReturnNum(L, count, nRet)); } var toggleIndex = (int)LuaScriptMgr.GetNumber(L, 2); var toggleObj = groupObj.transform.GetChild(toggleIndex - 1); //var toggleObj = LuaScriptMgr.GetUnityObject<GameObject>(L, 2); if (toggleObj == null) { HobaDebuger.LogWarning("SetGroupToggleOn: param 2 must be GameObject"); return(GameUtilWrap.CheckReturnNum(L, count, nRet)); } var toggle = toggleObj.GetComponent <Toggle>(); if (toggle == null) { HobaDebuger.LogWarning("SetGroupToggleOn: param 2 must have Toggle component " + GNewUITools.PrintScenePath(groupObj.transform, 5)); return(GameUtilWrap.CheckReturnNum(L, count, nRet)); } group.SetAllTogglesOff(); toggle.isOn = true; } else { GameUtilWrap.LogParamError("SetGroupToggleOn", count); } return(GameUtilWrap.CheckReturnNum(L, count, nRet)); }
protected virtual void LayoutChildren() { if (_ChildNodes.Count <= 0) { return; } float fx = 0; float fy = 0; int paddingx1 = 0; int paddingx2 = 0; int paddingy1 = 0; int paddingy2 = 0; if (_StartCorner == GridLayoutGroup.Corner.UpperLeft) { fx = 1; fy = -1; paddingx1 = _Padding.left; paddingx2 = _Padding.right; paddingy1 = _Padding.top; paddingy2 = _Padding.bottom; } else if (_StartCorner == GridLayoutGroup.Corner.UpperRight) { fx = -1; fy = -1; paddingx1 = _Padding.right; paddingx2 = _Padding.left; paddingy1 = _Padding.top; paddingy2 = _Padding.bottom; } else if (_StartCorner == GridLayoutGroup.Corner.LowerRight) { fx = -1; fy = 1; paddingx1 = _Padding.right; paddingx2 = _Padding.left; paddingy1 = _Padding.bottom; paddingy2 = _Padding.top; } else if (_StartCorner == GridLayoutGroup.Corner.LowerLeft) { fx = 1; fy = 1; paddingx1 = _Padding.left; paddingx2 = _Padding.right; paddingy1 = _Padding.bottom; paddingy2 = _Padding.top; } int i; int count; int index; float width = 0; float height = 0; float offset = 0; float x; float y; float max; if (_StartAxis == GridLayoutGroup.Axis.Horizontal) { count = Mathf.RoundToInt(_Size.x); if (count < 1) { HobaDebuger.LogWarning("GLayout size_x==0! " + GNewUITools.PrintScenePath(this.Trans)); //Debug.LogError("GLayout size_x==0!" + GNewUITools.PrintScenePath(this.Trans)); count = 1; } x = paddingx1 * fx; y = paddingy1 * fy; for (i = 0; i < _ChildNodes.Count; i++) { index = i % count; GLayout layout = _ChildNodes[i]; if (layout == null || !layout.gameObject.activeSelf /*|| layout.RectTrans.sizeDelta.x <= 0 || layout.RectTrans.sizeDelta.y <= 0*/) { continue; } ApplyLayoutToChild(layout); RectTransform rt = layout.RectTrans; float dsx = rt.sizeDelta.x /* * rt.localScale.x*/; float dsy = rt.sizeDelta.y /* * rt.localScale.y*/; layout.RectTrans.anchoredPosition = new Vector2(x + (fx > 0 ? rt.pivot.x : 1 - rt.pivot.x) * dsx, y + (fy > 0 ? rt.pivot.y : 1 - rt.pivot.y) * dsy); max = Mathf.Abs(x) + dsx; if (max > width) //最宽的那一行的宽度 { width = max; } if (dsy > offset) //一行中最高的那一个 { offset = dsy; } if (index < count - 1) { x += dsx * fx; x += _Spacing.x * fx; } else if (index == count - 1) { x = paddingx1 * fx; y += offset * fy; if (i < _ChildNodes.Count - 1) { y += _Spacing.y * fy; } offset = 0; } } width += paddingx2; y += offset * fy; y += paddingy2 * fy; height = Mathf.Abs(y); SetSize(width, height); } else if (_StartAxis == GridLayoutGroup.Axis.Vertical) { count = Mathf.RoundToInt(_Size.y); if (count < 1) { HobaDebuger.LogWarning("GLayout size_y==0! " + GNewUITools.PrintScenePath(this.Trans)); //Debug.LogError("GLayout size_x==0!" + GNewUITools.PrintScenePath(this.Trans)); count = 1; } x = paddingx1 * fx; y = paddingy1 * fy; for (i = 0; i < _ChildNodes.Count; i++) { index = i % count; GLayout layout = _ChildNodes[i]; if (layout == null || !layout.gameObject.activeSelf /*|| layout.RectTrans.sizeDelta.x <= 0 || layout.RectTrans.sizeDelta.y <= 0*/) { continue; } ApplyLayoutToChild(layout); RectTransform rt = layout.RectTrans; float dsx = rt.sizeDelta.x /* * rt.localScale.x */; float dsy = rt.sizeDelta.y /* * rt.localScale.y*/; layout.RectTrans.anchoredPosition = new Vector2(x + (fx > 0 ? rt.pivot.x : 1 - rt.pivot.x) * dsx, y + (fy > 0 ? rt.pivot.y : 1 - rt.pivot.y) * dsy); max = Mathf.Abs(y) + dsy; if (max > height) //最高的那一行的高度 { height = max; } if (dsx > offset) //一列中最宽的那一个 { offset = dsx; } if (index < count - 1) { y += dsy * fy; y += _Spacing.y * fy; } else if (index == count - 1) { y = paddingy1 * fy; x += offset * fx; if (i < _ChildNodes.Count - 1) { x += _Spacing.x * fx; } offset = 0; } } height += paddingy2; x += offset * fx; x += paddingx2 * fx; width = Mathf.Abs(x); SetSize(width, height); } }