Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by benfattino · Nov 26, 2011 at 05:38 PM · guirotatewindow

GUI Rotation

I use script to mouse zooming GUI window pressing button. Is it possible to make another button to rotate GUI window following mouse position? This is the script:

 var btnTexture:Texture;
 private var rtxt : float;
 private var txtiw : float;
 private var pressed:boolean = false;
 private var pressed2:boolean = false;
 private var recordMouseX:boolean = false;
 var ix = 5;
 var iy = 5;
 var bx = 25;
 var by = 25;
 var dbx =5;
 var dby =5;
 
 private var windowRect : Rect;
 
 
 private var hx : float;
 private var hy : float;
 private var hx2 : float;
 private var hy2 : float;
 private var hx3 : float;
 private var hy3 : float;
 
 private var mpx : float;
 private var mpy : float;
 private var mix : float;
 private var miy : float;
 
 function Start () {
 rtxt = (btnTexture.width/btnTexture.height);
 txtiw = Screen.width/2;
 
 hx = txtiw;
 hy = txtiw/rtxt;
 windowRect = Rect (ix, iy, hx, hy);
 }
 
 function Update () {
 
    if (Input.GetMouseButtonDown(0)){
 
     pressed = true;
 mix = mpx ;
 miy = mpy ;
 hx3 = hx;
 hy3 = hx/rtxt;
 }else if(Input.GetMouseButtonUp(0)){
     pressed = false;
     pressed2 = false;
 
     }
 
 
 ix = windowRect.x;
 iy = windowRect.y; 
 hx2 = hx3 + mpx - mix ;
 hy2 = hx2/rtxt;
 windowRect = Rect (ix, iy, hx, hy);
 }
 
 function OnGUI () {
 
     windowRect = GUI.Window (0, windowRect, DoMyWindow, "");
     var  mp : Event = Event.current;
 
      print( windowRect.x+ "   mouseX "+ mpx);
 
 
      mpx = mp.mousePosition.x;
      mpy = mp.mousePosition.y; 
 
 }
 
 
 function DoMyWindow (windowID : int){ 
     GUI.DragWindow (Rect (0,0, windowRect.width - bx -dbx, windowRect.height));
     GUI.DragWindow (Rect (0,0, windowRect.width, windowRect.height - by-dby));
     GUI.DrawTexture(Rect(0,0,hx,hy), btnTexture, ScaleMode.ScaleToFit, false, 0f);
 
     var rect = Rect (windowRect.width - bx - dbx, windowRect.height-by -dby,bx,by);
 
     if(windowRect.width<=bx +(dbx *2)  ){
        windowRect.width = bx+(dbx *2);
 
     }
          if( windowRect.height<=by+(dby*2) + 15 ){
        windowRect.height=by+(dby*2) +15;
 
 
     }
 
     if (pressed && (GUI.RepeatButton (rect, "+")) ){
    recordMouse = true;
        pressed2 = true;
     hx = hx2;
     hy = hy2;
 
     }else if(pressed && pressed2 &&  !rect.Contains(Input.mousePosition) ){
        hx = hx2;
        hy = hy2;
        } else if(!pressed ){
          GUI.RepeatButton (rect, "+");
        }else{
           GUI.RepeatButton (rect, "+");
        }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by perchik · Dec 02, 2011 at 07:07 PM

I think what you'll need to do is use GUIUTility.RotateAroundPivot. To make this work, you have to use an OpenGL type approach. First, store the GUI project matrix:

 Matrix4x4 matrixBackup = GUI.matrix;

Then you can rotate the GUI projection matrix, draw whatever you want to draw, and then reset the GUI matrix from the backup:

 GUIUtility.RotateAroundPivot(angle,  new Vector2(0,0));
 GUI.Box(new Rect(0,0, 1, 1));
 GUI.matrix = matrixBackup;

That should give you enough to at least figure out how to rotate the GUI. You could place the pivot point and then calculate the angle between the vector from the pivot to the object and the pivot to the mouse.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Add EditorUI elements when a button is pressed 0 Answers

how to get Gui in OnGUI function to resize with the window? 1 Answer

Move one GUI window when another is moved? 0 Answers

Elements in draggable window do not remain fixed [SOLVED] 2 Answers

simple gui question 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges