Initial update and merge of 5.1 Extensions package

Documentation next to update
Example videos to be done with each control / script

*Stretch Goal, filter issue requests for late additions, esp Vertical Snap
pull/413/head
Simon (darkside) Jackson 2015-08-30 00:31:59 +01:00
parent d9079e4732
commit db57fc1e21
43 changed files with 2391 additions and 142 deletions

View File

@ -1,23 +1,23 @@
///Credit ChoMPHi
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using UnityEngine.UI.Extensions;
namespace UnityEditor.UI
{
[CustomEditor(typeof(AccordionElement), true)]
public class AccordionElementEditor : ToggleEditor {
public override void OnInspectorGUI()
{
this.serializedObject.Update();
EditorGUILayout.PropertyField(this.serializedObject.FindProperty("m_MinHeight"));
this.serializedObject.ApplyModifiedProperties();
base.serializedObject.Update();
EditorGUILayout.PropertyField(base.serializedObject.FindProperty("m_IsOn"));
EditorGUILayout.PropertyField(base.serializedObject.FindProperty("m_Interactable"));
base.serializedObject.ApplyModifiedProperties();
}
}
using UnityEngine.UI.Extensions;
namespace UnityEditor.UI
{
[CustomEditor(typeof(AccordionElement), true)]
public class AccordionElementEditor : ToggleEditor {
public override void OnInspectorGUI()
{
this.serializedObject.Update();
EditorGUILayout.PropertyField(this.serializedObject.FindProperty("m_MinHeight"));
this.serializedObject.ApplyModifiedProperties();
base.serializedObject.Update();
EditorGUILayout.PropertyField(base.serializedObject.FindProperty("m_IsOn"));
EditorGUILayout.PropertyField(base.serializedObject.FindProperty("m_Interactable"));
base.serializedObject.ApplyModifiedProperties();
}
}
}

View File

@ -1,16 +1,16 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System.Collections;
namespace UnityEngine.UI.Extensions.Tweens
{
internal interface ITweenValue
{
void TweenValue(float floatPercentage);
bool ignoreTimeScale { get; }
float duration { get; }
bool ValidTarget();
void Finished();
}
{
internal interface ITweenValue
{
void TweenValue(float floatPercentage);
bool ignoreTimeScale { get; }
float duration { get; }
bool ValidTarget();
void Finished();
}
}

View File

@ -1,63 +1,63 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System.Collections;
namespace UnityEngine.UI.Extensions.Tweens
{
// Tween runner, executes the given tween.
// The coroutine will live within the given
// behaviour container.
internal class TweenRunner<T> where T : struct, ITweenValue
{
protected MonoBehaviour m_CoroutineContainer;
protected IEnumerator m_Tween;
// utility function for starting the tween
private static IEnumerator Start(T tweenInfo)
{
if (!tweenInfo.ValidTarget())
yield break;
float elapsedTime = 0.0f;
while (elapsedTime < tweenInfo.duration)
{
elapsedTime += tweenInfo.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
var percentage = Mathf.Clamp01 (elapsedTime / tweenInfo.duration);
tweenInfo.TweenValue (percentage);
yield return null;
}
tweenInfo.TweenValue (1.0f);
tweenInfo.Finished();
}
public void Init(MonoBehaviour coroutineContainer)
{
m_CoroutineContainer = coroutineContainer;
}
public void StartTween(T info)
{
if (m_CoroutineContainer == null)
{
Debug.LogWarning ("Coroutine container not configured... did you forget to call Init?");
return;
}
if (m_Tween != null)
{
m_CoroutineContainer.StopCoroutine (m_Tween);
m_Tween = null;
}
if (!m_CoroutineContainer.gameObject.activeInHierarchy)
{
info.TweenValue(1.0f);
return;
}
m_Tween = Start (info);
m_CoroutineContainer.StartCoroutine (m_Tween);
}
}
{
// Tween runner, executes the given tween.
// The coroutine will live within the given
// behaviour container.
internal class TweenRunner<T> where T : struct, ITweenValue
{
protected MonoBehaviour m_CoroutineContainer;
protected IEnumerator m_Tween;
// utility function for starting the tween
private static IEnumerator Start(T tweenInfo)
{
if (!tweenInfo.ValidTarget())
yield break;
float elapsedTime = 0.0f;
while (elapsedTime < tweenInfo.duration)
{
elapsedTime += tweenInfo.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
var percentage = Mathf.Clamp01 (elapsedTime / tweenInfo.duration);
tweenInfo.TweenValue (percentage);
yield return null;
}
tweenInfo.TweenValue (1.0f);
tweenInfo.Finished();
}
public void Init(MonoBehaviour coroutineContainer)
{
m_CoroutineContainer = coroutineContainer;
}
public void StartTween(T info)
{
if (m_CoroutineContainer == null)
{
Debug.LogWarning ("Coroutine container not configured... did you forget to call Init?");
return;
}
if (m_Tween != null)
{
m_CoroutineContainer.StopCoroutine (m_Tween);
m_Tween = null;
}
if (!m_CoroutineContainer.gameObject.activeInHierarchy)
{
info.TweenValue(1.0f);
return;
}
m_Tween = Start (info);
m_CoroutineContainer.StartCoroutine (m_Tween);
}
}
}

View File

@ -60,7 +60,7 @@ namespace UnityEngine.UI.Extensions
}
// private int scrollOffset; //offset of the selected item
private int _selectedIndex = 0;
// private int _selectedIndex = 0;
[SerializeField]
private int _itemsToDisplay;
@ -122,7 +122,7 @@ namespace UnityEngine.UI.Extensions
_panelItems = AvailableOptions.ToList();
RebuildPanel();
RedrawPanel();
//RedrawPanel(); - causes an initialisation failure in U5
return success;
}

View File

@ -59,7 +59,7 @@ namespace UnityEngine.UI.Extensions
}
// private int scrollOffset; //offset of the selected item
private int _selectedIndex = 0;
// private int _selectedIndex = 0;
[SerializeField]
private int _itemsToDisplay;
@ -120,7 +120,7 @@ namespace UnityEngine.UI.Extensions
_panelItems = AvailableOptions.ToList();
RebuildPanel();
RedrawPanel();
//RedrawPanel(); - causes an initialisation failure in U5
return success;
}

