日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php年月日滚动选择,Unity3d—做一个年月日选择器(Scroll Rect拖动效果优化)— 无限滚动 + 锁定元素...

發(fā)布時間:2023/12/4 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php年月日滚动选择,Unity3d—做一个年月日选择器(Scroll Rect拖动效果优化)— 无限滚动 + 锁定元素... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

[導(dǎo)讀]最近.....廢話不多說上效果圖用的是UGUI我先說思路通過判斷元素的位置信息來改變Hierarchy的順序 實現(xiàn)無限滾動改變位置的同時也要不斷的調(diào)整Content的位置防止亂跳元素鎖定就是直接鎖死的元素的移動范圍 當(dāng)只有拖動大于一定程度時

最近.....

廢話不多說上效果圖

用的是UGUI

我先說思路

通過判斷元素的位置信息來改變Hierarchy的順序 實現(xiàn)無限滾動

改變位置的同時也要不斷的調(diào)整Content的位置防止亂跳

元素鎖定就是直接鎖死的元素的移動范圍 當(dāng)只有拖動大于一定程度時才會發(fā)生改變

然后是面板設(shè)置

整體結(jié)構(gòu)是這樣子的

需要注意的是Content需要的兩個組件

Content的爸爸只需要一個腳本

大小改變曲線(大致就行)

顏色漸變曲線

最后是腳本using?System;

using?System.Collections;

using?System.Collections.Generic;

using?UnityEngine;

using?UnityEngine.EventSystems;

using?UnityEngine.UI;

