/// Credit Mrs. YakaYocha
/// Sourced from - https://www.youtube.com/channel/UCHp8LZ_0-iCvl-5pjHATsgw
/// Please donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RJ8D9FRFQF9VS
using UnityEngine.Events;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("Layout/Extensions/Vertical Scroller")]
public class UIVerticalScroller : MonoBehaviour
{
[Tooltip("Scrollable area (content of desired ScrollRect)")]
public RectTransform _scrollingPanel;
[Tooltip("Elements to populate inside the scroller")]
public GameObject[] _arrayOfElements;
[Tooltip("Center display area (position of zoomed content)")]
public RectTransform _center;
[Tooltip("Select the item to be in center on start. (optional)")]
public int StartingIndex = -1;
[Tooltip("Button to go to the next page. (optional)")]
public GameObject ScrollUpButton;
[Tooltip("Button to go to the previous page. (optional)")]
public GameObject ScrollDownButton;
[Tooltip("Event fired when a specific item is clicked, exposes index number of item. (optional)")]
public UnityEvent ButtonClicked;
private float[] distReposition;
private float[] distance;
//private int elementsDistance;
private int minElementsNum;
private int elementLength;
//private int elementHalfLength;
private float deltaY;
private string result;
public UIVerticalScroller() { }
public UIVerticalScroller(RectTransform scrollingPanel, GameObject[] arrayOfElements, RectTransform center)
{
_scrollingPanel = scrollingPanel;
_arrayOfElements = arrayOfElements;
_center = center;
}
public void Awake()
{
var scrollRect = GetComponent();
if (!_scrollingPanel)
{
_scrollingPanel = scrollRect.content;
}
if (!_center)
{
Debug.LogError("Please define the RectTransform for the Center viewport of the scrollable area");
}
if (_arrayOfElements == null || _arrayOfElements.Length == 0)
{
var childCount = scrollRect.content.childCount;
if (childCount > 0)
{
_arrayOfElements = new GameObject[childCount];
for (int i = 0; i < childCount; i++)
{
_arrayOfElements[i] = scrollRect.content.GetChild(i).gameObject;
}
}
}
}
public void Start()
{
if (_arrayOfElements.Length < 1)
{
Debug.Log("No child content found, exiting..");
return;
}
elementLength = _arrayOfElements.Length;
distance = new float[elementLength];
distReposition = new float[elementLength];
//get distance between buttons
//elementsDistance = (int)Mathf.Abs(_arrayOfElements[1].GetComponent().anchoredPosition.y - _arrayOfElements[0].GetComponent().anchoredPosition.y);
deltaY = _arrayOfElements[0].GetComponent().rect.height * elementLength / 3 * 2;
Vector2 startPosition = new Vector2(_scrollingPanel.anchoredPosition.x, -deltaY);
_scrollingPanel.anchoredPosition = startPosition;
for (var i = 0; i < _arrayOfElements.Length; i++)
{
AddListener(_arrayOfElements[i], i);
}
if (ScrollUpButton)
ScrollUpButton.GetComponent
源代码是上下滑动的,再上我改过之后的代码,左右滑动的;
/// Credit Mrs. YakaYocha
/// Sourced from - https://www.youtube.com/channel/UCHp8LZ_0-iCvl-5pjHATsgw
/// Please donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RJ8D9FRFQF9VS
using UnityEngine.Events;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("Layout/Extensions/Vertical Scroller")]
public class UIVerticalScrollerMove : MonoBehaviour
{
[Tooltip("Scrollable area (content of desired ScrollRect)")]
public RectTransform _scrollingPanel;//展示面板
[Tooltip("Elements to populate inside the scroller")]
public GameObject[] _arrayOfElements;//长度元素
[Tooltip("Center display area (position of zoomed content)")]
public RectTransform _center;//位置
[Tooltip("Select the item to be in center on start. (optional)")]
public int StartingIndex = -1;//初始指针(外界提供)
[Tooltip("Button to go to the next page. (optional)")]
public GameObject ScrollLeftButton;//左按钮
[Tooltip("Button to go to the previous page. (optional)")]
public GameObject ScrollRightButton;//右按钮
[Tooltip("Event fired when a specific item is clicked, exposes index number of item. (optional)")]
public UnityEvent ButtonClicked;//按钮点击
private float[] distReposition;//长度改变
private float[] distance;//长度列表
//private int elementsDistance;
private int minElementsNum;//最小元素数
private int elementLength;//元素长度
//private int elementHalfLength;
private float deltaX;//移动x
private string result;//结果
public UIVerticalScrollerMove() { }//构造函数
public UIVerticalScrollerMove(RectTransform scrollingPanel, GameObject[] arrayOfElements, RectTransform center)
{
_scrollingPanel = scrollingPanel;
_arrayOfElements = arrayOfElements;
_center = center;
}
//初始化启动
public void Awake()
{
var scrollRect = GetComponent();//获取到排列
if (!_scrollingPanel)
{
_scrollingPanel = scrollRect.content;//如果不是展示面板,获取该物体的可滚动的面板
}
if (!_center)//如果设置不成功,打印失败
{
Debug.LogError("Please define the RectTransform for the Center viewport of the scrollable area");
}
if (_arrayOfElements == null || _arrayOfElements.Length == 0)
{
var childCount = scrollRect.content.childCount;
if (childCount > 0)
{
_arrayOfElements = new GameObject[childCount];
for (int i = 0; i < childCount; i++)
{
_arrayOfElements[i] = scrollRect.content.GetChild(i).gameObject;
}
}
}//获取子物体的长度
}
//初始化启动
public void Start()
{
if (_arrayOfElements.Length < 1)
{
Debug.Log("No child content found, exiting..");
return;
}//没有子物体的时候,打印寻找失败
elementLength = _arrayOfElements.Length;
distance = new float[elementLength];
distReposition = new float[elementLength];//通过子物体的长度定义距离长度列表与移动长度列表
//get distance between buttons
//elementsDistance = (int)Mathf.Abs(_arrayOfElements[1].GetComponent().anchoredPosition.y - _arrayOfElements[0].GetComponent().anchoredPosition.y);
deltaX = _arrayOfElements[0].GetComponent().rect.width * elementLength / 3 * 2;
Vector2 startPosition = new Vector2( -deltaX,_scrollingPanel.anchoredPosition.y);
_scrollingPanel.anchoredPosition = startPosition;//获取到更改的按钮
for (var i = 0; i < _arrayOfElements.Length; i++)
{
AddListener(_arrayOfElements[i], i);
}//监听每个按钮上挂载的方法
//如果左右按钮的话,分别监听不同的方法
if (ScrollLeftButton)
ScrollLeftButton.GetComponent().onClick.AddListener(() => { ScrollLeft(); });
if (ScrollRightButton)
ScrollRightButton.GetComponent().onClick.AddListener(() => { ScrollRight(); });
//比较外界提供的初始指针并进行初始定位
if (StartingIndex > -1)
{
StartingIndex = StartingIndex > _arrayOfElements.Length ? _arrayOfElements.Length - 1 : StartingIndex;
SnapToElement(StartingIndex);
}
}
//让该物体监听到自己所对应的事件
private void AddListener(GameObject button, int index)
{
button.GetComponent().onClick.AddListener(() => DoSomething(index));
}
//index按钮对应的点击状态
private void DoSomething(int index)
{
if (ButtonClicked != null)
{
ButtonClicked.Invoke(index);
}
}
//逻辑更新
public void Update()
{
if (_arrayOfElements.Length < 1)
{
return;
}//子物体为空的时候返回
for (var i = 0; i < elementLength; i++)
{
distReposition[i] = _center.GetComponent().position.x - _arrayOfElements[i].GetComponent().position.x;
distance[i] = Mathf.Abs(distReposition[i]);
//Magnifying effect
float scale = Mathf.Max(0.7f, 1 / (1 + distance[i] / 200));
_arrayOfElements[i].GetComponent().transform.localScale = new Vector3(scale, scale, 1f);
}//不断更新可滑动面板下面的物体下面的动态数列
float minDistance = Mathf.Min(distance);//求出最小间距
for (var i = 0; i < elementLength; i++)
{
_arrayOfElements[i].GetComponent().interactable = false;
if (minDistance == distance[i])
{
minElementsNum = i;
_arrayOfElements[i].GetComponent().interactable = true;
result = _arrayOfElements[i].GetComponentInChildren().text;
}
}//除了被选中的物体,其余物体都是不可交互的
ScrollingElements(-_arrayOfElements[minElementsNum].GetComponent().anchoredPosition.x);//不断向着新坐标移动
}
//不断移动坐标,保证向着目标点移动
private void ScrollingElements(float position)
{
float newX= Mathf.Lerp(_scrollingPanel.anchoredPosition.x, position, Time.deltaTime * 1f);
Vector2 newPosition = new Vector2(newX,_scrollingPanel.anchoredPosition.y);
_scrollingPanel.anchoredPosition = newPosition;
}
public string GetResults()
{
return result;
}
//通过指针计算该物体在坐标栏下的位置
public void SnapToElement(int element)
{
float deltaElementPositionX = _arrayOfElements[0].GetComponent().rect.width * element;
Vector2 newPosition = new Vector2(-deltaElementPositionX,_scrollingPanel.anchoredPosition.y);
_scrollingPanel.anchoredPosition = newPosition;
}
//左右滑动
public void ScrollLeft()
{
float deltaLeft = _arrayOfElements[0].GetComponent().rect.width / 1.2f;
Vector2 newPositionLeft = new Vector2(_scrollingPanel.anchoredPosition.x-deltaLeft, _scrollingPanel.anchoredPosition.y);
_scrollingPanel.anchoredPosition = Vector2.Lerp(_scrollingPanel.anchoredPosition,newPositionLeft, 1);
}
public void ScrollRight()
{
float deltaRight = _arrayOfElements[0].GetComponent().rect.width / 1.2f;
Vector2 newPositionRight = new Vector2(_scrollingPanel.anchoredPosition.x+deltaRight, _scrollingPanel.anchoredPosition.y);
_scrollingPanel.anchoredPosition = newPositionRight;
}
}
}
这是可插件里面的类库,不过核心逻辑可以用Unity来重写,以上都有注释。
最后是引用方法:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UI.Extensions;
public class ScrollingCalendarTest : MonoBehaviour {
public RectTransform monthsScrollingPanel;
public GameObject monthsButtonPrefab;
private GameObject[] monthsButtons;
public RectTransform monthCenter;
private int monthsSet;
UIVerticalScrollerMove monthsVerticalScroller;
//Initialize Months
//生成预制体
private void InitializeMonths()
{
int[] months = new int[12];
monthsButtons = new GameObject[months.Length];
for (int i = 0; i < months.Length; i++)
{
string month = "";
months[i] = i;
GameObject clone = (GameObject)Instantiate(monthsButtonPrefab, new Vector3(i * 380,0, 0), Quaternion.Euler(new Vector3(0, 0, 0))) as GameObject;
clone.transform.SetParent(monthsScrollingPanel, false);
clone.transform.localScale = new Vector3(1, 1, 1);
month = ""+i;
clone.GetComponentInChildren().text = month;
clone.name = "Month_" + months[i];
clone.AddComponent();
monthsButtons[i] = clone;
}
}
// Use this for initialization
public void Awake()
{
InitializeMonths();
//Yes Unity complains about this but it doesn't matter in this case.
monthsVerticalScroller = new UIVerticalScrollerMove(monthsScrollingPanel, monthsButtons, monthCenter);
monthsVerticalScroller.Start();
}
public void SetDate()
{
// monthsSet = int.Parse(inputFieldMonths.text) - 1;
monthsVerticalScroller.SnapToElement(monthsSet);
}
void Update()
{
monthsVerticalScroller.Update();
string monthString = monthsVerticalScroller.GetResults();
}
public void MonthsScrollUp()
{
monthsVerticalScroller.ScrollLeft();
}
public void MonthsScrollDown()
{
monthsVerticalScroller.ScrollRight();
}
}
Enum是计算机编程语言中的一种数据类型---枚举类型。 在实际问题中,有些变量的取值被限定在一个有限的范围内。 例如,一个星期内只有七天 我们通常这样实现上面的定义:
public String monday;
public String tuesday;
public String wensday;
public String thursday
java.lang.IllegalStateException: No matching PlatformTransactionManager bean found for qualifier 'add' - neither qualifier match nor bean name match!
网上找了好多的资料没能解决,后来发现:项目中使用的是xml配置的方式配置事务,但是
原文:http://stackoverflow.com/questions/15585602/change-limit-for-mysql-row-size-too-large
异常信息:
Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAM
/**
* 格式化时间 2013/6/13 by 半仙 [email protected]
* 需要 pad 函数
* 接收可用的时间值.
* 返回替换时间占位符后的字符串
*
* 时间占位符:年 Y 月 M 日 D 小时 h 分 m 秒 s 重复次数表示占位数
* 如 YYYY 4占4位 YY 占2位<p></p>
* MM DD hh mm
在使用下面的命令是可以通过--help来获取更多的信息1,查询当前目录文件列表:ls
ls命令默认状态下将按首字母升序列出你当前文件夹下面的所有内容,但这样直接运行所得到的信息也是比较少的,通常它可以结合以下这些参数运行以查询更多的信息:
ls / 显示/.下的所有文件和目录
ls -l 给出文件或者文件夹的详细信息
ls -a 显示所有文件,包括隐藏文
Spring Tool Suite(简称STS)是基于Eclipse,专门针对Spring开发者提供大量的便捷功能的优秀开发工具。
在3.7.0版本主要做了如下的更新:
将eclipse版本更新至Eclipse Mars 4.5 GA
Spring Boot(JavaEE开发的颠覆者集大成者,推荐大家学习)的配置语言YAML编辑器的支持(包含自动提示,