public override GameObject Render(RenderContext renderContext, GameObject parentObject) { var go = CreateSelf(renderContext); var rect = go.GetComponent <RectTransform>(); if (parentObject) { //親のパラメータがある場合、親にする 後のAnchor定義のため rect.SetParent(parentObject.transform); } RenderedChildren = RenderChildren(renderContext, go); ElementUtil.SetupCanvasGroup(go, _canvasGroupParam); ElementUtil.SetupChildImageComponent(go, RenderedChildren); ElementUtil.SetupFillColor(go, FillColorParam); ElementUtil.SetupContentSizeFitter(go, ContentSizeFitterParam); ElementUtil.SetupLayoutGroup(go, LayoutParam); ElementUtil.SetupLayoutElement(go, LayoutElementParam); ElementUtil.SetupComponents(go, componentsJson); ElementUtil.SetupMask(go, MaskParam); SetAnchor(go, renderContext); return(go); }
public override GameObject Render(RenderContext renderContext, GameObject parentObject) { var go = CreateSelf(renderContext); var rect = go.GetComponent <RectTransform>(); if (parentObject) { // 親のパラメータがある場合、親にする // 後のAnchor設定のため これ以降でないと正確に設定できない rect.SetParent(parentObject.transform); } SetLayer(go, layer); SetAnchor(go, renderContext); // タッチイベントを取得するイメージコンポーネントになる ElementUtil.SetupFillColor(go, FillColorParam); // コンテンツ部分を入れるコンテナ var goContent = new GameObject("$Content"); SetLayer(goContent, layer); // Viewportと同じレイヤー var contentRect = goContent.AddComponent <RectTransform>(); goContent.transform.SetParent(go.transform); if (_content != null) { goContent.name = _content.Get("name") ?? ""; if (_content.ContainsKey("pivot")) { // ここのPivotはX,Yでくる contentRect.pivot = _content.GetDic("pivot").GetVector2("x", "y").Value; } if (_content.ContainsKey("anchor_min")) { contentRect.anchorMin = _content.GetDic("anchor_min").GetVector2("x", "y").Value; } if (_content.ContainsKey("anchor_max")) { contentRect.anchorMax = _content.GetDic("anchor_max").GetVector2("x", "y").Value; } if (_content.ContainsKey("offset_min")) { contentRect.offsetMin = _content.GetDic("offset_min").GetVector2("x", "y").Value; } if (_content.ContainsKey("offset_max")) { contentRect.offsetMax = _content.GetDic("offset_max").GetVector2("x", "y").Value; } if (_content.ContainsKey("layout")) { var contentLayout = _content.GetDic("layout"); ElementUtil.SetupLayoutGroup(goContent, contentLayout); } if (_content.ContainsKey("content_size_fitter")) { var contentSizeFitter = _content.GetDic("content_size_fitter"); var compSizeFitter = ElementUtil.SetupContentSizeFitter(goContent, contentSizeFitter); } } //Viewportのチャイルドはもとより、content向けのAnchor・Offsetを持っている RenderChildren(renderContext, goContent); ElementUtil.SetupRectMask2D(go, RectMask2DParam); // ScrollRectを設定した時点ではみでたContentがアジャストされる PivotがViewport内に入っていればOK ElementUtil.SetupScrollRect(go, goContent, _scrollRect); return(go); }
public override GameObject Render(RenderContext renderContext, GameObject parentObject) { var go = CreateSelf(renderContext); var rect = go.GetComponent <RectTransform>(); if (parentObject) { //親のパラメータがある場合、親にする 後のAnchor定義のため rect.SetParent(parentObject.transform); } SetAnchor(go, renderContext); var children = RenderChildren(renderContext, go); ElementUtil.SetupChildImageComponent(go, children); // DotsScrollberかどうかの判定に、Toggleがあるかどうかを確認する var toggleChild = children.Find(child => child.Item2 is ToggleElement); Scrollbar scrollbar; if (toggleChild == null) { scrollbar = go.AddComponent <Scrollbar>(); } else { // DotScrollbarとなる var dotScrollbar = go.AddComponent <DotsScrollbar>(); dotScrollbar.isAutoLayoutEnableOnEditMode = false; dotScrollbar.DotContainer = rect; dotScrollbar.DotPrefab = toggleChild.Item1.GetComponent <Toggle>(); // Toggleボタンの並びレイアウト ElementUtil.SetupLayoutGroup(go, LayoutParam); dotScrollbar.size = 1; // sizeを1にすることで、Toggleが複数Cloneされることをふせぐ scrollbar = dotScrollbar; } var direction = _scrollbar.Get("direction"); if (direction != null) { switch (direction) { case "left-to-right": case "ltr": case "x": scrollbar.direction = Scrollbar.Direction.LeftToRight; break; case "right-to-left": case "rtl": scrollbar.direction = Scrollbar.Direction.RightToLeft; break; case "bottom-to-top": case "btt": case "y": scrollbar.direction = Scrollbar.Direction.BottomToTop; break; case "top-to-bottom": case "ttb": scrollbar.direction = Scrollbar.Direction.TopToBottom; break; } } var handleClassName = _scrollbar.Get("handle_class"); if (handleClassName != null) { var found = children.Find(child => child.Item2.HasParsedName(handleClassName)); if (found != null) { scrollbar.handleRect = found.Item1.GetComponent <RectTransform>(); } } ElementUtil.SetupContentSizeFitter(go, ContentSizeFitterParam); return(go); }