public?class?DateControl?:?MonoBehaviour,?IBeginDragHandler,?IDragHandler,?IEndDragHandler?{

public?enum?ItemType?{?_year,?_month,?_day?}

public?ItemType?_itemtype;

RectTransform?conentRect;

RectTransform?targetRec;

Vector3?oldDragPos;

Vector3?newDragPos;

public?AnimationCurve?curve_scale;//改變大小曲線

public?AnimationCurve?curve_color;//漸變效果曲線

List?textList?=?new?List();

Button?testBtn;

float

itemHeight,?????????????//子項item的高

contentParentHeight,????//Content爸爸的高

itemNum,????????????????//子項數(shù)量

itemHeight_min,?????????//子項最小發(fā)生改變位置

itemHeight_max,?????????//子項最大發(fā)生改變位置

conentLimit,????????????//Conent糾正位置

conentSpacing;??????????//子項間隔大小

float?deltaX,?deltaY;

[HideInInspector]

public?static?int?_year,?_month,?_day;

[HideInInspector]

int?dateItemNum;

Color?itemColor_hig?=?new?Color32(255,?255,?255,?255);

void?Awake()?{

conentRect?=?transform.FindChild("Content").GetComponent();

targetRec?=?transform.parent.FindChild("HighlightTarget").GetComponent();

}

void?OnEnable()?{

ItemList();

}

void?Start()?{

switch?(_itemtype)?{

case?ItemType._year:?InstantiateData(15,?2017);?break;

case?ItemType._month:?InstantiateData(12,?12);?break;

case?ItemType._day:?InstantiateData(31,?31);?break;

}

itemNum?=?transform.FindChild("Content").childCount?-?1;

contentParentHeight?=?conentRect.parent.GetComponent().sizeDelta.y;

conentSpacing?=?conentRect.GetComponent().spacing?/?2;

itemHeight?=?textList[0].rectTransform.sizeDelta.y?+?conentSpacing;

if?(itemNum?%?2?==?0)?conentLimit?=?(itemHeight?+?5)?/?2;

else?conentLimit?=?0;

conentRect.anchoredPosition?=?new?Vector2(conentRect.anchoredPosition.x,?conentLimit);

deltaX?=?textList[0].GetComponent().sizeDelta.x;

deltaY?=?textList[0].GetComponent().sizeDelta.y;

Invoke("ItemList",?0.05f);

}

///?

///?生成子項item

///?

///?子項數(shù)量

///?子項最大值

void?InstantiateData(int?itemNum,?int?dat)?{

GameObject?go;

Text?testObj?=?conentRect.FindChild("Text").GetComponent();

for?(int?i?=?dat?-?itemNum?+?1;?i?<=?dat;?i++)?{

go?=?Instantiate(testObj.gameObject,?conentRect);

go.GetComponent().text?=?i.ToString();

go.name?=?i.ToString();

textList.Add(go.GetComponent());

ShowItem(true);

}

Destroy(conentRect.FindChild("Text").gameObject);

}

///?

///?是增加或減少

///?

///?

void?ShowItem(bool?isIncreaseOrdecrease)?{

itemHeight_min?=?-itemHeight;

if?(_itemtype?==?ItemType._day)?itemHeight_max?=?-itemHeight?*?itemNum?-?95;

else?itemHeight_max?=?-itemHeight?*?itemNum;

if?(isIncreaseOrdecrease)?{

foreach?(Text?rectItem?in?textList)?{

if?(rectItem.GetComponent().anchoredPosition.y?>?itemHeight_min)?{

print("+");

rectItem.transform.SetSiblingIndex((int)itemNum);

}

}

print(itemHeight_min);

}?else?{

foreach?(Text?rectItem?in?textList)?{

if?(rectItem.GetComponent().anchoredPosition.y?

print("-");

rectItem.transform.SetSiblingIndex(0);

}

}

print(itemHeight_max);

}

}

///?

///?漸變效果,改變大小,高亮顯示

///?

void?ItemList()?{

foreach?(Text?item?in?textList)?{

float?indexA?=?Mathf.Abs(item.GetComponent().position.y?-?targetRec.position.y);

float?indexSc_scale?=?Mathf.Abs(curve_scale.Evaluate(indexA?/?contentParentHeight));

float?indexSc_color?=?Mathf.Abs(curve_color.Evaluate(indexA?/?contentParentHeight));

if?(indexA?

item.color?=?itemColor_hig;

switch?(_itemtype)?{

case?ItemType._year:?_year?=?int.Parse(item.text);?break;

case?ItemType._month:?_month?=?int.Parse(item.text);?break;

case?ItemType._day:?_day?=?int.Parse(item.text);?break;

}

}?else?item.color?=?new?Color(0,?0,?0,?1?-?indexSc_color);

item.GetComponent().localScale?=?new?Vector3(1?-?indexSc_scale,?1?-?indexSc_scale?*?3,?1?-?indexSc_scale);

//item.GetComponent().sizeDelta?=?new?Vector2(deltaX?-?(deltaX?*?indexSc),?deltaY?-?(deltaY?*?indexSc));

}

}

///?

///?獲取int類型日期,并轉(zhuǎn)換為指定格式

///?

///?

public?static?string?GetDateInfo()?{?return?_year?+?"-"?+?_month?+?"-"?+?_day;?}

///?

///?糾正Conent位置

///?

void?UpdateEx()?{

if?(conentRect.anchoredPosition.y?>?conentLimit)?{

ShowItem(true);

conentRect.anchoredPosition?=?new?Vector2(conentRect.anchoredPosition.x,?conentRect.anchoredPosition.y?-?itemHeight);

}

if?(conentRect.anchoredPosition.y?

ShowItem(false);

conentRect.anchoredPosition?=?new?Vector2(conentRect.anchoredPosition.x,?conentRect.anchoredPosition.y?+?itemHeight);

}

}

///?

///?獲取拖拽信息并改變Conent位置

///?

///?

void?SetDraggedPosition(PointerEventData?eventData)?{

if?(RectTransformUtility.ScreenPointToWorldPointInRectangle(conentRect,?eventData.position,?eventData.pressEventCamera,?out?newDragPos))?{

newDragPos?=?eventData.position;

if?(Mathf.Abs(newDragPos.y?-?oldDragPos.y)?>=?itemHeight)?{

if?(newDragPos.y?>?oldDragPos.y)?{

conentRect.anchoredPosition?=?new?Vector2(conentRect.anchoredPosition.x,?conentRect.anchoredPosition.y?+?itemHeight);

oldDragPos?+=?new?Vector3(0,?itemHeight,?0);

ItemList();

}?else?{

conentRect.anchoredPosition?=?new?Vector2(conentRect.anchoredPosition.x,?conentRect.anchoredPosition.y?-?itemHeight);

oldDragPos?-=?new?Vector3(0,?itemHeight,?0);

ItemList();

}

}

}

}

///?

///?當(dāng)開始拖拽

///?

///?

public?void?OnBeginDrag(PointerEventData?eventData)?{

oldDragPos?=?eventData.position;

}

public?void?OnDrag(PointerEventData?eventData)?{

SetDraggedPosition(eventData);

UpdateEx();

}

public?void?OnEndDrag(PointerEventData?eventData)?{

SetDraggedPosition(eventData);

UpdateEx();

}

}

照著來的話基本沒什么問題

因為趕時間所以很多地方寫的簡單粗暴請諒解

如果調(diào)整元素大小或者間隙大小 需要改變itemHeight_min 和?itemHeight_max的值

他們分別為

itemHeight_min

itemHeight_max

也就是元素的最頂層和最底層的Y值

以上就是年月日選擇器的具體步驟

總結(jié)

以上是生活随笔為你收集整理的php年月日滚动选择,Unity3d—做一个年月日选择器(Scroll Rect拖动效果优化)— 无限滚动 + 锁定元素...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。