/// <summary> /// Create all nonexistent required components. /// </summary> public void Initialize() { for (int i = 0; i < transform.childCount; i++) { if (transform.GetChild(i).name == "Headers") { headersParent = transform.GetChild(i).GetComponent <RectTransform>(); } if (transform.GetChild(i).name == "Menus") { menusParent = transform.GetChild(i).GetComponent <RectTransform>(); if (menusParent.GetChild(0).name == "Content") { menusContent = menusParent.GetChild(0).GetComponent <RectTransform>(); } } } if (menusParent != null) { swipyMenu = menusParent.GetComponent <SwipyMenu>(); var scrollRect = menusParent.GetComponent <SwipyMenuScrollRect>(); swipyMenuScrollRect = scrollRect; swipyMenu.InitializeEditor(menusScrollRect: scrollRect, menusRect: menusParent); if (swipyMenu.menus.Length > 0) { firstToShowOnLoadMenu = swipyMenu.menus[swipyMenu.defaultMenuIndex]; } swipyMenu.menusMask = menusParent.GetComponent <RectMask2D>(); } else { CreateMenusBase(); } if (headersParent != null) { swipyMenu.InitializeEditor(headersRect: headersParent); } else { CreateHeadersBase(); } swipyMenu.headersMask = GetComponent <RectMask2D>(); DriveRectTransforms(); initialized = true; }
/// <summary> /// Create parent RectTaransform for menus, and all necessary components. /// </summary> private void CreateMenusBase() { var menusRect = CreateGOWithRectTransform("Menus", transform, offsetMax: new Vector2(0f, -20f)); menusParent = menusRect; cachedMenuRectSize = menusRect.rect.size; var contentRect = CreateGOWithRectTransform("Content", menusRect); menusContent = contentRect; var scrollRect = menusRect.gameObject.AddComponent <SwipyMenuScrollRect>(); scrollRect.vertical = false; scrollRect.content = contentRect; scrollRect.inertia = false; scrollRect.decelerationRate = 0.01f; scrollRect.scrollSensitivity = 0f; var sliderMenu = menusRect.gameObject.AddComponent <SwipyMenu>(); this.swipyMenu = sliderMenu; sliderMenu.headerSmoothness = swipyMenu.headerSmoothness; sliderMenu.menusSmoothness = swipyMenu.menusSmoothness; sliderMenu.menus = new SwipyMenu.Menu[0]; swipyMenuScrollRect = scrollRect; swipyMenu.InitializeEditor(headersParent, scrollRect, menusParent); if (menusRect.gameObject.GetComponent <RectMask2D>() == null) { swipyMenu.menusMask = menusRect.gameObject.AddComponent <RectMask2D>(); } if (gameObject.GetComponent <RectMask2D>() == null) { swipyMenu.headersMask = gameObject.AddComponent <RectMask2D>(); } }