View File

@ -236,7 +236,7 @@ namespace UnityEditor.UI
horizontalScrollSnapRoot.AddComponent<HorizontalScrollSnap>();
//Setup Content container
RectTransform rectTransformContent = childContent.AddComponent<RectTransform>();
RectTransform rectTransformContent = childContent.GetComponent<RectTransform>();
rectTransformContent.anchorMin = Vector2.zero;
rectTransformContent.anchorMax = new Vector2(1f, 1f);
//rectTransformContent.anchoredPosition = Vector2.zero;
@ -791,6 +791,21 @@ namespace UnityEditor.UI
SetDefaultColorTransitionValues(slider);
}
[MenuItem("GameObject/UI/Extensions/UI Line Renderer", false)]
static public void AddUILineRenderer(MenuCommand menuCommand)
{
GameObject go = CreateUIElementRoot("UI LineRenderer", menuCommand, s_ImageGUIElementSize);
go.AddComponent<UILineRenderer>();
Selection.activeGameObject = go;
}
[MenuItem("GameObject/UI/Extensions/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;
}
#endregion

View File

@ -5,15 +5,19 @@ namespace UnityEngine.UI.Extensions
{
public class ColorPickerTester : MonoBehaviour
{
public Renderer renderer;
public Renderer pickerRenderer;
public HSVPicker picker;
void Awake()
{
pickerRenderer = GetComponent<Renderer>();
}
// Use this for initialization
void Start()
{
picker.onValueChanged.AddListener(color =>
{
renderer.material.color = color;
pickerRenderer.material.color = color;
});
}
}

View File

@ -1,4 +1,4 @@
///Credit judah4
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using UnityEngine.Events;
@ -8,4 +8,4 @@ namespace UnityEngine.UI.Extensions
{
}
}
}

View File

@ -1,4 +1,4 @@
///Credit judah4
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using UnityEngine.EventSystems;

1074
Scripts/ImageExtended.cs Normal file

File diff suppressed because it is too large Load Diff

View File

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

83
Scripts/InputFocus.cs Normal file
View File

@ -0,0 +1,83 @@
/// Credit Zelek
/// Sourced from - http://forum.unity3d.com/threads/inputfield-focus-and-unfocus.306634/
/// Usage, assign component to Input field, set OnEndEdit function to the one in this script and the Click for the submit button to the buttonPressed function.
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(InputField))]
[AddComponentMenu("UI/Extensions/InputFocus")]
public class InputFocus : MonoBehaviour
{
#region Private Variables
// The input field we use for chat
protected InputField _inputField;
// When set to true, we will ignore the next time the "Enter" key is released
public bool _ignoreNextActivation = false;
#endregion
void Start()
{
_inputField = GetComponent<InputField>();
}
void Update()
{
// Check if the "Enter" key was just released with the chat input not focused
if (Input.GetKeyUp(KeyCode.Return) && !_inputField.isFocused)
{
// If we need to ignore the keypress, do nothing - otherwise activate the input field
if (_ignoreNextActivation)
{
_ignoreNextActivation = false;
}
else
{
_inputField.Select();
_inputField.ActivateInputField();
}
}
}
public void buttonPressed()
{
// Do whatever you want with the input field text here
// Make note of whether the input string was empty, and then clear it out
bool wasEmpty = _inputField.text == "";
_inputField.text = "";
// If the string was not empty, we should reactivate the input field
if (!wasEmpty)
{
_inputField.Select();
_inputField.ActivateInputField();
}
}
public void OnEndEdit(string textString)
{
// If the edit ended because we clicked away, don't do anything extra
if (!Input.GetKeyDown(KeyCode.Return))
{
return;
}
// Do whatever you want with the input field text here
// Make note of whether the input string was empty, and then clear it out
bool wasEmpty = _inputField.text == "";
_inputField.text = "";
// if the input string was empty, then allow the field to deactivate
if (wasEmpty)
{
_ignoreNextActivation = true;
}
}
}
}

