Search Unity

Can't Drag Window

Discussion in 'Immediate Mode GUI (IMGUI)' started by nickavv, Jan 15, 2008.

  1. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    This code puts my media player into a GUI Window. It works, except I can't click and drag the window.

    Code (csharp):
    1. var attachedAudio : AudioClip;
    2. var looping = false;
    3. var timeSinceStart = 0.0;
    4. var refreshTime = 0;
    5. var windowRect = Rect (20, 20, 400, 300);
    6.  
    7. function Start () {
    8.     CountSeconds ();
    9. }
    10.  
    11. function OnGUI () {
    12.     windowRect = GUILayout.Window (0, windowRect, PlayerWindow, "Wanilla Media Player");
    13. }
    14.  
    15. function PlayerWindow (windowID : int) {
    16.    
    17.     GUILayout.Label(timeSinceStart + " / " + attachedAudio.length + " seconds");
    18.    
    19.     GUILayout.BeginHorizontal();
    20.    
    21.     if (GUILayout.Button("Play")) {
    22.         audio.clip = attachedAudio;
    23.         audio.Play();
    24.         refreshTime = 1;
    25.     }
    26.     if (GUILayout.Button("Pause")) {
    27.         audio.clip = attachedAudio;
    28.         audio.Pause();
    29.         refreshTime = 0;
    30.     }
    31.     if (GUILayout.Button("Stop")) {
    32.         audio.clip = attachedAudio;
    33.         audio.Stop();
    34.         refreshTime = 0;
    35.         timeSinceStart = 0.0;
    36.     }
    37.    
    38.     GUILayout.EndHorizontal();
    39.    
    40.     timeSinceStart = GUILayout.HorizontalSlider (timeSinceStart, 0.0, attachedAudio.length);
    41.    
    42.    
    43.     GUILayout.BeginHorizontal();
    44.    
    45.     looping = GUILayout.Toggle (looping, "Loop");
    46.    
    47.     if (looping == true) {
    48.         audio.loop = true;
    49.     } else {
    50.         audio.loop = false;
    51.     }
    52.    
    53.     GUILayout.Label ("Pitch: " + audio.pitch);
    54.    
    55.     if (GUILayout.Button ("Reset Pitch")) {
    56.         audio.pitch = 1.0;
    57.     }
    58.    
    59.     GUILayout.EndHorizontal();
    60.     audio.pitch = GUILayout.HorizontalSlider (audio.pitch, 0.5, 2.0);
    61. }
    62.  
    63. function CountSeconds () {
    64.     while (timeSinceStart < attachedAudio.length) {
    65.         timeSinceStart ++;
    66.         yield WaitForSeconds (refreshTime);
    67.     }
    68. }
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Maybe because you're not using DragWindow? ;)

    --Eric
     
  3. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    o_O Whaaat? Well, after looking it up, that worked, but still. All of the documentation for GUILayout.Window says that it is draggable, and none of the examples have GUI.DragWindow in them. How was I supposed to figure it out?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    'Cause the docs say so? :) "Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user."

    Might want to look here again. ;)

    --Eric
     
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Is the playing length of the audio file going to stay the same with a lot of wild pitch bending? It would be cool if so.
     
  6. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    Eric - I was looking at the GUILayout.Window page, not the GUI.Window page. Theres nothing about drag on there except "Can be optionally dragged by the end user"

    Jessy - I'm still working on getting the playback head to work, but from what I've seen, the song gets shorter as you bend the pitch up. Unless Unity has Pitch Bending that doesn't increase speed as well?
     
  7. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Either way has its benefits and drawbacks. I think an algorithm that kept length the same would be the most useful, but that also introduces more artifacts.