Merged new controls / features / readme added in 4.x series
Added new DiamondGraph primitive --HG-- branch : develop_5.2release
commit
f543bdb568
43
README.md
43
README.md
|
@ -36,8 +36,6 @@ Control | Description | Menu Command | Component Command | Notes | Credits
|
|||
| | | Component / UI / Extensions / AccordionItem |[demo video](http://forum.unity3d.com/threads/accordion-type-layout.271818/)| ChoMPHi
|
||||
**HSVPicker** | A colour picker UI | N/A | UI / Extensions / HSVPicker | Project folder includes prefab and sample scene | judah4
|
||||
**SelectionBox** | An RTS style selection box control | UI / Extensions / Selection Box | UI / Extensions / Selection Box |[tutorial video](https://www.youtube.com/watch?v=UtM3HejKL5s)| Korindian, BenZed
|
||||
**HorizontalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | UI / Extensions / Horizontal Scroll Snap | UI / Extensions / Horizontal Scroll Snap |[tutorial video](https://www.youtube.com/watch?v=KJlIlWHlfMo)| BinaryX
|
||||
**VerticalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | UI / Extensions / Vertical Scroll Snap | UI / Extensions / Vertical Scroll Snap |[tutorial video](https://www.youtube.com/watch?v=KJlIlWHlfMo)| BinaryX, Simon Darkside Jackson
|
||||
**UIButton** | Improved Button control with additional events (PointerDown, PointerUp, PointerClick and PointerHeld) | UI / Extensions / UI Button | UI / Extensions / UI Button |Will update video, this has now been updated to a more reusable Selectable extension| AriathTheWise
|
||||
**UIFlippable** | Improved Image control with image flipping options | UI / Extensions / UI Flippable | UI / Extensions / Flippable |[tutorial video](https://www.youtube.com/watch?v=Htt2RNa2qy0)| ChoMPHi
|
||||
**UIWindowBase** | A draggable Window implementation | UI / Extensions / UI Window Base | UI / Extensions / UI Window Base |[tutorial video](https://www.youtube.com/watch?v=Htt2RNa2qy0)| GXMark, alexzzzz, CaoMengde777, TroyDavis
|
||||
|
@ -46,8 +44,32 @@ Control | Description | Menu Command | Component Command | Notes | Credits
|
|||
**DropDownList** | A basic drop down list with text and image support | UI / Extensions / Dropdown List | UI / Extensions / Dropdown List |[tutorial video](https://www.youtube.com/watch?v=JrEfs47FoOE)| Perchik
|
||||
**BoundToolTip** | An alternate Tooltip implementation with central listener | UI / Extensions / Bound Tooltip / Tooltip | UI / Extensions / Bound Tooltip / Tooltip Item | Offset and tooltip placement needs work | Martin Sharkbomb
|
||||
| | | UI / Extensions / Bound Tooltip / Tooltip Trigger | | Martin Sharkbomb
|
||||
**LineRenderer** | Graphic control for drawing lines in the UI System | UI / Extensions / UI Line Renderer | UI / Extensions / UI Line Renderer |[tutorial video](https://www.youtube.com/watch?v=OElcWAZGHi0)| jack.sydorenko
|
||||
**UILineTextureRenderer** | Graphic control for drawing lines in the UI System | UI / Extensions / UI Line Texture Renderer | UI / Extensions / UI Line Texture Renderer |[tutorial video](https://www.youtube.com/watch?v=OElcWAZGHi0)| jack.sydorenko, jonbro5556
|
||||
|
||||
|
||||
## Primatives ##
|
||||
================
|
||||
|
||||
Control | Description | Menu Command | Component Command | Notes | Credits
|
||||
--------- | -------------- | ---------------------- | ---------------------------- | ------- | ----------
|
||||
**LineRenderer** | Graphic control for drawing lines in the UI System | UI / Extensions / Primatives / UI Line Renderer | UI / Extensions / Primatives / UI Line Renderer |[tutorial video](https://www.youtube.com/watch?v=OElcWAZGHi0)| jack.sydorenko
|
||||
**UILineTextureRenderer** | Graphic control for drawing lines in the UI System | UI / Extensions / Primatives / UI Line Texture Renderer | UI / Extensions / Primatives / UI Line Texture Renderer |[tutorial video](https://www.youtube.com/watch?v=OElcWAZGHi0)| jack.sydorenko, jonbro5556
|
||||
**UICircle** | Graphic control for drawing circles in the UI System | UI / Extensions / Primatives / UI Circle | UI / Extensions / Primatives / UI Circle || zge
|
||||
**DiamondGraph** | Graphic control for drawing a diamond in the UI System | UI / Extensions / Primatives / DiamondGraph | UI / Extensions / Primatives / DiamondGraph |5.2+ only| koohddang
|
||||
|
||||
|
||||
|
||||
## Layouts ##
|
||||
================
|
||||
|
||||
Layout | Description | Menu Command | Component Command | Notes | Credits
|
||||
--------- | -------------- | ---------------------- | ---------------------------- | ------- | ----------
|
||||
**HorizontalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | Layout / Extensions / Horizontal Scroll Snap | Layout / Extensions / Horizontal Scroll Snap |[tutorial video](https://www.youtube.com/watch?v=KJlIlWHlfMo)| BinaryX
|
||||
**VerticalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | Layout / Extensions / Vertical Scroll Snap | Layout / Extensions / Vertical Scroll Snap |[tutorial video](https://www.youtube.com/watch?v=KJlIlWHlfMo)| BinaryX, Simon Darkside Jackson
|
||||
**FlowLayoutGroup** | A more rugged grid style layout group || Layout / Extensions / Flow Layout Group | [Example Video](https://www.youtube.com/watch?v=tMe_3tJTZvc) | Simie
|
||||
**RadialLayout** | A radial layout system || Layout / Extensions / Radial Layout || Danny Goodayle
|
||||
**TileSizeFitter** | A fitter layout that will shink / expand content by tiles || Layout / Extensions / TileSizeFitter || Ges
|
||||
|
||||
|
||||
|
||||
## Effect components ##
|
||||
=====================
|
||||
|
@ -62,6 +84,14 @@ Effect | Description | Component Command | Notes | Credits
|
|||
**RaycastMask** | An example of an enhanced mask component able to work with the image data. Enables picking on image parts and not just the Rect Transform | UI / Effects / Extensions / Raycast Mask | | senritsu
|
||||
**UIFlippable** | Image component effect to flip the graphic | UI / Effects / Extensions / UI Flippable | | ChoMPHi
|
||||
|
||||
## VR Components##
|
||||
=======================
|
||||
|
||||
Component | Description | Component Command | Notes | Credits
|
||||
--------- | -------------- | ---------------------------- | ------- | ------
|
||||
**VRCursor** | Cursor script for VR use (requires VRInputModule) | UI / Extensions / VR Cursoe | | Ralph Barbagallo
|
||||
**VRInputModule** | Input module to support the VR Cursor | Event / Vr Input Module | | Ralph Barbagallo
|
||||
|
||||
|
||||
## Additional Components##
|
||||
=======================
|
||||
|
@ -71,7 +101,6 @@ Component | Description | Component Command | Notes | Credits
|
|||
**ReturnKeyTrigger** | Does something?? | UI / Extensions / ReturnKey Trigger | | Melang, ddreaper
|
||||
**TabNavigation** | An example Tab navigation script, updated to add manual navigation | UI / Extensions / Tab Navigation | | Melang, omatase
|
||||
**uGUITools** | | Menu / uGUI | | Senshi
|
||||
**FlowLayoutGroup** | A more rugged grid style layout group | Layout / Extensions / Flow Layout Group | [Example Video](https://www.youtube.com/watch?v=tMe_3tJTZvc) | Simie
|
||||
**ScrollRectTweener** | Tweening solution for ScrollRects, add smoothing automatically | UI / Extensions / ScrollRectTweener | | Martin Sharkbomb
|
||||
**ScrollRectLinker** | ScrollRect Linker script, enable multiple ScrollRects to move together | UI / Extensions / ScrollRectLinker | | Martin Sharkbomb
|
||||
**ScrollRectEx** | Improved ScrollRect control, enables support for Nested ScrollRects | UI / Extensions / ScrollRectEx | | CaptainSchnittchen, GamesRUs
|
||||
|
@ -79,11 +108,13 @@ Component | Description | Component Command | Notes | Credits
|
|||
**ImageExtended** | Improved Image control with rotation support and use of filled type without an Image (useful for masks) | UI / Extensions / Image Extended | | Ges
|
||||
**UIScrollToSelection** | Enables a ScrollRect to scroll based on the selected child automatically | UI / Extensions / UIScrollToSelection | | zero3growlithe
|
||||
**AimerInputModule** | Replacement Input module to allow for a reciclue to interace with WorldSpace canvas UI | UI / Extensions / Aimer Input Module | | Chris Trueman
|
||||
**UISeclectableExtension** | Refactor of original UI Button control, can now add Press/Release and Hold events to any Selectable control | UI / Extensions / UI Selectable Extension | | AriathTheWise / Simon Jackson
|
||||
**UISelectableExtension** | Refactor of original UI Button control, can now add Press/Release and Hold events to any Selectable control | UI / Extensions / UI Selectable Extension | | AriathTheWise / Simon Jackson
|
||||
**switchToRectTransform** | RectTransform extension method to move one Rect to another | N/A | | Izitmee
|
||||
|
||||
|
||||
*More to come*
|
||||
|
||||
=======================
|
||||
### How do I get set up? ###
|
||||
|
||||
Either clone / download this repository to your machine and then copy the scripts in, or use the pre-packaged .UnityPackage for your version of Unity and import it as a custom package in to your project.
|
||||
|
|
|
@ -207,7 +207,7 @@ namespace UnityEditor.UI
|
|||
|
||||
#region UI Extensions "Create" Menu items
|
||||
|
||||
[MenuItem("GameObject/UI/Extensions/Horizontal Scroll Snap", false)]
|
||||
[MenuItem("GameObject/Layout/Extensions/Horizontal Scroll Snap", false)]
|
||||
static public void AddHorizontalScrollSnap(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject horizontalScrollSnapRoot = CreateUIElementRoot("Horizontal Scroll Snap", menuCommand, s_ThickGUIElementSize);
|
||||
|
@ -278,7 +278,7 @@ namespace UnityEditor.UI
|
|||
Selection.activeGameObject = horizontalScrollSnapRoot;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/UI/Extensions/Vertical Scroll Snap", false)]
|
||||
[MenuItem("GameObject/Layout/Extensions/Vertical Scroll Snap", false)]
|
||||
static public void AddVerticallScrollSnap(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject verticalScrollSnapRoot = CreateUIElementRoot("Vertical Scroll Snap", menuCommand, s_ThickGUIElementSize);
|
||||
|
@ -866,7 +866,7 @@ namespace UnityEditor.UI
|
|||
SetDefaultColorTransitionValues(slider);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/UI/Extensions/UI Line Renderer", false)]
|
||||
[MenuItem("GameObject/UI/Extensions/Primitives/UI Line Renderer", false)]
|
||||
static public void AddUILineRenderer(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject go = CreateUIElementRoot("UI LineRenderer", menuCommand, s_ImageGUIElementSize);
|
||||
|
@ -874,13 +874,29 @@ namespace UnityEditor.UI
|
|||
Selection.activeGameObject = go;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/UI/Extensions/UI Line Texture Renderer", false)]
|
||||
[MenuItem("GameObject/UI/Extensions/Primitives/UI Line Texture Renderer", false)]
|
||||
static public void AddUILineTextureRenderer(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject go = CreateUIElementRoot("UI LineTextureRenderer", menuCommand, s_ImageGUIElementSize);
|
||||
go.AddComponent<UILineTextureRenderer>();
|
||||
Selection.activeGameObject = go;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/UI/Extensions/Primitives/UI Circle", false)]
|
||||
static public void AddUICircle(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject go = CreateUIElementRoot("UI Circle", menuCommand, s_ImageGUIElementSize);
|
||||
go.AddComponent<UICircle>();
|
||||
Selection.activeGameObject = go;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/UI/Extensions/Primitives/Diamond Graph", false)]
|
||||
static public void AddDiamondGraph(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject go = CreateUIElementRoot("Diamond Graph", menuCommand, s_ImageGUIElementSize);
|
||||
go.AddComponent<DiamondGraph>();
|
||||
Selection.activeGameObject = go;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/// Credit Vicente Russo
|
||||
/// Sourced from - https://bitbucket.org/ddreaper/unity-ui-extensions/issues/23/returnkeytriggersbutton
|
||||
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Usage: Add this component to the input and add the function to execute to the EnterSubmit event of this script
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(InputField))]
|
||||
[AddComponentMenu("UI/Extensions/Input Field Submit")]
|
||||
public class InputFieldEnterSubmit : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class EnterSubmitEvent : UnityEvent<string> { }
|
||||
|
||||
public EnterSubmitEvent EnterSubmit;
|
||||
private InputField _input;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_input = GetComponent<InputField>();
|
||||
_input.onEndEdit.AddListener(OnEndEdit);
|
||||
}
|
||||
|
||||
public void OnEndEdit(string txt)
|
||||
{
|
||||
if (!Input.GetKeyDown(KeyCode.Return) && !Input.GetKeyDown(KeyCode.KeypadEnter)) return;
|
||||
EnterSubmit.Invoke(txt);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bfc77d7b04a86f845b59fb0979e8ec53
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -0,0 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 759c961dc0e85a348ab9cd1278319ca0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Holds the rects that will make up the current row being processed
|
||||
/// </summary>
|
||||
private readonly IList<RectTransform> _rowList = new List<RectTransform>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Main layout method
|
||||
/// </summary>
|
||||
|
@ -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 -= 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<RectTransform> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
/// Credit Danny Goodayle
|
||||
/// 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();
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnValidate()
|
||||
{
|
||||
base.OnValidate();
|
||||
CalculateRadial();
|
||||
}
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ebce7906e5d20a4fb26d8b510b81926
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -0,0 +1,107 @@
|
|||
/// Credit Ges
|
||||
/// 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<RectTransform>(); 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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 614c629b8dffdb548b9bef9189606bb9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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;
|
|
@ -0,0 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce526e6e0c6202e4e9c5ee35dd79295d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
|
@ -0,0 +1,41 @@
|
|||
/// Credit koohddang
|
||||
/// Sourced from - http://forum.unity3d.com/threads/onfillvbo-to-onpopulatemesh-help.353977/#post-2299311
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("UI/Extensions/Primitives/Diamond Graph")]
|
||||
public class DiamondGraph : Graphic
|
||||
{
|
||||
public float a = 1;
|
||||
public float b = 1;
|
||||
public float c = 1;
|
||||
public float d = 1;
|
||||
|
||||
protected override void OnPopulateMesh(Mesh m)
|
||||
{
|
||||
float wHalf = rectTransform.rect.width / 2;
|
||||
//float hHalf = rectTransform.rect.height / 2;
|
||||
a = Math.Min(1, Math.Max(0, a));
|
||||
b = Math.Min(1, Math.Max(0, b));
|
||||
c = Math.Min(1, Math.Max(0, c));
|
||||
d = Math.Min(1, Math.Max(0, d));
|
||||
|
||||
Color32 color32 = color;
|
||||
using (var vh = new VertexHelper())
|
||||
{
|
||||
vh.AddVert(new Vector3(-wHalf * a, 0), color32, new Vector2(0f, 0f));
|
||||
vh.AddVert(new Vector3(0, wHalf * b), color32, new Vector2(0f, 1f));
|
||||
vh.AddVert(new Vector3(wHalf * c, 0), color32, new Vector2(1f, 1f));
|
||||
vh.AddVert(new Vector3(0, -wHalf * d), color32, new Vector2(1f, 0f));
|
||||
|
||||
vh.AddTriangle(0, 1, 2);
|
||||
vh.AddTriangle(2, 3, 0);
|
||||
vh.FillMesh(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 891530df3841c0041ab9982359e02e0f
|
||||
timeCreated: 1442708993
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,133 @@
|
|||
/// Credit zge
|
||||
/// 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/Primitives/UI Circle")]
|
||||
public class UICircle : Graphic
|
||||
{
|
||||
[SerializeField]
|
||||
Texture m_Texture;
|
||||
[Range(0, 100)]
|
||||
public int fillPercent = 100;
|
||||
public bool fill = true;
|
||||
public int thickness = 5;
|
||||
[Range(0, 360)]
|
||||
public int segments = 360;
|
||||
|
||||
public override Texture mainTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Texture == null ? s_WhiteTexture : m_Texture;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Texture to be used.
|
||||
/// </summary>
|
||||
public Texture texture
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Texture;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (m_Texture == value)
|
||||
return;
|
||||
|
||||
m_Texture = value;
|
||||
SetVerticesDirty();
|
||||
SetMaterialDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
this.thickness = (int)Mathf.Clamp(this.thickness, 0, rectTransform.rect.width / 2);
|
||||
}
|
||||
|
||||
protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs)
|
||||
{
|
||||
UIVertex[] vbo = new UIVertex[4];
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
var vert = UIVertex.simpleVert;
|
||||
vert.color = color;
|
||||
vert.position = vertices[i];
|
||||
vert.uv0 = uvs[i];
|
||||
vbo[i] = vert;
|
||||
}
|
||||
return vbo;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnPopulateMesh(Mesh toFill)
|
||||
{
|
||||
float outer = -rectTransform.pivot.x * rectTransform.rect.width;
|
||||
float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.thickness;
|
||||
|
||||
toFill.Clear();
|
||||
var vbo = new VertexHelper(toFill);
|
||||
|
||||
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;
|
||||
|
||||
vbo.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
|
||||
|
||||
}
|
||||
|
||||
if (vbo.currentVertCount > 3)
|
||||
{
|
||||
vbo.FillMesh(toFill);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8185cad1aa202d04ebb9e14ffa533a87
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[AddComponentMenu("UI/Extensions/UILineRenderer")]
|
||||
[AddComponentMenu("UI/Extensions/Primitives/UILineRenderer")]
|
||||
public class UILineRenderer : MaskableGraphic
|
||||
{
|
||||
[SerializeField]
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[AddComponentMenu("UI/Extensions/UILineTextureRenderer")]
|
||||
[AddComponentMenu("UI/Extensions/Primitives/UILineTextureRenderer")]
|
||||
public class UILineTextureRenderer : MaskableGraphic
|
||||
{
|
||||
[SerializeField]
|
|
@ -0,0 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ed31929d883df147b53ffeddcb4f25c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
|
@ -0,0 +1,24 @@
|
|||
/// Credit Izitmee
|
||||
/// Sourced from - http://forum.unity3d.com/threads/find-anchoredposition-of-a-recttransform-relative-to-another-recttransform.330560/#post-2300992
|
||||
/// Updated by Brave Michael - 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the anchoredPosition of the first RectTransform to the second RectTransform,
|
||||
/// taking into consideration offset, anchors and pivot, and returns the new anchoredPosition
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 977482c1b88728145ba612c0fdec3b92
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -0,0 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c84a253080bc0ec4995041aa5a6656ae
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
|
@ -0,0 +1,49 @@
|
|||
/// Credit Ralph Barbagallo (www.flarb.com /www.ralphbarbagallo.com / @flarb)
|
||||
/// Sourced from - http://forum.unity3d.com/threads/vr-cursor-possible-unity-4-6-gui-bug-or-is-it-me
|
||||
|
||||
using System.Collections;
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[AddComponentMenu("UI/Extensions/VR Cursor")]
|
||||
public class VRCursor : MonoBehaviour
|
||||
{
|
||||
public float xSens;
|
||||
public float ySens;
|
||||
|
||||
private Collider currentCollider;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 thisPosition;
|
||||
|
||||
thisPosition.x = Input.mousePosition.x * xSens;
|
||||
thisPosition.y = Input.mousePosition.y * ySens - 1;
|
||||
thisPosition.z = transform.position.z;
|
||||
|
||||
transform.position = thisPosition;
|
||||
|
||||
VRInputModule.cursorPosition = transform.position;
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && currentCollider)
|
||||
{
|
||||
VRInputModule.PointerSubmit(currentCollider.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
//print("OnTriggerEnter other " + other.gameObject);
|
||||
VRInputModule.PointerEnter(other.gameObject);
|
||||
currentCollider = other;
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
//print("OnTriggerExit other " + other.gameObject);
|
||||
VRInputModule.PointerExit(other.gameObject);
|
||||
currentCollider = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3d7a94ee2faf9f04696882b3a2cbf035
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -0,0 +1,67 @@
|
|||
/// Credit Ralph Barbagallo (www.flarb.com /www.ralphbarbagallo.com / @flarb)
|
||||
/// Sourced from - http://forum.unity3d.com/threads/vr-cursor-possible-unity-4-6-gui-bug-or-is-it-me
|
||||
/// Fix supplied by - http://forum.unity3d.com/threads/vr-cursor-possible-unity-4-6-gui-bug-or-is-it-me.296934/
|
||||
|
||||
using UnityEngine.EventSystems;
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[AddComponentMenu("Event/VR Input Module")]
|
||||
public class VRInputModule : BaseInputModule
|
||||
{
|
||||
public static GameObject targetObject;
|
||||
|
||||
static VRInputModule _singleton;
|
||||
|
||||
private int counter;
|
||||
|
||||
private static bool mouseClicked;
|
||||
public static Vector3 cursorPosition;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
_singleton = this;
|
||||
}
|
||||
|
||||
public override void Process()
|
||||
{
|
||||
if (targetObject == null)
|
||||
{
|
||||
mouseClicked = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void PointerSubmit(GameObject obj)
|
||||
{
|
||||
targetObject = obj;
|
||||
mouseClicked = true;
|
||||
if (mouseClicked)
|
||||
{
|
||||
//BaseEventData data = GetBaseEventData(); //Original from Process(). Can't be called here so is replaced by the next line:
|
||||
BaseEventData data = new BaseEventData(_singleton.eventSystem);
|
||||
data.selectedObject = targetObject;
|
||||
ExecuteEvents.Execute(targetObject, data, ExecuteEvents.submitHandler);
|
||||
print("clicked " + targetObject.name);
|
||||
mouseClicked = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void PointerExit(GameObject obj)
|
||||
{
|
||||
print("PointerExit " + obj.name);
|
||||
PointerEventData pEvent = new PointerEventData(_singleton.eventSystem);
|
||||
ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.pointerExitHandler);
|
||||
ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.deselectHandler); //This fixes the problem
|
||||
}
|
||||
|
||||
public static void PointerEnter(GameObject obj)
|
||||
{
|
||||
print("PointerEnter " + obj.name);
|
||||
PointerEventData pEvent = new PointerEventData(_singleton.eventSystem);
|
||||
pEvent.pointerEnter = obj;
|
||||
RaycastResult rcr = new RaycastResult() { worldPosition = cursorPosition };
|
||||
pEvent.pointerCurrentRaycast = rcr;
|
||||
ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.pointerEnterHandler);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 303ab8dad3437bf46814373cfb86cc5d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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": "BSD"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1dbb3faeb54e2a4498b2472b8760548b
|
||||
TextScriptImporter:
|
||||
userData:
|
Loading…
Reference in New Issue