View File

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

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c4c2c5317e2b50f42b0302414577a62d
folderAsset: yes
timeCreated: 1440843775
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,64 @@
/// Credit .entity
/// Sourced from - http://forum.unity3d.com/threads/rescale-panel.309226/
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/RescalePanels/RescaleDragPanel")]
public class RescaleDragPanel : MonoBehaviour, IPointerDownHandler, IDragHandler
{
private Vector2 pointerOffset;
private RectTransform canvasRectTransform;
private RectTransform panelRectTransform;
private Transform goTransform;
void Awake()
{
Canvas canvas = GetComponentInParent<Canvas>();
if (canvas != null)
{
canvasRectTransform = canvas.transform as RectTransform;
panelRectTransform = transform.parent as RectTransform;
goTransform = transform.parent;
}
}
public void OnPointerDown(PointerEventData data)
{
panelRectTransform.SetAsLastSibling();
RectTransformUtility.ScreenPointToLocalPointInRectangle(panelRectTransform, data.position, data.pressEventCamera, out pointerOffset);
}
public void OnDrag(PointerEventData data)
{
if (panelRectTransform == null)
return;
Vector2 pointerPosition = ClampToWindow(data);
Vector2 localPointerPosition;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(
canvasRectTransform, pointerPosition, data.pressEventCamera, out localPointerPosition
))
{
panelRectTransform.localPosition = localPointerPosition - new Vector2(pointerOffset.x * goTransform.localScale.x, pointerOffset.y * goTransform.localScale.y);
}
}
Vector2 ClampToWindow(PointerEventData data)
{
Vector2 rawPointerPosition = data.position;
Vector3[] canvasCorners = new Vector3[4];
canvasRectTransform.GetWorldCorners(canvasCorners);
float clampedX = Mathf.Clamp(rawPointerPosition.x, canvasCorners[0].x, canvasCorners[2].x);
float clampedY = Mathf.Clamp(rawPointerPosition.y, canvasCorners[0].y, canvasCorners[2].y);
Vector2 newPointerPosition = new Vector2(clampedX, clampedY);
return newPointerPosition;
}
}
}

View File

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

View File

@ -0,0 +1,62 @@
/// Credit .entity
/// Sourced from - http://forum.unity3d.com/threads/rescale-panel.309226/
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/RescalePanels/RescalePanel")]
public class RescalePanel : MonoBehaviour, IPointerDownHandler, IDragHandler
{
public Vector2 minSize;
public Vector2 maxSize;
private RectTransform rectTransform;
private Transform goTransform;
private Vector2 currentPointerPosition;
private Vector2 previousPointerPosition;
private RectTransform thisRectTransform;
Vector2 sizeDelta;
void Awake()
{
rectTransform = transform.parent.GetComponent<RectTransform>();
goTransform = transform.parent;
thisRectTransform = GetComponent<RectTransform>();
sizeDelta = thisRectTransform.sizeDelta;
}
public void OnPointerDown(PointerEventData data)
{
rectTransform.SetAsLastSibling();
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, data.position, data.pressEventCamera, out previousPointerPosition);
}
public void OnDrag(PointerEventData data)
{
if (rectTransform == null)
return;
Vector3 scaleDelta = goTransform.localScale;
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, data.position, data.pressEventCamera, out currentPointerPosition);
Vector2 resizeValue = currentPointerPosition - previousPointerPosition;
scaleDelta += new Vector3(-resizeValue.y * 0.001f, -resizeValue.y * 0.001f, 0f);
scaleDelta = new Vector3(
Mathf.Clamp(scaleDelta.x, minSize.x, maxSize.x),
Mathf.Clamp(scaleDelta.y, minSize.y, maxSize.y),
1
);
goTransform.localScale = scaleDelta;
previousPointerPosition = currentPointerPosition;
float resizeDeltaValue = sizeDelta.x / goTransform.localScale.x;
Vector2 newSizeDelta = new Vector2(resizeDeltaValue, resizeDeltaValue);
thisRectTransform.sizeDelta = newSizeDelta;
}
}
}

View File

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

View File

