Merge 4.x changes in to 5.2.x source

Accepted new UICornerCut component

--HG--
branch : develop_5.2
pull/413/head
Simon (darkside) Jackson 2015-10-09 20:53:04 +01:00
commit 73e92119c6
19 changed files with 1513 additions and 17 deletions

View File

@ -25,7 +25,10 @@ To get started with the project, here's a little guide:
[![View Getting Started Video](http://img.youtube.com/vi/sVLeYmsNQAI/0.jpg)](http://www.youtube.com/watch?v=sVLeYmsNQAI "Unity UI getting started video") [![View Getting Started Video](http://img.youtube.com/vi/sVLeYmsNQAI/0.jpg)](http://www.youtube.com/watch?v=sVLeYmsNQAI "Unity UI getting started video")
--- ---
## Updates: ##
Update 1.0.0.4
[![View Getting Started Video](http://img.youtube.com/vi/oF48Qpaq3ls/0.jpg)](http://www.youtube.com/watch?v=oF48Qpaq3ls "Update 1.0.0.4 for the Unity UI Extensions Project")
---
## Controls and extensions listed in this project are: ## ## Controls and extensions listed in this project are: ##
## Controls ## ## Controls ##
@ -54,9 +57,9 @@ Control | Description | Menu Command | Component Command | Notes | Credits
--------- | -------------- | ---------------------- | ---------------------------- | ------- | ---------- --------- | -------------- | ---------------------- | ---------------------------- | ------- | ----------
**LineRenderer** | Graphic control for drawing lines in the UI System | UI / Extensions / Primitives / UI Line Renderer | UI / Extensions / Primitives / UI Line Renderer |[tutorial video](https://www.youtube.com/watch?v=OElcWAZGHi0)| jack.sydorenko **LineRenderer** | Graphic control for drawing lines in the UI System | UI / Extensions / Primitives / UI Line Renderer | UI / Extensions / Primitives / 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 / Primitives / UI Line Texture Renderer | UI / Extensions / Primitives / UI Line Texture Renderer |[tutorial video](https://www.youtube.com/watch?v=OElcWAZGHi0)| jack.sydorenko, jonbro5556 **UILineTextureRenderer** | Graphic control for drawing lines in the UI System | UI / Extensions / Primitives / UI Line Texture Renderer | UI / Extensions / Primitives / 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 / Primitives / UI Circle | UI / Extensions / Primitives / UI Circle || zge **UICircle** | Graphic control for drawing circles in the UI System | UI / Extensions / Primitives / UI Circle | UI / Extensions / Primitives / UI Circle |[tutorial video](https://www.youtube.com/watch?v=2KOnEKAVua0)| zge
**DiamondGraph** | Graphic control for drawing a diamond in the UI System | UI / Extensions / Primitives / DiamondGraph | UI / Extensions / Primitives / DiamondGraph |5.2+ only| koohddang **DiamondGraph** | Graphic control for drawing a diamond in the UI System | UI / Extensions / Primitives / DiamondGraph | UI / Extensions / Primitives / DiamondGraph |5.2+ only [tutorial video](https://www.youtube.com/watch?v=2KOnEKAVua0)| koohddang
**UICornerCut** | Graphic control for drawing a diamond in the UI System | UI/Extensions/Primitives/Cut Corners | UI/Extensions/Primitives/Cut Corners || Freezy
## Layouts ## ## Layouts ##
@ -67,9 +70,12 @@ Layout | Description | Menu Command | Component Command | Notes | Credits
**HorizontalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | UI / Extensions / Horizontal Scroll Snap | Layout / Extensions / Horizontal Scroll Snap |[tutorial video](https://www.youtube.com/watch?v=KJlIlWHlfMo)| BinaryX **HorizontalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | UI / 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 | UI / Extensions / Vertical Scroll Snap | Layout / Extensions / Vertical Scroll Snap |[tutorial video](https://www.youtube.com/watch?v=KJlIlWHlfMo)| BinaryX, Simon Darkside Jackson **VerticalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | UI / 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 **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 **RadialLayout** | A radial layout system || Layout / Extensions / Radial Layout |[tutorial video](https://www.youtube.com/watch?v=iUlk0d2RDMs)| Danny Goodayle
**TileSizeFitter** | A fitter layout that will shink / expand content by tiles || Layout / Extensions / TileSizeFitter || Ges **TileSizeFitter** | A fitter layout that will shink / expand content by tiles || Layout / Extensions / TileSizeFitter |[tutorial video](https://www.youtube.com/watch?v=AkQNWl8mnxg)| Ges
**ScrollSnap** | An alternate scroll snap control supporting both Horizontal and Vertial layous in one control | UI / Extensions / Fixed Item Scroll / Snap Horizontal Single Item||| xesenix
|| UI / Extensions / Fixed Item Scroll / Snap Horizontal Multiple Item||| xesenix
|| UI / Extensions / Fixed Item Scroll / Snap Vertical Single Item||| xesenix
|| UI / Extensions / Fixed Item Scroll / Snap Vertical Multiple Item||| xesenix
## Effect components ## ## Effect components ##
@ -85,6 +91,7 @@ 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 **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 **UIFlippable** | Image component effect to flip the graphic | UI / Effects / Extensions / UI Flippable | | ChoMPHi
## VR Components## ## VR Components##
======================= =======================
@ -94,6 +101,14 @@ Component | Description | Component Command | Notes | Credits
**VRInputModule** | Input module to support the VR Cursor | Event / Vr Input Module | | Ralph Barbagallo **VRInputModule** | Input module to support the VR Cursor | Event / Vr Input Module | | Ralph Barbagallo
## Input Modules ##
=======================
Component | Description | Component Command | Notes | Credits
--------- | -------------- | ---------------------------- | ------- | ------
**AimerInputModule** | Replacement Input module to allow for a reciclue to interace with WorldSpace canvas UI | Event / Extensions / Aimer Input Module | | Chris Trueman
**GamePadInputModule** | Stripped down SIM Input module for just gamepad/keybord input | Event / Extensions / GamePad Input Module | | Simon (darkside) Jackson
## Additional Components## ## Additional Components##
======================= =======================
@ -108,7 +123,6 @@ Component | Description | Component Command | Notes | Credits
**InputFocus** | Enhanced InputField control for forms, enables Enter to submit and other features | UI / Extensions / InputFocus | | Zelek **InputFocus** | Enhanced InputField control for forms, enables Enter to submit and other features | UI / Extensions / InputFocus | | Zelek
**ImageExtended** | Improved Image control with rotation support and use of filled type without an Image (useful for masks) | UI / Extensions / Image Extended | | Ges **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 **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
**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 **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 **switchToRectTransform** | RectTransform extension method to move one Rect to another | N/A | | Izitmee

View File

@ -898,6 +898,14 @@ namespace UnityEditor.UI
Selection.activeGameObject = go; Selection.activeGameObject = go;
} }
[MenuItem("GameObject/UI/Extensions/Primitives/Cut Corners", false)]
static public void AddCutCorners(MenuCommand menuCommand)
{
GameObject go = CreateUIElementRoot("Cut Corners", menuCommand, s_ImageGUIElementSize);
go.AddComponent<UICornerCut>();
Selection.activeGameObject = go;
}
#endregion #endregion
#region Helper Functions #region Helper Functions
@ -1031,6 +1039,269 @@ namespace UnityEditor.UI
return buttonRoot; return buttonRoot;
} }
#endregion
#region New ScrollSnapCode
static public void FixedScrollSnapBase(MenuCommand menuCommand, string name, ScrollSnap.ScrollDirection direction, int itemVisible, int itemCount, Vector2 itemSize)
{
GameObject scrollSnapRoot = CreateUIElementRoot(name, menuCommand, s_ThickGUIElementSize);
GameObject itemList = CreateUIObject("List", scrollSnapRoot);
// Set RectTransform to stretch
RectTransform rectTransformScrollSnapRoot = scrollSnapRoot.GetComponent<RectTransform>();
rectTransformScrollSnapRoot.anchorMin = new Vector2(0.5f, 0.5f);
rectTransformScrollSnapRoot.anchorMax = new Vector2(0.5f, 0.5f);
rectTransformScrollSnapRoot.anchoredPosition = Vector2.zero;
if (direction == ScrollSnap.ScrollDirection.Horizontal)
{
rectTransformScrollSnapRoot.sizeDelta = new Vector2(itemVisible * itemSize.x, itemSize.y);
}
else
{
rectTransformScrollSnapRoot.sizeDelta = new Vector2(itemSize.x, itemVisible * itemSize.y);
}
Image image = scrollSnapRoot.AddComponent<Image>();
image.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpriteResourcePath);
image.type = Image.Type.Sliced;
image.color = new Color(1f, 1f, 1f, 1f);
Mask listMask = scrollSnapRoot.AddComponent<Mask>();
listMask.showMaskGraphic = false;
ScrollRect scrollRect = scrollSnapRoot.AddComponent<ScrollRect>();
scrollRect.vertical = direction == ScrollSnap.ScrollDirection.Vertical;
scrollRect.horizontal = direction == ScrollSnap.ScrollDirection.Horizontal;
ScrollSnap scrollSnap = scrollSnapRoot.AddComponent<ScrollSnap>();
scrollSnap.direction = direction;
scrollSnap.itemsVisibleAtOnce = itemVisible;
//Setup Content container
RectTransform rectTransformContent = itemList.GetComponent<RectTransform>();
rectTransformContent.anchorMin = Vector2.zero;
rectTransformContent.anchorMax = new Vector2(1f, 1f);
//rectTransformContent.anchoredPosition = Vector2.zero;
rectTransformContent.sizeDelta = Vector2.zero;
scrollRect.content = rectTransformContent;
//Setup Item list container
if (direction == ScrollSnap.ScrollDirection.Horizontal)
{
itemList.AddComponent<HorizontalLayoutGroup> ();
ContentSizeFitter sizeFitter = itemList.AddComponent<ContentSizeFitter>();
sizeFitter.horizontalFit = ContentSizeFitter.FitMode.MinSize;
}
else
{
itemList.AddComponent<VerticalLayoutGroup> ();
ContentSizeFitter sizeFitter = itemList.AddComponent<ContentSizeFitter>();
sizeFitter.verticalFit = ContentSizeFitter.FitMode.MinSize;
}
//Setup children
for (var i = 0; i < itemCount; i ++)
{
GameObject item = CreateUIObject (string.Format("Item_{0:00}", i), itemList);
GameObject childText = CreateUIObject ("Text", item);
Image pageImage = item.AddComponent<Image> ();
pageImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite> (kStandardSpritePath);
pageImage.type = Image.Type.Sliced;
pageImage.color = s_DefaultSelectableColor;
LayoutElement elementLayout = item.AddComponent<LayoutElement> ();
if (direction == ScrollSnap.ScrollDirection.Horizontal)
{
elementLayout.minWidth = itemSize.x;
}
else
{
elementLayout.minHeight = itemSize.y;
}
RectTransform rectTransformPage01 = item.GetComponent<RectTransform> ();
rectTransformPage01.anchorMin = new Vector2 (0f, 0.5f);
rectTransformPage01.anchorMax = new Vector2 (0f, 0.5f);
//rectTransformPage01.anchoredPosition = Vector2.zero;
//rectTransformPage01.sizeDelta = Vector2.zero;
rectTransformPage01.pivot = new Vector2 (0f, 0.5f);
//Setup Text on Page01
Text text = childText.AddComponent<Text> ();
text.text = item.name;
text.alignment = TextAnchor.MiddleCenter;
text.color = new Color (0.196f, 0.196f, 0.196f);
//Setup Text 1st Child
RectTransform rectTransformPage01Text = childText.GetComponent<RectTransform> ();
rectTransformPage01Text.anchorMin = new Vector2 (0.5f, 0.5f);
rectTransformPage01Text.anchorMax = new Vector2 (0.5f, 0.5f);
//rectTransformPage01Text.anchoredPosition = Vector2.zero;
//rectTransformPage01Text.sizeDelta = Vector2.zero;
rectTransformPage01Text.pivot = new Vector2 (0.5f, 0.5f);
}
Selection.activeGameObject = scrollSnapRoot;
}
[MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Horizontal Single Item", false)]
static public void AddFixedItemScrollSnapHorizontalSingle(MenuCommand menuCommand)
{
FixedScrollSnapBase (menuCommand, "Scroll Snap Horizontal Single", ScrollSnap.ScrollDirection.Horizontal, 1, 3, new Vector2(100, 100));
}
[MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Horizontal Multiple Items", false)]
static public void AddFixedItemScrollSnapHorizontalMultiple(MenuCommand menuCommand)
{
FixedScrollSnapBase (menuCommand, "Scroll Snap Horizontal Multiple", ScrollSnap.ScrollDirection.Horizontal, 3, 15, new Vector2(100, 100));
}
[MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Vertical Single Item", false)]
static public void AddFixedItemScrollSnapVerticalSingle(MenuCommand menuCommand)
{
FixedScrollSnapBase (menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 1, 3, new Vector2(100, 100));
}
[MenuItem("GameObject/UI/Extensions/Fixed Item Scroll/Snap Vertical Multiple Items", false)]
static public void AddFixedItemScrollSnapVerticalMultiple(MenuCommand menuCommand)
{
FixedScrollSnapBase (menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 3, 15, new Vector2(100, 100));
}
#endregion #endregion
} }
} }

View File

@ -7,7 +7,8 @@ namespace UnityEngine.UI.Extensions
{ {
public class HexRGB : MonoBehaviour public class HexRGB : MonoBehaviour
{ {
public Text textColor; // Unity 5.1/2 needs an InputFiled vs grabbing the text component
public InputField hexInput;
public HSVPicker hsvpicker; public HSVPicker hsvpicker;
@ -15,7 +16,7 @@ namespace UnityEngine.UI.Extensions
{ {
Color color = hsvpicker.currentColor; Color color = hsvpicker.currentColor;
string hex = ColorToHex(color); string hex = ColorToHex(color);
textColor.text = hex; hexInput.text = hex;
} }
public static string ColorToHex(Color color) public static string ColorToHex(Color color)
@ -28,8 +29,7 @@ namespace UnityEngine.UI.Extensions
public void ManipulateViaHex2RGB() public void ManipulateViaHex2RGB()
{ {
string hex = textColor.text; string hex = hexInput.text;
Vector3 rgb = Hex2RGB(hex); Vector3 rgb = Hex2RGB(hex);
Color color = NormalizeVector4(rgb, 255f, 1f); print(rgb); Color color = NormalizeVector4(rgb, 255f, 1f); print(rgb);

View File

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: a0789c2f62bad6b4c800a3dc502fa18e
folderAsset: yes
DefaultImporter:
userData:

View File

@ -4,7 +4,7 @@
namespace UnityEngine.EventSystems.Extensions namespace UnityEngine.EventSystems.Extensions
{ {
[RequireComponent(typeof(EventSystem))] [RequireComponent(typeof(EventSystem))]
[AddComponentMenu("UI/Extensions/Aimer Input Module")] [AddComponentMenu("Event/Extensions/Aimer Input Module")]
public class AimerInputModule : PointerInputModule public class AimerInputModule : PointerInputModule
{ {
/// <summary> /// <summary>

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f7d3d69aa5226dc4493464d3b5e4ddc3 guid: 08b9f423b73fdfb47b59e7de89863600
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []

View File

@ -0,0 +1,226 @@
/// Credit Simon (darkside) Jackson
/// Sourced from - UI SIM source and My Brain
namespace UnityEngine.EventSystems
{
[AddComponentMenu("Event/Extensions/GamePad Input Module")]
public class GamePadInputModule : BaseInputModule
{
private float m_PrevActionTime;
Vector2 m_LastMoveVector;
int m_ConsecutiveMoveCount = 0;
protected GamePadInputModule()
{}
[SerializeField]
private string m_HorizontalAxis = "Horizontal";
/// <summary>
/// Name of the vertical axis for movement (if axis events are used).
/// </summary>
[SerializeField]
private string m_VerticalAxis = "Vertical";
/// <summary>
/// Name of the submit button.
/// </summary>
[SerializeField]
private string m_SubmitButton = "Submit";
/// <summary>
/// Name of the submit button.
/// </summary>
[SerializeField]
private string m_CancelButton = "Cancel";
[SerializeField]
private float m_InputActionsPerSecond = 10;
[SerializeField]
private float m_RepeatDelay = 0.1f;
public float inputActionsPerSecond
{
get { return m_InputActionsPerSecond; }
set { m_InputActionsPerSecond = value; }
}
public float repeatDelay
{
get { return m_RepeatDelay; }
set { m_RepeatDelay = value; }
}
/// <summary>
/// Name of the horizontal axis for movement (if axis events are used).
/// </summary>
public string horizontalAxis
{
get { return m_HorizontalAxis; }
set { m_HorizontalAxis = value; }
}
/// <summary>
/// Name of the vertical axis for movement (if axis events are used).
/// </summary>
public string verticalAxis
{
get { return m_VerticalAxis; }
set { m_VerticalAxis = value; }
}
public string submitButton
{
get { return m_SubmitButton; }
set { m_SubmitButton = value; }
}
public string cancelButton
{
get { return m_CancelButton; }
set { m_CancelButton = value; }
}
public override bool ShouldActivateModule()
{
if (!base.ShouldActivateModule())
return false;
var shouldActivate = true;
shouldActivate |= Input.GetButtonDown(m_SubmitButton);
shouldActivate |= Input.GetButtonDown(m_CancelButton);
shouldActivate |= !Mathf.Approximately(Input.GetAxisRaw(m_HorizontalAxis), 0.0f);
shouldActivate |= !Mathf.Approximately(Input.GetAxisRaw(m_VerticalAxis), 0.0f);
return shouldActivate;
}
public override void ActivateModule()
{
StandaloneInputModule StandAloneSystem = GetComponent<StandaloneInputModule>();
if (StandAloneSystem && StandAloneSystem.enabled)
{
Debug.LogError("StandAloneInputSystem should not be used with the GamePadInputModule, " +
"please remove it from the Event System in this scene or disable it when this module is in use");
}
base.ActivateModule();
var toSelect = eventSystem.currentSelectedGameObject;
if (toSelect == null)
toSelect = eventSystem.firstSelectedGameObject;
eventSystem.SetSelectedGameObject(toSelect, GetBaseEventData());
}
public override void DeactivateModule()
{
base.DeactivateModule();
}
public override void Process()
{
bool usedEvent = SendUpdateEventToSelectedObject();
if (eventSystem.sendNavigationEvents)
{
if (!usedEvent)
usedEvent |= SendMoveEventToSelectedObject();
if (!usedEvent)
SendSubmitEventToSelectedObject();
}
}
/// <summary>
/// Process submit keys.
/// </summary>
protected bool SendSubmitEventToSelectedObject()
{
if (eventSystem.currentSelectedGameObject == null)
return false;
var data = GetBaseEventData();
if (Input.GetButtonDown(m_SubmitButton))
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
if (Input.GetButtonDown(m_CancelButton))
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
return data.used;
}
private Vector2 GetRawMoveVector()
{
Vector2 move = Vector2.zero;
move.x = Input.GetAxisRaw(m_HorizontalAxis);
move.y = Input.GetAxisRaw(m_VerticalAxis);
if (Input.GetButtonDown(m_HorizontalAxis))
{
if (move.x < 0)
move.x = -1f;
if (move.x > 0)
move.x = 1f;
}
if (Input.GetButtonDown(m_VerticalAxis))
{
if (move.y < 0)
move.y = -1f;
if (move.y > 0)
move.y = 1f;
}
return move;
}
/// <summary>
/// Process events.
/// </summary>
protected bool SendMoveEventToSelectedObject()
{
float time = Time.unscaledTime;
Vector2 movement = GetRawMoveVector();
if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f))
{
m_ConsecutiveMoveCount = 0;
return false;
}
// If user pressed key again, always allow event
bool allow = Input.GetButtonDown(m_HorizontalAxis) || Input.GetButtonDown(m_VerticalAxis);
bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);
if (!allow)
{
// Otherwise, user held down key or axis.
// If direction didn't change at least 90 degrees, wait for delay before allowing consequtive event.
if (similarDir && m_ConsecutiveMoveCount == 1)
allow = (time > m_PrevActionTime + m_RepeatDelay);
// If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate.
else
allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond);
}
if (!allow)
return false;
var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);
if (!similarDir)
m_ConsecutiveMoveCount = 0;
m_ConsecutiveMoveCount++;
m_PrevActionTime = time;
m_LastMoveVector = movement;
return axisEventData.used;
}
protected bool SendUpdateEventToSelectedObject()
{
if (eventSystem.currentSelectedGameObject == null)
return false;
var data = GetBaseEventData();
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.updateSelectedHandler);
return data.used;
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 26158f38115d49a4a915f46c7eced4ab
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -165,7 +165,7 @@ namespace UnityEngine.UI.Extensions
var h = CalculateRowVerticalOffset(groupHeight, yOffset, currentRowHeight); var h = CalculateRowVerticalOffset(groupHeight, yOffset, currentRowHeight);
currentRowWidth -= SpacingX; currentRowWidth -= SpacingX;
// Layout the final row // Layout the final row
LayoutRow(_rowList, currentRowWidth, currentRowHeight, workingWidth - SpacingX, padding.left, h, axis); LayoutRow(_rowList, currentRowWidth, currentRowHeight, workingWidth - (_rowList.Count > 1 ? SpacingX : 0), padding.left, h, axis);
} }
_rowList.Clear(); _rowList.Clear();

View File

@ -0,0 +1,495 @@
/// Credit BinaryX
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1945602
/// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
/// Update by xesenix - rewrited almost entire code
/// - configuration for direction move instead of 2 concurrent class (easiear to change direction in editor)
/// - supports list layouted with horizontal or vertical layout need to match direction with type of layout used
/// - dynamicly checks if scrolled list size changes and recalculates anchor positions
/// and item size based on itemsVisibleAtOnce and size of root container
/// if you dont wish to use this auto resize turn of autoLayoutItems
/// - fixed current page made it independant from pivot
/// - replaced pagination with delegate function
using System;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[ExecuteInEditMode]
[RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("UI/Extensions/Scroll Snap")]
public class ScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
{
// needed becouse of reversed behavior of axis Y compared to X
// (positions of children lower in children list in horizontal directions grows when in vertical it gets smaller)
public enum ScrollDirection {
Horizontal,
Vertical
};
public delegate void PageSnapChange(int page);
public event PageSnapChange onPageChange;
public ScrollDirection direction = ScrollDirection.Horizontal;
protected ScrollRect scrollRect;
protected RectTransform scrollRectTransform;
protected Transform listContainerTransform;
protected RectTransform rectTransform;
protected int items = 0;
int pages;
protected int startingPage = 0;
// anchor points to lerp to to see child on certain indexes
protected Vector3[] pageAnchorPositions;
protected Vector3 lerpTarget;
protected bool lerp;
// item list related
protected float listContainerMinPosition;
protected float listContainerMaxPosition;
protected float listContainerSize;
protected RectTransform listContainerRectTransform;
protected Vector2 listContainerCachedSize;
protected float itemSize;
[Tooltip("Button to go to the next page. (optional)")]
public GameObject nextButton;
[Tooltip("Button to go to the previous page. (optional)")]
public GameObject prevButton;
[Tooltip("Number of items visible in one page of scroll frame.")]
[RangeAttribute(1,100)]
public int itemsVisibleAtOnce = 1;
[Tooltip("Sets minimum width of list items to 1/itemsVisibleAtOnce.")]
public bool autoLayoutItems = true;
[Tooltip("If you wish to update scrollbar numberOfSteps to number of active children on list.")]
public bool linkScrolbarSteps = false;
public Boolean useFastSwipe = true;
public int fastSwipeThreshold = 100;
// drag related
protected bool startDrag = true;
protected Vector3 positionOnDragStart = new Vector3();
protected int pageOnDragStart;
protected bool fastSwipeTimer = false;
protected int fastSwipeCounter = 0;
protected int fastSwipeTarget = 10;
// Use this for initialization
void Start()
{
lerp = false;
scrollRect = gameObject.GetComponent<ScrollRect> ();
scrollRectTransform = gameObject.GetComponent<RectTransform> ();
listContainerTransform = scrollRect.content;
listContainerRectTransform = listContainerTransform.GetComponent<RectTransform> ();
rectTransform = listContainerTransform.gameObject.GetComponent<RectTransform> ();
UpdateListItemsSize();
UpdateListItemPositions();
ChangePage (CurrentPage ());
if (nextButton)
{
nextButton.GetComponent<Button> ().onClick.AddListener (() => { NextScreen (); });
}
if (prevButton)
{
prevButton.GetComponent<Button> ().onClick.AddListener (() => { PreviousScreen (); });
}
}
public void UpdateListItemsSize()
{
float size = 0;
if (direction == ScrollSnap.ScrollDirection.Horizontal)
{
size = scrollRectTransform.rect.width / itemsVisibleAtOnce;
}
else
{
size = scrollRectTransform.rect.height / itemsVisibleAtOnce;
}
itemSize = size;
if (autoLayoutItems && size != itemSize)
{
if (direction == ScrollSnap.ScrollDirection.Horizontal)
{
foreach (var tr in listContainerTransform)
{
GameObject child = ((Transform)tr).gameObject;
if (child.activeInHierarchy)
{
var childLayout = child.GetComponent<LayoutElement> ();
if (childLayout == null)
{
childLayout = child.AddComponent<LayoutElement> ();
}
childLayout.minWidth = itemSize;
}
}
}
else
{
foreach (var tr in listContainerTransform)
{
GameObject child = ((Transform)tr).gameObject;
if (child.activeInHierarchy)
{
var childLayout = child.GetComponent<LayoutElement> ();
if (childLayout == null)
{
childLayout = child.AddComponent<LayoutElement> ();
}
childLayout.minHeight = itemSize;
}
}
}
}
}
public void UpdateListItemPositions()
{
if (!listContainerRectTransform.rect.size.Equals(listContainerCachedSize))
{
// checking how many children of list are active
int activeCount = 0;
foreach (var tr in listContainerTransform) {
if (((Transform)tr).gameObject.activeInHierarchy) {
activeCount++;
}
}
// if anything changed since last check reinitialize anchors list
items = 0;
Array.Resize(ref pageAnchorPositions, activeCount);
if (activeCount > 0)
{
pages = Mathf.Max (activeCount - itemsVisibleAtOnce + 1, 1);
if (direction == ScrollDirection.Horizontal)
{
// looking for list spanning range min/max
scrollRect.horizontalNormalizedPosition = 0;
listContainerMaxPosition = listContainerTransform.localPosition.x;
scrollRect.horizontalNormalizedPosition = 1;
listContainerMinPosition = listContainerTransform.localPosition.x;
listContainerSize = listContainerMaxPosition - listContainerMinPosition;
for (var i = 0; i < pages; i ++)
{
pageAnchorPositions[i] = new Vector3(
listContainerMaxPosition - itemSize * i,
listContainerTransform.localPosition.y,
listContainerTransform.localPosition.z
);
}
}
else
{
// looking for list spanning range
scrollRect.verticalNormalizedPosition = 1;
listContainerMinPosition = listContainerTransform.localPosition.y;
scrollRect.verticalNormalizedPosition = 0;
listContainerMaxPosition = listContainerTransform.localPosition.y;
listContainerSize = listContainerMaxPosition - listContainerMinPosition;
for (var i = 0; i < pages; i ++)
{
pageAnchorPositions[i] = new Vector3(
listContainerTransform.localPosition.x,
listContainerMinPosition + itemSize * i,
listContainerTransform.localPosition.z
);
}
foreach (var tr in listContainerTransform) {
if (((Transform)tr).gameObject.activeInHierarchy) {
activeCount++;
}
}
}
UpdateScrollbar(linkScrolbarSteps);
startingPage = Mathf.Min(startingPage, pages);
ResetPage();
}
items = activeCount;
listContainerCachedSize.Set (listContainerRectTransform.rect.size.x, listContainerRectTransform.rect.size.y);
}
}
public void ResetPage()
{
if (direction == ScrollDirection.Horizontal)
{
scrollRect.horizontalNormalizedPosition = pages > 1 ? (float)startingPage / (float)(pages - 1) : 0;
}
else
{
scrollRect.verticalNormalizedPosition = pages > 1 ? (float)(pages - startingPage - 1) / (float)(pages - 1) : 0;
}
}
protected void UpdateScrollbar(bool linkSteps)
{
if (linkSteps)
{
if (direction == ScrollDirection.Horizontal)
{
if (scrollRect.horizontalScrollbar != null)
{
scrollRect.horizontalScrollbar.numberOfSteps = pages;
}
}
else
{
if (scrollRect.verticalScrollbar != null)
{
scrollRect.verticalScrollbar.numberOfSteps = pages;
}
}
}
else
{
if (direction == ScrollDirection.Horizontal)
{
if (scrollRect.horizontalScrollbar != null)
{
scrollRect.horizontalScrollbar.numberOfSteps = 0;
}
}
else
{
if (scrollRect.verticalScrollbar != null)
{
scrollRect.verticalScrollbar.numberOfSteps = 0;
}
}
}
}
void Update()
{
UpdateListItemsSize();
UpdateListItemPositions();
if (lerp)
{
UpdateScrollbar(false);
listContainerTransform.localPosition = Vector3.Lerp(listContainerTransform.localPosition, lerpTarget, 7.5f * Time.deltaTime);
if (Vector3.Distance(listContainerTransform.localPosition, lerpTarget) < 0.001f)
{
listContainerTransform.localPosition = lerpTarget;
lerp = false;
UpdateScrollbar(linkScrolbarSteps);
}
//change the info bullets at the bottom of the screen. Just for visual effect
if (Vector3.Distance(listContainerTransform.localPosition, lerpTarget) < 10f)
{
ChangePage(CurrentPage());
}
}
if (fastSwipeTimer)
{
fastSwipeCounter++;
}
}
private bool fastSwipe = false; //to determine if a fast swipe was performed
//Function for switching screens with buttons
public void NextScreen()
{
UpdateListItemPositions ();
if (CurrentPage() < pages - 1)
{
lerp = true;
lerpTarget = pageAnchorPositions[CurrentPage() + 1];
ChangePage(CurrentPage() + 1);
}
}
//Function for switching screens with buttons
public void PreviousScreen()
{
UpdateListItemPositions ();
if (CurrentPage() > 0)
{
lerp = true;
lerpTarget = pageAnchorPositions[CurrentPage() - 1];
ChangePage(CurrentPage() - 1);
}
}
//Because the CurrentScreen function is not so reliable, these are the functions used for swipes
private void NextScreenCommand()
{
if (pageOnDragStart < pages - 1)
{
int targetPage = Mathf.Min(pages - 1, pageOnDragStart + itemsVisibleAtOnce);
lerp = true;
lerpTarget = pageAnchorPositions[targetPage];
ChangePage(targetPage);
}
}
//Because the CurrentScreen function is not so reliable, these are the functions used for swipes
private void PrevScreenCommand()
{
if (pageOnDragStart > 0)
{
int targetPage = Mathf.Max(0, pageOnDragStart - itemsVisibleAtOnce);
lerp = true;
lerpTarget = pageAnchorPositions[targetPage];
ChangePage(targetPage);
}
}
//returns the current screen that the is seeing
public int CurrentPage()
{
float pos;
if (direction == ScrollDirection.Horizontal)
{
pos = listContainerMaxPosition - listContainerTransform.localPosition.x;
pos = Mathf.Clamp(pos, 0, listContainerSize);
}
else
{
pos = listContainerTransform.localPosition.y - listContainerMinPosition;
pos = Mathf.Clamp(pos, 0, listContainerSize);
}
float page = pos / itemSize;
return Mathf.Clamp(Mathf.RoundToInt(page), 0, pages);
}
//changes the bullets on the bottom of the page - pagination
private void ChangePage(int currentPage)
{
startingPage = currentPage;
if (onPageChange != null)
{
onPageChange(currentPage);
}
}
#region Interfaces
public void OnBeginDrag(PointerEventData eventData)
{
UpdateScrollbar(false);
fastSwipeCounter = 0;
fastSwipeTimer = true;
positionOnDragStart = eventData.position;
pageOnDragStart = CurrentPage();
}
public void OnEndDrag(PointerEventData eventData)
{
startDrag = true;
float change = 0;
if (direction == ScrollDirection.Horizontal)
{
change = positionOnDragStart.x - eventData.position.x;
}
else
{
change = -positionOnDragStart.y + eventData.position.y;
}
if (useFastSwipe)
{
fastSwipe = false;
fastSwipeTimer = false;
if (fastSwipeCounter <= fastSwipeTarget)
{
if (Math.Abs(change) > fastSwipeThreshold)
{
fastSwipe = true;
}
}
if (fastSwipe)
{
if (change > 0)
{
NextScreenCommand();
}
else
{
PrevScreenCommand();
}
}
else
{
lerp = true;
lerpTarget = pageAnchorPositions[CurrentPage()];
}
}
else
{
lerp = true;
lerpTarget = pageAnchorPositions[CurrentPage()];
}
}
public void OnDrag(PointerEventData eventData)
{
lerp = false;
if (startDrag)
{
OnBeginDrag(eventData);
startDrag = false;
}
}
#endregion
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c598b387777d96643991be3f0b6c98c2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
[AddComponentMenu("UI/Extensions/Primitives/UI Circle")] [AddComponentMenu("UI/Extensions/Primitives/UI Circle")]
public class UICircle : Graphic public class UICircle : MaskableGraphic
{ {
[SerializeField] [SerializeField]
Texture m_Texture; Texture m_Texture;

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7a6e620ffa5a4e64b8875761130d0139
timeCreated: 1444419848
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,127 @@
/// Credit zero3growlithe
/// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648
/// Update by xesenix - based on UIScrollToSelection centers on selected element in scrollrect which can move in XY
/// you can restrict movement by locking axis on ScrollRect component
/*USAGE:
Simply place the script on the ScrollRect that contains the selectable children we'll be scroling to
and drag'n'drop the RectTransform of the options "container" that we'll be scrolling.*/
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(ScrollRect))]
public class UIScrollToSelectionXY : MonoBehaviour
{
#region Variables
// settings
public float scrollSpeed = 10f;
[SerializeField]
private RectTransform layoutListGroup;
// temporary variables
private RectTransform targetScrollObject;
private bool scrollToSelection = true;
// references
private RectTransform scrollWindow;
private RectTransform currentCanvas;
private ScrollRect targetScrollRect;
#endregion
// Use this for initialization
private void Start()
{
targetScrollRect = GetComponent<ScrollRect>();
scrollWindow = targetScrollRect.GetComponent<RectTransform>();
}
// Update is called once per frame
private void Update()
{
ScrollRectToLevelSelection();
}
private void ScrollRectToLevelSelection()
{
// FIX: if you dont do that here events can have null value
var events = EventSystem.current;
// check main references
bool referencesAreIncorrect =
(targetScrollRect == null || layoutListGroup == null || scrollWindow == null);
if (referencesAreIncorrect == true)
{
return;
}
// get calculation references
RectTransform selection = events.currentSelectedGameObject != null ?
events.currentSelectedGameObject.GetComponent<RectTransform>() :
null;
if (selection != targetScrollObject)
{
scrollToSelection = true;
}
// check if scrolling is possible
bool isScrollDirectionUnknown = (selection == null || scrollToSelection == false);
if (isScrollDirectionUnknown == true || selection.transform.parent != layoutListGroup.transform)
{
return;
}
bool finishedX = false, finishedY = false;
if (targetScrollRect.vertical)
{
// move the current scroll rect to correct position
float selectionPos = -selection.anchoredPosition.y;
//float elementHeight = layoutListGroup.sizeDelta.y / layoutListGroup.transform.childCount;
//float maskHeight = currentCanvas.sizeDelta.y + scrollWindow.sizeDelta.y;
float listPixelAnchor = layoutListGroup.anchoredPosition.y;
// get the element offset value depending on the cursor move direction
float offlimitsValue = 0;
offlimitsValue = listPixelAnchor - selectionPos;
// move the target scroll rect
targetScrollRect.verticalNormalizedPosition += (offlimitsValue / layoutListGroup.sizeDelta.y) * Time.deltaTime * scrollSpeed;
finishedY = Mathf.Abs(offlimitsValue) < 2f;
}
if (targetScrollRect.horizontal)
{
// move the current scroll rect to correct position
float selectionPos = -selection.anchoredPosition.x;
//float elementWidth = layoutListGroup.sizeDelta.x / layoutListGroup.transform.childCount;
//float maskWidth = currentCanvas.sizeDelta.y + scrollWindow.sizeDelta.y;
float listPixelAnchor = layoutListGroup.anchoredPosition.x;
// get the element offset value depending on the cursor move direction
float offlimitsValue = 0;
offlimitsValue = listPixelAnchor - selectionPos;
// move the target scroll rect
targetScrollRect.horizontalNormalizedPosition += (offlimitsValue / layoutListGroup.sizeDelta.x) * Time.deltaTime * scrollSpeed;
finishedX = Mathf.Abs(offlimitsValue) < 2f;
}
// check if we reached our destination
if (finishedX && finishedY) {
scrollToSelection = false;
}
// save last object we were "heading to" to prevent blocking
targetScrollObject = selection;
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6580683838fcc12479150dd5e76e6b2e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -0,0 +1,314 @@
/// Credit drHogan
/// Sourced from - http://www.hammerandravens.com/multi-use-tooltip-system-in-unity3d/
namespace UnityEngine.UI.Extensions
{
public class HoverTooltip : MonoBehaviour
{
//manually selectable padding for the background image
public int horizontalPadding;
public int verticalPadding;
//tooltip text
public Text thisText;
//horizontal layout of the tooltip
public HorizontalLayoutGroup hlG;
//tooltip background image
public RectTransform bgImage;
Image bgImageSource;
//needed as the layout refreshes only on the first Update() call
bool firstUpdate;
//if the tooltip is inside a UI element
bool inside;
//size of the tooltip, needed to track if out of screen
// public float width;
// public float height;
//detect canvas mode so to apply different behaviors to different canvas modes, currently only RenderMode.ScreenSpaceCamera implemented
int canvasMode;
RenderMode GUIMode;
//the scene GUI camera
Camera GUICamera;
//the default tooltip object has the following pivots, so that the offset from the mouse is always proportional to the screen resolution (the y pivot)
//Pivot(0.5,-0.5)
//screen viewport corners for out of screen detection
Vector3 lowerLeft;
Vector3 upperRight;
//scale factor of proportionality to the reference resolution (1280x720)
float currentYScaleFactor;
float currentXScaleFactor;
//standard X and Y offsets of the new tooltip
float defaultYOffset;
float defaultXOffset;
//real on screen sizes of the tooltip object
float tooltipRealHeight;
float tooltipRealWidth;
// Use this for initialization
void Start()
{
//in this line you need to change the string in order to get your Camera //TODO MAYBE DO IT FROM THE INSPECTOR
GUICamera = GameObject.Find("GUICamera").GetComponent<Camera>();
GUIMode = this.transform.parent.parent.GetComponent<Canvas>().renderMode;
bgImageSource = bgImage.GetComponent<Image>();
//at start the pointer is never to be considered over and UI element
inside = false;
//assign the tooltip to the singleton GUI class manager for fast access
//TacticalGUIManager.tgm.mmttp = this;
//hide the tooltip
HideTooltipVisibility();
this.transform.parent.gameObject.SetActive(false);
}
//single string input tooltip
public void SetTooltip(string text)
{
NewTooltip();
//init tooltip string
thisText.text = text;
//call the position function
OnScreenSpaceCamera();
}
//multi string/line input tooltip (each string of the input array is a new line)
public void SetTooltip(string[] texts)
{
NewTooltip();
//build up the tooltip line after line with the input
string tooltipText = "";
int index = 0;
foreach (string newLine in texts)
{
if (index == 0)
{
tooltipText += newLine;
}
else
{
tooltipText += ("\n" + newLine);
}
index++;
}
//init tooltip string
thisText.text = tooltipText;
//call the position function
OnScreenSpaceCamera();
}
//temporary call to don't fuck up old code, will be removed
public void SetTooltip(string text, bool test)
{
NewTooltip();
//init tooltip string
thisText.text = text;
//call the position function
OnScreenSpaceCamera();
}
//position function, currently not working correctly due to the use of pivots and not manual offsets, soon to be fixed
public void OnScreenSpaceCamera()
{
//get the dynamic position of the pous in viewport coordinates
Vector3 newPos = GUICamera.ScreenToViewportPoint(Input.mousePosition);
// store in val the updated position (x or y) of the tooltip edge of interest
float val;
//store the new offset to impose in case of out of screen
float yOffSet = 0f;
float xOffSet = 0f;
//check for right edge of screen
//obtain the x coordinate of the right edge of the tooltip
val = ((GUICamera.ViewportToScreenPoint(newPos).x) + (tooltipRealWidth * bgImage.pivot.x));
//evaluate if the right edge of the tooltip goes out of screen
if (val > (upperRight.x))
{
float distFromRight = upperRight.x - val;
xOffSet = distFromRight;
//assign the new modified coordinates to the tooltip and convert to screen coordinates
Vector3 newTooltipPos = new Vector3(GUICamera.ViewportToScreenPoint(newPos).x + xOffSet, 0f, 0f);
newPos.x = GUICamera.ScreenToViewportPoint(newTooltipPos).x;
}
//check for left edge of screen
//obtain the x coordinate of the left edge of the tooltip
val = ((GUICamera.ViewportToScreenPoint(newPos).x) - (tooltipRealWidth * bgImage.pivot.x));
//evaluate if the left edge of the tooltip goes out of screen
if (val < (lowerLeft.x))
{
float distFromLeft = lowerLeft.x - val;
xOffSet = -distFromLeft;
//assign the new modified coordinates to the tooltip and convert to screen coordinates
Vector3 newTooltipPos = new Vector3(GUICamera.ViewportToScreenPoint(newPos).x - xOffSet, 0f, 0f);
newPos.x = GUICamera.ScreenToViewportPoint(newTooltipPos).x;
}
//check for upper edge of the screen
//obtain the y coordinate of the upper edge of the tooltip
val = ((GUICamera.ViewportToScreenPoint(newPos).y) - ((bgImage.sizeDelta.y * currentYScaleFactor * (bgImage.pivot.y)) - (tooltipRealHeight)));
//evaluate if the upper edge of the tooltip goes out of screen
if (val > (upperRight.y))
{
float distFromUpper = upperRight.y - val;
yOffSet = (bgImage.sizeDelta.y * currentYScaleFactor * (bgImage.pivot.y));
if (distFromUpper > (defaultYOffset * 0.75))
{
//shorten the temporary offset up to a certain distance from the tooltip
yOffSet = distFromUpper;
}
else
{
//if the distance becomes too short flip the tooltip to below the pointer (by offset+twice the height of the tooltip)
yOffSet = ((defaultYOffset) - (tooltipRealHeight) * 2f);
}
//assign the new modified coordinates to the tooltip and convert to screen coordinates
Vector3 newTooltipPos = new Vector3(newPos.x, GUICamera.ViewportToScreenPoint(newPos).y + yOffSet, 0f);
newPos.y = GUICamera.ScreenToViewportPoint(newTooltipPos).y;
}
//check for lower edge of the screen
//obtain the y coordinate of the lower edge of the tooltip
val = ((GUICamera.ViewportToScreenPoint(newPos).y) - ((bgImage.sizeDelta.y * currentYScaleFactor * (bgImage.pivot.y))));
//evaluate if the upper edge of the tooltip goes out of screen
if (val < (lowerLeft.y))
{
float distFromLower = lowerLeft.y - val;
yOffSet = (bgImage.sizeDelta.y * currentYScaleFactor * (bgImage.pivot.y));
if (distFromLower < (defaultYOffset * 0.75 - tooltipRealHeight))
{
//shorten the temporary offset up to a certain distance from the tooltip
yOffSet = distFromLower;
}
else
{
//if the distance becomes too short flip the tooltip to above the pointer (by twice the height of the tooltip)
yOffSet = ((tooltipRealHeight) * 2f);
}
//assign the new modified coordinates to the tooltip and convert to screen coordinates
Vector3 newTooltipPos = new Vector3(newPos.x, GUICamera.ViewportToScreenPoint(newPos).y + yOffSet, 0f);
newPos.y = GUICamera.ScreenToViewportPoint(newTooltipPos).y;
}
this.transform.parent.transform.position = new Vector3(GUICamera.ViewportToWorldPoint(newPos).x, GUICamera.ViewportToWorldPoint(newPos).y, 0f);
this.transform.parent.gameObject.SetActive(true);
inside = true;
}
//call to hide tooltip when hovering out from the object
public void HideTooltip()
{
if (GUIMode == RenderMode.ScreenSpaceCamera)
{
if (this != null)
{
this.transform.parent.gameObject.SetActive(false);
inside = false;
HideTooltipVisibility();
}
}
}
// Update is called once per frame
void Update()
{
LayoutInit();
if (inside)
{
if (GUIMode == RenderMode.ScreenSpaceCamera)
{
OnScreenSpaceCamera();
}
}
}
//this function is used in order to setup the size of the tooltip by cheating on the HorizontalLayoutBehavior. The resize is done in the first update.
void LayoutInit()
{
if (firstUpdate)
{
firstUpdate = false;
bgImage.sizeDelta = new Vector2(hlG.preferredWidth + horizontalPadding, hlG.preferredHeight + verticalPadding);
defaultYOffset = (bgImage.sizeDelta.y * currentYScaleFactor * (bgImage.pivot.y));
defaultXOffset = (bgImage.sizeDelta.x * currentXScaleFactor * (bgImage.pivot.x));
tooltipRealHeight = bgImage.sizeDelta.y * currentYScaleFactor;
tooltipRealWidth = bgImage.sizeDelta.x * currentXScaleFactor;
ActivateTooltipVisibility();
}
}
//init basic variables on a new tooltip set
void NewTooltip()
{
firstUpdate = true;
lowerLeft = GUICamera.ViewportToScreenPoint(new Vector3(0.0f, 0.0f, 0.0f));
upperRight = GUICamera.ViewportToScreenPoint(new Vector3(1.0f, 1.0f, 0.0f));
currentYScaleFactor = Screen.height / this.transform.root.GetComponent<CanvasScaler>().referenceResolution.y;
currentXScaleFactor = Screen.width / this.transform.root.GetComponent<CanvasScaler>().referenceResolution.x;
}
//used to visualize the tooltip one update call after it has been built (to avoid flickers)
public void ActivateTooltipVisibility()
{
Color textColor = thisText.color;
thisText.color = new Color(textColor.r, textColor.g, textColor.b, 1f);
bgImageSource.color = new Color(bgImageSource.color.r, bgImageSource.color.g, bgImageSource.color.b, 0.8f);
}
//used to hide the tooltip so that it can be made visible one update call after it has been built (to avoid flickers)
public void HideTooltipVisibility()
{
Color textColor = thisText.color;
thisText.color = new Color(textColor.r, textColor.g, textColor.b, 0f);
bgImageSource.color = new Color(bgImageSource.color.r, bgImageSource.color.g, bgImageSource.color.b, 0f);
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 87cd933870c6506418344281b3cb86fc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -1,6 +1,6 @@
{ {
"name": "Unity UI Extensions", "name": "Unity UI Extensions",
"version": "1.0.4", "version": "1.0.5",
"description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community",
"author": "Simon darkside Jackson <@SimonDarksideJ>", "author": "Simon darkside Jackson <@SimonDarksideJ>",
"contributors": [{ "contributors": [{