unity 3d类似 苹果的滑动菜单
2013-11-29 20:19
357 查看
var MySkin : GUISkin;
var PrcRect : Rect[];
var PrcNum : int;
var PrcRectX : float[];
var PrcRectY : float[];
var PrcRectW : float[];
var PrcRectH : float[];
var PrcState : boolean[];
var PrcID : int;
var Scral : float;
var PrcSpeed : float;
function Start()
{
PrcNum = 10;
PrcSpeed = 100.0;
PrcRect = new Rect[PrcNum];
PrcRectX = new float[PrcNum];
PrcRectY = new float[PrcNum];
PrcRectW = new float[PrcNum];
PrcRectH = new float[PrcNum];
PrcState = new boolean[PrcNum];
for( i = 0; i < PrcNum; i++ )
{
PrcState[i] = false;
if( i==0 )
{
PrcRectX[0] = 200;
PrcRectY[0] = 200;
PrcRectW[0] = 50.0;
PrcRectH[0] = 50.0;
}else
{
PrcRectX[i] = PrcRectX[i-1]+PrcRectW[i-1];
PrcRectY[i] = PrcRectY[i-1];
PrcRectW[i] = PrcRectW[i-1];
PrcRectH[i] = PrcRectH[i-1];
}
}
}
function Update (){
for( i = 1; i < PrcNum; i++ )
{
if( PrcState[i] )
{
if( PrcRectW[i] <100.0 )
{
Scral-=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]-=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]+=PrcSpeed*Time.deltaTime;
PrcRectH[i]+=PrcSpeed*Time.deltaTime;
}
if( PrcRectW[i-1] <70.0 )
{
Scral-=PrcSpeed*Time.deltaTime/2;
PrcRectY[i-1]-=PrcSpeed*Time.deltaTime/2;
PrcRectW[i-1]+=PrcSpeed*Time.deltaTime;
PrcRectH[i-1]+=PrcSpeed*Time.deltaTime;
}
if(i<PrcNum-1 && PrcRectW[i+1] <70.0)
{
Scral-=PrcSpeed*Time.deltaTime/2;
PrcRectY[i+1]-=PrcSpeed*Time.deltaTime/2;
PrcRectW[i+1]+=PrcSpeed*Time.deltaTime;
PrcRectH[i+1]+=PrcSpeed*Time.deltaTime;
}
}
else
{
if( i == PrcID-1|| i == PrcID+1 )
{
if( PrcRectW[PrcID] <
100.0 && PrcRectW[i] >70.0 )
{
Scral+=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]+=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]-=PrcSpeed*Time.deltaTime;
PrcRectH[i]-=PrcSpeed*Time.deltaTime;
}
}
else
{
if( PrcRectW[i] >50.0 )
{
Scral+=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]+=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]-=PrcSpeed*Time.deltaTime;
PrcRectH[i]-=PrcSpeed*Time.deltaTime;
}
}
}
if( i==0 )
{
PrcRectX[0] = Scral + 200;
PrcRect[0] = Rect (PrcRectX[0], PrcRectY[0], PrcRectW[0], PrcRectH[0]);
}
else
{
PrcRectX[i] = PrcRectX[i-1]+PrcRectW[i-1];
PrcRect[i] = Rect (PrcRectX[i], PrcRectY[i], PrcRectW[i], PrcRectH[i]);
}
}
}
function OnGUI() {
GUI.skin = MySkin ;
for( i = 0; i < PrcNum; i++ )
{
if (PrcRect[i].Contains(Event.current.mousePosition)){
PrcID = i;
PrcState[i] = true;
}else
{
PrcState[i] = false;
}
if( !Rect( PrcRectX[0],PrcRectY[0],PrcRectW[0]*(PrcNum +1),PrcRectH[0] ).Contains(
Event.current.mousePosition ) )
{
if( PrcRectW[i] >50.0 ){
Scral+=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]+=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]-=PrcSpeed*Time.deltaTime;
PrcRectH[i]-=PrcSpeed*Time.deltaTime;
}
}
}
for( i = 0; i < PrcNum; i++ )
{
GUI.Button( PrcRect[i],"" );
}
}
var PrcRect : Rect[];
var PrcNum : int;
var PrcRectX : float[];
var PrcRectY : float[];
var PrcRectW : float[];
var PrcRectH : float[];
var PrcState : boolean[];
var PrcID : int;
var Scral : float;
var PrcSpeed : float;
function Start()
{
PrcNum = 10;
PrcSpeed = 100.0;
PrcRect = new Rect[PrcNum];
PrcRectX = new float[PrcNum];
PrcRectY = new float[PrcNum];
PrcRectW = new float[PrcNum];
PrcRectH = new float[PrcNum];
PrcState = new boolean[PrcNum];
for( i = 0; i < PrcNum; i++ )
{
PrcState[i] = false;
if( i==0 )
{
PrcRectX[0] = 200;
PrcRectY[0] = 200;
PrcRectW[0] = 50.0;
PrcRectH[0] = 50.0;
}else
{
PrcRectX[i] = PrcRectX[i-1]+PrcRectW[i-1];
PrcRectY[i] = PrcRectY[i-1];
PrcRectW[i] = PrcRectW[i-1];
PrcRectH[i] = PrcRectH[i-1];
}
}
}
function Update (){
for( i = 1; i < PrcNum; i++ )
{
if( PrcState[i] )
{
if( PrcRectW[i] <100.0 )
{
Scral-=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]-=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]+=PrcSpeed*Time.deltaTime;
PrcRectH[i]+=PrcSpeed*Time.deltaTime;
}
if( PrcRectW[i-1] <70.0 )
{
Scral-=PrcSpeed*Time.deltaTime/2;
PrcRectY[i-1]-=PrcSpeed*Time.deltaTime/2;
PrcRectW[i-1]+=PrcSpeed*Time.deltaTime;
PrcRectH[i-1]+=PrcSpeed*Time.deltaTime;
}
if(i<PrcNum-1 && PrcRectW[i+1] <70.0)
{
Scral-=PrcSpeed*Time.deltaTime/2;
PrcRectY[i+1]-=PrcSpeed*Time.deltaTime/2;
PrcRectW[i+1]+=PrcSpeed*Time.deltaTime;
PrcRectH[i+1]+=PrcSpeed*Time.deltaTime;
}
}
else
{
if( i == PrcID-1|| i == PrcID+1 )
{
if( PrcRectW[PrcID] <
100.0 && PrcRectW[i] >70.0 )
{
Scral+=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]+=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]-=PrcSpeed*Time.deltaTime;
PrcRectH[i]-=PrcSpeed*Time.deltaTime;
}
}
else
{
if( PrcRectW[i] >50.0 )
{
Scral+=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]+=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]-=PrcSpeed*Time.deltaTime;
PrcRectH[i]-=PrcSpeed*Time.deltaTime;
}
}
}
if( i==0 )
{
PrcRectX[0] = Scral + 200;
PrcRect[0] = Rect (PrcRectX[0], PrcRectY[0], PrcRectW[0], PrcRectH[0]);
}
else
{
PrcRectX[i] = PrcRectX[i-1]+PrcRectW[i-1];
PrcRect[i] = Rect (PrcRectX[i], PrcRectY[i], PrcRectW[i], PrcRectH[i]);
}
}
}
function OnGUI() {
GUI.skin = MySkin ;
for( i = 0; i < PrcNum; i++ )
{
if (PrcRect[i].Contains(Event.current.mousePosition)){
PrcID = i;
PrcState[i] = true;
}else
{
PrcState[i] = false;
}
if( !Rect( PrcRectX[0],PrcRectY[0],PrcRectW[0]*(PrcNum +1),PrcRectH[0] ).Contains(
Event.current.mousePosition ) )
{
if( PrcRectW[i] >50.0 ){
Scral+=PrcSpeed*Time.deltaTime/2;
PrcRectY[i]+=PrcSpeed*Time.deltaTime/2;
PrcRectW[i]-=PrcSpeed*Time.deltaTime;
PrcRectH[i]-=PrcSpeed*Time.deltaTime;
}
}
}
for( i = 0; i < PrcNum; i++ )
{
GUI.Button( PrcRect[i],"" );
}
}
相关文章推荐
- 开源项目推荐(2):Android SlidingMenu 实现类似与Path2.0和Facebook滑动菜单
- Android类似qq消息滑动菜单
- 【Unity 3D】学习笔记六:Slider控件(滑动条)
- css+javascript实现苹果电脑桌面菜单滑动效果
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效
- 类似滑动苹果解锁Text
- unity制作一个3d旋转菜单
- 实现可以滑动的GrildView,类似美团网首页的GrildView功能菜单
- Android实现类似3D Touch菜单功能
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效
- Swift 类似网易新闻的滑动菜单
- 源码解析:3D推拉门式滑动菜单
- unityios开发--NGUI类似QQ菜单实现
- 【Unity 3D学习】获取鼠标滑动方向(上下左右)-控制摄像机围绕物体旋转
- unity3d鼠标滑动UIImage从而实现3D模型在UIImage上的左右旋转(RawImage映射)
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效
- Android-实现类似3DTouch菜单功能
- Unity类似手机通知栏的滑动效果
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效