@ -0,0 +1,60 @@
/// Credit .entity
/// Sourced from - http://forum.unity3d.com/threads/rescale-panel.309226/
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/RescalePanels/ResizePanel")]
public class ResizePanel : MonoBehaviour, IPointerDownHandler, IDragHandler
{
public Vector2 minSize;
public Vector2 maxSize;
private RectTransform rectTransform;
private Vector2 currentPointerPosition;
private Vector2 previousPointerPosition;
private float ratio;
void Awake()
{
rectTransform = transform.parent.GetComponent<RectTransform>();
float originalWidth;
float originalHeight;
originalWidth = rectTransform.rect.width;
originalHeight = rectTransform.rect.height;
ratio = originalHeight / originalWidth;
minSize = new Vector2(0.1f * originalWidth, 0.1f * originalHeight);
maxSize = new Vector2(10f * originalWidth, 10f * originalHeight);
}
public void OnPointerDown(PointerEventData data)
{
rectTransform.SetAsLastSibling();
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, data.position, data.pressEventCamera, out previousPointerPosition);
}
public void OnDrag(PointerEventData data)
{
if (rectTransform == null)
return;
Vector2 sizeDelta = rectTransform.sizeDelta;
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, data.position, data.pressEventCamera, out currentPointerPosition);
Vector2 resizeValue = currentPointerPosition - previousPointerPosition;
sizeDelta += new Vector2(resizeValue.x, ratio * resizeValue.x);
sizeDelta = new Vector2(
Mathf.Clamp(sizeDelta.x, minSize.x, maxSize.x),
Mathf.Clamp(sizeDelta.y, minSize.y, maxSize.y)
);
rectTransform.sizeDelta = sizeDelta;
previousPointerPosition = currentPointerPosition;
}
}
}

View File

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

109
Scripts/ScrollRectEx.cs Normal file
View File

