public void OnPointerDown(PointerEventData eventData) { if (isClickDisabled) { return; } fadeOut = false; var shapeImage = shape.ShapeImage; UiThemeUtil.AddChild(ref ripple, "Ripple", shapeImage.transform, uiSo); ripple.transform.SetSiblingIndex(0); ripple.gameObject.SetActive(true); var rippleRect = ripple.rectTransform; var shapeRect = shapeImage.rectTransform; ripple.sprite = uiTheme.GetShape(UiThemeShapeType.Circle).sprite; ripple.preserveAspect = true; ripple.type = Image.Type.Simple; ripple.color = uiTheme.GetColor(UiThemeUtil.ToLightColor[shape.colorType]).color; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle( shapeImage.rectTransform, eventData.position, eventData.pressEventCamera, out var localPoint )) { return; } rippleRect.anchorMax = Vector2.one * .5f; rippleRect.anchorMin = Vector2.one * .5f; rippleRect.anchoredPosition = localPoint; var shapeSize = shapeRect.rect.size; var shapeMid = shapeSize * 0.5f; var size = Mathf.Max( shapeMid.x + Mathf.Abs(localPoint.x), shapeMid.y + Mathf.Abs(localPoint.y) ) * 2.0f; if (rippleRoutine != null) { StopCoroutine(rippleRoutine); } rippleRoutine = StartCoroutine(OnRipple(size)); }
public IEnumerable <GameObject> Initialize(UiSo ui, UiTheme theme) { shape = UnityUtil.GetRequiredComp <UiThemeShapeBeh>(this); shape.hideFlags = ui.isVerboseDebug ? HideFlags.None : HideFlags.HideInInspector; UiThemeUtil.AddChild(ref textBeh, "Text", transform, ui); shape.Initialize(ui, theme); textBeh.Initialize(ui, theme); textBeh.SetFontType(UIThemeFontType.Button); textBeh.SetAlignment(TextAnchor.MiddleCenter); textBeh.SetValue(text); shape.SetShapeType(shapeType); shapeRipple = UnityUtil.GetRequiredComp <UiThemeShapeRipple>(this); shapeRipple.Initialize(ui, theme); shapeRipple.SetDisabled(isClickDisabled); shapeRipple.hideFlags = ui.isVerboseDebug ? HideFlags.None : HideFlags.HideInInspector; shape.hideFlags = ui.isVerboseDebug ? HideFlags.None : HideFlags.HideInInspector; SetClickDisabled(isClickDisabled); return(UnityUtil.Once(gameObject)); }
public IEnumerable <GameObject> Initialize(UiSo ui, UiTheme theme) { UiThemeUtil.AddChild(ref textBeh, "Label", transform, ui); if (UiThemeUtil.AddChild(ref boxShapeBeh, "Box", transform, ui)) { boxShapeBeh.gameObject.AddComponent <UiThemeShapeRipple>(); } UiThemeUtil.AddChild(ref checkShapeBeh, "Check", boxShapeBeh.transform, ui); ripple = boxShapeBeh.gameObject.GetComponent <UiThemeShapeRipple>(); textBeh.Initialize(ui, theme); boxShapeBeh.Initialize(ui, theme); checkShapeBeh.Initialize(ui, theme); ripple.Initialize(ui, theme); textBeh.SetAlignment(TextAnchor.MiddleRight); textBeh.SetColor(labelColor); textBeh.SetValue(label); textBeh.SetFontType(UIThemeFontType.Body); PositionBox(ui, boxShapeBeh.GetComponent <RectTransform>()); boxShapeBeh.SetHasShadow(true); boxShapeBeh.SetColorType(boxColor); boxShapeBeh.SetShapeType(UiThemeShapeType.RoundedSquare); boxShapeBeh.SetIsOutline(false); checkShapeBeh.SetHasShadow(false); var checkRect = checkShapeBeh.GetComponent <RectTransform>(); checkRect.offsetMax = Vector2.one * -2.0f; checkRect.offsetMin = Vector2.one * 2.0f; checkShapeBeh.SetShapeType(UiThemeShapeType.Check); checkShapeBeh.SetIsOutline(false); var textRect = textBeh.GetComponent <RectTransform>(); textRect.offsetMax = Vector2.right * (-ui.checkboxSize - 5); boxShapeBeh.SetColorType(boxColor); boxShapeBeh.SetShapeType(UiThemeShapeType.RoundedSquare); SetChecked(isChecked); SetClickDisabled(isClickDisabled); return(UnityUtil.Once(gameObject)); }
public IEnumerable <GameObject> Initialize(UiSo aUi, UiTheme aTheme) { ui = aUi; theme = aTheme; var initObjs = new List <GameObject> { gameObject }; SetHasShadow(hasShadow); if (UiThemeUtil.AddChild(ref shapeImage, "Shape", transform, ui)) { shapeImage.gameObject.AddComponent <Mask>(); } SetShapeType(shapeType); SetColorType(colorType); initObjs.Add(shapeImage.gameObject); var mask = shapeImage.gameObject.GetComponent <Mask>(); mask.showMaskGraphic = true; shapeImage.raycastTarget = true; return(initObjs); }
public void SetHasShadow(bool nowHasShadow) { hasShadow = nowHasShadow; var shape = theme.GetShape(shapeType); if (!hasShadow && shadowImage != null) { DestroyImmediate(shadowImage.gameObject); shadowImage = null; } if (hasShadow) { UiThemeUtil.AddChild(ref shadowImage, "Shadow", transform, ui); var shadowTransform = shadowImage.gameObject.GetComponent <RectTransform>(); shadowTransform.sizeDelta = Vector2.one * (shape.shadowSize * 2.0f); shadowTransform.anchoredPosition = Vector2.zero; shadowImage.sprite = shape.shadow; shadowImage.type = shape.imageType; shadowImage.preserveAspect = shape.preserveAspect; shadowImage.raycastTarget = false; shadowTransform.SetSiblingIndex(0); } }
public IEnumerable <GameObject> Initialize(UiSo aUi, UiTheme theme) { ui = aUi; windowShape = UnityUtil.GetRequiredComp <UiThemeShapeBeh>(this); windowShape.hideFlags = ui.GetHideFlags(); openMotion = UnityUtil.GetRequiredComp <UiMotionBeh>(this); openMotion.hideFlags = ui.GetHideFlags(); openMotion.offset = Vector2.right * (size.x + position.x); var rectTransform = GetComponent <RectTransform>(); rectTransform.anchorMin = Vector2.one; rectTransform.anchorMax = Vector2.one; rectTransform.pivot = Vector2.one; rectTransform.sizeDelta = size; if (UiThemeUtil.AddChild(ref layoutGroup, "Layout", transform, ui)) { layoutGroup.padding = new RectOffset(12, 12, 12, 12); layoutGroup.spacing = 6; } layoutGroup.childForceExpandHeight = false; layoutGroup.childForceExpandWidth = true; layoutGroup.childControlHeight = true; layoutGroup.childControlWidth = true; layoutGroup.gameObject.hideFlags = HideFlags.None; UiThemeUtil.AddChild(ref closeButtonRowLayout, "Modal Row", layoutGroup.transform, ui); closeButtonRowLayout.preferredWidth = 25; closeButtonRowLayout.preferredHeight = 25; closeButtonRowLayout.minHeight = 25; closeButtonRowLayout.minWidth = 25; closeButtonRowLayout.flexibleWidth = 1.0f; closeButtonRowLayout.flexibleHeight = 0; closeButtonRowLayout.gameObject.hideFlags = HideFlags.None; UiThemeUtil.AddChild(ref contentRowLayout, "Content Row", layoutGroup.transform, ui); contentRowLayout.flexibleWidth = 1.0f; contentRowLayout.flexibleHeight = 1.0f; contentRowLayout.gameObject.hideFlags = HideFlags.None; closeButtonRowLayout.transform.SetSiblingIndex(0); contentRowLayout.transform.SetSiblingIndex(1); UiThemeUtil.AddChild(ref closeButton, "Close Button", closeButtonRowLayout.transform, ui); closeButton.shapeType = UiThemeShapeType.Circle; closeButton.colorType = UIThemeColorType.Secondary; closeButton.text = "x"; closeButton.Initialize(ui, theme); closeButton.gameObject.hideFlags = ui.GetHideFlags(); var closeTransform = closeButton.GetComponent <RectTransform>(); closeTransform.anchorMax = Vector2.one; closeTransform.anchorMin = Vector2.right; closeTransform.pivot = Vector2.right + Vector2.up * .5f; closeTransform.sizeDelta = Vector2.right * 25; return(UnityUtil.Once(gameObject)); }