unity 3d类似 苹果的滑动菜单

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],"" );  

 }

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值