@ -0,0 +1,109 @@
/// Credit CaptainSchnittchen
/// Credit TouchPad (OnScroll function) update - GamesRUs
/// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648
/*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 System;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/ScrollRectEx")]
public class ScrollRectEx : ScrollRect
{
private bool routeToParent = false;
/// <summary>
/// Do action for all parents
/// </summary>
private void DoForParents<T>(Action<T> action) where T : IEventSystemHandler
{
Transform parent = transform.parent;
while (parent != null)
{
foreach (var component in parent.GetComponents<Component>())
{
if (component is T)
action((T)(IEventSystemHandler)component);
}
parent = parent.parent;
}
}
/// <summary>
/// Always route initialize potential drag event to parents
/// </summary>
public override void OnInitializePotentialDrag(PointerEventData eventData)
{
DoForParents<IInitializePotentialDragHandler>((parent) => { parent.OnInitializePotentialDrag(eventData); });
base.OnInitializePotentialDrag(eventData);
}
/// <summary>
/// Drag event
/// </summary>
public override void OnDrag(UnityEngine.EventSystems.PointerEventData eventData)
{
if (routeToParent)
DoForParents<IDragHandler>((parent) => { parent.OnDrag(eventData); });
else
base.OnDrag(eventData);
}
/// <summary>
/// Begin drag event
/// </summary>
public override void OnBeginDrag(UnityEngine.EventSystems.PointerEventData eventData)
{
if (!horizontal && Math.Abs(eventData.delta.x) > Math.Abs(eventData.delta.y))
routeToParent = true;
else if (!vertical && Math.Abs(eventData.delta.x) < Math.Abs(eventData.delta.y))
routeToParent = true;
else
routeToParent = false;
if (routeToParent)
DoForParents<IBeginDragHandler>((parent) => { parent.OnBeginDrag(eventData); });
else
base.OnBeginDrag(eventData);
}
/// <summary>
/// End drag event
/// </summary>
public override void OnEndDrag(UnityEngine.EventSystems.PointerEventData eventData)
{
if (routeToParent)
DoForParents<IEndDragHandler>((parent) => { parent.OnEndDrag(eventData); });
else
base.OnEndDrag(eventData);
routeToParent = false;
}
public override void OnScroll(PointerEventData eventData)
{
if (!horizontal && Math.Abs(eventData.scrollDelta.x) > Math.Abs(eventData.scrollDelta.y))
{
routeToParent = true;
}
else if (!vertical && Math.Abs(eventData.scrollDelta.x) < Math.Abs(eventData.scrollDelta.y))
{
routeToParent = true;
}
else
{
routeToParent = false;
}
if (routeToParent)
DoForParents<IScrollHandler>((parent) => {
parent.OnScroll(eventData);
});
else
base.OnScroll(eventData);
}
}
}

View File

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

View File

@ -0,0 +1,17 @@
/// Credit Feaver1968
/// Sourced from - http://forum.unity3d.com/threads/scroll-to-the-bottom-of-a-scrollrect-in-code.310919/
namespace UnityEngine.UI.Extensions
{
public static class ScrollRectExtensions
{
public static void ScrollToTop(this ScrollRect scrollRect)
{
scrollRect.normalizedPosition = new Vector2(0, 1);
}
public static void ScrollToBottom(this ScrollRect scrollRect)
{
scrollRect.normalizedPosition = new Vector2(0, 0);
}
}
}

View File

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

View File

@ -0,0 +1,34 @@
/// Credit Martin Sharkbomb
/// Sourced from - http://www.sharkbombs.com/2015/08/26/unity-ui-scrollrect-tools/
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("UI/Extensions/ScrollRectLinker")]
public class ScrollRectLinker : MonoBehaviour
{
public bool clamp = true;
[SerializeField]
ScrollRect controllingScrollRect;
ScrollRect scrollRect;
void Awake()
{
scrollRect = GetComponent<ScrollRect>();
if (controllingScrollRect != null)
controllingScrollRect.onValueChanged.AddListener(MirrorPos);
}
void MirrorPos(Vector2 scrollPos)
{
if (clamp)
scrollRect.normalizedPosition = new Vector2(Mathf.Clamp01(scrollPos.x), Mathf.Clamp01(scrollPos.y));
else
scrollRect.normalizedPosition = scrollPos;
}
}
}

View File

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

View File

@ -0,0 +1,141 @@
/// Credit Martin Sharkbomb
/// Sourced from - http://www.sharkbombs.com/2015/08/26/unity-ui-scrollrect-tools/
using System.Collections;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("UI/Extensions/ScrollRectTweener")]
public class ScrollRectTweener : MonoBehaviour, IDragHandler
{
ScrollRect scrollRect;
Vector2 startPos;
Vector2 targetPos;
bool wasHorizontal;
bool wasVertical;
public float moveSpeed = 5000f;
public bool disableDragWhileTweening = false;
void Awake()
{
scrollRect = GetComponent<ScrollRect>();
wasHorizontal = scrollRect.horizontal;
wasVertical = scrollRect.vertical;
}
public void ScrollHorizontal(float normalizedX)
{
Scroll(new Vector2(normalizedX, scrollRect.verticalNormalizedPosition));
}
public void ScrollHorizontal(float normalizedX, float duration)
{
Scroll(new Vector2(normalizedX, scrollRect.verticalNormalizedPosition), duration);
}
public void ScrollVertical(float normalizedY)
{
Scroll(new Vector2(scrollRect.horizontalNormalizedPosition, normalizedY));
}
public void ScrollVertical(float normalizedY, float duration)
{
Scroll(new Vector2(scrollRect.horizontalNormalizedPosition, normalizedY), duration);
}
public void Scroll(Vector2 normalizedPos)
{
Scroll(normalizedPos, GetScrollDuration(normalizedPos));
}
float GetScrollDuration(Vector2 normalizedPos)
{
Vector2 currentPos = GetCurrentPos();
return Vector2.Distance(DeNormalize(currentPos), DeNormalize(normalizedPos)) / moveSpeed;
}
Vector2 DeNormalize(Vector2 normalizedPos)
{
return new Vector2(normalizedPos.x * scrollRect.content.rect.width, normalizedPos.y * scrollRect.content.rect.height);
}
Vector2 GetCurrentPos()
{
return new Vector2(scrollRect.horizontalNormalizedPosition, scrollRect.verticalNormalizedPosition);
}
public void Scroll(Vector2 normalizedPos, float duration)
{
startPos = GetCurrentPos();
targetPos = normalizedPos;
if (disableDragWhileTweening)
LockScrollability();
StopAllCoroutines();
StartCoroutine(DoMove(duration));
}
IEnumerator DoMove(float duration)
{
// Abort if movement would be too short
if (duration < 0.05f)
yield break;
Vector2 posOffset = targetPos - startPos;
float currentTime = 0f;
while (currentTime < duration)
{
currentTime += Time.deltaTime;
scrollRect.normalizedPosition = EaseVector(currentTime, startPos, posOffset, duration);
yield return null;
}
scrollRect.normalizedPosition = targetPos;
if (disableDragWhileTweening)
RestoreScrollability();
}
public Vector2 EaseVector(float currentTime, Vector2 startValue, Vector2 changeInValue, float duration)
{
return new Vector2(
changeInValue.x * Mathf.Sin(currentTime / duration * (Mathf.PI / 2)) + startValue.x,
changeInValue.y * Mathf.Sin(currentTime / duration * (Mathf.PI / 2)) + startValue.y
);
}
public void OnDrag(PointerEventData eventData)
{
if (!disableDragWhileTweening)
StopScroll();
}
void StopScroll()
{
StopAllCoroutines();
if (disableDragWhileTweening)
RestoreScrollability();
}
void LockScrollability()
{
scrollRect.horizontal = false;
scrollRect.vertical = false;
}
void RestoreScrollability()
{
scrollRect.horizontal = wasHorizontal;
scrollRect.vertical = wasVertical;
}
}
}

View File

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

View File

@ -1,5 +1,5 @@
/// Original Credit Korindian
/// Sourced from - http://forum.unity3d.com/threads/rts-style-drag-selection-box.265739/
/// Original Credit Korindian
/// Sourced from - http://forum.unity3d.com/threads/rts-style-drag-selection-box.265739/
/// Updated Credit BenZed
/// Sourced from - http://forum.unity3d.com/threads/color-picker.267043/

View File

@ -1,31 +1,31 @@
///Original Credit Korindian
///Sourced from - http://forum.unity3d.com/threads/rts-style-drag-selection-box.265739/
///Original Credit Korindian
///Sourced from - http://forum.unity3d.com/threads/rts-style-drag-selection-box.265739/
///Updated Credit BenZed
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions
{
/*
* Implement this interface on any MonoBehaviour that you'd like to be considered selectable.
*/
public interface IBoxSelectable {
bool selected {
get;
set;
}
bool preSelected {
get;
set;
}
//This property doesn't actually need to be implemented, as this interface should already be placed on a MonoBehaviour, which will
//already have it. Defining it here only allows us access to the transform property by casting through the selectable interface.
Transform transform {
get;
}
}
namespace UnityEngine.UI.Extensions
{
/*
* Implement this interface on any MonoBehaviour that you'd like to be considered selectable.
*/
public interface IBoxSelectable {
bool selected {
get;
set;
}
bool preSelected {
get;
set;
}
//This property doesn't actually need to be implemented, as this interface should already be placed on a MonoBehaviour, which will
//already have it. Defining it here only allows us access to the transform property by casting through the selectable interface.
Transform transform {
get;
}
}
}

