Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GUIKit001 - Plug and Play Interface for iPhone, iPad, PC/MAC

Discussion in 'iOS and tvOS' started by col000r, Sep 13, 2010.

  1. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @brendang For OrientationControl there's only the examples, the comments in all the scripts and this video. What sort of documentation would you like to see other than that? Let me know what you need and I'll cook something up!

    @Void77 Have a look at the OrientationControl examples! There's a button that always stays in the top right corner no matter what the resolution and orientation and a touch-strip at the bottom of the screen that always spans the entire width and always sticks to the bottom.

    For loading assets depending on retina or non-retina display have a look at the function LoadResourcesAndScaleRects() - it's called once in the beginning and if you add your own images there they should be ready for use at the end of Awake().

    There's going to be another update to GUIKit001 (hopefully sometime today) that brings a few new features from OrienationControl. Just like in OrientationControl there will be 2 new values (screenWidth and screenHeight) that can be used as a replacement for Screen.width and Screen.height (you'll see what that's good for in a minute...) and there will be a new function called ScaleRect() that scales a Rect by the current scaleFactor (1.0 for normal displays and 2.0 of double resolution on Retina displays)

    With these two new additions it will be a lot more straightforward to position GUIElements. You can simply do something like this now:

    Code (csharp):
    1. GUI.Button(ScaleRect(new Rect(-100, -21, 200, 42)), "Click me");
    A button, centered on screen that scales with scaleFactor. This shows how to position something at an absolute offset to the center of the screen.

    Or an example of how to position something at an edge: An 80px high (on non-retina displays) box along the bottom of the screen:

    Code (csharp):
    1. GUI.Box(new Rect(-screenWidth*0.5f, 0f + screenHeight * 0.5f - 80f * scaleFactor, screenWidth, 80f * scaleFactor), GUIContent.none);
    Now all of this assumes you're applying the guiMatrix that StandardGUI (or OrientationControl) provides since that handles all the orientation-changes... If you use UnityGUI Controls (like Buttons, etc.) you don't have to deal with handling Mouse and Touch input since UnityGUI does it for you. But if you want to create more specific interactions you can do it like this:

    Code (csharp):
    1. foreach (Touch touch in Input.touches){ //Check all touches
    2.     Vector3 pos = new Vector3(touch.position.x, Screen.height - touch.position.y, 0.0f); //flip y to transform from touch space to GUI space
    3.     Vector3 transformedPos = guiMatrix.inverse.MultiplyPoint3x4(pos); //Multiply the touch in gui space by the inverse of the GUIMatrix and you get the exact point of the touch in the same coordinate system that StandardGUI works with.
    4.    
    5.     if(new Rect(-screenWidth*0.5f, 0f + screenHeight * 0.5f - 80f * scaleFactor, screenWidth, 80f * scaleFactor).Contains(transformedPos)) { //So now we can check if the touch is inside the Box we used as an example above.
    6.         Debug.Log("Inside the Box!");
    7.     }
    8. }
    You should now have a box that sticks to the bottom of the screen in any Orientation and at any resolution! - Again: check out the OrientationControl example scene for fairly simple working example!

    Hope this helps and wasn't too much random information at once! :)
     
    Last edited: Oct 26, 2010
  2. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    I just got the kit and it is awesome! I have one question (for now) will you send an email out with an update link?
     
  3. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    Thanks a lot! Yes. I'll send an email as soon as I have everything packaged and uploaded!
     
  4. jingato

    jingato

    Joined:
    Jun 23, 2010
    Posts:
    299
    This system looks really nice. I'm just curious if it can fit the needs for my game. I need to create my GUI similar to the one in angry birds. I need to start at the main screen, then instead of having the sliding list of levels, have a sliding list of worlds. Once you click a world you will be brought to the list of levels for that world. I'd like to show the levels as a list of small icons instead of big sliders. Is this something Your system can do at the moment?

    Thanks

    here's an example
     
  5. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @jingato: The list of levels is not something it does out of the box. Furthermore GUIKit001 isn't a system of its own, it's a ready-made Interface that's built with UnityGUI. That being said, I'm sure you could add another step to the level selection in a reasonable amount of time, but you'll need to gain a basic understanding of how StandardGUI is built first, and then add your code in all the right places. I'm sure you could duplicate the code that determines if levels are available, completed or locked for the worlds and for the list of levels you could maybe even use a GUI.SelectionGrid... Or write a for-loop that positions all the individual pieces. Hope this helps! Let me know if you have any other questions!
     
  6. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    Thanks for the replies col000r

    So far I kinda went with simple buttons that are using the GUImatrix

    i.e.
    Code (csharp):
    1.  
    2.  
    3. var Play:Texture;
    4. var mySkin : GUISkin;
    5.  
    6. function OnGUI ()
    7. {
    8.     GUI.skin = mySkin;
    9.     GUI.matrix = OrientationControl.instance.guiMatrix; //Use the guiMatrix provided by OrientationControl
    10.    
    11.     if(GUI.Button(new Rect (-35,50,Play.width,Play.height), Play))
    12.     {
    13.     Application.LoadLevel(2);
    14.     }
    15.  
    16.    
    17. }
    18.  
    everything seems to be working fine on the pc version of unity and ive yet to see if it properly scales the gui


    Anyways, ive come to ask a question regarding the background for the "base" scene, (scene0) , is it possible instead of having a background image hide the "next scene in queue" to have a fully fledge 3d scene as the menus background?

    I gave it a try and noticed the only issue was getting the background scene back after loading a level and quiting that level, "quiting" the level, would simply just bring me back to the main menu screen while the old level is still being displayed


    I tried testing the idea out of on your Quit button actions to also tell it to load the background scene, unfortunately that outputted errors,

    it was specfically in the "function QuitToMainMenu()" commands


    Anyways so far, ive dissecting the code trying to understand it more, trying to integrate it into my project has been a challenge , (specifically because i want the main menu to look different from the base that youve provided us, it totally understand that this was made for more of a plug and play approach , no worries not hammering at ya for it :p)

    Ill be posting updates on my progress, I'm going to adjust the standardGUI to provide with a few more panels and options that im looking for.

    Major suggestion though would be a tutorial on possibly integrating GUIKIT into a project (maybe have both gui.textures and gui.button complications and show us the most efficient way to get them integrated)

    overall kickass, and youre doing great on the support!
     
  7. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    There's a variable in the inspector called testRetinaDisplay - setting this to true will force it to use retina resolution for testing purposes. (I made it private in OrientationControl, but just make it public if you want to test)
    The even better option would be to switch to iOS platform mode in the build settings and set the game view aspect to iPhone4 - StandardGUI or OrientationControl will detect that and switch to retina resolution. (this happens in Awake)

    The example you gave above won't scale yet, because using the provided matrix only ensures the correct orientation. You still have to load the right images and use scaleFactor in your Rects. I've gone over your example and added the necessary pieces to ensure it would scale as well:

    Code (csharp):
    1. var playImgName : String = "PlayImg";
    2. private var playImg : Texture2D; //will be filled with the right Texture2D in start
    3. var mySkinName : String = "customSkin";
    4. private var mySkin : GUISkin; ////will be filled with the right GUISkin in start
    5. private var on : boolean = false;
    6.  
    7.  
    8. function Start () {
    9.     while(!OrientationControl.instance) yield; //Make sure the OrientationControl singleton exists before going on
    10.     playImg = Resources.Load(OrientationControl.instance.GetCurrentResourcePath() + playImgName, typeof(Texture2D)); //Resource-paths for 100% and 200% assets are defined in OrientationControl: resourcePath100Percent, resourcePath200Percent   
    11.     mySkin = Resources.Load(OrientationControl.instance.GetCurrentResourcePath() + mySkinName, typeof(GUISkin)); //Resource-paths for 100% and 200% assets are defined in OrientationControl: resourcePath100Percent, resourcePath200Percent   
    12.     on = true; //done, switch on OnGUI
    13. }
    14.  
    15.  
    16. function OnGUI ()
    17. {
    18.     if(on) { //Only do this once everything is done loading
    19.         GUI.skin = mySkin;
    20.         GUI.matrix = OrientationControl.instance.guiMatrix; //Use the guiMatrix provided by OrientationControl
    21.        
    22.         if(GUI.Button(new Rect (-35 * OrientationControl.instance.scaleFactor, 50 * OrientationControl.instance.scaleFactor, playImg.width, playImg.height), playImg))
    23.         {
    24.             Application.LoadLevel(2);
    25.         }
    26.     }
    27.  
    28. }
    Yeah, currently if you quit back out of a level, the level stays in the background and only gets destroyed once you load into another level. If you want a 3D background I'd suggest you make a duplicate of LoadLevelAndCloseMenu() that doesn't close the menu, but only replaces the level and run that once when StandardGUI is done initializing and once from within QuitToMainMenu().

    ... 20 mins later ...

    ok, I just tried this and I like it! This will be a starting-point for the next update. I'll wait for more new stuff before I send out another update to everyone - I don't want to spam people with updates all too often... But if you want it now, PM me the email-address that you bought it with and I'll send you the modified files!

    A tutorial for positioning GUI-Elements with StandardGUI or OrienationControl is a good idea! I'll look into this the next time I have a few hours available!
     
  8. WebWolfRussian

    WebWolfRussian

    Joined:
    Feb 5, 2010
    Posts:
    123
    Hello. If you will create example like Andry Birds... its will be very very cool. And i think many peoples will buy it. You should make under categories.
    I want too it like Angry Birds. :)
     
    Last edited: Oct 27, 2010
  9. afrim

    afrim

    Joined:
    Oct 8, 2009
    Posts:
    4
    Will the keyboard pop up in Android when you select a text field? I am told that they keyboard has not been exposed by Unity 3 yet. Also are there any joystick / touchpad components?
     
  10. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    Awesome stuff cool000r, ive been able to successfully start moving my project over, running into a few oddities that i cant figure out tho

    at the moment i could do this two ways, Im trying to make a FaceBook/Twitter button using the "News" button on the main menu, ive stripped down the code to where its working but its not displaying the img, keep in mind ive given it all its proper counter variable counter parts (rects,imageloading,scaling etc), but either im missing something still or im doing something in the script, the img refuses to load, the button reacts to my actions tho.

    In essence this should be working like a simple button now (with all the pop up features which i want) , which the script above works in displaying the texture, but it simply isnt showing up, theres no errors indicating that im missing anything in the console.

    I added these lines of code to the StandardGUI

    heres the code below

    Currently the positioning of these guielements has been a breeze with the "var mainMenuFaceBookRect" code,, the sliders in the inspector really make it faster than guessing, etc.

    Its one reason im avoiding the button script youve provided since i wasnt able to get the same code working on it (would simply not move).

    Code (csharp):
    1.                
    2. // These are also the variables and modifications to some lines that I have added for the new buttons
    3.  
    4. private var mainMenuFaceBookImg : Texture2D;
    5. private var mainMenuTwitterImg : Texture2D;
    6.  
    7.  
    8.  var mainMenuFaceBookRect = new Rect(-230, 105, 460, 47);
    9.  var mainMenuTwitterRect = new Rect(-230, 105, 460, 47);
    10.  
    11. mainMenuFaceBookImg = Resources.Load(basePath + "StandardGUI/" + mainFaceBookImgName, Texture2D);
    12. mainMenuTwitterImg = Resources.Load(basePath + "StandardGUI/" + mainTwitterImgName, Texture2D);
    13.  
    14. mainMenuFaceBookRect = ScaleRect(mainMenuFaceBookRect, factor);
    15. mainMenuTwitterRect = ScaleRect(mainMenuTwitterRect, factor);
    16.  
    17.  
    18. //heres the button code based off the news button
    19.  
    20. //FaceBook-Box
    21.                 if(GUI.Button(mainMenuFaceBookRect, mainMenuFaceBookImg))
    22.             {
    23.                
    24.                 AudioController.inst.PlaySound(1);
    25.                 if(newsTextTargetURL != "http://www.facebook.com/pages/Alien-Abduction/150328011667210")
    26.                 { //if there's a link, ask if player wants to visit:
    27.                     showPopupWindow = true; //this causes all gui to be disabled and for the popup to show - look further down at the end of OnGUI...
    28.                     popupString = "Open Link in Browser?";
    29.                     popupMessageYes = "OpenLink"; //This function will be called if the user chooses YES in the popup!
    30.                 }
    31.                
    32.             }
    33.  

    Oddity #2

    As you can see in the button script you provided me, my original made the button play a sound when pressed, the script works fine, except for the fact that the audio is played when the finger is on the button , and itll continue to finish the audioclip after the finger is released, (oh by the way, i changed it to a GUI.Repeatbutton for my situation) , I took a look at audiocontroller so get a sense of what was going on, and i couldnt help but notice the "AudioSwitchOff" function

    I was hoping it would do what my original script did and kill the audio file as soon as the touch was released, but i kept getting an overload error with trying to add this code

    I have an entirely different method of using the audioclip, at the moment what the button is accomplishing is,

    "Play this audioclip and also turn my variable that will enable the beam artwork in the scene, once finger is gone turn off the artwork and also stop the audioclip"

    thats the current method, but I have another way , and thats just slapping the audioclip on the beam object itself , and have it turn on when the beam object is enabled. (quick fix work around, incase the method you provide is long or you recommend me to do it this new alternative way)

    Aside from that the biggest challenge will be how to integrate the iPhoneControls.js script and also the Joystick.js from Unity tutorials and the Penelope Tutorial project, (they use gui.textures for the joystick , i rather like it be more clean and universal with OnGUI, let me know if you know how to do a joystick in this! ;D)


    Once again col000r ,you kickass!, ill be eagerly awaiting the update for the 3d background :D
     
  11. jingato

    jingato

    Joined:
    Jun 23, 2010
    Posts:
    299
    Two things, do you have any plans to add the functionality of having categories with different levels underneath them right out of the box in the future. I think this is a pretty standard way games to work. You rarely see a game with just a single giant list of levels.

    Also, is it possible to modify the way it handles the level loading? In the tutorial it says you need to parent everything in your scene to an object tagged "level". Couldn't it just save all the items in an array before it loads the level and them loop through the array to delete them. Or before it loads the level create an empty gameObject tagged "level" and parent everything to it. them load in the level. I'm just trying to avoid having to go back through every finished level I have. Plus my code is instantiating lots of things at the level start. Wouldn't I have to go through and make sure all my code parents these items to the level gameObject as well?
     
  12. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @Void77

    I think the Button is set to TextOnly in the GUISkins, so that could be why it ignores the image... You'd have to change the value called "ImagePosition" in the Button-part of the 2 GUISkins to "ImageLeft" or something like that. Or if you don't want the border to show around your image create a new custom style at the bottom of the skin that contains no images for the different states and do a GUI.Button(Rect, image, mySkin.GetStyle("nameOfYourNewCustomStyle"))

    ad #2: So you want the sound to play as long as you hold the button and then stop? Maybe you could first do AudioController.inst.SetLooping(true) and then AudioController.inst.PlayBackgroundSound(id or string goes here) to start it (that way the AudioController would load the clip into the audiosource and play it and loop it until you tell it to stop. The function you use now instead calls audio.PlayOneShot() and I'm not really sure if you can even stop that one at all...) and then add a new function to stop the sound like this:

    Code (csharp):
    1. function StopSound (empty : boolean) {
    2.    
    3.     audio.Stop();
    4.     if(empty) audio.clip = null;
    5.     on = false;
    6.    
    7. }
    and call this with AudioController.inst.StopSound(true); when you want it to stop. I've used AudioController in 2 projects, but I've never needed to stop a sound since I only used very short once. That's why no real Stop-function existed. Btw: SwitchAudioOff is not at all what you want, since it turns off the sound in the entire game - it's what gets called when you set the sound volume to 0 on the settings screen.
     
  13. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @jingato: Adding a 2nd level of levels might be worth a though. Initially we tried to not tailor it to much to any one kind of game and keep the menus to a minimum that everyone could build upon. For example, there's a variable in the inspector that lets you skip level selection altogether and jumps right into the game when you hit play. Doing the same for a second level of levels might be nice, but I'm also a bit scared of doing that because the more we add the more complicated it will get to get into the code...

    Using one root GameObject and a tag was the simplest solution we could come up with. Is there a way to get the contents of an additively loaded level? Or did you mean to remember all the stuff that belongs to the GUI and then delete everything else but that. That could work and might be a good idea, I'll try that. But you'd still need to go into each level and add the AssignCamera script so that StandardGUI knows which cameras you want to rotate...
     
  14. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @akacaj: We don't have any joystick components in the kit at the moment. So far GUIKit001 is all about menus and giving you ways to make your other UnityGUI interface-stuff orientation and resolution independent.
    The StandardGUI doesn't use textfields, so there's no keyboard handling at all in there. If you want to use textfields on iPhone/Android you'll have to deal with the input yourself for now, sorry.
     
  15. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    I don't remember getting an email about the update, is it out?
     
  16. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    col000r

    any chance for a possible joystick implementation in the future


    im currently finishing up my project, the only problem left is the joysticks scale and position when detecting the ipad/iphone, id love to have it all be part of the the gui system instead of a guitexture in all the scenes

    thanks
     
  17. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @Crazy Robot: Please DM me your email-address or send an email to support@gameassets.net and I'll send it again!

    @Void77: Are you using the dual joysticks from the penelope project or something completely different? If you send me the joystick code I'll see what I can do to assist you in making it orientation and resolution independent!
     
  18. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    I am indeed using penelopes script,

    here it is attached below

    Code (csharp):
    1.  
    2. //////////////////////////////////////////////////////////////
    3. // Joystick.js
    4. // Penelope iPhone Tutorial
    5. //
    6. // Joystick creates a movable joystick (via GUITexture) that
    7. // handles touch input, taps, and phases. Dead zones can control
    8. // where the joystick input gets picked up and can be normalized.
    9. //
    10. // Optionally, you can enable the touchPad property from the editor
    11. // to treat this Joystick as a TouchPad. A TouchPad allows the finger
    12. // to touch down at any point and it tracks the movement relatively
    13. // without moving the graphic
    14. //////////////////////////////////////////////////////////////
    15.  
    16. @script RequireComponent( GUITexture )
    17.  
    18.  
    19.  
    20.  
    21.  
    22.  
    23.  
    24.  
    25.  
    26.  
    27.  
    28.  
    29.  
    30. // A simple class for bounding how far the GUITexture will move
    31. class Boundary
    32. {
    33.     var min : Vector2 = Vector2.zero;
    34.     var max : Vector2 = Vector2.zero;
    35. }
    36.  
    37. static private var joysticks : Joystick[];                  // A static collection of all joysticks
    38. static private var enumeratedJoysticks : boolean = false;
    39. static private var tapTimeDelta : float = 0.3;              // Time allowed between taps
    40. static var multiTouchEnabled = true;
    41.  
    42. var touchPad : boolean;                                     // Is this a TouchPad?
    43. var touchZone : Rect;
    44. var deadZone : Vector2 = Vector2.zero;                      // Control when position is output
    45. var normalize : boolean = false;                            // Normalize output after the dead-zone?
    46. var position : Vector2;                                     // [-1, 1] in x,y
    47. var tapCount : int;                                         // Current tap count
    48.  
    49.  
    50. private var lastFingerId = -1;                              // Finger last used for this joystick
    51. private var tapTimeWindow : float;                          // How much time there is left for a tap to occur
    52. private var fingerDownPos : Vector2;
    53. private var fingerDownTime : float;
    54. private var firstDeltaTime : float = 0.5;
    55.  
    56.  
    57.  
    58. var playImgName : String = "PlayImg";
    59. private var playImg : GUITexture; //will be filled with the right GUITexture in start
    60.  
    61.  
    62.  
    63.  
    64. private var gui : GUITexture;                               // Joystick graphic
    65. private var defaultRect : Rect;                             // Default position / extents of the joystick graphic
    66. private var guiBoundary : Boundary = Boundary();            // Boundary for joystick graphic
    67. private var guiTouchOffset : Vector2;                       // Offset to apply to touch input
    68. private var guiCenter : Vector2;                            // Center of joystick
    69.  
    70. function Start()
    71. {
    72.     // Cache this component at startup instead of looking up every frame   
    73.     gui = GetComponent( GUITexture );
    74.    
    75.     // Store the default rect for the gui, so we can snap back to it
    76.     defaultRect = gui.pixelInset;  
    77.    
    78.     if ( touchPad )
    79.     {
    80.         // If a texture has been assigned, then use the rect ferom the gui as our touchZone
    81.         if ( gui.texture )
    82.             touchZone = gui.pixelInset;
    83.     }
    84.     else
    85.     {              
    86.         // This is an offset for touch input to match with the top left
    87.         // corner of the GUI
    88.         guiTouchOffset.x = defaultRect.width * 0.3;
    89.         guiTouchOffset.y = defaultRect.height * 0.3;
    90.        
    91.         // Cache the center of the GUI, since it doesn't change
    92.         guiCenter.x = defaultRect.x + guiTouchOffset.x;
    93.         guiCenter.y = defaultRect.y + guiTouchOffset.y;
    94.        
    95.         // Let's build the GUI boundary, so we can clamp joystick movement
    96.         guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
    97.         guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
    98.         guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
    99.         guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;
    100.     }
    101. }
    102.  
    103. function Disable()
    104. {
    105.     gameObject.active = false;
    106.     enumeratedJoysticks = false;
    107. }
    108.  
    109. function ResetJoystick()
    110. {
    111.     // Release the finger control and set the joystick back to the default position
    112.     gui.pixelInset = defaultRect;
    113.     lastFingerId = -1;
    114.     position = Vector2.zero;
    115.     fingerDownPosition = Vector2.zero;
    116.    
    117.     if ( touchPad )
    118.         gui.color.a = 0.2; 
    119. }
    120.  
    121. function IsFingerDown() : boolean
    122. {
    123.     return (lastFingerId != -1);
    124. }
    125.    
    126. function LatchedFinger( fingerId : int )
    127. {
    128.     // If another joystick has latched this finger, then we must release it
    129.     if ( lastFingerId == fingerId )
    130.         ResetJoystick();
    131. }
    132.  
    133.  
    134. function Awake()
    135. {
    136.  
    137.     if ( !enumeratedJoysticks )
    138.     {
    139.         // Collect all joysticks in the game, so we can relay finger latching messages
    140.         joysticks = FindObjectsOfType( Joystick );
    141.         enumeratedJoysticks = true;
    142.     }  
    143.        
    144.     var count = Input.touchCount;
    145.    
    146.     // Adjust the tap time window while it still available
    147.     if ( tapTimeWindow > 0 )
    148.         tapTimeWindow -= Time.deltaTime;
    149.     else
    150.         tapCount = 0;
    151.    
    152.     if ( count == 0 )
    153.         ResetJoystick();
    154.     else
    155.     {
    156.         for(var i : int = 0;i < count; i++)
    157.         {
    158.             var touch : Touch = Input.GetTouch(i);         
    159.             var guiTouchPos : Vector2 = touch.position - guiTouchOffset;
    160.    
    161.             var shouldLatchFinger = false;
    162.             if ( touchPad )
    163.             {              
    164.                 if ( touchZone.Contains( touch.position ) )
    165.                     shouldLatchFinger = true;
    166.             }
    167.             else if ( gui.HitTest( touch.position ) )
    168.             {
    169.                 shouldLatchFinger = true;
    170.             }      
    171.    
    172.             // Latch the finger if this is a new touch
    173.             if ( shouldLatchFinger  ( lastFingerId == -1 || lastFingerId != touch.fingerId ) )
    174.             {
    175.                
    176.                 if ( touchPad )
    177.                 {
    178.                     gui.color.a = 0.15;
    179.                    
    180.                     lastFingerId = touch.fingerId;
    181.                     fingerDownPos = touch.position;
    182.                     fingerDownTime = Time.time;
    183.                 }
    184.                
    185.                 lastFingerId = touch.fingerId;
    186.                
    187.                 // Accumulate taps if it is within the time window
    188.                 if ( tapTimeWindow > 0 )
    189.                     tapCount++;
    190.                 else
    191.                 {
    192.                     tapCount = 1;
    193.                     tapTimeWindow = tapTimeDelta;
    194.                 }
    195.                                            
    196.                 // Tell other joysticks we've latched this finger
    197.                 for ( var j : Joystick in joysticks )
    198.                 {
    199.                     if ( j != this )
    200.                         j.LatchedFinger( touch.fingerId );
    201.                 }                      
    202.             }              
    203.    
    204.             if ( lastFingerId == touch.fingerId )
    205.             {  
    206.                 // Override the tap count with what the iPhone SDK reports if it is greater
    207.                 // This is a workaround, since the iPhone SDK does not currently track taps
    208.                 // for multiple touches
    209.                 if ( touch.tapCount > tapCount )
    210.                     tapCount = touch.tapCount;
    211.                
    212.                 if ( touchPad )
    213.                 {  
    214.                     // For a touchpad, let's just set the position directly based on distance from initial touchdown
    215.                     position.x = Mathf.Clamp( ( touch.position.x - fingerDownPos.x ) / ( touchZone.width / 2 ), -1, 1 );
    216.                     position.y = Mathf.Clamp( ( touch.position.y - fingerDownPos.y ) / ( touchZone.height / 2 ), -1, 1 );
    217.                 }
    218.                 else
    219.                 {                  
    220.                     // Change the location of the joystick graphic to match where the touch is
    221.                     gui.pixelInset.x = Mathf.Clamp( guiTouchPos.x, guiBoundary.min.x, guiBoundary.max.x );
    222.                     gui.pixelInset.y = Mathf.Clamp( guiTouchPos.y, guiBoundary.min.y, guiBoundary.max.y );     
    223.                 }
    224.                
    225.                 if ( touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled )
    226.                     ResetJoystick();                   
    227.             }          
    228.         }
    229.    
    230.    
    231.     if ( !touchPad )
    232.     {
    233.         // Get a value between -1 and 1 based on the joystick graphic location
    234.         position.x = ( gui.pixelInset.x + guiTouchOffset.x - guiCenter.x ) / guiTouchOffset.x;
    235.         position.y = ( gui.pixelInset.y + guiTouchOffset.y - guiCenter.y ) / guiTouchOffset.y;
    236.     }
    237.    
    238.     // Adjust for dead zone
    239.     var absoluteX = Mathf.Abs( position.x );
    240.     var absoluteY = Mathf.Abs( position.y );
    241.    
    242.     if ( absoluteX < deadZone.x )
    243.     {
    244.         // Report the joystick as being at the center if it is within the dead zone
    245.         position.x = 0;
    246.     }
    247.     else if ( normalize )
    248.     {
    249.         // Rescale the output after taking the dead zone into account
    250.         position.x = Mathf.Sign( position.x ) * ( absoluteX - deadZone.x ) / ( 1 - deadZone.x );
    251.     }
    252.        
    253.     if ( absoluteY < deadZone.y )
    254.     {
    255.         // Report the joystick as being at the center if it is within the dead zone
    256.         position.y = 0;
    257.     }
    258.     else if ( normalize )
    259.     {
    260.         // Rescale the output after taking the dead zone into account
    261.         position.y = Mathf.Sign( position.y ) * ( absoluteY - deadZone.y ) / ( 1 - deadZone.y );
    262.     }
    263. }
    264.  
    265.    
    266. }
    267.  
    268.    
    269.  

    thanks again col00r!!
     
  19. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    I just looked again, I think I did get it. Update 3???
     
  20. gamesurgeon

    gamesurgeon

    Joined:
    Oct 11, 2009
    Posts:
    427
    So, I bought the GUISkin, and it is fantastic. I've been wondering why people don't sell skins more often, I really enjoy them. It's hard to make a good looking skin and Unity, and you guys nailed it. Elegant and simple.

    However, I believe I've encountered a bug. If you create a new window and then create a button within that GUI at (0, 0) it goes off the window. It seems that some weird offset is taking place within the left side of the window. Attached is an image with the button "Lower" at (0, 50) in the window. As you can see, there is an odd offset that the window has on the left side -- it does not fully incase the button. Please fix this! I'd like to not have random numbers floating around to add to the buffer.

    Other than that I am 100% satisfied. Please create more skins :) I'd love to buy 'em! Maybe an exact iPhone GUI? I'd like to be able to create native iOS looking apps. in Unity.
     

    Attached Files:

    Last edited: Nov 10, 2010
  21. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    any update?
     
  22. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @Crazy Robot Yes, Update 3 was the last one! Expect the next one in a short while...


    @Void77 I finally found time to look at the joystick code (Sorry it took a while, I've been moving house and office this last week...) So here's what I've come up with based on the original Penelope tutorial Joystick code. (The attached unitypackage contains the script and my two test-images)

    3 important things:

    • anchorToBottomRight: false puts the joystick in the bottom-left corner (in any orientation and any resolution!), true puts it in the lower-right corner
    • defaultRect is not an absolute position, but the offset from the corner you selected above! - Leave this at 0,0,0,0 and it will automatically fill it with some example values that make sense... Or to name an example: (32, -96, 64, 64) will put it in the lower left corner with a 32 pixel padding - Think of the lower left corner as (0,0), so it starts at 32 to the right and 96 pixels up and then goes to the right and down for 64 pixels each. - If StandardGUI detects a retina-display all these values will be scaled up automatically...
    • per default it's looking for either Resources/GUI/100percent/JoystickImg or Resources/GUI/200percent/JoystickImg, but you can set the 2 paths in the inspector yourself

    One bit of warning: My focus was on getting this to work, so you might want to clean up the code a bit if you've got time. :)
     

    Attached Files:

  23. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @gamesurgeon I'm afraid that's a bit of weirdness on the part of unity. There's nothing in the skin that would allow us to set a padding for the content of a window. So you'll have to deal with that inside the window function, sorry... The offset to the left happens because the drop-shadow is part of the window border graphics and that's where the content area of the window starts... The only help I can offer is that the content-area starts exactly at (19,50)...

    Thanks for the kind praise! We'll definitely do more skins along the way. (We've got 2 skins halfway done actually, but we're also working on a new game...)

    An exact copy of the iPhone GUI is a good idea, but could be a problem... I'm not sure Apple would allow Apps that copy their OS appearance, but don't actually use their code?
     
  24. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    COL000R U ARE EFFING AWESOME!, thanks again, im definitely testing this out today!!
     
  25. FreakFish

    FreakFish

    Joined:
    Jun 4, 2010
    Posts:
    119
    (Void)
    Thanks for the joystick script , it works great and is what we wanted, we also were thinking of using it for some other parts of our gui, mainly because of the Texture2d/scale code u now implemented in the script

    (FreakFish)
    Sadly testing has boarded the failboat :( We tried stripping down the joystick script you gave us to work for normal buttons which has been a success for the most part - the buttons are working properly on the PC. Sadly we now have to sort out our energy bar that changes texture depending on the energy variable. Before we started using GUI kit we had put several "var EnergyBar_1 : Texture2D" (for example) variables in place and a system of if statements to decide when to change them (I'll include the script at the end). We've run into issues with...

    (Void)
    OnGUI - we first believed this would have worked thinking OnGUI is constantly updating, we tried something along the lines of this

    Code (csharp):
    1.  
    2. function OnGUI ()
    3. {
    4.     if(ready)
    5.     {
    6.         GUI.matrix = stdGUI.guiMatrix;
    7.         GUI.color = guiColor;
    8.        
    9.         if (BeamTexture.energy >= 360)
    10.         {
    11.             GUI.DrawTexture(currentTouchRect, BeamEnergyGUIImg_6);
    12.         }
    13.         if (BeamTexture.energy >= 288  BeamTexture.energy < 360)    {
    14.             GUI.DrawTexture(currentTouchRect, BeamEnergyGUIImg_5);
    etc etc...

    this doesnt work because, the GUI.DrawTexture isnt something that is being updated constantly, we need to change that texture on specific variable hits, and before we did it with simple if/else statements on guitextures.

    (FreakFish)
    Please, please, please give us a stripped down version of the joystick script we can mess with, we're finding it rather difficult to edit this script as we had no part in its original creation :'(

    Much love from Void and ><>FreakFish<><
     
  26. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    OnGUI does update all the time, so in principle your approach should work!

    I've cooked up a minimalistic script that lets you specify the names of a couple of images - just change the size of the imgName array to how many you want and enter the names of the images (these images have to exist in 100 and 200 percent versions in the paths specified in resourcePath100Percent and resourcePath200percent) - it then loads the right images in Start and displays one of them in OnGUI. - Change the activeImgID to select which one to display.

    It's being displayed in the upper-left corner, but there's a commented-out version for displaying it in the bottom-left corner in the code.

    Code (csharp):
    1. var stdGUI : StandardGUI;
    2.  
    3. var resourcePath100Percent : String = "GUI/100percent/"; //normal image resources will be loaded from this location
    4. var resourcePath200Percent : String = "GUI/200percent/"; //image resources for retina display will be loaded from this location
    5.     //If you turn these two into non-private vars in StandardGUI you can take them directly form there doing stdGUI.resourcePath100Percent, etc.
    6.  
    7. var imgName : String[] = new String[0]; //fill with names of your images
    8. private var img : Texture2D[] = new Texture2D[0]; //will be filled with the right Texture2Ds in Start
    9. var activeImgID : int = 0; //show image with this id
    10.  
    11. private var ready : boolean = false;
    12.  
    13.  
    14. function Start()
    15. {
    16.  
    17.     //Find StandardGUI
    18.     if(!stdGUI) {
    19.         var stdGO : GameObject = GameObject.Find("GUI");
    20.         stdGUI = stdGO.GetComponent("StandardGUI");
    21.     }
    22.  
    23.     //Load correct images
    24.     var resourcePath : String = resourcePath100Percent;
    25.     if(stdGUI.scaleFactor >= 1.5) resourcePath = resourcePath200Percent;
    26.     img = new Texture2D[imgName.Length];
    27.     for(var i : int = 0; i < imgName.Length; i++) {
    28.         img[i] = Resources.Load(resourcePath + imgName[i], Texture2D);
    29.     }
    30.    
    31.     ready = true;
    32. }
    33.  
    34.  
    35.  
    36. function OnGUI ()
    37. {
    38.     if(ready) {
    39.         GUI.matrix = stdGUI.guiMatrix;
    40.         //GUI.DrawTexture(new Rect(-stdGUI.screenWidth * 0.5 + 10 * stdGUI.scaleFactor, stdGUI.screenHeight * 0.5 - 10 * stdGUI.scaleFactor - img[activeImgID].height, img[activeImgID].width, img[activeImgID].height), img[activeImgID]); //Bottom Left
    41.         GUI.DrawTexture(new Rect(-stdGUI.screenWidth * 0.5 + 10 * stdGUI.scaleFactor, -stdGUI.screenHeight * 0.5 + 10 * stdGUI.scaleFactor, img[activeImgID].width, img[activeImgID].height), img[activeImgID]); //Top Left
    42.     }
    43. }

    Hope this helps!

    PS: We're actually working on some new stuff for StandardGUI and OrientationControl that makes positioning objects on edges and in corners much easier...
     
  27. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    awesome stuff col000r , works perfectly awesome, we'll let you know if anything pops ups! , and sick! cant wait for the update !
     
  28. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    no problem, good luck with your game!
     
  29. rakudoor

    rakudoor

    Joined:
    Nov 12, 2009
    Posts:
    16
    I want to know what the difference is?

    GUIKit001
    $185.00

    GUISkin001 Deluxe
    $24.95

    SwipeControl
    $24.95

    OrientationControl
    $25.00

    GUIKit001 = GUISkin001 Deluxe + SwipeControl + OrientationControl?
     
    Last edited: Nov 17, 2010
  30. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    GUIKit001 is a pre-made interface (we call it StandardGUI) that works in any orientation and any resolution + all our other components (as they are used by it). It's aimed at people who don't want to spend 1+ months building their own menu or want a solid base to build upon. It's fully functional and easy to re-skin (webplayer here, videotutrial here)

    GUISkin001: Versatility is a professionally designed GUISkin. Use this if you don't like the default GUISkin that comes with Unity. It also includes some nice extras, like iOS-style sliders, input-fields with x-buttons, etc. The Deluxe version includes the skin in 200% resolution for retina displays and all source-files, so you can modify the look easily or even use it as a template for building your own GUISkins. (Check out all included elements in the webplayer demo)

    SwipeControl can be used to create image galleries, level selection screens, scrolling credits, etc. and works with touch and mouse input. Think iPhone-image-gallery swiping. (Check out the webplayer demo)

    OrientationControl is the extracted core of our StandardGUI. Using OrientationControl you can build your GUI so that it will work in any orientation and any resolution (including 100% and 200% on retina displays). With StandardGUI we tried to create an interface that would fit most basic games, but if your game requires unique interface screens, or if you want to build your interface from scratch for whatever reason: OrienationControl provides an easy way to load different resolution images depending on if your game is run on retina or non-retina displays and rotates your game softly when you turn your device to a new orientation. (Check out this video overview)

    So, GUIKit001 = StandardGUI + GUISkin001 Deluxe + SwipeControl + OrientationControl

    Hope this helps! Feedback is always welcome!
     
  31. rakudoor

    rakudoor

    Joined:
    Nov 12, 2009
    Posts:
    16
    Thank you very much, I have purchased GUIKit001, and tested it on my iPhone 3gs ,iPad and iPhone4 ,it is perfect.
     
  32. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
  33. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    And one more question - if you enable the "Skip Level Selection" option, how do you set the scene that is loaded when the player chooses to start the game?
     
  34. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @geppetto I think that's a bug that should really be fixed by UT. But I have an idea about how to circumvent it: One could set a variable in OnApplicationPause (something like iWasPaused = true) and then check for it in Update or FixedUpdate, so once you resume it will know that it had been paused and you can set savedMusicLevel to 0.0 to restart the music (this will make it think that the user changed the volume from 0.0 to the current level set in musicLevel and will thus restart the music) - haven't tried this yet though. Please also report it as a bug to UT!

    If you enable Skip Level Selection it doesn't load any level, it simply fades out the menu and shows what's in the current scene. But that's easy to change: Look for this code for the Start Button in OnGUI:

    Code (csharp):
    1. if(skipLevelSelection) {
    2.     AnimateMenu(0, Vector3(1, 0.0, 0), 0.0, 0.5);
    3.     CloseMenu();
    Just replace CloseMenu(); with something like this:

    Code (csharp):
    1. LoadLevelAndCloseMenu(levelSceneNames[0]);
    This will load the first ([0]) level from your levelSceneNames array, but you could just as well just give it the name of the scene you want to load directly...
     
  35. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Thanks - level loading is all working now. I'll play with the music thing and see what I come up with.
     
  36. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    How do I control the sounds with the slider? I'm temp using your pause menu, but it does not control the sound in the game, do I need to add the audiocontroller to every sound in the scene?

    Thanks,
     
  37. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    You don't need to use the included AudioController, just do these 2 things:

    A) Make sure the script that handles your audio reads the audio/music volume from PlayerPrefs.GetFloat("SoundLevel"); and PlayerPrefs.GetFloat("MusicLevel");

    B) In StandardGUI check out the function SaveSettings() and notice how it calls the Initialize function on SoundController when a volume change is detected. You might want to replace this with code for your own audio script, so it gets told about volume changes and doesn't have to check the PlayerPrefs continually!
     
  38. jingato

    jingato

    Joined:
    Jun 23, 2010
    Posts:
    299
    I was wondering, is the code done in C# or in Javascript? I'm going to have to do a bit of customizing, as mentioned before, and I'd rather not have to work in javascript.
     
  39. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    Both JS and C# versions are included. Just delete the ones you don't need from each project!
     
  40. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Hey col000r - one more thing that's got me stumped. When starting the game from the GUI, the new scene loads, the music keeps playing, but the music volume takes a sudden dip. It's dropping to maybe half the original volume.

    Any ideas where that might be coming from?
     
  41. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    Hm... wild guess without knowing any more details: in StandardGUI, what did you set the musicLevel to? Initially it's at 0.6 - that's the default value that will be saved into playerprefs the very first time you (or the players) launch the game. Maybe you never apply that same value in your custom code?

    FYI: There's a flushPlayerPrefs checkbox in the GUIDebugWindow script. If you check it all the playerprefs will be cleared in Awake - that way you can test what it will be like the first time you start the game (in this case: it will take the musicLevel value that was set in the inspector rather than the one previously saved to the playerprefs)

    If that doesn't help, please let me know more about the issue! (I can only tell that it works as it should in the default project...)
     
  42. aschenk

    aschenk

    Joined:
    Nov 27, 2010
    Posts:
    1
    Hi,

    I just bought GUI Kit and it's been pretty smooth integrating into our project with a few hiccups. One of those hiccups is that each level's (Scene) Render Settings are completely ignored when using the level select.

    While I could programmatically assign ambient light, skybox, fog, and the other settings I'd rather not have to go through all the levels to do this. I'm surprised no one else has had this problem, so am I just missing something?

    Thanks in advance.
     
  43. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    Yeah, loading levels additively ignores the new scene's settings. But you can use this script:

    ApplyRenderSettings.cs
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ApplyRenderSettings : MonoBehaviour {
    5.  
    6.     public bool read = true; //Set this to read the values from the settings. then press play, copy the gameObject, stop, delete the gameObject and paste in the one you copied.
    7.  
    8.     public bool fog;
    9.     public Color fogColor;
    10.     public float fogDensity;
    11.     public Color ambientLight;
    12.     public float haloStrength;
    13.     public float flareStrength;
    14.     public Material skybox;
    15.  
    16.  
    17.     void Start () {
    18.         if(read) {
    19.             fog = RenderSettings.fog;
    20.             fogColor = RenderSettings.fogColor;
    21.             fogDensity = RenderSettings.fogDensity;
    22.             ambientLight = RenderSettings.ambientLight;
    23.             haloStrength = RenderSettings.haloStrength;
    24.             flareStrength = RenderSettings.flareStrength;
    25.             skybox = RenderSettings.skybox;
    26.             read = false;
    27.         } else {
    28.             RenderSettings.fog = fog;
    29.             RenderSettings.fogColor = fogColor;
    30.             RenderSettings.fogDensity = fogDensity;
    31.             RenderSettings.ambientLight = ambientLight;
    32.             RenderSettings.haloStrength = haloStrength;
    33.             RenderSettings.flareStrength = flareStrength;
    34.             RenderSettings.skybox = skybox;
    35.    
    36.             Destroy(this);
    37.         }
    38.     }
    39. }
    40.  
    • Load into a scene
    • put the script on an empty GameObject
    • run the scene (if read==true, all the settings will be copied from RenderSettings into the script)
    • copy the gameObject while the game is still running
    • stop the game and delete the gameObject
    • now paste in the gameObject that has all the values set, from the clipboard - done!

    Just ran into this the other day myself - in our current game the RenderSettings don't change much, just the skybox is different, so I wrote this script... hope it helps!
     
  44. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    Hey cool0r, quick question, I noticed my GUI interface (except the pause button) is not rotating with the camera , I made sure their properly labeled to the "GUI" label/layer, and im not sure what i could possibly be missing. any idea?

    Im using the scripts you provided in the previous posts
     
  45. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    Most important question: you're applying the guiMayrix that StandardGUI provides to GUI.matrix in the beginning of every OnGUI function that holds something you want to rotate, right?
     
  46. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    Code (csharp):
    1. function OnGUI ()
    2. {
    3.     if(ready)
    4.     {
    5.         [B]GUI.matrix = stdGUI.guiMatrix;[/B]
    6.         //GUI.DrawTexture(new Rect(-stdGUI.screenWidth * 0.5 + 10 * stdGUI.scaleFactor, stdGUI.screenHeight * 0.5 - 10 * stdGUI.scaleFactor - img[activeImgID].height, img[activeImgID].width, img[activeImgID].height), img[activeImgID]); //Bottom Left
    7.         GUI.DrawTexture(new Rect(stdGUI.screenWidth * 0.5 - 70 * stdGUI.scaleFactor, stdGUI.screenHeight * 0.5 - 140 * stdGUI.scaleFactor, img[activeImgID].width, img[activeImgID].height), img[activeImgID]); //Top Left
    8.     }
    if you mean by that line of code, then yes. all of them have it
     
  47. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    That's a good start :) the matrix is what makes everything rotate. If the pause button rotates then the everything is okay with the matrix. Do you get any relevant errors or warnings in the scene? My guess is that StandardGUI isn't assigned properly. You're using Javascript, right? Could you please try and remove the C# scripts folder from the project? Because if you're looking for StandardGUI in the Start function of your script, for some reason unity finds the C# version instead of the Js one and fails to assign it without giving much of an error. - I reported a bug on this a while ago...

    Long story short: please try and delete the c# version of the scripts from the project if you use the js version.
     
  48. Void77

    Void77

    Joined:
    Jun 11, 2010
    Posts:
    41
    i have absolutely no C# copies of the scripts in my folder, ill investigate soon, at the moment i have moved onto on working for alternative options for Pause Button, I went ahead and tried to dissect your code to work for my benefits, and unfortunately i might have broken it again XD , instead of all the settings options when pressing the Pause button im trying to get a title rect and three buttons , a "Menu" "Resume" and "Replay" (it would display an entirely different menu and not the settings menu) , I gave it a shot but im not sure what the connection between the Settings code and the Pause button code are sharing because it seems to have made the button disappear all together, Ive attached the code below, and have been hammering my head at this for a couple hours now, in the mean time ill come back to the gui issue, ive attached the code below for a my "new" pause actions, let me know if you can suggest something! thanks!

    Code (csharp):
    1.    
    2.     }
    3.        
    4.         //Alien Abduction Pause MENU - ID 1
    5.        
    6.         if(guiOpacity[1] > 0.0  Rect(-1, -1, 2, 2).Contains(matPos[1]))
    7.         {
    8.        
    9.             GUI.color.a = guiOpacity[1];
    10.        
    11.             quat.eulerAngles = matAngle[1];
    12.             matpos = Vector3(Mathf.Round(Screen.width * matPos[1].x), Mathf.Round(Screen.height * matPos[1].y), matPos[1].z); //set position to the center of the screen
    13.             GUI.matrix = guiMatrix * Matrix4x4.TRS(matpos, quat, Vector3.Scale(matScale[1], globalScale)); 
    14.        
    15.             if(!orientationIsLandscape) { //For Portrait
    16.  
    17.                 PausedB1LTempRect = PausedB1LRect;
    18.                 PausedB2LTempRect = PausedB2LRect;
    19.                 PausedB3LTempRect = PausedB3LRect;
    20.             } else { //For Landscape
    21.  
    22.                 PausedB1TempRect = PausedB1Rect;
    23.                 PausedB2TempRect = PausedB2Rect;
    24.                 PausedB3TempRect = PausedB3Rect;   
    25.             }
    26.            
    27.             if(pauseMenuOn)
    28.             {
    29.                 if(GUI.Button(PausedB1TempRect, "Quit"))
    30.                 {
    31.                     AudioController.inst.PlaySound(1); 
    32.                     showPopupWindow = true; //this cases all gui to be disabled and for the popup to show - look further down at the end of OnGUI...
    33.                     popupString = "Do you really want to quit?";
    34.                     popupMessageYes = "QuitToMainMenu"; //This function will be called if the user chooses YES in the popup!
    35.                 }      
    36.                 if(GUI.Button(PausedB2TempRect, "Resume"))
    37.                 {  
    38.                     AudioController.inst.PlaySound(1);
    39.                     AnimateMenu(1, Vector3(1.5, 0.0, 0), 0.0, 0.5);        
    40.                     CloseMenu();
    41.                 }
    42.                 if(GUI.Button(PausedB3TempRect, "Replay"))
    43.                 {  
    44.                     AudioController.inst.PlaySound(1);
    45.                     AnimateMenu(1, Vector3(1.5, 0.0, 0), 0.0, 0.5);        
    46.                 }
    47.             }
    48.        
    49.            
    50.         }
     
  49. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @Void77: If you don't want the settings stuff to show in the pause menu but you still want it to display on the settings page, I suggest you move it into the else part of if(pauseMenuOn) (in the SETTINGS section of OnGUI) - that will be easier than trying to add another section just for the pause menu.

    I'll send you a DM with that section of the code.
     
  50. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    A little helper for locking/unlocking/completing levels (will be included in the next update as well):

    LevelStatus.cs (If you want to use it from JS, make sure to put it in the Plugins folder)

    You can now simply do the following from everywhere in your code:

    • LevelStatus.Lock(levelID); //lock level
    • LevelStatus.Unlock(levelID); //unlock level
    • LevelStatus.Complete(levelID); //complete level
    • LevelStatus.Get(levelID); //returns the status of the given level

    That's easier than dealing with PlayerPrefs manually.

    If you use this, you might want to add the following code to the QuitToMainMenu() function in StandardGUI:

    JS:
    Code (csharp):
    1. for(var l : int = 0; l < levelStatus.length; l++) {
    2.     levelStatus[l] = PlayerPrefs.GetInt("LevelStatus" + l);
    3. }
    C#:
    Code (csharp):
    1. for(int l = 0; l < levelStatus.Length; l++) {
    2.     levelStatus[l] = PlayerPrefs.GetInt("LevelStatus" + l);
    3. }

    This makes sure that any changes you perform during a level are reflected in the LevelSelection when you enter the level selection after hitting quit in the pause menu.
     

    Attached Files: