2020-10-23 01:50:33 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
using System.Reflection;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
using System.Text;
|
2020-10-24 20:18:42 +11:00
|
|
|
|
using TMPro;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
using UnityEngine;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
using UnityEngine.EventSystems;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace ExplorerBeta.UI
|
|
|
|
|
{
|
2020-10-24 20:18:42 +11:00
|
|
|
|
public static class UIFactory
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
private static Vector2 thickSize = new Vector2(160f, 30f);
|
|
|
|
|
private static Vector2 thinSize = new Vector2(160f, 20f);
|
|
|
|
|
private static Color defaultTextColor = new Color(0.95f, 0.95f, 0.95f, 1f);
|
|
|
|
|
private static Font m_defaultFont;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-10-25 20:57:34 +11:00
|
|
|
|
public static GameObject CreateUIObject(string name, GameObject parent, Vector2 size = default)
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
|
|
|
|
GameObject obj = new GameObject(name);
|
|
|
|
|
|
|
|
|
|
var rect = obj.AddComponent<RectTransform>();
|
|
|
|
|
if (size != default)
|
2020-10-24 20:18:42 +11:00
|
|
|
|
{
|
2020-10-23 01:50:33 +11:00
|
|
|
|
rect.sizeDelta = size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetParentAndAlign(obj, parent);
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetDefaultTextValues(Text lbl)
|
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
lbl.color = defaultTextColor;
|
|
|
|
|
|
|
|
|
|
if (!m_defaultFont)
|
|
|
|
|
{
|
|
|
|
|
m_defaultFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lbl.font = m_defaultFont;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 20:57:34 +11:00
|
|
|
|
private static void SetDefaultColorTransitionValues(Selectable selectable)
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
2020-10-25 20:57:34 +11:00
|
|
|
|
ColorBlock colors = selectable.colors;
|
|
|
|
|
colors.normalColor = new Color(0.4f, 0.4f, 0.4f);
|
2020-10-24 00:41:55 +11:00
|
|
|
|
colors.highlightedColor = new Color(0.45f, 0.45f, 0.45f);
|
|
|
|
|
colors.pressedColor = new Color(0.1f, 0.1f, 0.1f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
colors.disabledColor = new Color(0.7f, 0.7f, 0.7f);
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
// fix to make all buttons become de-selected after being clicked.
|
|
|
|
|
// this is because i'm not setting any ColorBlock.selectedColor, because it is commonly stripped.
|
|
|
|
|
if (selectable is Button button)
|
2020-10-27 00:54:08 +11:00
|
|
|
|
{
|
|
|
|
|
#if CPP
|
|
|
|
|
button.onClick.AddListener(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
button.OnDeselect(null);
|
|
|
|
|
}));
|
|
|
|
|
#else
|
|
|
|
|
button.onClick.AddListener(Deselect);
|
|
|
|
|
|
|
|
|
|
void Deselect()
|
|
|
|
|
{
|
|
|
|
|
button.OnDeselect(null);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-10-25 20:57:34 +11:00
|
|
|
|
|
|
|
|
|
selectable.colors = colors;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetParentAndAlign(GameObject child, GameObject parent)
|
|
|
|
|
{
|
|
|
|
|
if (parent == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
child.transform.SetParent(parent.transform, false);
|
|
|
|
|
SetLayerRecursively(child);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 20:18:42 +11:00
|
|
|
|
public static void SetLayerRecursively(GameObject go)
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
|
|
|
|
go.layer = 5;
|
|
|
|
|
Transform transform = go.transform;
|
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
|
|
|
{
|
2020-10-23 02:56:22 +11:00
|
|
|
|
SetLayerRecursively(transform.GetChild(i).gameObject);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 19:55:02 +11:00
|
|
|
|
public static GameObject CreatePanel(GameObject parent, string name, out GameObject content)
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject panelObj = CreateUIObject($"Panel_{name}", parent, thickSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
RectTransform rect = panelObj.GetComponent<RectTransform>();
|
|
|
|
|
rect.anchorMin = Vector2.zero;
|
|
|
|
|
rect.anchorMax = Vector2.one;
|
|
|
|
|
rect.anchoredPosition = Vector2.zero;
|
|
|
|
|
rect.sizeDelta = Vector2.zero;
|
|
|
|
|
|
|
|
|
|
Image image = panelObj.AddComponent<Image>();
|
2020-10-23 19:55:02 +11:00
|
|
|
|
image.type = Image.Type.Filled;
|
|
|
|
|
image.color = new Color(0.05f, 0.05f, 0.05f);
|
|
|
|
|
|
|
|
|
|
var group = panelObj.AddComponent<VerticalLayoutGroup>();
|
|
|
|
|
group.padding.left = 3;
|
|
|
|
|
group.padding.right = 3;
|
|
|
|
|
group.padding.bottom = 3;
|
|
|
|
|
group.padding.top = 3;
|
|
|
|
|
group.childControlHeight = true;
|
|
|
|
|
group.childControlWidth = true;
|
|
|
|
|
group.childForceExpandHeight = true;
|
|
|
|
|
group.childForceExpandWidth = true;
|
|
|
|
|
|
|
|
|
|
content = new GameObject("Content");
|
|
|
|
|
content.transform.parent = panelObj.transform;
|
|
|
|
|
|
|
|
|
|
Image image2 = content.AddComponent<Image>();
|
|
|
|
|
image2.type = Image.Type.Filled;
|
|
|
|
|
image2.color = new Color(0.1f, 0.1f, 0.1f);
|
|
|
|
|
|
|
|
|
|
var group2 = content.AddComponent<VerticalLayoutGroup>();
|
|
|
|
|
group2.padding.left = 5;
|
|
|
|
|
group2.padding.right = 5;
|
|
|
|
|
group2.padding.bottom = 5;
|
|
|
|
|
group2.padding.top = 5;
|
|
|
|
|
group2.spacing = 5;
|
|
|
|
|
group2.childControlHeight = true;
|
|
|
|
|
group2.childControlWidth = true;
|
|
|
|
|
group2.childForceExpandHeight = false;
|
|
|
|
|
group2.childForceExpandWidth = true;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
return panelObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameObject CreateVerticalGroup(GameObject parent, Color color = default)
|
|
|
|
|
{
|
2020-10-23 19:55:02 +11:00
|
|
|
|
var groupObj = CreateUIObject("VerticalLayout", parent);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
var horiGroup = groupObj.AddComponent<VerticalLayoutGroup>();
|
|
|
|
|
horiGroup.childAlignment = TextAnchor.UpperLeft;
|
|
|
|
|
horiGroup.childControlWidth = false;
|
|
|
|
|
|
|
|
|
|
var image = groupObj.AddComponent<Image>();
|
|
|
|
|
if (color != default)
|
|
|
|
|
image.color = color;
|
|
|
|
|
else
|
|
|
|
|
image.color = new Color(44f / 255f, 44f / 255f, 44f / 255f);
|
|
|
|
|
|
|
|
|
|
return groupObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameObject CreateHorizontalGroup(GameObject parent, Color color = default)
|
2020-10-24 20:18:42 +11:00
|
|
|
|
{
|
2020-10-23 01:50:33 +11:00
|
|
|
|
var groupObj = CreateUIObject("HorizontalLayout", parent);
|
|
|
|
|
|
|
|
|
|
var horiGroup = groupObj.AddComponent<HorizontalLayoutGroup>();
|
|
|
|
|
horiGroup.childAlignment = TextAnchor.UpperLeft;
|
|
|
|
|
horiGroup.childControlWidth = false;
|
|
|
|
|
|
|
|
|
|
var image = groupObj.AddComponent<Image>();
|
|
|
|
|
if (color != default)
|
|
|
|
|
image.color = color;
|
|
|
|
|
else
|
|
|
|
|
image.color = new Color(44f / 255f, 44f / 255f, 44f / 255f);
|
|
|
|
|
|
|
|
|
|
return groupObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameObject CreateLabel(GameObject parent, TextAnchor alignment)
|
2020-10-24 20:18:42 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject labelObj = CreateUIObject("Label", parent, thinSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
var text = labelObj.AddComponent<Text>();
|
|
|
|
|
SetDefaultTextValues(text);
|
|
|
|
|
text.alignment = alignment;
|
2020-10-24 20:18:42 +11:00
|
|
|
|
text.supportRichText = true;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
return labelObj;
|
2020-10-24 20:18:42 +11:00
|
|
|
|
}
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
public static GameObject CreateButton(GameObject parent)
|
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject buttonObj = CreateUIObject("Button", parent, thinSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
GameObject textObj = new GameObject("Text");
|
|
|
|
|
textObj.AddComponent<RectTransform>();
|
|
|
|
|
SetParentAndAlign(textObj, buttonObj);
|
|
|
|
|
|
|
|
|
|
Image image = buttonObj.AddComponent<Image>();
|
|
|
|
|
image.type = Image.Type.Sliced;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
image.color = new Color(1, 1, 1, 1);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
SetDefaultColorTransitionValues(buttonObj.AddComponent<Button>());
|
|
|
|
|
|
|
|
|
|
Text text = textObj.AddComponent<Text>();
|
|
|
|
|
text.text = "Button";
|
|
|
|
|
SetDefaultTextValues(text);
|
|
|
|
|
text.alignment = TextAnchor.MiddleCenter;
|
|
|
|
|
|
|
|
|
|
RectTransform rect = textObj.GetComponent<RectTransform>();
|
|
|
|
|
rect.anchorMin = Vector2.zero;
|
|
|
|
|
rect.anchorMax = Vector2.one;
|
|
|
|
|
rect.sizeDelta = Vector2.zero;
|
|
|
|
|
|
|
|
|
|
return buttonObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameObject CreateSlider(GameObject parent)
|
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
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;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
bgImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
RectTransform bgRect = bgObj.GetComponent<RectTransform>();
|
|
|
|
|
bgRect.anchorMin = new Vector2(0f, 0.25f);
|
|
|
|
|
bgRect.anchorMax = new Vector2(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;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
fillImage.color = new Color(0.3f, 0.3f, 0.3f, 1.0f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
|
|
|
|
|
|
|
|
|
|
RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
|
|
|
|
|
handleSlideRect.sizeDelta = new Vector2(-20f, 0f);
|
|
|
|
|
handleSlideRect.anchorMin = new Vector2(0f, 0f);
|
|
|
|
|
handleSlideRect.anchorMax = new Vector2(1f, 1f);
|
|
|
|
|
|
|
|
|
|
Image handleImage = handleObj.AddComponent<Image>();
|
2020-10-27 00:54:08 +11:00
|
|
|
|
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
handleObj.GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 0f);
|
|
|
|
|
|
|
|
|
|
Slider slider = sliderObj.AddComponent<Slider>();
|
|
|
|
|
slider.fillRect = fillObj.GetComponent<RectTransform>();
|
|
|
|
|
slider.handleRect = handleObj.GetComponent<RectTransform>();
|
|
|
|
|
slider.targetGraphic = handleImage;
|
|
|
|
|
slider.direction = Slider.Direction.LeftToRight;
|
|
|
|
|
SetDefaultColorTransitionValues(slider);
|
|
|
|
|
|
|
|
|
|
return sliderObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameObject CreateScrollbar(GameObject parent)
|
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject scrollObj = CreateUIObject("Scrollbar", parent, thinSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
GameObject slideAreaObj = CreateUIObject("Sliding Area", scrollObj);
|
|
|
|
|
GameObject handleObj = CreateUIObject("Handle", slideAreaObj);
|
|
|
|
|
|
|
|
|
|
Image scrollImage = scrollObj.AddComponent<Image>();
|
|
|
|
|
scrollImage.type = Image.Type.Sliced;
|
2020-10-23 19:55:02 +11:00
|
|
|
|
scrollImage.color = new Color(0.1f, 0.1f, 0.1f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
Image handleImage = handleObj.AddComponent<Image>();
|
|
|
|
|
handleImage.type = Image.Type.Sliced;
|
2020-10-23 19:55:02 +11:00
|
|
|
|
handleImage.color = new Color(0.4f, 0.4f, 0.4f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
RectTransform slideAreaRect = slideAreaObj.GetComponent<RectTransform>();
|
|
|
|
|
slideAreaRect.sizeDelta = new Vector2(-20f, -20f);
|
|
|
|
|
slideAreaRect.anchorMin = Vector2.zero;
|
|
|
|
|
slideAreaRect.anchorMax = Vector2.one;
|
|
|
|
|
|
|
|
|
|
RectTransform handleRect = handleObj.GetComponent<RectTransform>();
|
|
|
|
|
handleRect.sizeDelta = new Vector2(20f, 20f);
|
|
|
|
|
|
|
|
|
|
Scrollbar scrollbar = scrollObj.AddComponent<Scrollbar>();
|
|
|
|
|
scrollbar.handleRect = handleRect;
|
|
|
|
|
scrollbar.targetGraphic = handleImage;
|
|
|
|
|
SetDefaultColorTransitionValues(scrollbar);
|
|
|
|
|
|
|
|
|
|
return scrollObj;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
public static GameObject CreateToggle(GameObject parent, out Toggle toggle, out Text text)
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject toggleObj = CreateUIObject("Toggle", parent, thinSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
GameObject bgObj = CreateUIObject("Background", toggleObj);
|
|
|
|
|
GameObject checkObj = CreateUIObject("Checkmark", bgObj);
|
|
|
|
|
GameObject labelObj = CreateUIObject("Label", toggleObj);
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
toggle = toggleObj.AddComponent<Toggle>();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
toggle.isOn = true;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
var toggleComp = toggle;
|
|
|
|
|
#if CPP
|
|
|
|
|
toggle.onValueChanged.AddListener(new Action<bool>((bool val) =>
|
|
|
|
|
{
|
|
|
|
|
toggleComp.OnDeselect(null);
|
|
|
|
|
}));
|
|
|
|
|
#else
|
|
|
|
|
toggle.onValueChanged.AddListener(Deselect);
|
|
|
|
|
|
|
|
|
|
void Deselect(bool _)
|
|
|
|
|
{
|
|
|
|
|
toggleComp.OnDeselect(null);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
Image bgImage = bgObj.AddComponent<Image>();
|
|
|
|
|
bgImage.type = Image.Type.Sliced;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
bgImage.color = new Color(0.1f, 0.1f, 0.1f, 1.0f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
Image checkImage = checkObj.AddComponent<Image>();
|
2020-10-27 00:54:08 +11:00
|
|
|
|
checkImage.color = new Color(90f/255f, 115f/255f, 90f/255f, 1.0f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
text = labelObj.AddComponent<Text>();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
text.text = "Toggle";
|
|
|
|
|
SetDefaultTextValues(text);
|
|
|
|
|
|
|
|
|
|
toggle.graphic = checkImage;
|
|
|
|
|
toggle.targetGraphic = bgImage;
|
|
|
|
|
SetDefaultColorTransitionValues(toggle);
|
|
|
|
|
|
|
|
|
|
RectTransform bgRect = bgObj.GetComponent<RectTransform>();
|
|
|
|
|
bgRect.anchorMin = new Vector2(0f, 1f);
|
|
|
|
|
bgRect.anchorMax = new Vector2(0f, 1f);
|
|
|
|
|
bgRect.anchoredPosition = new Vector2(10f, -10f);
|
|
|
|
|
bgRect.sizeDelta = new Vector2(20f, 20f);
|
|
|
|
|
|
|
|
|
|
RectTransform checkRect = checkObj.GetComponent<RectTransform>();
|
|
|
|
|
checkRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
|
|
|
checkRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
|
|
|
checkRect.anchoredPosition = Vector2.zero;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
checkRect.sizeDelta = new Vector2(14f, 14f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
RectTransform labelRect = labelObj.GetComponent<RectTransform>();
|
|
|
|
|
labelRect.anchorMin = new Vector2(0f, 0f);
|
|
|
|
|
labelRect.anchorMax = new Vector2(1f, 1f);
|
|
|
|
|
labelRect.offsetMin = new Vector2(23f, 1f);
|
|
|
|
|
labelRect.offsetMax = new Vector2(-5f, -2f);
|
|
|
|
|
return toggleObj;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 20:18:42 +11:00
|
|
|
|
public static GameObject CreateTMPInput(GameObject parent)
|
|
|
|
|
{
|
|
|
|
|
GameObject mainObj = CreateUIObject("InputField (TMP)", parent);
|
|
|
|
|
|
|
|
|
|
Image mainImage = mainObj.AddComponent<Image>();
|
|
|
|
|
mainImage.type = Image.Type.Sliced;
|
|
|
|
|
mainImage.color = new Color(38f / 255f, 38f / 255f, 38f / 255f, 1.0f);
|
|
|
|
|
|
|
|
|
|
var mainInput = mainObj.AddComponent<TMP_InputField>();
|
2020-10-27 00:54:08 +11:00
|
|
|
|
var nav = mainInput.navigation;
|
|
|
|
|
nav.mode = Navigation.Mode.None;
|
|
|
|
|
mainInput.navigation = nav;
|
2020-10-24 20:18:42 +11:00
|
|
|
|
mainInput.richText = true;
|
|
|
|
|
mainInput.isRichTextEditingAllowed = true;
|
|
|
|
|
mainInput.lineType = TMP_InputField.LineType.MultiLineNewline;
|
|
|
|
|
mainInput.interactable = true;
|
|
|
|
|
mainInput.transition = Selectable.Transition.ColorTint;
|
|
|
|
|
mainInput.onFocusSelectAll = false;
|
|
|
|
|
|
|
|
|
|
var mainColors = mainInput.colors;
|
|
|
|
|
mainColors.normalColor = new Color(1, 1, 1, 1);
|
|
|
|
|
mainColors.highlightedColor = new Color(245f / 255f, 245f / 255f, 245f / 255f, 1.0f);
|
|
|
|
|
mainColors.pressedColor = new Color(200f / 255f, 200f / 255f, 200f / 255f, 1.0f);
|
|
|
|
|
mainColors.highlightedColor = new Color(245f / 255f, 245f / 255f, 245f / 255f, 1.0f);
|
|
|
|
|
mainInput.colors = mainColors;
|
|
|
|
|
|
|
|
|
|
var mainGroup = mainObj.AddComponent<VerticalLayoutGroup>();
|
|
|
|
|
mainGroup.childControlHeight = true;
|
|
|
|
|
mainGroup.childControlWidth = true;
|
|
|
|
|
mainGroup.childForceExpandWidth = true;
|
|
|
|
|
mainGroup.childForceExpandHeight = true;
|
|
|
|
|
|
2020-10-25 20:57:34 +11:00
|
|
|
|
var textArea = CreateUIObject("TextArea", mainObj);
|
2020-10-24 20:18:42 +11:00
|
|
|
|
textArea.AddComponent<RectMask2D>();
|
|
|
|
|
|
|
|
|
|
var textAreaRect = textArea.GetComponent<RectTransform>();
|
|
|
|
|
textAreaRect.anchorMin = new Vector2(0, 0);
|
|
|
|
|
textAreaRect.anchorMax = new Vector2(1, 1);
|
|
|
|
|
textAreaRect.offsetMin = new Vector2(10, 7);
|
|
|
|
|
textAreaRect.offsetMax = new Vector2(10, 6);
|
|
|
|
|
|
|
|
|
|
mainInput.textViewport = textArea.GetComponent<RectTransform>();
|
|
|
|
|
|
|
|
|
|
var placeHolderObj = CreateUIObject("Placeholder", textArea);
|
|
|
|
|
var placeholderText = placeHolderObj.AddComponent<TextMeshProUGUI>();
|
|
|
|
|
placeholderText.fontSize = 16;
|
2020-10-25 20:57:34 +11:00
|
|
|
|
placeholderText.text = "...";
|
2020-10-24 20:18:42 +11:00
|
|
|
|
placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
|
|
|
|
|
|
|
|
|
|
var placeHolderRect = placeHolderObj.GetComponent<RectTransform>();
|
|
|
|
|
placeHolderRect.anchorMin = Vector2.zero;
|
|
|
|
|
placeHolderRect.anchorMax = Vector2.one;
|
|
|
|
|
placeHolderRect.offsetMin = Vector2.zero;
|
|
|
|
|
placeHolderRect.offsetMax = Vector2.zero;
|
|
|
|
|
|
|
|
|
|
var placeholderLayout = placeHolderObj.AddComponent<LayoutElement>();
|
|
|
|
|
placeholderLayout.preferredWidth = 990;
|
|
|
|
|
placeholderLayout.flexibleWidth = 500;
|
|
|
|
|
|
|
|
|
|
mainInput.placeholder = placeholderText;
|
|
|
|
|
|
|
|
|
|
var inputTextObj = CreateUIObject("Text", textArea);
|
|
|
|
|
var inputText = inputTextObj.AddComponent<TextMeshProUGUI>();
|
|
|
|
|
inputText.fontSize = 16;
|
|
|
|
|
inputText.text = "";
|
|
|
|
|
inputText.color = new Color(1f, 1f, 1f, 1f);
|
|
|
|
|
|
|
|
|
|
var inputTextRect = inputTextObj.GetComponent<RectTransform>();
|
|
|
|
|
inputTextRect.anchorMin = Vector2.zero;
|
|
|
|
|
inputTextRect.anchorMax = Vector2.one;
|
|
|
|
|
inputTextRect.offsetMin = Vector2.zero;
|
|
|
|
|
inputTextRect.offsetMax = Vector2.zero;
|
|
|
|
|
|
|
|
|
|
var test = inputTextObj.AddComponent<LayoutElement>();
|
|
|
|
|
test.preferredWidth = 990;
|
|
|
|
|
test.flexibleWidth = 500;
|
|
|
|
|
|
|
|
|
|
mainInput.textComponent = inputText;
|
|
|
|
|
|
|
|
|
|
return mainObj;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 01:50:33 +11:00
|
|
|
|
public static GameObject CreateInputField(GameObject parent)
|
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject inputObj = CreateUIObject("InputField", parent, thickSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
GameObject placeholderObj = CreateUIObject("Placeholder", inputObj);
|
|
|
|
|
GameObject textObj = CreateUIObject("Text", inputObj);
|
|
|
|
|
|
|
|
|
|
Image inputImage = inputObj.AddComponent<Image>();
|
|
|
|
|
inputImage.type = Image.Type.Sliced;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
inputImage.color = new Color(0.1f, 0.1f, 0.1f, 1.0f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
InputField inputField = inputObj.AddComponent<InputField>();
|
|
|
|
|
SetDefaultColorTransitionValues(inputField);
|
|
|
|
|
|
|
|
|
|
Text text = textObj.AddComponent<Text>();
|
|
|
|
|
text.text = "";
|
|
|
|
|
text.supportRichText = false;
|
|
|
|
|
SetDefaultTextValues(text);
|
|
|
|
|
|
|
|
|
|
Text placeholderText = placeholderObj.AddComponent<Text>();
|
|
|
|
|
placeholderText.text = "Enter text...";
|
|
|
|
|
placeholderText.fontStyle = FontStyle.Italic;
|
|
|
|
|
Color color = text.color;
|
|
|
|
|
color.a *= 0.5f;
|
|
|
|
|
placeholderText.color = color;
|
|
|
|
|
|
|
|
|
|
RectTransform textRect = textObj.GetComponent<RectTransform>();
|
|
|
|
|
textRect.anchorMin = Vector2.zero;
|
|
|
|
|
textRect.anchorMax = Vector2.one;
|
|
|
|
|
textRect.sizeDelta = Vector2.zero;
|
|
|
|
|
textRect.offsetMin = new Vector2(10f, 6f);
|
|
|
|
|
textRect.offsetMax = new Vector2(-10f, -7f);
|
|
|
|
|
|
|
|
|
|
RectTransform placeholderRect = placeholderObj.GetComponent<RectTransform>();
|
|
|
|
|
placeholderRect.anchorMin = Vector2.zero;
|
|
|
|
|
placeholderRect.anchorMax = Vector2.one;
|
|
|
|
|
placeholderRect.sizeDelta = Vector2.zero;
|
|
|
|
|
placeholderRect.offsetMin = new Vector2(10f, 6f);
|
|
|
|
|
placeholderRect.offsetMax = new Vector2(-10f, -7f);
|
|
|
|
|
inputField.textComponent = text;
|
|
|
|
|
inputField.placeholder = placeholderText;
|
|
|
|
|
|
|
|
|
|
return inputObj;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
public static GameObject CreateDropdown(GameObject parent, out Dropdown dropdown)
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
GameObject dropdownObj = CreateUIObject("Dropdown", parent, thickSize);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
GameObject labelObj = CreateUIObject("Label", dropdownObj);
|
|
|
|
|
GameObject templateObj = CreateUIObject("Template", dropdownObj);
|
|
|
|
|
GameObject viewportObj = CreateUIObject("Viewport", templateObj);
|
|
|
|
|
GameObject contentObj = CreateUIObject("Content", viewportObj);
|
|
|
|
|
GameObject itemObj = CreateUIObject("Item", contentObj);
|
|
|
|
|
GameObject itemBgObj = CreateUIObject("Item Background", itemObj);
|
|
|
|
|
GameObject itemCheckObj = CreateUIObject("Item Checkmark", itemObj);
|
|
|
|
|
GameObject itemLabelObj = CreateUIObject("Item Label", itemObj);
|
|
|
|
|
|
|
|
|
|
GameObject scrollbarObj = CreateScrollbar(templateObj);
|
|
|
|
|
scrollbarObj.name = "Scrollbar";
|
|
|
|
|
Scrollbar scrollbar = scrollbarObj.GetComponent<Scrollbar>();
|
|
|
|
|
scrollbar.SetDirection(Scrollbar.Direction.BottomToTop, true);
|
|
|
|
|
|
|
|
|
|
RectTransform scrollRectTransform = scrollbarObj.GetComponent<RectTransform>();
|
|
|
|
|
scrollRectTransform.anchorMin = Vector2.right;
|
|
|
|
|
scrollRectTransform.anchorMax = Vector2.one;
|
|
|
|
|
scrollRectTransform.pivot = Vector2.one;
|
|
|
|
|
scrollRectTransform.sizeDelta = new Vector2(scrollRectTransform.sizeDelta.x, 0f);
|
|
|
|
|
|
|
|
|
|
Text itemLabelText = itemLabelObj.AddComponent<Text>();
|
|
|
|
|
SetDefaultTextValues(itemLabelText);
|
|
|
|
|
itemLabelText.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
|
|
|
|
|
Image itemBgImage = itemBgObj.AddComponent<Image>();
|
2020-10-27 00:54:08 +11:00
|
|
|
|
itemBgImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
|
|
|
|
|
|
|
|
|
|
Toggle itemToggle = itemObj.AddComponent<Toggle>();
|
|
|
|
|
itemToggle.targetGraphic = itemBgImage;
|
|
|
|
|
itemToggle.isOn = true;
|
|
|
|
|
var colors = itemToggle.colors;
|
|
|
|
|
colors.normalColor = new Color(0.15f, 0.15f, 0.15f, 1.0f);
|
|
|
|
|
colors.highlightedColor = new Color(0.25f, 0.25f, 0.25f, 1.0f);
|
|
|
|
|
itemToggle.colors = colors;
|
|
|
|
|
|
|
|
|
|
#if CPP
|
|
|
|
|
itemToggle.onValueChanged.AddListener(new Action<bool>((bool val) => { itemToggle.OnDeselect(null); }));
|
|
|
|
|
#else
|
|
|
|
|
itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });
|
|
|
|
|
#endif
|
2020-10-23 01:50:33 +11:00
|
|
|
|
Image templateImage = templateObj.AddComponent<Image>();
|
|
|
|
|
templateImage.type = Image.Type.Sliced;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
ScrollRect scrollRect = templateObj.AddComponent<ScrollRect>();
|
2020-10-23 19:55:02 +11:00
|
|
|
|
scrollRect.content = contentObj.GetComponent<RectTransform>();
|
|
|
|
|
scrollRect.viewport = viewportObj.GetComponent<RectTransform>();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
scrollRect.horizontal = false;
|
|
|
|
|
scrollRect.movementType = ScrollRect.MovementType.Clamped;
|
|
|
|
|
scrollRect.verticalScrollbar = scrollbar;
|
|
|
|
|
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
|
|
|
|
scrollRect.verticalScrollbarSpacing = -3f;
|
|
|
|
|
|
|
|
|
|
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
|
|
|
|
|
|
|
|
|
|
Image viewportImage = viewportObj.AddComponent<Image>();
|
|
|
|
|
viewportImage.type = Image.Type.Sliced;
|
|
|
|
|
|
|
|
|
|
Text labelText = labelObj.AddComponent<Text>();
|
|
|
|
|
SetDefaultTextValues(labelText);
|
|
|
|
|
labelText.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
|
|
|
|
|
Image dropdownImage = dropdownObj.AddComponent<Image>();
|
2020-10-27 00:54:08 +11:00
|
|
|
|
dropdownImage.color = new Color(0.2f, 0.2f, 0.2f, 1);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
dropdownImage.type = Image.Type.Sliced;
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
dropdown = dropdownObj.AddComponent<Dropdown>();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
dropdown.targetGraphic = dropdownImage;
|
|
|
|
|
dropdown.template = templateObj.GetComponent<RectTransform>();
|
|
|
|
|
dropdown.captionText = labelText;
|
|
|
|
|
dropdown.itemText = itemLabelText;
|
2020-10-27 00:54:08 +11:00
|
|
|
|
itemLabelText.text = "1";
|
2020-10-23 01:50:33 +11:00
|
|
|
|
dropdown.options.Add(new Dropdown.OptionData
|
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
text = "2"
|
2020-10-23 01:50:33 +11:00
|
|
|
|
});
|
2020-10-23 19:55:02 +11:00
|
|
|
|
dropdown.options.Add(new Dropdown.OptionData
|
|
|
|
|
{
|
2020-10-27 00:54:08 +11:00
|
|
|
|
text = "3"
|
2020-10-23 19:55:02 +11:00
|
|
|
|
});
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-10-23 19:55:02 +11:00
|
|
|
|
dropdown.RefreshShownValue();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
RectTransform labelRect = labelObj.GetComponent<RectTransform>();
|
|
|
|
|
labelRect.anchorMin = Vector2.zero;
|
|
|
|
|
labelRect.anchorMax = Vector2.one;
|
|
|
|
|
labelRect.offsetMin = new Vector2(10f, 6f);
|
|
|
|
|
labelRect.offsetMax = new Vector2(-25f, -7f);
|
|
|
|
|
|
|
|
|
|
RectTransform templateRect = templateObj.GetComponent<RectTransform>();
|
|
|
|
|
templateRect.anchorMin = new Vector2(0f, 0f);
|
|
|
|
|
templateRect.anchorMax = new Vector2(1f, 0f);
|
|
|
|
|
templateRect.pivot = new Vector2(0.5f, 1f);
|
|
|
|
|
templateRect.anchoredPosition = new Vector2(0f, 2f);
|
|
|
|
|
templateRect.sizeDelta = new Vector2(0f, 150f);
|
|
|
|
|
|
|
|
|
|
RectTransform viewportRect = viewportObj.GetComponent<RectTransform>();
|
|
|
|
|
viewportRect.anchorMin = new Vector2(0f, 0f);
|
|
|
|
|
viewportRect.anchorMax = new Vector2(1f, 1f);
|
|
|
|
|
viewportRect.sizeDelta = new Vector2(-18f, 0f);
|
|
|
|
|
viewportRect.pivot = new Vector2(0f, 1f);
|
|
|
|
|
|
|
|
|
|
RectTransform contentRect = contentObj.GetComponent<RectTransform>();
|
|
|
|
|
contentRect.anchorMin = new Vector2(0f, 1f);
|
|
|
|
|
contentRect.anchorMax = new Vector2(1f, 1f);
|
|
|
|
|
contentRect.pivot = new Vector2(0.5f, 1f);
|
|
|
|
|
contentRect.anchoredPosition = new Vector2(0f, 0f);
|
|
|
|
|
contentRect.sizeDelta = new Vector2(0f, 28f);
|
|
|
|
|
|
|
|
|
|
RectTransform itemRect = itemObj.GetComponent<RectTransform>();
|
|
|
|
|
itemRect.anchorMin = new Vector2(0f, 0.5f);
|
|
|
|
|
itemRect.anchorMax = new Vector2(1f, 0.5f);
|
|
|
|
|
itemRect.sizeDelta = new Vector2(0f, 20f);
|
|
|
|
|
|
|
|
|
|
RectTransform itemBgRect = itemBgObj.GetComponent<RectTransform>();
|
|
|
|
|
itemBgRect.anchorMin = Vector2.zero;
|
|
|
|
|
itemBgRect.anchorMax = Vector2.one;
|
|
|
|
|
itemBgRect.sizeDelta = Vector2.zero;
|
|
|
|
|
|
|
|
|
|
RectTransform itemLabelRect = itemLabelObj.GetComponent<RectTransform>();
|
|
|
|
|
itemLabelRect.anchorMin = Vector2.zero;
|
|
|
|
|
itemLabelRect.anchorMax = Vector2.one;
|
|
|
|
|
itemLabelRect.offsetMin = new Vector2(20f, 1f);
|
|
|
|
|
itemLabelRect.offsetMax = new Vector2(-10f, -2f);
|
|
|
|
|
templateObj.SetActive(false);
|
|
|
|
|
|
|
|
|
|
return dropdownObj;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 20:18:42 +11:00
|
|
|
|
public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
2020-10-23 19:55:02 +11:00
|
|
|
|
GameObject scrollObj = CreateUIObject("Scroll View", parent);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-10-24 00:41:55 +11:00
|
|
|
|
var mainLayout = scrollObj.AddComponent<LayoutElement>();
|
|
|
|
|
mainLayout.flexibleWidth = 999;
|
|
|
|
|
mainLayout.flexibleHeight = 999;
|
|
|
|
|
mainLayout.preferredHeight = 200;
|
|
|
|
|
mainLayout.preferredWidth = 200;
|
|
|
|
|
|
2020-10-23 01:50:33 +11:00
|
|
|
|
GameObject viewportObj = CreateUIObject("Viewport", scrollObj);
|
2020-10-23 19:55:02 +11:00
|
|
|
|
|
|
|
|
|
var viewportGroup = viewportObj.AddComponent<VerticalLayoutGroup>();
|
|
|
|
|
viewportGroup.childControlHeight = true;
|
|
|
|
|
viewportGroup.childControlWidth = true;
|
|
|
|
|
viewportGroup.childForceExpandHeight = true;
|
|
|
|
|
viewportGroup.childForceExpandWidth = true;
|
|
|
|
|
|
|
|
|
|
content = CreateUIObject("Content", viewportObj);
|
|
|
|
|
|
|
|
|
|
var 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;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
GameObject horiScroll = CreateScrollbar(scrollObj);
|
|
|
|
|
horiScroll.name = "Scrollbar Horizontal";
|
2020-10-23 19:55:02 +11:00
|
|
|
|
SetParentAndAlign(horiScroll, scrollObj);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-10-23 19:55:02 +11:00
|
|
|
|
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);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-10-23 19:55:02 +11:00
|
|
|
|
GameObject vertScroll = CreateScrollbar(scrollObj);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
vertScroll.name = "Scrollbar Vertical";
|
2020-10-23 19:55:02 +11:00
|
|
|
|
SetParentAndAlign(vertScroll, scrollObj);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
vertScroll.GetComponent<Scrollbar>().SetDirection(Scrollbar.Direction.BottomToTop, true);
|
|
|
|
|
|
2020-10-23 19:55:02 +11:00
|
|
|
|
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);
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
RectTransform viewportRect = viewportObj.GetComponent<RectTransform>();
|
|
|
|
|
viewportRect.anchorMin = Vector2.zero;
|
|
|
|
|
viewportRect.anchorMax = Vector2.one;
|
|
|
|
|
viewportRect.sizeDelta = Vector2.zero;
|
|
|
|
|
viewportRect.pivot = Vector2.up;
|
|
|
|
|
|
2020-10-23 19:55:02 +11:00
|
|
|
|
RectTransform contentRect = content.GetComponent<RectTransform>();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
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>();
|
2020-10-23 19:55:02 +11:00
|
|
|
|
scrollRect.verticalScrollbar = vertScroll.GetComponent<Scrollbar>();
|
|
|
|
|
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
|
|
|
|
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
|
|
|
|
scrollRect.horizontalScrollbarSpacing = -3f;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
scrollRect.verticalScrollbarSpacing = -3f;
|
2020-10-23 19:55:02 +11:00
|
|
|
|
scrollRect.scrollSensitivity = 25;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
Image scrollImage = scrollObj.AddComponent<Image>();
|
2020-10-24 20:18:42 +11:00
|
|
|
|
scrollImage.type = Image.Type.Filled;
|
|
|
|
|
|
|
|
|
|
scrollImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
Image viewportImage = viewportObj.AddComponent<Image>();
|
2020-10-27 00:54:08 +11:00
|
|
|
|
//viewportImage.sprite = Theme.mask;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
viewportImage.type = Image.Type.Sliced;
|
2020-10-24 20:18:42 +11:00
|
|
|
|
viewportImage.color = new Color(1, 1, 1, 1);
|
|
|
|
|
|
|
|
|
|
var mask = viewportObj.AddComponent<Mask>();
|
|
|
|
|
mask.showMaskGraphic = false;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
|
|
|
|
return scrollObj;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|