View File

@ -0,0 +1,36 @@
/// <summary>
/// Tool script taken from the UI source as it's set to Internal for some reason. So to use in the extensions project it is needed here also.
/// </summary>
///
namespace UnityEngine.UI.Extensions
{
internal static class SetPropertyUtility
{
public static bool SetColor(ref Color currentValue, Color newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetStruct<T>(ref T currentValue, T newValue) where T: struct
{
if (currentValue.Equals(newValue))
return false;
currentValue = newValue;
return true;
}
public static bool SetClass<T>(ref T currentValue, T newValue) where T: class
{
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
return false;
currentValue = newValue;
return true;
}
}
}

View File

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

View File

@ -4,16 +4,22 @@
/// - bug fix to prevent crash if no control selected
/// - updated to support new semantics for EventSystem in later 4.6 builds
/// - autoselect "firstSelectedGameObject" since it doesn't seem to work automatically
/// Updated 08-29-15 - On request of Issue #13 on repo, added a manual navigation order.
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
public enum NavigationMode { Auto = 0, Manual = 1};
[RequireComponent(typeof(EventSystem))]
[AddComponentMenu("Event/Extensions/Tab Navigation Helper")]
public class TabNavigationHelper : MonoBehaviour
{
private EventSystem _system;
[Tooltip("The path to take when user is tabbing through ui components.")]
public Selectable[] NavigationPath;
[Tooltip("Use the default Unity navigation system or a manual fixed order using Navigation Path")]
public NavigationMode NavigationMode;
void Start()
{
@ -50,6 +56,18 @@ namespace UnityEngine.UI.Extensions
next = _system.firstSelectedGameObject.GetComponent<Selectable>();
}
}
else if(NavigationMode == NavigationMode.Manual)
{
for (var i = 0; i < NavigationPath.Length; i++)
{
if (_system.currentSelectedGameObject != NavigationPath[i].gameObject) continue;
next = i == (NavigationPath.Length - 1) ? NavigationPath[0] : NavigationPath[i + 1];
break;
}
}
else if (_system.currentSelectedGameObject == null)
{
next = _system.firstSelectedGameObject.GetComponent<Selectable>();

View File

@ -32,11 +32,11 @@ namespace UnityEngine.UI.Extensions
//if the tooltip is inside a UI element
private bool _inside;
private bool _xShifted, _yShifted = false;
// private bool _xShifted, _yShifted = false;
private float width, height, canvasWidth, canvasHeight;
private int screenWidth, screenHeight;
// private int screenWidth, screenHeight;
private float YShift,xShift;
@ -57,17 +57,15 @@ namespace UnityEngine.UI.Extensions
_inside = false;
//size of the screen
screenWidth = Screen.width;
screenHeight = Screen.height;
// screenWidth = Screen.width;
// screenHeight = Screen.height;
xShift = 0f;
YShift = -30f;
_xShifted = _yShifted = false;
// _xShifted = _yShifted = false;
this.gameObject.SetActive(false);
}
//Call this function externally to set the text of the template and activate the tooltip

181
Scripts/UILineRenderer.cs Normal file
View File

@ -0,0 +1,181 @@
/// Credit jack.sydorenko
/// Sourced from - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/UILineRenderer")]
public class UILineRenderer : Graphic
{
[SerializeField]
Texture m_Texture;
[SerializeField]
Rect m_UVRect = new Rect(0f, 0f, 1f, 1f);
public float LineThickness = 2;
public bool UseMargins;
public Vector2 Margin;
public Vector2[] Points;
public bool relativeSize;
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();
}
}
/// <summary>
/// UV rectangle used by the texture.
/// </summary>
public Rect uvRect
{
get
{
return m_UVRect;
}
set
{
if (m_UVRect == value)
return;
m_UVRect = value;
SetVerticesDirty();
}
}
protected override void OnFillVBO(List<UIVertex> vbo)
{
// requires sets of quads
if (Points == null || Points.Length < 2)
Points = new[] { new Vector2(0, 0), new Vector2(1, 1) };
var capSize = 24;
var sizeX = rectTransform.rect.width;
var sizeY = rectTransform.rect.height;
var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;
// don't want to scale based on the size of the rect, so this is switchable now
if (!relativeSize)
{
sizeX = 1;
sizeY = 1;
}
// build a new set of points taking into account the cap sizes.
// would be cool to support corners too, but that might be a bit tough :)
var pointList = new List<Vector2>();
pointList.Add(Points[0]);
var capPoint = Points[0] + (Points[1] - Points[0]).normalized * capSize;
pointList.Add(capPoint);
// should bail before the last point to add another cap point
for (int i = 1; i < Points.Length - 1; i++)
{
pointList.Add(Points[i]);
}
capPoint = Points[Points.Length - 1] - (Points[Points.Length - 1] - Points[Points.Length - 2]).normalized * capSize;
pointList.Add(capPoint);
pointList.Add(Points[Points.Length - 1]);
var TempPoints = pointList.ToArray();
if (UseMargins)
{
sizeX -= Margin.x;
sizeY -= Margin.y;
offsetX += Margin.x / 2f;
offsetY += Margin.y / 2f;
}
vbo.Clear();
Vector2 prevV1 = Vector2.zero;
Vector2 prevV2 = Vector2.zero;
for (int i = 1; i < TempPoints.Length; i++)
{
var prev = TempPoints[i - 1];
var cur = TempPoints[i];
prev = new Vector2(prev.x * sizeX + offsetX, prev.y * sizeY + offsetY);
cur = new Vector2(cur.x * sizeX + offsetX, cur.y * sizeY + offsetY);
float angle = Mathf.Atan2(cur.y - prev.y, cur.x - prev.x) * 180f / Mathf.PI;
var v1 = prev + new Vector2(0, -LineThickness / 2);
var v2 = prev + new Vector2(0, +LineThickness / 2);
var v3 = cur + new Vector2(0, +LineThickness / 2);
var v4 = cur + new Vector2(0, -LineThickness / 2);
v1 = RotatePointAroundPivot(v1, prev, new Vector3(0, 0, angle));
v2 = RotatePointAroundPivot(v2, prev, new Vector3(0, 0, angle));
v3 = RotatePointAroundPivot(v3, cur, new Vector3(0, 0, angle));
v4 = RotatePointAroundPivot(v4, cur, new Vector3(0, 0, angle));
Vector2 uvTopLeft = Vector2.zero;
Vector2 uvBottomLeft = new Vector2(0, 1);
Vector2 uvTopCenter = new Vector2(0.5f, 0);
Vector2 uvBottomCenter = new Vector2(0.5f, 1);
Vector2 uvTopRight = new Vector2(1, 0);
Vector2 uvBottomRight = new Vector2(1, 1);
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
if (i > 1)
SetVbo(vbo, new[] { prevV1, prevV2, v1, v2 }, uvs);
if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == TempPoints.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };
SetVbo(vbo, new[] { v1, v2, v3, v4 }, uvs);
prevV1 = v3;
prevV2 = v4;
}
}
protected void SetVbo(List<UIVertex> vbo, Vector2[] vertices, Vector2[] uvs)
{
for (int i = 0; i < vertices.Length; i++)
{
var vert = UIVertex.simpleVert;
vert.color = color;
vert.position = vertices[i];
vert.uv0 = uvs[i];
vbo.Add(vert);
}
}
public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
{
Vector3 dir = point - pivot; // get point direction relative to pivot
dir = Quaternion.Euler(angles) * dir; // rotate it
point = dir + pivot; // calculate rotated point
return point; // return it
}
}
}

