您的位置:首页 > 移动开发 > Unity3D

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],"" );  
 }
 
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: