public UIComponentSpriteBorder(string name, IntBorder border, float width, float height, string color, float alpha, bool isInteractive = false) { this.name = "nineSlice"; spriteName = name; this.border = border; this.width = width; this.height = height; this.color = color; this.alpha = alpha; this.isInteractive = isInteractive; }
public UIData(Transform root, Transform tr) { Vector2 piv = new Vector2(0.5f, 0.5f); if (tr is RectTransform) { piv = (tr as RectTransform).pivot; } Vector2 pos = root.InverseTransformPoint(tr.position); name = tr.name; pivot = new Float2(piv.x, piv.y); scale = new Float2(tr.localScale.x, tr.localScale.y); position = new Int2(pos.x, pos.y); localPosition = new Int2(tr.localPosition.x * 1, tr.localPosition.y * 1); go = tr.gameObject; Component comp = tr.GetComponent <SpriteRenderer>(); if (comp != null) { SpriteRenderer c = comp as SpriteRenderer; if (c.sprite != null) { component = new UIComponentSprite(c.sprite.name, Utill.Utill.ColorToHex(c.color), c.color.a , comp.GetComponent <UIInteractive>() != null ? true : false); } else { component = new UIComponentSprite("null", Utill.Utill.ColorToHex(c.color), c.color.a , comp.GetComponent <UIInteractive>() != null ? true : false); (component as UIComponentSprite).width = (tr as RectTransform).sizeDelta.x; (component as UIComponentSprite).height = (tr as RectTransform).sizeDelta.y; } } comp = tr.GetComponent <Image>(); if (comp != null) { Image image = comp as Image; Button button = tr.GetComponent <Button>(); if (button != null) { string normal = ""; string over = ""; string push = ""; string disabled = ""; int transition = 0; bool isBorder = false; IntBorder border = new IntBorder(); int width = 0; int height = 0; if (image.type == Image.Type.Sliced) { isBorder = true; float rate = image.sprite.pixelsPerUnit / 100f; Vector4 bor = image.sprite.border; bor /= rate; border = new IntBorder(bor); width = (int)image.rectTransform.sizeDelta.x; height = (int)image.rectTransform.sizeDelta.y; } if (button.transition == Selectable.Transition.SpriteSwap) { transition = 2; normal = image.sprite.name; over = button.spriteState.highlightedSprite != null ? button.spriteState.highlightedSprite.name : normal; push = button.spriteState.pressedSprite != null ? button.spriteState.pressedSprite.name : normal; disabled = button.spriteState.disabledSprite != null ? button.spriteState.disabledSprite.name : ""; component = new UIComponentButton(transition, normal, over, push, disabled); if (isBorder) { UIComponentButton componentButton = component as UIComponentButton; componentButton.isBorder = isBorder; componentButton.border = border; componentButton.width = width; componentButton.height = height; } } else if (button.transition == Selectable.Transition.ColorTint) { transition = 1; normal = "0x" + Utill.Utill.ColorToHex(button.colors.normalColor); over = "0x" + Utill.Utill.ColorToHex(button.colors.highlightedColor); push = "0x" + Utill.Utill.ColorToHex(button.colors.pressedColor); disabled = "0x" + Utill.Utill.ColorToHex(button.colors.disabledColor); component = new UIComponentButton(transition, normal, over, push, disabled); UIComponentButton componentButton = component as UIComponentButton; componentButton.spriteName = image.sprite.name; if (isBorder) { componentButton.isBorder = isBorder; componentButton.border = border; componentButton.width = width; componentButton.height = height; } } } else if (image.sprite != null && image.type == Image.Type.Sliced) { float rate = image.sprite.pixelsPerUnit / 100f; Vector4 bor = image.sprite.border; bor /= rate; component = new UIComponentSpriteBorder(image.sprite.name , new IntBorder(bor) , image.rectTransform.sizeDelta.x , image.rectTransform.sizeDelta.y , Utill.Utill.ColorToHex(image.color) , image.color.a , comp.GetComponent <UIInteractive>() != null ? true : false ); } else if (image.sprite != null && image.type == Image.Type.Tiled) { float rate = image.sprite.pixelsPerUnit / 100f; component = new UIComponentSpriteTiled(image.sprite.name , image.rectTransform.sizeDelta.x , image.rectTransform.sizeDelta.y , Utill.Utill.ColorToHex(image.color) , image.color.a , comp.GetComponent <UIInteractive>() != null ? true : false ); } else { //component = new UIComponentSprite(image.sprite.name, Utill.Utill.ColorToHex(image.color), image.color.a // , comp.GetComponent<UIInteractive>() != null ? true : false); if (image.sprite != null) { component = new UIComponentSprite(image.sprite.name, Utill.Utill.ColorToHex(image.color), image.color.a , comp.GetComponent <UIInteractive>() != null ? true : false); } else { component = new UIComponentSprite("null", Utill.Utill.ColorToHex(image.color), image.color.a , comp.GetComponent <UIInteractive>() != null ? true : false); (component as UIComponentSprite).width = (tr as RectTransform).sizeDelta.x; (component as UIComponentSprite).height = (tr as RectTransform).sizeDelta.y; } } } comp = tr.GetComponent <Text>(); if (comp != null) { Text text = comp as Text; int width = 0; if (text.horizontalOverflow == HorizontalWrapMode.Wrap) { width = (int)text.rectTransform.sizeDelta.x; } bool isNormal = tr.GetComponent <UINormalFont>() == null ? false : true; string align = text.alignment.ToString().Replace("Upper", "").Replace("Middle", "").Replace("Lower", ""); component = new UIComponentText(text.font.name, text.text.Replace("\n", "\\n").Replace("\r", ""), text.fontSize , Utill.Utill.ColorToHex(text.color), align.ToLower(), width, isNormal); } comp = tr.GetComponent <UIInputField>(); if (comp != null) { UIInputField input = comp as UIInputField; RectTransform rtr = comp.GetComponent <RectTransform>(); component = new UIComponentInput(input.placeholder, (int)rtr.sizeDelta.x, (int)rtr.sizeDelta.y , input.fontSize, Utill.Utill.ColorToHex(input.fontColor), Utill.Utill.ColorToHex(input.placeholderColor) , input.isTextArea, input.isPassword, input.isNumberOnly); } comp = tr.GetComponent <UIScroll>(); if (comp != null) { UIScroll scroll = comp as UIScroll; component = new UIComponentScroll(scroll.scrollArea.name, scroll.scrollMask.name, scroll.scrollbar_bar.name, scroll.scrollbar_bg.name); } comp = tr.GetComponent <UIMask>(); if (comp != null) { RectTransform rtr = comp.GetComponent <RectTransform>(); component = new UIComponentMask((int)rtr.sizeDelta.x, (int)rtr.sizeDelta.y); } comp = tr.GetComponent <UIToggleGroup>(); if (comp != null) { UIToggleGroup tg = comp as UIToggleGroup; component = new UIComponentToggleGroup(tg.toggles, tg.defaultIndex); } int count = tr.childCount; for (int i = 0; i < count; i++) { children.Add(new UIData(root, tr.transform.GetChild(i))); } }