View File

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

View File

@ -0,0 +1,182 @@
/// Credit Martin Sharkbomb
/// Based on original LineRender script by jack.sydorenko
/// Sourced from - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/UILineTextureRenderer")]
public class UILineTextureRenderer : Graphic
{
[SerializeField]
Texture m_Texture;
[SerializeField]
Rect m_UVRect = new Rect(0f, 0f, 1f, 1f);
public float LineThickness = 2;
public bool UseMargins;
public Vector2 Margin;
public Vector2[] Points;
public bool relativeSize;
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();
}
}
/// <summary>
/// UV rectangle used by the texture.
/// </summary>
public Rect uvRect
{
get
{
return m_UVRect;
}
set
{
if (m_UVRect == value)
return;
m_UVRect = value;
SetVerticesDirty();
}
}
protected override void OnFillVBO(List<UIVertex> vbo)
{
// requires sets of quads
if (Points == null || Points.Length < 2)
Points = new[] { new Vector2(0, 0), new Vector2(1, 1) };
var capSize = 24;
var sizeX = rectTransform.rect.width;
var sizeY = rectTransform.rect.height;
var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;
// don't want to scale based on the size of the rect, so this is switchable now
if (!relativeSize)
{
sizeX = 1;
sizeY = 1;
}
// build a new set of points taking into account the cap sizes.
// would be cool to support corners too, but that might be a bit tough :)
var pointList = new List<Vector2>();
pointList.Add(Points[0]);
var capPoint = Points[0] + (Points[1] - Points[0]).normalized * capSize;
pointList.Add(capPoint);
// should bail before the last point to add another cap point
for (int i = 1; i < Points.Length - 1; i++)
{
pointList.Add(Points[i]);
}
capPoint = Points[Points.Length - 1] - (Points[Points.Length - 1] - Points[Points.Length - 2]).normalized * capSize;
pointList.Add(capPoint);
pointList.Add(Points[Points.Length - 1]);
var TempPoints = pointList.ToArray();
if (UseMargins)
{
sizeX -= Margin.x;
sizeY -= Margin.y;
offsetX += Margin.x / 2f;
offsetY += Margin.y / 2f;
}
vbo.Clear();
Vector2 prevV1 = Vector2.zero;
Vector2 prevV2 = Vector2.zero;
for (int i = 1; i < TempPoints.Length; i++)
{
var prev = TempPoints[i - 1];
var cur = TempPoints[i];
prev = new Vector2(prev.x * sizeX + offsetX, prev.y * sizeY + offsetY);
cur = new Vector2(cur.x * sizeX + offsetX, cur.y * sizeY + offsetY);
float angle = Mathf.Atan2(cur.y - prev.y, cur.x - prev.x) * 180f / Mathf.PI;
var v1 = prev + new Vector2(0, -LineThickness / 2);
var v2 = prev + new Vector2(0, +LineThickness / 2);
var v3 = cur + new Vector2(0, +LineThickness / 2);
var v4 = cur + new Vector2(0, -LineThickness / 2);
v1 = RotatePointAroundPivot(v1, prev, new Vector3(0, 0, angle));
v2 = RotatePointAroundPivot(v2, prev, new Vector3(0, 0, angle));
v3 = RotatePointAroundPivot(v3, cur, new Vector3(0, 0, angle));
v4 = RotatePointAroundPivot(v4, cur, new Vector3(0, 0, angle));
Vector2 uvTopLeft = Vector2.zero;
Vector2 uvBottomLeft = new Vector2(0, 1);
Vector2 uvTopCenter = new Vector2(0.5f, 0);
Vector2 uvBottomCenter = new Vector2(0.5f, 1);
Vector2 uvTopRight = new Vector2(1, 0);
Vector2 uvBottomRight = new Vector2(1, 1);
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
if (i > 1)
SetVbo(vbo, new[] { prevV1, prevV2, v1, v2 }, uvs);
if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == TempPoints.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };
SetVbo(vbo, new[] { v1, v2, v3, v4 }, uvs);
prevV1 = v3;
prevV2 = v4;
}
}
protected void SetVbo(List<UIVertex> vbo, Vector2[] vertices, Vector2[] uvs)
{
for (int i = 0; i < vertices.Length; i++)
{
var vert = UIVertex.simpleVert;
vert.color = color;
vert.position = vertices[i];
vert.uv0 = uvs[i];
vbo.Add(vert);
}
}
public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
{
Vector3 dir = point - pivot; // get point direction relative to pivot
dir = Quaternion.Euler(angles) * dir; // rotate it
point = dir + pivot; // calculate rotated point
return point; // return it
}
}
}

View File

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

View File

@ -1,17 +1,19 @@
/// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648
/*USAGE:
Simply place the script on the ScrollRect that contains the selectable children we'll be scroling to
/// Credit zero3growlithe
/// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648
/*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 UIScrollToSelection : MonoBehaviour
{
/* ### VARIABLES ============================================================== */
#region Variables
// settings
public float scrollSpeed = 10f;
@ -29,8 +31,8 @@ namespace UnityEngine.UI.Extensions
private ScrollRect targetScrollRect;
private EventSystem events = EventSystem.current;
#endregion
/* ### MAIN METHODS =========================================================== */
// Use this for initialization
private void Start()
{

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6099846579e92994a8eb58147565e5b6
timeCreated: 1440889727
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ba77f83df2a458247a09d6017fed6ec2
timeCreated: 1440890266
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant: