ScrollView 常用
//m_scroll.content 的 Pivot.Y 要 = 1;
m_scroll.verticalNormalizedPosition = 1; //回到最顶
m_scroll.content.ForceUpdateRectTransforms();
注:
verticalNormalizedPosition = 1 - (ScrollRectY * curPage / (ContentRectY - ScrollRectY))
自适应Image常用
void ImageSizeClamp(RawImage img, float maxX, float maxY)
{
img.SetNativeSize();
float sr = Mathf.Min(
maxX / img.rectTransform.sizeDelta.x,
maxY / img.rectTransform.sizeDelta.y);
img.rectTransform.localScale = new Vector3(sr, sr, sr);
}
获取图片名
m_name = img.name.split('.')[0];
一:https://blog.csdn.net/MikeW138/article/details/91872444
List前后数值
有时候需要获取List的前后两个数字,如果直接加减1的话有可能超出范围。增加的话可以使用 %来取余数,但是减少的话 %不能取正余数,于是…
while(curID < 0) {curID += idList.length; } //视乎情况是否需要
int curIdPlus = (curID + 1) % idList.length;
int curIdMinus = (curID + idList.length- 1) % idList.length;
DoProgress(idList[curIdMinus]);