Finish GameObject Inspector, start Search page, some other UI changes/fixes

This commit is contained in:
sinaioutlander committed 2020-11-06 20:42:16 +11:00
1 parent e175e9c438
commit 2efc3f6578
28 files changed
+2301 -1184

No files matched your search

+312 -82
View File
@@ -222,7 +222,7 @@ namespace UnityExplorer.UI
return labelObj;
}
public static GameObject CreateButton(GameObject parent)
public static GameObject CreateButton(GameObject parent, Color normalColor = default)
{
GameObject buttonObj = CreateUIObject("Button", parent, thinSize);
@@ -236,6 +236,14 @@ namespace UnityExplorer.UI
SetDefaultColorTransitionValues(buttonObj.AddComponent<Button>());
if (normalColor != default)
{
var btn = buttonObj.GetComponent<Button>();
var colors = btn.colors;
colors.normalColor = normalColor;
btn.colors = colors;
}
Text text = textObj.AddComponent<Text>();
text.text = "Button";
SetDefaultTextValues(text);
@@ -249,6 +257,74 @@ namespace UnityExplorer.UI
return buttonObj;
}
//public static GameObject CreateSlider(GameObject parent)
//{
// GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
// GameObject bgObj = CreateUIObject("Background", sliderObj);
// GameObject fillAreaObj = CreateUIObject("Fill Area", sliderObj);
// GameObject fillObj = CreateUIObject("Fill", fillAreaObj);
// GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
// GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
// Image bgImage = bgObj.AddComponent<Image>();
// bgImage.type = Image.Type.Sliced;
// bgImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
// RectTransform bgRect = bgObj.GetComponent<RectTransform>();
// bgRect.anchorMin = new Vector2(0f, dynamic ? 0f : 0.25f);
// bgRect.anchorMax = new Vector2(1f, dynamic ? 1f : 0.75f);
// bgRect.sizeDelta = new Vector2(0f, 0f);
// RectTransform fillAreaRect = fillAreaObj.GetComponent<RectTransform>();
// fillAreaRect.anchorMin = new Vector2(0f, 0.25f);
// fillAreaRect.anchorMax = new Vector2(1f, 0.75f);
// fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
// fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
// Image fillImage = fillObj.AddComponent<Image>();
// fillImage.type = Image.Type.Sliced;
// fillImage.color = dynamic ? Color.clear : new Color(0.3f, 0.3f, 0.3f, 1.0f);
// fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
// RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
// handleSlideRect.anchorMin = new Vector2(0f, 0f);
// handleSlideRect.anchorMax = new Vector2(1f, 1f);
// handleSlideRect.offsetMin = new Vector2(15f, 20f);
// handleSlideRect.offsetMax = new Vector2(-15f, 0f);
// handleSlideRect.sizeDelta = new Vector2(dynamic ? -30f : -20f, 0f);
// Image handleImage = handleObj.AddComponent<Image>();
// handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
// var handleRect = handleObj.GetComponent<RectTransform>();
// handleRect.sizeDelta = new Vector2(dynamic ? 25f : 20f, dynamic ? 25f : 0f);
// if (dynamic)
// {
// handleRect.offsetMin = new Vector2(-15f, -20f);
// handleRect.offsetMax = Vector2.zero;
// var sliderBarLayout = sliderObj.AddComponent<LayoutElement>();
// sliderBarLayout.minWidth = 25;
// sliderBarLayout.flexibleWidth = 0;
// sliderBarLayout.minHeight = 25;
// sliderBarLayout.flexibleHeight = 5000;
// bgRect.offsetMax = new Vector2(-15f, 0f);
// }
// Slider slider = sliderObj.AddComponent<Slider>();
// slider.fillRect = fillObj.GetComponent<RectTransform>();
// slider.handleRect = handleObj.GetComponent<RectTransform>();
// slider.targetGraphic = handleImage;
// slider.direction = dynamic ? Slider.Direction.BottomToTop : Slider.Direction.LeftToRight;
// SetDefaultColorTransitionValues(slider);
// return sliderObj;
//}
public static GameObject CreateSlider(GameObject parent)
{
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
@@ -611,14 +687,14 @@ namespace UnityExplorer.UI
dropdown.captionText = labelText;
dropdown.itemText = itemLabelText;
itemLabelText.text = "1";
dropdown.options.Add(new Dropdown.OptionData
{
text = "2"
});
dropdown.options.Add(new Dropdown.OptionData
{
text = "3"
});
//dropdown.options.Add(new Dropdown.OptionData
//{
// text = "2"
//});
//dropdown.options.Add(new Dropdown.OptionData
//{
// text = "3"
//});
dropdown.RefreshShownValue();
@@ -670,91 +746,245 @@ namespace UnityExplorer.UI
public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
{
GameObject scrollObj = CreateUIObject("Scroll View", parent);
GameObject mainObj = CreateUIObject("DynamicScrollView", parent);
LayoutElement mainLayout = scrollObj.AddComponent<LayoutElement>();
mainLayout.flexibleWidth = 999;
mainLayout.flexibleHeight = 999;
mainLayout.preferredHeight = 200;
mainLayout.preferredWidth = 200;
var mainLayout = mainObj.AddComponent<LayoutElement>();
mainLayout.minWidth = 100;
mainLayout.minHeight = 100;
mainLayout.flexibleWidth = 5000;
mainLayout.flexibleHeight = 5000;
GameObject viewportObj = CreateUIObject("Viewport", scrollObj);
Image mainImage = mainObj.AddComponent<Image>();
mainImage.type = Image.Type.Filled;
mainImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
VerticalLayoutGroup viewportGroup = viewportObj.AddComponent<VerticalLayoutGroup>();
viewportGroup.childControlHeight = true;
viewportGroup.childControlWidth = true;
viewportGroup.childForceExpandHeight = true;
viewportGroup.childForceExpandWidth = true;
GameObject viewportObj = CreateUIObject("Viewport", mainObj);
content = CreateUIObject("Content", viewportObj);
VerticalLayoutGroup contentGroup = content.AddComponent<VerticalLayoutGroup>();
contentGroup.padding.left = 5;
contentGroup.padding.right = 5;
contentGroup.padding.top = 5;
contentGroup.padding.bottom = 5;
contentGroup.childControlHeight = false;
contentGroup.childControlWidth = true;
contentGroup.childForceExpandHeight = false;
contentGroup.childForceExpandWidth = true;
GameObject horiScroll = CreateScrollbar(scrollObj);
horiScroll.name = "Scrollbar Horizontal";
SetParentAndAlign(horiScroll, scrollObj);
RectTransform horiRect = horiScroll.GetComponent<RectTransform>();
horiRect.anchorMin = Vector2.zero;
horiRect.anchorMax = Vector2.right;
horiRect.pivot = Vector2.zero;
horiRect.sizeDelta = new Vector2(0f, horiRect.sizeDelta.y);
GameObject vertScroll = CreateScrollbar(scrollObj);
vertScroll.name = "Scrollbar Vertical";
SetParentAndAlign(vertScroll, scrollObj);
vertScroll.GetComponent<Scrollbar>().SetDirection(Scrollbar.Direction.BottomToTop, true);
RectTransform vertRect = vertScroll.GetComponent<RectTransform>();
vertRect.anchorMin = Vector2.right;
vertRect.anchorMax = Vector2.one;
vertRect.pivot = Vector2.one;
vertRect.sizeDelta = new Vector2(vertRect.sizeDelta.x, 0f);
RectTransform viewportRect = viewportObj.GetComponent<RectTransform>();
var viewportRect = viewportObj.GetComponent<RectTransform>();
viewportRect.anchorMin = Vector2.zero;
viewportRect.anchorMax = Vector2.one;
viewportRect.sizeDelta = Vector2.zero;
viewportRect.pivot = Vector2.up;
viewportRect.pivot = new Vector2(0.0f, 1.0f);
viewportRect.sizeDelta = new Vector2(-15.0f, 0.0f);
viewportRect.offsetMax = new Vector2(-20.0f, 0.0f);
RectTransform contentRect = content.GetComponent<RectTransform>();
contentRect.anchorMin = Vector2.up;
contentRect.anchorMax = Vector2.one;
contentRect.pivot = Vector2.up;
viewportObj.AddComponent<Image>().color = Color.white;
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
ScrollRect scrollRect = scrollObj.AddComponent<ScrollRect>();
scrollRect.content = contentRect;
scrollRect.viewport = viewportRect;
scrollRect.horizontalScrollbar = horiScroll.GetComponent<Scrollbar>();
scrollRect.verticalScrollbar = vertScroll.GetComponent<Scrollbar>();
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.horizontalScrollbarSpacing = -3f;
scrollRect.verticalScrollbarSpacing = -3f;
content = CreateUIObject("Content", viewportObj);
var contentRect = content.GetComponent<RectTransform>();
contentRect.anchorMin = new Vector2(0.0f, 1.0f);
contentRect.anchorMax = new Vector2(1.0f, 1.0f);
contentRect.pivot = new Vector2(0.0f, 1.0f);
contentRect.sizeDelta = new Vector2(5f, 0f);
contentRect.offsetMax = new Vector2(0f, 0f);
var contentFitter = content.AddComponent<ContentSizeFitter>();
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
var contentLayout = content.AddComponent<VerticalLayoutGroup>();
contentLayout.childForceExpandHeight = true;
contentLayout.childControlHeight = true;
contentLayout.childForceExpandWidth = true;
contentLayout.childControlWidth = true;
contentLayout.padding.left = 5;
contentLayout.padding.right = 5;
contentLayout.padding.top = 5;
contentLayout.padding.bottom = 5;
contentLayout.spacing = 5;
GameObject scrollBar = CreateUIObject("DynamicScrollbar", mainObj);
var scrollbarLayout = scrollBar.AddComponent<VerticalLayoutGroup>();
scrollbarLayout.childForceExpandHeight = true;
scrollbarLayout.childControlHeight = true;
RectTransform scrollBarRect = scrollBar.GetComponent<RectTransform>();
scrollBarRect.anchorMin = new Vector2(1.0f, 0.0f);
scrollBarRect.anchorMax = new Vector2(1.0f, 1.0f);
scrollBarRect.sizeDelta = new Vector2(15.0f, 0.0f);
scrollBarRect.offsetMin = new Vector2(-15.0f, 0.0f);
GameObject hiddenBar = CreateScrollbar(scrollBar);
var hiddenScroll = hiddenBar.GetComponent<Scrollbar>();
hiddenScroll.SetDirection(Scrollbar.Direction.BottomToTop, true);
for (int i = 0; i < hiddenBar.transform.childCount; i++)
{
var child = hiddenBar.transform.GetChild(i);
child.gameObject.SetActive(false);
}
CreateScrollSlider(scrollBar, out Slider scrollSlider);
// Back to the main scrollview ScrollRect, setting it up now that we have all references.
var scrollRect = mainObj.AddComponent<ScrollRect>();
scrollRect.horizontal = false;
scrollRect.vertical = true;
scrollRect.verticalScrollbar = hiddenScroll;
scrollRect.movementType = ScrollRect.MovementType.Clamped;
scrollRect.scrollSensitivity = 25;
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.Permanent;
Image scrollImage = scrollObj.AddComponent<Image>();
scrollImage.type = Image.Type.Filled;
scrollRect.viewport = viewportRect;
scrollRect.content = contentRect;
scrollImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
// Create a custom DynamicScrollbar module
new SliderScrollbar(hiddenScroll, scrollSlider);
Image viewportImage = viewportObj.AddComponent<Image>();
//viewportImage.sprite = Theme.mask;
viewportImage.type = Image.Type.Sliced;
viewportImage.color = new Color(1, 1, 1, 1);
Mask mask = viewportObj.AddComponent<Mask>();
mask.showMaskGraphic = false;
return scrollObj;
return mainObj;
}
public static GameObject CreateScrollSlider(GameObject parent, out Slider slider)
{
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
GameObject bgObj = CreateUIObject("Background", sliderObj);
GameObject fillAreaObj = CreateUIObject("Fill Area", sliderObj);
GameObject fillObj = CreateUIObject("Fill", fillAreaObj);
GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
RectTransform bgRect = bgObj.GetComponent<RectTransform>();
bgRect.anchorMin = Vector2.zero;
bgRect.anchorMax = Vector2.one;
bgRect.sizeDelta = Vector2.zero;
bgRect.offsetMax = new Vector2(-10f, 0f);
RectTransform fillAreaRect = fillAreaObj.GetComponent<RectTransform>();
fillAreaRect.anchorMin = new Vector2(0f, 0.25f);
fillAreaRect.anchorMax = new Vector2(1f, 0.75f);
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddComponent<Image>();
fillImage.type = Image.Type.Sliced;
fillImage.color = Color.clear;
fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
handleSlideRect.anchorMin = new Vector2(0f, 0f);
handleSlideRect.anchorMax = new Vector2(1f, 1f);
handleSlideRect.offsetMin = new Vector2(15f, 25f);
handleSlideRect.offsetMax = new Vector2(-15f, 0f);
handleSlideRect.sizeDelta = new Vector2(-30f, -25f);
Image handleImage = handleObj.AddComponent<Image>();
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
var handleRect = handleObj.GetComponent<RectTransform>();
handleRect.sizeDelta = new Vector2(15f, 25f);
handleRect.offsetMin = new Vector2(-13f, -23f);
handleRect.offsetMax = new Vector2(3f, -2f);
var sliderBarLayout = sliderObj.AddComponent<LayoutElement>();
sliderBarLayout.minWidth = 25;
sliderBarLayout.flexibleWidth = 0;
sliderBarLayout.minHeight = 25;
sliderBarLayout.flexibleHeight = 5000;
slider = sliderObj.AddComponent<Slider>();
slider.fillRect = fillObj.GetComponent<RectTransform>();
slider.handleRect = handleObj.GetComponent<RectTransform>();
slider.targetGraphic = handleImage;
slider.direction = Slider.Direction.BottomToTop;
SetDefaultColorTransitionValues(slider);
return sliderObj;
}
//public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
//{
// GameObject scrollObj = CreateUIObject("Scroll View", parent);
// LayoutElement mainLayout = scrollObj.AddComponent<LayoutElement>();
// mainLayout.flexibleWidth = 999;
// mainLayout.flexibleHeight = 999;
// mainLayout.preferredHeight = 200;
// mainLayout.preferredWidth = 200;
// GameObject viewportObj = CreateUIObject("Viewport", scrollObj);
// VerticalLayoutGroup viewportGroup = viewportObj.AddComponent<VerticalLayoutGroup>();
// viewportGroup.childControlHeight = true;
// viewportGroup.childControlWidth = true;
// viewportGroup.childForceExpandHeight = true;
// viewportGroup.childForceExpandWidth = true;
// content = CreateUIObject("Content", viewportObj);
// VerticalLayoutGroup contentGroup = content.AddComponent<VerticalLayoutGroup>();
// contentGroup.padding.left = 5;
// contentGroup.padding.right = 5;
// contentGroup.padding.top = 5;
// contentGroup.padding.bottom = 5;
// contentGroup.childControlHeight = false;
// contentGroup.childControlWidth = true;
// contentGroup.childForceExpandHeight = false;
// contentGroup.childForceExpandWidth = true;
// GameObject horiScroll = CreateScrollbar(scrollObj);
// horiScroll.name = "Scrollbar Horizontal";
// SetParentAndAlign(horiScroll, scrollObj);
// RectTransform horiRect = horiScroll.GetComponent<RectTransform>();
// horiRect.anchorMin = Vector2.zero;
// horiRect.anchorMax = Vector2.right;
// horiRect.pivot = Vector2.zero;
// horiRect.sizeDelta = new Vector2(0f, horiRect.sizeDelta.y);
// GameObject vertScroll = CreateScrollbar(scrollObj);
// vertScroll.name = "Scrollbar Vertical";
// SetParentAndAlign(vertScroll, scrollObj);
// vertScroll.GetComponent<Scrollbar>().SetDirection(Scrollbar.Direction.BottomToTop, true);
// RectTransform vertRect = vertScroll.GetComponent<RectTransform>();
// vertRect.anchorMin = Vector2.right;
// vertRect.anchorMax = Vector2.one;
// vertRect.pivot = Vector2.one;
// vertRect.sizeDelta = new Vector2(vertRect.sizeDelta.x, 0f);
// RectTransform viewportRect = viewportObj.GetComponent<RectTransform>();
// viewportRect.anchorMin = Vector2.zero;
// viewportRect.anchorMax = Vector2.one;
// viewportRect.sizeDelta = Vector2.zero;
// viewportRect.pivot = Vector2.up;
// RectTransform contentRect = content.GetComponent<RectTransform>();
// contentRect.anchorMin = Vector2.up;
// contentRect.anchorMax = Vector2.one;
// contentRect.pivot = Vector2.up;
// ScrollRect scrollRect = scrollObj.AddComponent<ScrollRect>();
// scrollRect.content = contentRect;
// scrollRect.viewport = viewportRect;
// scrollRect.horizontalScrollbar = horiScroll.GetComponent<Scrollbar>();
// scrollRect.verticalScrollbar = vertScroll.GetComponent<Scrollbar>();
// scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
// scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
// scrollRect.horizontalScrollbarSpacing = -3f;
// scrollRect.verticalScrollbarSpacing = -3f;
// scrollRect.scrollSensitivity = 25;
// Image scrollImage = scrollObj.AddComponent<Image>();
// scrollImage.type = Image.Type.Filled;
// scrollImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
// Image viewportImage = viewportObj.AddComponent<Image>();
// //viewportImage.sprite = Theme.mask;
// viewportImage.type = Image.Type.Sliced;
// viewportImage.color = new Color(1, 1, 1, 1);
// Mask mask = viewportObj.AddComponent<Mask>();
// mask.showMaskGraphic = false;
// return scrollObj;
//}
}
}