Merge with develop-Unity5.1
commit
e654fb5434
|
@ -84,9 +84,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
image.color = color;
|
image.color = color;
|
||||||
}
|
}
|
||||||
else if (renderer)
|
else if (GetComponent<UnityEngine.Renderer>())
|
||||||
{
|
{
|
||||||
renderer.material.color = color;
|
GetComponent<UnityEngine.Renderer>().material.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
} else {
|
} else {
|
||||||
//If it doesn't have a rectTransform, we need to get the radius so we can use it as an area around the center to detect a click.
|
//If it doesn't have a rectTransform, we need to get the radius so we can use it as an area around the center to detect a click.
|
||||||
//This works because a 2D or 3D renderer will both return a radius
|
//This works because a 2D or 3D renderer will both return a radius
|
||||||
var radius = selectable.transform.renderer.bounds.extents.magnitude;
|
var radius = selectable.transform.GetComponent<UnityEngine.Renderer>().bounds.extents.magnitude;
|
||||||
|
|
||||||
var selectableScreenPoint = GetScreenPointOfSelectable(selectable);
|
var selectableScreenPoint = GetScreenPointOfSelectable(selectable);
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
Simply place the script on the ScrollRect that contains the selectable children we'll be scroling to
|
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.*/
|
and drag'n'drop the RectTransform of the options "container" that we'll be scrolling.*/
|
||||||
|
|
||||||
using UnityEngine;
|
|
||||||
using System.Collections;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
public class UIScrollToSelection : MonoBehaviour {
|
namespace UnityEngine.UI.Extensions
|
||||||
|
{
|
||||||
|
public class UIScrollToSelection : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
/* ### VARIABLES ============================================================== */
|
/* ### VARIABLES ============================================================== */
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
public float scrollSpeed = 10f;
|
public float scrollSpeed = 10f;
|
||||||
|
@ -28,30 +28,34 @@ public class UIScrollToSelection : MonoBehaviour {
|
||||||
private RectTransform currentCanvas;
|
private RectTransform currentCanvas;
|
||||||
private ScrollRect targetScrollRect;
|
private ScrollRect targetScrollRect;
|
||||||
|
|
||||||
|
private EventSystem events = EventSystem.current;
|
||||||
|
|
||||||
/* ### MAIN METHODS =========================================================== */
|
/* ### MAIN METHODS =========================================================== */
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
private void Start () {
|
private void Start()
|
||||||
|
{
|
||||||
targetScrollRect = GetComponent<ScrollRect>();
|
targetScrollRect = GetComponent<ScrollRect>();
|
||||||
scrollWindow = targetScrollRect.GetComponent<RectTransform>();
|
scrollWindow = targetScrollRect.GetComponent<RectTransform>();
|
||||||
currentCanvas = transform.root.GetComponent<RectTransform>();
|
currentCanvas = transform.root.GetComponent<RectTransform>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
private void Update () {
|
private void Update()
|
||||||
|
{
|
||||||
ScrollRectToLevelSelection();
|
ScrollRectToLevelSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScrollRectToLevelSelection (){
|
private void ScrollRectToLevelSelection()
|
||||||
|
{
|
||||||
// check main references
|
// check main references
|
||||||
bool referencesAreIncorrect =
|
bool referencesAreIncorrect =
|
||||||
(targetScrollRect == null || layoutListGroup == null || scrollWindow == null);
|
(targetScrollRect == null || layoutListGroup == null || scrollWindow == null);
|
||||||
if (referencesAreIncorrect == true){
|
if (referencesAreIncorrect == true)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get calculation references
|
// get calculation references
|
||||||
EventSystem events = EventSystem.current;
|
|
||||||
RectTransform selection = events.currentSelectedGameObject != null ?
|
RectTransform selection = events.currentSelectedGameObject != null ?
|
||||||
events.currentSelectedGameObject.GetComponent<RectTransform>() :
|
events.currentSelectedGameObject.GetComponent<RectTransform>() :
|
||||||
null;
|
null;
|
||||||
|
@ -96,11 +100,5 @@ public class UIScrollToSelection : MonoBehaviour {
|
||||||
// save last object we were "heading to" to prevent blocking
|
// save last object we were "heading to" to prevent blocking
|
||||||
targetScrollObject = selection;
|
targetScrollObject = selection;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* ### ENUMS ================================================================== */
|
|
||||||
|
|
||||||
|
|
||||||
/* ### CUSTOM TYPES =========================================================== */
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a5f5420166e1c6d4f849661cbdbc52f8
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
Loading…
Reference in New Issue