diff --git a/Scripts/Editor/UIExtensionsMenuOptions.cs b/Scripts/Editor/UIExtensionsMenuOptions.cs index 79e1197..03d4d70 100644 --- a/Scripts/Editor/UIExtensionsMenuOptions.cs +++ b/Scripts/Editor/UIExtensionsMenuOptions.cs @@ -866,7 +866,7 @@ namespace UnityEditor.UI SetDefaultColorTransitionValues(slider); } - [MenuItem("GameObject/UI/Extensions/UI Line Renderer", false)] + [MenuItem("GameObject/UI/Extensions/Primatives/UI Line Renderer", false)] static public void AddUILineRenderer(MenuCommand menuCommand) { GameObject go = CreateUIElementRoot("UI LineRenderer", menuCommand, s_ImageGUIElementSize); @@ -874,13 +874,21 @@ namespace UnityEditor.UI Selection.activeGameObject = go; } - [MenuItem("GameObject/UI/Extensions/UI Line Texture Renderer", false)] + [MenuItem("GameObject/UI/Extensions/Primatives/UI Line Texture Renderer", false)] static public void AddUILineTextureRenderer(MenuCommand menuCommand) { GameObject go = CreateUIElementRoot("UI LineTextureRenderer", menuCommand, s_ImageGUIElementSize); go.AddComponent(); Selection.activeGameObject = go; } + + [MenuItem("GameObject/UI/Extensions/Primatives/UI Circle", false)] + static public void AddUICircle(MenuCommand menuCommand) + { + GameObject go = CreateUIElementRoot("UI Circle", menuCommand, s_ImageGUIElementSize); + go.AddComponent(); + Selection.activeGameObject = go; + } #endregion diff --git a/Scripts/InputFieldEnterSubmit.cs b/Scripts/InputFieldEnterSubmit.cs index a1d6873..56e9a55 100644 --- a/Scripts/InputFieldEnterSubmit.cs +++ b/Scripts/InputFieldEnterSubmit.cs @@ -1,11 +1,15 @@ -/// Usage: Add this component to the input and add the -/// function to execute to the EnterSubmit event of this script +/// Credit Vicente Russo +/// Sourced from - https://bitbucket.org/ddreaper/unity-ui-extensions/issues/23/returnkeytriggersbutton -using UnityEngine; -using UnityEngine.UI; using UnityEngine.Events; +namespace UnityEngine.UI.Extensions +{ +/// +/// Usage: Add this component to the input and add the function to execute to the EnterSubmit event of this script +/// [RequireComponent(typeof(InputField))] +[AddComponentMenu("UI/Extensions/Input Field Submit")] public class InputFieldEnterSubmit : MonoBehaviour { @@ -28,3 +32,4 @@ public class InputFieldEnterSubmit : MonoBehaviour } } +} diff --git a/Scripts/InputFieldEnterSubmit.cs.meta b/Scripts/InputFieldEnterSubmit.cs.meta new file mode 100644 index 0000000..f8e8522 --- /dev/null +++ b/Scripts/InputFieldEnterSubmit.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bfc77d7b04a86f845b59fb0979e8ec53 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/Layout.meta b/Scripts/Layout.meta new file mode 100644 index 0000000..0f460bb --- /dev/null +++ b/Scripts/Layout.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 759c961dc0e85a348ab9cd1278319ca0 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/FlowLayoutGroup.cs b/Scripts/Layout/FlowLayoutGroup.cs similarity index 77% rename from Scripts/FlowLayoutGroup.cs rename to Scripts/Layout/FlowLayoutGroup.cs index 49f6a3f..3d4c050 100644 --- a/Scripts/FlowLayoutGroup.cs +++ b/Scripts/Layout/FlowLayoutGroup.cs @@ -1,7 +1,8 @@ /// Credit Simie /// Sourced from - http://forum.unity3d.com/threads/flowlayoutgroup.296709/ /// Example http://forum.unity3d.com/threads/flowlayoutgroup.296709/ - +/// Update by Martin Sharkbomb - http://forum.unity3d.com/threads/flowlayoutgroup.296709/#post-1977028 +/// Last item alignment fix by Vicente Russo - https://bitbucket.org/ddreaper/unity-ui-extensions/issues/22/flow-layout-group-align using System.Collections.Generic; @@ -13,80 +14,82 @@ namespace UnityEngine.UI.Extensions [AddComponentMenu("Layout/Extensions/Flow Layout Group")] public class FlowLayoutGroup : LayoutGroup { - public float Spacing = 0f; - + public float SpacingX = 0f; + public float SpacingY = 0f; + public bool ExpandHorizontalSpacing = false; + public bool ChildForceExpandWidth = false; public bool ChildForceExpandHeight = false; - + private float _layoutHeight; - + public override void CalculateLayoutInputHorizontal() { - + base.CalculateLayoutInputHorizontal(); - + var minWidth = GetGreatestMinimumChildWidth() + padding.left + padding.right; - + SetLayoutInputForAxis(minWidth, -1, -1, 0); - + } - + public override void SetLayoutHorizontal() { SetLayout(rectTransform.rect.width, 0, false); } - + public override void SetLayoutVertical() { SetLayout(rectTransform.rect.width, 1, false); } - + public override void CalculateLayoutInputVertical() { _layoutHeight = SetLayout(rectTransform.rect.width, 1, true); } - + protected bool IsCenterAlign { get { return childAlignment == TextAnchor.LowerCenter || childAlignment == TextAnchor.MiddleCenter || - childAlignment == TextAnchor.UpperCenter; + childAlignment == TextAnchor.UpperCenter; } } - + protected bool IsRightAlign { get { return childAlignment == TextAnchor.LowerRight || childAlignment == TextAnchor.MiddleRight || - childAlignment == TextAnchor.UpperRight; + childAlignment == TextAnchor.UpperRight; } } - + protected bool IsMiddleAlign { get { return childAlignment == TextAnchor.MiddleLeft || childAlignment == TextAnchor.MiddleRight || - childAlignment == TextAnchor.MiddleCenter; + childAlignment == TextAnchor.MiddleCenter; } } - + protected bool IsLowerAlign { get { return childAlignment == TextAnchor.LowerLeft || childAlignment == TextAnchor.LowerRight || - childAlignment == TextAnchor.LowerCenter; + childAlignment == TextAnchor.LowerCenter; } } - + /// /// Holds the rects that will make up the current row being processed /// private readonly IList _rowList = new List(); - + /// /// Main layout method /// @@ -96,93 +99,95 @@ namespace UnityEngine.UI.Extensions public float SetLayout(float width, int axis, bool layoutInput) { var groupHeight = rectTransform.rect.height; - + // Width that is available after padding is subtracted var workingWidth = rectTransform.rect.width - padding.left - padding.right; - + // Accumulates the total height of the rows, including spacing and padding. var yOffset = IsLowerAlign ? (float)padding.bottom : (float)padding.top; - + var currentRowWidth = 0f; var currentRowHeight = 0f; - + for (var i = 0; i < rectChildren.Count; i++) { - + // LowerAlign works from back to front var index = IsLowerAlign ? rectChildren.Count - 1 - i : i; - + var child = rectChildren[index]; - + var childWidth = LayoutUtility.GetPreferredSize(child, 0); var childHeight = LayoutUtility.GetPreferredSize(child, 1); - - // Max child width is layout group with - padding + + // Max child width is layout group width - padding childWidth = Mathf.Min(childWidth, workingWidth); - + // If adding this element would exceed the bounds of the row, // go to a new line after processing the current row if (currentRowWidth + childWidth > workingWidth) { - - currentRowWidth -= Spacing; - + + currentRowWidth -= SpacingX; + // Process current row elements positioning if (!layoutInput) { - + var h = CalculateRowVerticalOffset(groupHeight, yOffset, currentRowHeight); LayoutRow(_rowList, currentRowWidth, currentRowHeight, workingWidth, padding.left, h, axis); - + } - + // Clear existing row _rowList.Clear(); - + // Add the current row height to total height accumulator, and reset to 0 for the next row yOffset += currentRowHeight; - yOffset += Spacing; - + yOffset += SpacingY; + currentRowHeight = 0; currentRowWidth = 0; - + } - + currentRowWidth += childWidth; _rowList.Add(child); - + // We need the largest element height to determine the starting position of the next line if (childHeight > currentRowHeight) { currentRowHeight = childHeight; } - currentRowWidth += Spacing; + // Don't do this for the last one + if (i < rectChildren.Count - 1 ) + currentRowWidth += SpacingX; } - + if (!layoutInput) { var h = CalculateRowVerticalOffset(groupHeight, yOffset, currentRowHeight); - currentRowWidth -= Spacing; + currentRowWidth -= SpacingX; // Layout the final row LayoutRow(_rowList, currentRowWidth, currentRowHeight, workingWidth, padding.left, h, axis); } - + _rowList.Clear(); - + // Add the last rows height to the height accumulator yOffset += currentRowHeight; yOffset += IsLowerAlign ? padding.top : padding.bottom; - + if (layoutInput) { - + if(axis == 1) SetLayoutInputForAxis(yOffset, yOffset, -1, axis); - + } - + return yOffset; } - + private float CalculateRowVerticalOffset(float groupHeight, float yOffset, float currentRowHeight) { float h; - + if (IsLowerAlign) { h = groupHeight - yOffset - currentRowHeight; } else if (IsMiddleAlign) { @@ -192,36 +197,46 @@ namespace UnityEngine.UI.Extensions } return h; } - + protected void LayoutRow(IList contents, float rowWidth, float rowHeight, float maxWidth, float xOffset, float yOffset, int axis) { var xPos = xOffset; - + if (!ChildForceExpandWidth && IsCenterAlign) xPos += (maxWidth - rowWidth) * 0.5f; else if (!ChildForceExpandWidth && IsRightAlign) xPos += (maxWidth - rowWidth); - + var extraWidth = 0f; + var extraSpacing = 0f; if (ChildForceExpandWidth) { extraWidth = (maxWidth - rowWidth)/_rowList.Count; } - + else if (ExpandHorizontalSpacing) { + extraSpacing = (maxWidth - rowWidth)/(_rowList.Count - 1); + if (_rowList.Count > 1) { + if (IsCenterAlign) + xPos -= extraSpacing * 0.5f * (_rowList.Count - 1); + else if (IsRightAlign) + xPos -= extraSpacing * (_rowList.Count - 1); + } + } + for (var j = 0; j < _rowList.Count; j++) { - + var index = IsLowerAlign ? _rowList.Count - 1 - j : j; - + var rowChild = _rowList[index]; - + var rowChildWidth = LayoutUtility.GetPreferredSize(rowChild, 0) + extraWidth; var rowChildHeight = LayoutUtility.GetPreferredSize(rowChild, 1); - + if (ChildForceExpandHeight) rowChildHeight = rowHeight; - + rowChildWidth = Mathf.Min(rowChildWidth, maxWidth); - + var yPos = yOffset; if (IsMiddleAlign) @@ -229,25 +244,31 @@ namespace UnityEngine.UI.Extensions else if (IsLowerAlign) yPos += (rowHeight - rowChildHeight); + // + if (ExpandHorizontalSpacing && j > 0) + xPos += extraSpacing; + if (axis == 0) SetChildAlongAxis(rowChild, 0, xPos, rowChildWidth); else SetChildAlongAxis(rowChild, 1, yPos, rowChildHeight); - xPos += rowChildWidth + Spacing; + // Don't do horizontal spacing for the last one + if (j < _rowList.Count - 1 ) + xPos += rowChildWidth + SpacingX; } } - + public float GetGreatestMinimumChildWidth() { var max = 0f; - + for (var i = 0; i < rectChildren.Count; i++) { var w = LayoutUtility.GetMinWidth(rectChildren[i]); - + max = Mathf.Max(w, max); } - + return max; } } diff --git a/Scripts/FlowLayoutGroup.cs.meta b/Scripts/Layout/FlowLayoutGroup.cs.meta similarity index 100% rename from Scripts/FlowLayoutGroup.cs.meta rename to Scripts/Layout/FlowLayoutGroup.cs.meta diff --git a/Scripts/HorizontalScrollSnap.cs b/Scripts/Layout/HorizontalScrollSnap.cs similarity index 96% rename from Scripts/HorizontalScrollSnap.cs rename to Scripts/Layout/HorizontalScrollSnap.cs index aafef0a..d2e6f2a 100644 --- a/Scripts/HorizontalScrollSnap.cs +++ b/Scripts/Layout/HorizontalScrollSnap.cs @@ -8,7 +8,7 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { [RequireComponent(typeof(ScrollRect))] - [AddComponentMenu("UI/Extensions/Horizontal Scroll Snap")] + [AddComponentMenu("Layout/Extensions/Horizontal Scroll Snap")] public class HorizontalScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler { private Transform _screensContainer; diff --git a/Scripts/HorizontalScrollSnap.cs.meta b/Scripts/Layout/HorizontalScrollSnap.cs.meta similarity index 100% rename from Scripts/HorizontalScrollSnap.cs.meta rename to Scripts/Layout/HorizontalScrollSnap.cs.meta diff --git a/Scripts/Layout/RadialLayout.cs b/Scripts/Layout/RadialLayout.cs new file mode 100644 index 0000000..9982877 --- /dev/null +++ b/Scripts/Layout/RadialLayout.cs @@ -0,0 +1,81 @@ + +/// Credit ?? +/// Sourced from - http://www.justapixel.co.uk/radial-layouts-nice-and-simple-in-unity3ds-ui-system/ +/// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect. + +/* +Radial Layout Group by Just a Pixel (Danny Goodayle) - http://www.justapixel.co.uk +Copyright (c) 2015 +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +namespace UnityEngine.UI.Extensions +{ +[AddComponentMenu("Layout/Extensions/Radial Layout")] +public class RadialLayout : LayoutGroup { + public float fDistance; + [Range(0f,360f)] + public float MinAngle, MaxAngle, StartAngle; + protected override void OnEnable() { base.OnEnable(); CalculateRadial(); } + public override void SetLayoutHorizontal() + { + } + public override void SetLayoutVertical() + { + } + public override void CalculateLayoutInputVertical() + { + CalculateRadial(); + } + public override void CalculateLayoutInputHorizontal() + { + CalculateRadial(); + } + protected override void OnValidate() + { + base.OnValidate(); + CalculateRadial(); + } + void CalculateRadial() + { + m_Tracker.Clear(); + if (transform.childCount == 0) + return; + float fOffsetAngle = ((MaxAngle - MinAngle)) / (transform.childCount -1); + + float fAngle = StartAngle; + for (int i = 0; i < transform.childCount; i++) + { + RectTransform child = (RectTransform)transform.GetChild(i); + if (child != null) + { + //Adding the elements to the tracker stops the user from modifiying their positions via the editor. + m_Tracker.Add(this, child, + DrivenTransformProperties.Anchors | + DrivenTransformProperties.AnchoredPosition | + DrivenTransformProperties.Pivot); + Vector3 vPos = new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0); + child.localPosition = vPos * fDistance; + //Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points. + child.anchorMin = child.anchorMax = child.pivot = new Vector2(0.5f, 0.5f); + fAngle += fOffsetAngle; + } + } + + } +} +} diff --git a/Scripts/Layout/RadialLayout.cs.meta b/Scripts/Layout/RadialLayout.cs.meta new file mode 100644 index 0000000..167703a --- /dev/null +++ b/Scripts/Layout/RadialLayout.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1ebce7906e5d20a4fb26d8b510b81926 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/Layout/TileSizeFitter.cs b/Scripts/Layout/TileSizeFitter.cs new file mode 100644 index 0000000..ee8abfb --- /dev/null +++ b/Scripts/Layout/TileSizeFitter.cs @@ -0,0 +1,104 @@ +/// Credit ?? +/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-3#post-2280109 + +using System.Collections; +using UnityEngine.EventSystems; + +namespace UnityEngine.UI.Extensions +{ +[ExecuteInEditMode] +[RequireComponent(typeof(RectTransform))] +[AddComponentMenu("Layout/Extensions/Tile Size Fitter")] +public class TileSizeFitter : UIBehaviour, ILayoutSelfController +{ + [SerializeField] private Vector2 m_Border = Vector2.zero; + public Vector2 Border { get { return m_Border; } set { if (SetPropertyUtility.SetStruct(ref m_Border, value)) SetDirty(); } } + + [SerializeField] private Vector2 m_TileSize = Vector2.zero; + public Vector2 TileSize { get { return m_TileSize; } set { if (SetPropertyUtility.SetStruct(ref m_TileSize, value)) SetDirty(); } } + + [System.NonSerialized] private RectTransform m_Rect; + private RectTransform rectTransform { get { if (m_Rect == null) m_Rect = GetComponent(); return m_Rect; } } + + private DrivenRectTransformTracker m_Tracker; + + #region Unity Lifetime calls + + protected override void OnEnable() + { + base.OnEnable(); + SetDirty(); + } + + protected override void OnDisable() + { + m_Tracker.Clear(); + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + base.OnDisable(); + } + + #endregion + + protected override void OnRectTransformDimensionsChange() + { + UpdateRect(); + } + + private void UpdateRect() + { + if (!IsActive()) + return; + + m_Tracker.Clear(); + + m_Tracker.Add(this, rectTransform, + DrivenTransformProperties.Anchors | + DrivenTransformProperties.AnchoredPosition); + rectTransform.anchorMin = Vector2.zero; + rectTransform.anchorMax = Vector2.one; + rectTransform.anchoredPosition = Vector2.zero; + + m_Tracker.Add(this, rectTransform, + DrivenTransformProperties.SizeDeltaX | + DrivenTransformProperties.SizeDeltaY); + Vector2 sizeDelta = GetParentSize() - Border; + if (TileSize.x > 0.001f) + sizeDelta.x -= Mathf.Floor(sizeDelta.x / TileSize.x) * TileSize.x; + else + sizeDelta.x = 0; + if (TileSize.y > 0.001f) + sizeDelta.y -= Mathf.Floor(sizeDelta.y / TileSize.y) * TileSize.y; + else + sizeDelta.y = 0; + rectTransform.sizeDelta = -sizeDelta; + } + + private Vector2 GetParentSize() + { + RectTransform parent = rectTransform.parent as RectTransform; + if (!parent) + return Vector2.zero; + return parent.rect.size; + } + + public virtual void SetLayoutHorizontal() { } + public virtual void SetLayoutVertical() { } + + protected void SetDirty() + { + if (!IsActive()) + return; + + UpdateRect(); + } + +#if UNITY_EDITOR + protected override void OnValidate() + { + m_TileSize.x = Mathf.Clamp(m_TileSize.x, 0.001f, 1000f); + m_TileSize.y = Mathf.Clamp(m_TileSize.y, 0.001f, 1000f); + SetDirty(); + } +#endif +} +} \ No newline at end of file diff --git a/Scripts/Layout/TileSizeFitter.cs.meta b/Scripts/Layout/TileSizeFitter.cs.meta new file mode 100644 index 0000000..1a442d3 --- /dev/null +++ b/Scripts/Layout/TileSizeFitter.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 614c629b8dffdb548b9bef9189606bb9 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/VerticalScrollSnap.cs b/Scripts/Layout/VerticalScrollSnap.cs similarity index 96% rename from Scripts/VerticalScrollSnap.cs rename to Scripts/Layout/VerticalScrollSnap.cs index 44ead39..58f20e7 100644 --- a/Scripts/VerticalScrollSnap.cs +++ b/Scripts/Layout/VerticalScrollSnap.cs @@ -8,7 +8,7 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { [RequireComponent(typeof(ScrollRect))] - [AddComponentMenu("UI/Extensions/Vertical Scroll Snap")] + [AddComponentMenu("Layout/Extensions/Vertical Scroll Snap")] public class VerticalScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler { private Transform _screensContainer; diff --git a/Scripts/VerticalScrollSnap.cs.meta b/Scripts/Layout/VerticalScrollSnap.cs.meta similarity index 100% rename from Scripts/VerticalScrollSnap.cs.meta rename to Scripts/Layout/VerticalScrollSnap.cs.meta diff --git a/Scripts/Primatives.meta b/Scripts/Primatives.meta new file mode 100644 index 0000000..ab52354 --- /dev/null +++ b/Scripts/Primatives.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: ce526e6e0c6202e4e9c5ee35dd79295d +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/Primatives/UICircle.cs b/Scripts/Primatives/UICircle.cs new file mode 100644 index 0000000..3d745e5 --- /dev/null +++ b/Scripts/Primatives/UICircle.cs @@ -0,0 +1,121 @@ +/// Credit ?? +/// Sourced from - http://forum.unity3d.com/threads/draw-circles-or-primitives-on-the-new-ui-canvas.272488/#post-2293224 + +using System.Collections.Generic; + +namespace UnityEngine.UI.Extensions +{ + [AddComponentMenu("UI/Extensions/Primatives/UI Circle")] + public class UICircle : Graphic + { + [SerializeField] + Texture m_Texture; + [Range(0, 100)] + public int fillPercent = 100; + public bool fill = true; + public float thickness = 5; + [Range(0, 360)] + public int segments = 360; + + public override Texture mainTexture + { + get + { + return m_Texture == null ? s_WhiteTexture : m_Texture; + } + } + + + /// + /// Texture to be used. + /// + public Texture texture + { + get + { + return m_Texture; + } + set + { + if (m_Texture == value) + return; + + m_Texture = value; + SetVerticesDirty(); + SetMaterialDirty(); + } + } + + protected void SetVbo(List vbo, Vector2[] vertices, Vector2[] uvs) + { + for (int i = 0; i < vertices.Length; i++) + { + var vert = UIVertex.simpleVert; + vert.color = color; + vert.position = vertices[i]; + vert.uv0 = uvs[i]; + vbo.Add(vert); + } + } + + + protected override void OnFillVBO(List vbo) + { + float outer = -rectTransform.pivot.x * rectTransform.rect.width; + float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.thickness; + + vbo.Clear(); + + Vector2 prevX = Vector2.zero; + Vector2 prevY = Vector2.zero; + Vector2 uv0 = new Vector2(0, 0); + Vector2 uv1 = new Vector2(0, 1); + Vector2 uv2 = new Vector2(1, 1); + Vector2 uv3 = new Vector2(1, 0); + Vector2 pos0; + Vector2 pos1; + Vector2 pos2; + Vector2 pos3; + + float f = (this.fillPercent / 100f); + float degrees = 360f / segments; + int fa = (int)((segments + 1) * f); + + + for (int i = 0; i < fa; i++) + { + float rad = Mathf.Deg2Rad * (i * degrees); + float c = Mathf.Cos(rad); + float s = Mathf.Sin(rad); + + uv0 = new Vector2(0, 1); + uv1 = new Vector2(1, 1); + uv2 = new Vector2(1, 0); + uv3 = new Vector2(0, 0); + + pos0 = prevX; + pos1 = new Vector2(outer * c, outer * s); + + if (fill) + { + pos2 = Vector2.zero; + pos3 = Vector2.zero; + } + else + { + pos2 = new Vector2(inner * c, inner * s); + pos3 = prevY; + } + + prevX = pos1; + prevY = pos2; + + SetVbo(vbo, new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }); + + } + + } + + + } +} \ No newline at end of file diff --git a/Scripts/Primatives/UICircle.cs.meta b/Scripts/Primatives/UICircle.cs.meta new file mode 100644 index 0000000..b321084 --- /dev/null +++ b/Scripts/Primatives/UICircle.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8185cad1aa202d04ebb9e14ffa533a87 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/UILineRenderer.cs b/Scripts/Primatives/UILineRenderer.cs similarity index 96% rename from Scripts/UILineRenderer.cs rename to Scripts/Primatives/UILineRenderer.cs index e1b0700..a3d5273 100644 --- a/Scripts/UILineRenderer.cs +++ b/Scripts/Primatives/UILineRenderer.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace UnityEngine.UI.Extensions { - [AddComponentMenu("UI/Extensions/UILineRenderer")] + [AddComponentMenu("UI/Extensions/Primatives/UILineRenderer")] public class UILineRenderer : MaskableGraphic { [SerializeField] diff --git a/Scripts/UILineRenderer.cs.meta b/Scripts/Primatives/UILineRenderer.cs.meta similarity index 100% rename from Scripts/UILineRenderer.cs.meta rename to Scripts/Primatives/UILineRenderer.cs.meta diff --git a/Scripts/UILineTextureRenderer.cs b/Scripts/Primatives/UILineTextureRenderer.cs similarity index 96% rename from Scripts/UILineTextureRenderer.cs rename to Scripts/Primatives/UILineTextureRenderer.cs index fbaaabd..dc6a84d 100644 --- a/Scripts/UILineTextureRenderer.cs +++ b/Scripts/Primatives/UILineTextureRenderer.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace UnityEngine.UI.Extensions { - [AddComponentMenu("UI/Extensions/UILineTextureRenderer")] + [AddComponentMenu("UI/Extensions/Primatives/UILineTextureRenderer")] public class UILineTextureRenderer : MaskableGraphic { [SerializeField] diff --git a/Scripts/UILineTextureRenderer.cs.meta b/Scripts/Primatives/UILineTextureRenderer.cs.meta similarity index 100% rename from Scripts/UILineTextureRenderer.cs.meta rename to Scripts/Primatives/UILineTextureRenderer.cs.meta diff --git a/Scripts/Utilities.meta b/Scripts/Utilities.meta new file mode 100644 index 0000000..19e3a76 --- /dev/null +++ b/Scripts/Utilities.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 8ed31929d883df147b53ffeddcb4f25c +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/SetPropertyUtility.cs b/Scripts/Utilities/SetPropertyUtility.cs similarity index 100% rename from Scripts/SetPropertyUtility.cs rename to Scripts/Utilities/SetPropertyUtility.cs diff --git a/Scripts/SetPropertyUtility.cs.meta b/Scripts/Utilities/SetPropertyUtility.cs.meta similarity index 100% rename from Scripts/SetPropertyUtility.cs.meta rename to Scripts/Utilities/SetPropertyUtility.cs.meta diff --git a/Scripts/Utilities/switchToRectTransform.cs b/Scripts/Utilities/switchToRectTransform.cs new file mode 100644 index 0000000..fa72367 --- /dev/null +++ b/Scripts/Utilities/switchToRectTransform.cs @@ -0,0 +1,24 @@ +/// Credit ?? +/// Sourced from - http://forum.unity3d.com/threads/find-anchoredposition-of-a-recttransform-relative-to-another-recttransform.330560/#post-2300992 + +namespace UnityEngine.UI.Extensions +{ + + public static class RectTransformExtension + { +/// +/// Converts the anchoredPosition of the first RectTransform to the second RectTransform, +/// taking into consideration offset, anchors and pivot, and returns the new anchoredPosition +/// +public static Vector2 switchToRectTransform(this RectTransform from, RectTransform to) + { + Vector2 localPoint; + Vector2 fromPivotDerivedOffset = new Vector2(from.rect.width * from.pivot.x + from.rect.xMin, from.rect.height * from.pivot.y + from.rect.yMin); + Vector2 screenP = RectTransformUtility.WorldToScreenPoint(null, from.position); + screenP += fromPivotDerivedOffset; + RectTransformUtility.ScreenPointToLocalPointInRectangle(to, screenP, null, out localPoint); + Vector2 pivotDerivedOffset = new Vector2(to.rect.width * to.pivot.x + to.rect.xMin, to.rect.height * to.pivot.y + to.rect.yMin); + return to.anchoredPosition + localPoint - pivotDerivedOffset; + } + } +} \ No newline at end of file diff --git a/Scripts/Utilities/switchToRectTransform.cs.meta b/Scripts/Utilities/switchToRectTransform.cs.meta new file mode 100644 index 0000000..3a4c175 --- /dev/null +++ b/Scripts/Utilities/switchToRectTransform.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 977482c1b88728145ba612c0fdec3b92 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/package.json b/package.json new file mode 100644 index 0000000..229fcd4 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "Unity UI Extensions", + "version": "1.0.4", + "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", + "author": "Simon darkside Jackson <@SimonDarksideJ>", + "contributors": [{ + "name": "Foo Bar", + "email": "foo.bar@example.com" +}], + "repository": { + "type": "hg", + "url": "https://ddreaper@bitbucket.org/ddreaper/unity-ui-extensions" +}, + "bugs": { + "url": "https://bitbucket.org/ddreaper/unity-ui-extensions/issues" +}, + "keywords": [ + "nodejitsu", + "example", + "browsenpm" +], + "license": "MIT" +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..c07e1f7 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: 1dbb3faeb54e2a4498b2472b8760548b +TextScriptImporter: + userData: