2012-05-17 2 views
0

내 gui 화면에 텍스처 2d가 있습니다. 손가락 터치 회전으로 +540도 -540도까지이 텍스처를 회전시키고 싶습니다. 이 제한을 초과하면 회전이 멈춰야합니다. 수 any1 도움 ??touchmove로 540도까지 texture2d 회전

답변

0
public Texture2D steering; 
    public static TouchControl Instance; 
    public float angleRotate=0f; 
    public float carRotation=0f; 
    public int finger; 


    private Matrix4x4 savedMatrix; 
    private float steerAngleRad; 
    public float steerAngleDeg; 
    private float steerAngleRadTemp; 
    public float steerAngleDegTemp; 
    private float dx=0f; 
    private float dy=0f; 
    private int i; 
    private float newAngle =0f; 
    private float initAngle; 
    private float rotationLimit=540f; 
    public float secondWheelRot=0f; 
    private float preRotDeg=0f; 
    private float angleDiff=0f; 
    private bool clockWheel=false; 
    private bool onlyOnce=false; 

    private Vector2 steeringPos; 
    private Vector2 centre; 
    private bool inXRange=false; 
    private bool inYRange=false; 
// private bool moving=false; 
    private float steeringWidth=0f; 
    private float steeringHeight=0f; 

    private float gobackSpeed=20f; 

    void Start() 
    { 
     Instance=this; 
     i=0; 
     finger=3; 
     steeringPos=new Vector2(Screen.width*0.025f,Screen.height*0.68f); 
     steeringWidth=Screen.width*0.12f; 
     steeringHeight=steeringWidth; 
     centre = new Vector2(steeringPos.x + steeringWidth/2, steeringPos.y + steeringHeight/2); 
    } 

    void Update() 
    { 

     if(Input.touchCount>0 && (!PauseButton.pauseFlag && !DamageBar.Instance.levelLost && !GameTimer.Instance.levelLost && !CommonIndicator.Instance.levelComplete)) 
     { 
      for(i=0;i< Input.touchCount; ++i) 
      { 
       if(Input.GetTouch(i).position.x > 0f && Input.GetTouch(i).position.x < steeringWidth+Screen.width*0.1f) 
       { 
        inXRange=true; 
       } 
       else 
       { 
        inXRange=false; 
       } 
       if(Input.GetTouch(i).position.y > 0f && Input.GetTouch(i).position.y < Screen.height-(steeringPos.y)) 
       { 
        inYRange=true; 
       } 
       else 
       { 
        inYRange=false; 
       } 

       ///////////////if touch is in the range///////////////////// 
       if(inXRange && inYRange) 
       { 
        if(Input.GetTouch(i).phase==TouchPhase.Began) 
        { 
         finger=Input.touches[i].fingerId; 
         dx=Input.GetTouch(i).position.x-centre.x; 
         dy=Input.GetTouch(i).position.y-(Screen.height-centre.y); 
         steerAngleRadTemp=Mathf.Atan2(dy,dx); 
         steerAngleDegTemp=-steerAngleRadTemp*Mathf.Rad2Deg; 
        } 
        if((Input.GetTouch(i).phase==TouchPhase.Stationary || Input.GetTouch(i).phase==TouchPhase.Moved)) 
        { 
         preRotDeg=newAngle; 
         if(preRotDeg<-180f && preRotDeg>-360f) 
         { 
          preRotDeg+=360f; 
         } 
         if(preRotDeg>180f && preRotDeg<360f) 
         { 
          preRotDeg-=360f; 
         } 
         dx=Input.GetTouch(i).position.x-centre.x; 
         dy=Input.GetTouch(i).position.y-(Screen.height-centre.y); 
         steerAngleRad=Mathf.Atan2(dy,dx); 
         steerAngleDeg=-steerAngleRad*Mathf.Rad2Deg; 
         angleRotate=steerAngleDeg-steerAngleDegTemp; 
         newAngle=angleRotate; 
         if(newAngle<-180f && newAngle>-360f) 
         { 
          newAngle+=360f; 
         } 
         if(newAngle>180f && newAngle<360f) 
         { 
          newAngle-=360f; 
         } 
         if(!onlyOnce) 
         { 
          onlyOnce=true; 
          if(newAngle>preRotDeg) 
           clockWheel=true; 
          else 
           clockWheel=false; 
         } 
         if(clockWheel && preRotDeg>0f && newAngle < 0f) 
         { 
          clockWheel=true; 
         } 
         else if(clockWheel && preRotDeg<0f && newAngle >0f) 
         { 
          clockWheel=true; 
         } 
         else if(!clockWheel && preRotDeg>0f && newAngle <0f) 
         { 
          clockWheel=false; 
         } 
         else if(!clockWheel && preRotDeg<0f && newAngle >0f) 
         { 
          clockWheel=false; 
         } 
         else if(newAngle>preRotDeg) 
         { 
          clockWheel=true; 
         } 
         else if(newAngle<preRotDeg) 
         { 
          clockWheel=false; 
         } 
         if(Mathf.Abs(newAngle)>Mathf.Abs(preRotDeg)) 
         { 
          angleDiff=Mathf.Abs(newAngle)-Mathf.Abs(preRotDeg); 
         } 
         else 
         { 
          angleDiff=Mathf.Abs(preRotDeg)-Mathf.Abs(newAngle); 
         } 
         if(clockWheel) 
         { 
          carRotation+=angleDiff; 
          secondWheelRot+=angleDiff; 
          if(secondWheelRot>rotationLimit) 
          { 
           secondWheelRot=rotationLimit; 
          } 
         } 
         else 
         { 
          carRotation-=angleDiff; 
          secondWheelRot-=angleDiff; 
          if(secondWheelRot<-rotationLimit) 
          { 
           secondWheelRot=-rotationLimit; 
          } 
         } 
        } 
//     else 
//     { 
//      steeringToZero();      
//     } 
        if(Input.GetTouch(i).phase==TouchPhase.Ended)// && Input.touches[i].fingerId != AccControl.Instance.finger) 
        { 
         onlyOnce=false; 
         carRotation=0f; 
         angleRotate=0f; 
         newAngle=0f; 
         steeringToZero(); 
         finger=3; 
        } 
       } 
       else if(!AccControl.Instance.onPadTouch && finger==3) 
       { 
        steeringToZero();      
       } 
      } 
     } 
     else if(Input.touchCount==0) 
     { 
      steeringToZero(); 
     } 
     if(Input.touchCount==1 && AccControl.Instance.onPadTouch) 
     { 
      steeringToZero(); 
     } 
     if (Input.GetKeyDown(KeyCode.Escape) && !PauseButton.pauseFlag) 
     { 
      Application.LoadLevel("MainMenu"); 
     } 
    } 
    void steeringToZero() 
    { 
     if(secondWheelRot>0) 
     { 
      secondWheelRot-=gobackSpeed/(Input.touchCount+1); 
     } 
     else if(secondWheelRot<0) 
     { 
      secondWheelRot+=gobackSpeed/(Input.touchCount+1); 
     } 
     if(secondWheelRot<gobackSpeed && secondWheelRot>-gobackSpeed) 
     { 
      secondWheelRot=0f; 
     } 

    } 

    void OnGUI() 
    { 
     savedMatrix = GUI.matrix; 
     GUIUtility.RotateAroundPivot(carRotation,centre); 
     GUI.DrawTexture(new Rect(steeringPos.x,steeringPos.y, steeringWidth, steeringHeight), steering); 
     GUI.matrix = savedMatrix; 
    } 
1

GUI 질감을 회전시킬 수 없다고 생각합니다. 당신이 원하는대로 할 수있는 최선의 방법은 평면을 아이 카메라로 지정하여 카메라를 마주 보게하고 원하는대로 그 평면을 회전시키는 것입니다.

관련 문제