parent
8a01b08e7b
commit
7fe6f4197b
|
@ -163,7 +163,7 @@ namespace UnityEditor.UI
|
||||||
var esys = Object.FindFirstObjectByType<EventSystem>();
|
var esys = Object.FindFirstObjectByType<EventSystem>();
|
||||||
#else
|
#else
|
||||||
var esys = Object.FindObjectOfType<EventSystem>();
|
var esys = Object.FindObjectOfType<EventSystem>();
|
||||||
#endif
|
#endif
|
||||||
if (esys == null)
|
if (esys == null)
|
||||||
{
|
{
|
||||||
var eventSystem = new GameObject("EventSystem");
|
var eventSystem = new GameObject("EventSystem");
|
||||||
|
@ -677,91 +677,91 @@ namespace UnityEditor.UI
|
||||||
|
|
||||||
Selection.activeGameObject = uiVerticalScrollerRoot;
|
Selection.activeGameObject = uiVerticalScrollerRoot;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UIHorizontal Scroller
|
#region UIHorizontal Scroller
|
||||||
[MenuItem("GameObject/UI/Extensions/Layout/UI Horizontal Scroller", false)]
|
[MenuItem("GameObject/UI/Extensions/Layout/UI Horizontal Scroller", false)]
|
||||||
static public void AddUIHorizontalScroller(MenuCommand menuCommand)
|
static public void AddUIHorizontalScroller(MenuCommand menuCommand)
|
||||||
{
|
{
|
||||||
GameObject uiHorizontalScrollerRoot = CreateUIElementRoot("UI Horizontal Scroller", menuCommand, s_ThickGUIElementSize);
|
GameObject uiHorizontalScrollerRoot = CreateUIElementRoot("UI Horizontal Scroller", menuCommand, s_ThickGUIElementSize);
|
||||||
|
|
||||||
GameObject uiScrollerCenter = CreateUIObject("Center", uiHorizontalScrollerRoot);
|
GameObject uiScrollerCenter = CreateUIObject("Center", uiHorizontalScrollerRoot);
|
||||||
|
|
||||||
GameObject childContent = CreateUIObject("Content", uiHorizontalScrollerRoot);
|
GameObject childContent = CreateUIObject("Content", uiHorizontalScrollerRoot);
|
||||||
|
|
||||||
// Set RectTransform to stretch
|
// Set RectTransform to stretch
|
||||||
RectTransform rectTransformScrollSnapRoot = uiHorizontalScrollerRoot.GetComponent<RectTransform>();
|
RectTransform rectTransformScrollSnapRoot = uiHorizontalScrollerRoot.GetComponent<RectTransform>();
|
||||||
rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f);
|
rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f);
|
||||||
rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f);
|
rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f);
|
||||||
rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero;
|
rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero;
|
||||||
rectTransformScrollSnapRoot.sizeDelta = new Vector2(500f, 150f);
|
rectTransformScrollSnapRoot.sizeDelta = new Vector2(500f, 150f);
|
||||||
|
|
||||||
// Add required ScrollRect
|
// Add required ScrollRect
|
||||||
ScrollRect sr = uiHorizontalScrollerRoot.AddComponent<ScrollRect>();
|
ScrollRect sr = uiHorizontalScrollerRoot.AddComponent<ScrollRect>();
|
||||||
sr.vertical = false;
|
sr.vertical = false;
|
||||||
sr.horizontal = true;
|
sr.horizontal = true;
|
||||||
sr.movementType = ScrollRect.MovementType.Unrestricted;
|
sr.movementType = ScrollRect.MovementType.Unrestricted;
|
||||||
var uiscr = uiHorizontalScrollerRoot.AddComponent<UIHorizontalScroller>();
|
var uiscr = uiHorizontalScrollerRoot.AddComponent<UIHorizontalScroller>();
|
||||||
|
|
||||||
//Setup container center point
|
//Setup container center point
|
||||||
RectTransform rectTransformCenter = uiScrollerCenter.GetComponent<RectTransform>();
|
RectTransform rectTransformCenter = uiScrollerCenter.GetComponent<RectTransform>();
|
||||||
rectTransformCenter.anchorMin = new Vector2(0.3f, 0f);
|
rectTransformCenter.anchorMin = new Vector2(0.3f,0f);
|
||||||
rectTransformCenter.anchorMax = new Vector2(0.6f, 1f);
|
rectTransformCenter.anchorMax = new Vector2(0.6f,1f);
|
||||||
rectTransformCenter.sizeDelta = Vector2.zero;
|
rectTransformCenter.sizeDelta = Vector2.zero;
|
||||||
|
|
||||||
uiscr.Center = uiScrollerCenter.GetComponent<RectTransform>();
|
uiscr.Center = uiScrollerCenter.GetComponent<RectTransform>();
|
||||||
|
|
||||||
//Setup Content container
|
//Setup Content container
|
||||||
RectTransform rectTransformContent = childContent.GetComponent<RectTransform>();
|
RectTransform rectTransformContent = childContent.GetComponent<RectTransform>();
|
||||||
rectTransformContent.anchorMin = Vector2.zero;
|
rectTransformContent.anchorMin = Vector2.zero;
|
||||||
rectTransformContent.anchorMax = new Vector2(1f, 1f);
|
rectTransformContent.anchorMax = new Vector2(1f, 1f);
|
||||||
rectTransformContent.sizeDelta = Vector2.zero;
|
rectTransformContent.sizeDelta = Vector2.zero;
|
||||||
|
|
||||||
sr.content = rectTransformContent;
|
sr.content = rectTransformContent;
|
||||||
|
|
||||||
// Add sample children
|
// Add sample children
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
GameObject childPage = CreateUIObject("Page_" + i, childContent);
|
GameObject childPage = CreateUIObject("Page_" + i, childContent);
|
||||||
|
|
||||||
GameObject childText = CreateUIObject("Text", childPage);
|
GameObject childText = CreateUIObject("Text", childPage);
|
||||||
|
|
||||||
//Setup 1st Child
|
//Setup 1st Child
|
||||||
Image pageImage = childPage.AddComponent<Image>();
|
Image pageImage = childPage.AddComponent<Image>();
|
||||||
pageImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
|
pageImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
|
||||||
pageImage.type = Image.Type.Sliced;
|
pageImage.type = Image.Type.Sliced;
|
||||||
pageImage.color = s_DefaultSelectableColor;
|
pageImage.color = s_DefaultSelectableColor;
|
||||||
|
|
||||||
RectTransform rectTransformPage = childPage.GetComponent<RectTransform>();
|
RectTransform rectTransformPage = childPage.GetComponent<RectTransform>();
|
||||||
rectTransformPage.anchorMin = new Vector2(0.5f, 0);
|
rectTransformPage.anchorMin = new Vector2(0.5f, 0);
|
||||||
rectTransformPage.anchorMax = new Vector2(0.5f, 1f);
|
rectTransformPage.anchorMax = new Vector2(0.5f, 1f);
|
||||||
rectTransformPage.sizeDelta = new Vector2(80f, 0f);
|
rectTransformPage.sizeDelta = new Vector2(80f, 0f);
|
||||||
rectTransformPage.pivot = new Vector2(0.5f, 0.5f);
|
rectTransformPage.pivot = new Vector2(0.5f, 0.5f);
|
||||||
rectTransformPage.localPosition = new Vector3(80 * i, 0, 0);
|
rectTransformPage.localPosition = new Vector3(80 * i, 0, 0);
|
||||||
childPage.AddComponent<Button>();
|
childPage.AddComponent<Button>();
|
||||||
|
|
||||||
var childCG = childPage.AddComponent<CanvasGroup>();
|
var childCG = childPage.AddComponent<CanvasGroup>();
|
||||||
childCG.interactable = false;
|
childCG.interactable = false;
|
||||||
|
|
||||||
//Setup Text on Item
|
//Setup Text on Item
|
||||||
Text text = childText.AddComponent<Text>();
|
Text text = childText.AddComponent<Text>();
|
||||||
text.text = "Item_" + i;
|
text.text = "Item_" + i;
|
||||||
text.alignment = TextAnchor.MiddleCenter;
|
text.alignment = TextAnchor.MiddleCenter;
|
||||||
text.color = new Color(0.196f, 0.196f, 0.196f);
|
text.color = new Color(0.196f, 0.196f, 0.196f);
|
||||||
|
|
||||||
//Setup Text on Item
|
//Setup Text on Item
|
||||||
RectTransform rectTransformPageText = childText.GetComponent<RectTransform>();
|
RectTransform rectTransformPageText = childText.GetComponent<RectTransform>();
|
||||||
rectTransformPageText.anchorMin = new Vector2(0.5f, 0.5f);
|
rectTransformPageText.anchorMin = new Vector2(0.5f, 0.5f);
|
||||||
rectTransformPageText.anchorMax = new Vector2(0.5f, 0.5f);
|
rectTransformPageText.anchorMax = new Vector2(0.5f, 0.5f);
|
||||||
rectTransformPageText.pivot = new Vector2(0.5f, 0.5f);
|
rectTransformPageText.pivot = new Vector2(0.5f, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Selection.activeGameObject = uiHorizontalScrollerRoot;
|
Selection.activeGameObject = uiHorizontalScrollerRoot;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UI Button
|
#region UI Button
|
||||||
[MenuItem("GameObject/UI/Extensions/Controls/UI Button", false)]
|
[MenuItem("GameObject/UI/Extensions/Controls/UI Button", false)]
|
||||||
static public void AddUIButton(MenuCommand menuCommand)
|
static public void AddUIButton(MenuCommand menuCommand)
|
||||||
{
|
{
|
||||||
GameObject uiButtonRoot = CreateUIElementRoot("UI Button", menuCommand, s_ThickGUIElementSize);
|
GameObject uiButtonRoot = CreateUIElementRoot("UI Button", menuCommand, s_ThickGUIElementSize);
|
||||||
|
@ -1370,14 +1370,6 @@ namespace UnityEditor.UI
|
||||||
Selection.activeGameObject = go;
|
Selection.activeGameObject = go;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/UI/Extensions/Primitives/UI SquircleBorder", false)]
|
|
||||||
static public void AddUISquircleBorder(MenuCommand menuCommand)
|
|
||||||
{
|
|
||||||
GameObject go = CreateUIElementRoot("UI SquircleBorder", menuCommand, s_ImageGUIElementSize);
|
|
||||||
go.AddComponent<UISquircleBorder>();
|
|
||||||
Selection.activeGameObject = go;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MenuItem("GameObject/UI/Extensions/Primitives/UI Circle", false)]
|
[MenuItem("GameObject/UI/Extensions/Primitives/UI Circle", false)]
|
||||||
static public void AddUICircle(MenuCommand menuCommand)
|
static public void AddUICircle(MenuCommand menuCommand)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
public class UISquircleBorder : UIPrimitiveBase
|
public class UISquircleBorder : UIPrimitiveBase
|
||||||
{
|
{
|
||||||
const float C = 1.0f;
|
const float C = 1.0f;
|
||||||
|
public enum Type
|
||||||
|
{
|
||||||
|
Classic,
|
||||||
|
Scaled
|
||||||
|
}
|
||||||
|
|
||||||
[Space]
|
[Space]
|
||||||
public Type squircleType = Type.Scaled;
|
public Type squircleType = Type.Scaled;
|
||||||
[Range(1, 40)]
|
[Range(1, 40)]
|
||||||
|
|
Loading…
Reference in New Issue