Unity Community


Page 38 of 155 FirstFirst ... 2836373839404888138 ... LastLast
Results 741 to 760 of 3093

  1. Posts
    10
    Can you explain the difference between the 2D UI and 3D UI objects? Can they be used together, etc.


  2. Location
    Toronto, ON
    Posts
    1,901
    The only difference is in the camera used to draw them. Ortho camera is used for the 2D UI and a perspective camera is used for the 3D UI. They can be used together safely. In example 3 (the orc) the UI itself is 3D, but tooltips are 2D.


  3. Posts
    10
    @ArenMook, thanks, I have been using Example 1 - Interaction, and haven't gotten to the Orc yet. I did not know if more was involved.

    Do you recommend any animation package that can work with NGUI? That can move objects around after state has been sent?

    I have written a bunch of animation classes that work with NGUI and is working, just wondering if I should use another package.
    Last edited by parkerdc; 01-08-2012 at 10:29 AM.


  4. Location
    Toronto, ON
    Posts
    1,901
    I'm currently working on a simple built-in tweening system that will go live in the next update. If you need more advanced animations, you can just create them using Unity itself (Right click in project view -> Create -> Animation).


  5. Posts
    10
    ArenMook, you are awesome, a simple tween system is exactly what I need!


  6. Posts
    50
    Quote Originally Posted by ArenMook View Post
    As promised, no raycasts needed:.
    Ah of course, nice and clean! Im good at making things overly complicated

    Today I was wondering over how to deactivate gui elements the most efficient way. Lets say I have a lot of UI elements with fairly complex compositions (Lots of game objects and UIWidgets), and I want these to stop being rendered. Is the best way to iterate through the hierarchy and go gameObject.active = false, or is there some shortcut through the UIPanel so that the gameobjects themselves can stay active while the UIWidget is not rendered by the panel? Similar to just turning off a gameobjects renderer (I usually do that instead of turning off gameobjects completely).


  7. Location
    Toronto, ON
    Posts
    1,901
    I suggest organizing your UI to have several sub-roots that you can activate/deactivate using SetActiveRecursively:
    Code:  
    1. gameObject.SetActiveRecursively(false);
    If you want to disable all widgets but keep game objects active:
    Code:  
    1. UIWidget[] widgets = gameObject.GetComponentsInChildren<UIWidget>();
    2. foreach (UIWidget w in widgets) w.enabled = false;
    ... but the colliders will still be active, so I suggest you go with my original suggestion.


  8. Location
    Santa Fe, New Mexico, USA
    Posts
    988
    Hi Aren, is the trimmed texturepacker atlas feature compatible with using UIFonts as sprite within UIAtlas? Entering the PixelRect for the font could get kinda crazy with trimming enabled... It's already hard to get the correct PixelRect just without trimmed sprites. Can you give any guidelines for reading the texturepacker .txt file and interpreting what needs to be entered in PixelRect? Thanks


  9. Location
    Toronto, ON
    Posts
    1,901
    Yup, fully supported.

    No need to manually enter anything anymore. Select the atlas on UIFont and choose the font's sprite.


  10. Location
    Santa Fe, New Mexico, USA
    Posts
    988
    @Aren, wow- I just did that and the UIFont inspector updated automagically. That's some pretty impressive coding Thanks much


  11. Location
    Toronto, ON
    Posts
    1,901
    A PM I just received gave me a perfect idea for the next example: iTunes style playlist.


  12. Location
    Toronto, ON
    Posts
    1,901
    Quote Originally Posted by parkerdc View Post
    ArenMook, you are awesome, a simple tween system is exactly what I need!
    It's a part of 1.28, now available for download via the PayPal link.

    It's fairly rudimentary. For example in order to make a widget expand and shrink in a loop, you can attach a TweenScale to it and check the "loop" parameter. There's also TweenPosition, TweenRotation, and TweenColor. TweenColor is capable of tweening widget colors, renderer material color, or light colors -- whatever it finds on the game object it's attached to.

    Usage via code is equally simple:
    Code:  
    1. TweenColor.Begin(gameObject, duration, color);
    You can change the method of interpolation like so:
    Code:  
    1. TweenColor.Begin(gameObject, duration, color).method = Tweener.Method.EaseInOut;
    UIState series of scripts have been updated to use the tweening scripts.

    I'll add an example for it in a bit.


  13. Posts
    10
    I bought all your packages from the app store except BT (PayPal). I will have to wait for the app store to get the update.

    I took the uistateposition, created a new class and added this code to the bottom of the update.

    Code:  
    1. if (Mathf.RoundToInt(mTrans.localPosition.x) == positions[index].x && Mathf.RoundToInt(mTrans.localPosition.y) == positions[index].y && Mathf.RoundToInt(mTrans.localPosition.x) == positions[index].z)
    2.  
    3. if (currentState < positions.Length) currentState += 1;

    I created various positions that the logo falls into place and red player walks. Once they reach the position, continue onto the next one. They stop at the end.

    The other class I created was to cycle through positions, going back to the begining once reaching the end.


    Last edited by parkerdc; 01-08-2012 at 02:27 PM.


  14. Location
    Toronto, ON
    Posts
    1,901
    I still say using Unity's built-in animation is your best bet for anything past simple tweening

    1.28 should be on the asset store tomorrow.


  15. Location
    Santa Fe, New Mexico, USA
    Posts
    988
    Hi Aren, the Trim support for TexturePacker seems to work great! Only this problem: every time when I reimport the TP Import TextAsset, all my sprite's sizes got reset back to pixel perfect. Is that a regression of previous bug? It's time consuming to go back and resize every sprite just because the atlas had some new stuff added to it.


  16. Posts
    10
    Thanks for the update. I was under the impression that there is a big overhead when using Unity's built in animation.

    Do you know of a good tutorial on how to use the built in animation?
    Last edited by parkerdc; 01-08-2012 at 02:42 PM.


  17. Location
    Toronto, ON
    Posts
    1,901
    @mindlube: That must be a regression bug. I'll track it down.

    @parkerdc: Nope, can't say I do... I learned it just by playing around with it. It's fairly simple though -- you get a graph, and if you are in Record mode, you can just move the timeline, move the objects into place, then hit Play and see it come alive.


  18. Location
    Santa Fe, New Mexico, USA
    Posts
    988
    Aren, I'm using 1.26 from the App Store. I just did a test, and the same happens for non-trimmed atlases as well. So I could just be confused what the normal behavior was though: I was sizing directly my UISprites, instead of parenting them to gameobject and scaling/transforming the parent instead.That would be more advisable, right?


  19. Posts
    50
    @arenmook: Thanks for your suggestions regarding how to best turn of widgets!

    A question, when adding a collider to a widget that was just created (in code), is there something special to keep in mind? Look at this short code for example:
    Code:  
    1. UILabel labelWidget = (UILabel)UIManager.AddUIWidget<UILabel>(labelRootGO, "notUsedForLabels");
    2. labelWidget.font = UIManager.GetUIFont(boldFont) as UIFont;
    3. labelWidget.text = "LABEL TEXT";
    4. labelWidget.MakePixelPerfect();
    5.  
    6. UIManager.AddCollider(labelWidget.gameObject);
    The first to lines set the widget up through my simple UIManager (It creates a gameobject and adds it to the UI hierarchy (The root that has the UIPanel) and set the correct layer and so on), the second line just gets the right font.

    The problem is that the collider added by AddCollider gets a size of zero (the code is a copy of the stuff in NGUIMenu minus the editor code stuff). If I add it through the menu later in runtime everything is correct. Is it that the UIPanel has not yet updated the sprite and its size?

    Edit: It seems to work for UISprites.

    Edit2: labelWidget.visibleSize returns (0,0) but if I instead run labelWidget.font.CalculatePrintedSize I get the correct values.. I dont understand this, but it works the way I want it now, I think
    Last edited by mydingefnysen; 01-08-2012 at 03:50 PM.


  20. Location
    Germany
    Posts
    527

    Feature Request Mobile

    Hello,
    i just bought NGUI and am quite pleased with it so far. While i was trying to set up my GUI with it, i thought, oh well, why not try to make everything with it, and in my case that is.... tadaaaaaa, mobile joystick.
    You know, there is a joystick prefab in the mobile package (i guess), and since this is a GUI, it should be handled by any guysolution - or it ads up drawcalls.
    Furthermore, one could pimp it a bit.

    I guess some other users would appreciate this as well, as the one draw call gui is typically a mobile thingy.

    as Ngui uses C# only this evening i ported the unitys joystick.js to c#. Seems to work, i got no errors.
    But now i am stuck, as we need to replace everything concerning GUITexture (which this script relies on) to UISprite, or whatever you use. Its not much, one merely needs to retrieve the actual screenrepresentations RECT of the joystick texture.
    As for Pimping it up:
    The existing joystick ONLY works on mobile devices. Because of the input things. It would be much nicer to have additional MouseInput available at least in the editor, to test a game a bit there (For other machines, i actually cannot see any use in this) A relative restposition graphic would also by nice (i mean basically a circle underneath, that is static, but the user can see how much he moved the joystick (well actually the developer only needs to put an appropriate graphic underneath the joystick sprite)).
    Second thing to pimp would be the position of the joystick. Unitys solution is fixed. I like the idea of centering the joystick on Touchdown. So people with large hands have the center of it more to the middle of the screen.

    I will try to port it myself more, when i find the time (hard with two children). But i am not a too good coder especially not in C. If you think its a good idea to incorporate this, here is my joystick port so far:

    Code:  
    1. using UnityEngine;
    2.  
    3. /// <summary>
    4. /// Attach this script to a child of a draggable window to make it tilt as it's dragged.
    5. /// Look at how it's used in Example 6.
    6. /// </summary>
    7.  
    8. public class JStickBoundary
    9. {
    10.     public Vector2 min = Vector2.zero;
    11.     public Vector2 max = Vector2.zero;
    12. }
    13.  
    14.  
    15. public class NGUIjoystick : MonoBehaviour
    16. {
    17.                     // A static collection of all joysticks
    18.  
    19.  
    20.     static private NGUIjoystick[] joysticks;                    // A static collection of all joysticks
    21.     static private bool enumeratedJoysticks=false;
    22.     static private float tapTimeDelta = 0.3f;                   // Time allowed between taps
    23.  
    24.     public bool touchPad;                                               // Is this a TouchPad?
    25.     public Rect touchZone;
    26.     public float deadZone = 0;                                          // Control when position is output
    27.     public bool normalize = false;                                  // Normalize output after the dead-zone?
    28.     public Vector2 position;                                            // [-1, 1] in x,y
    29.     public int tapCount;                                                // Current tap count
    30.  
    31.     private int lastFingerId = -1;                              // Finger last used for this joystick
    32.     private float tapTimeWindow;                                // How much time there is left for a tap to occur
    33.     private Vector2 fingerDownPos;
    34.     private float fingerDownTime;
    35.     private float firstDeltaTime = 0.5f;
    36.  
    37.     private GUITexture guiSprite;                                       // Joystick graphic
    38.     private Rect defaultRect;                                   // Default position / extents of the joystick graphic
    39.     private JStickBoundary guiBoundary = new JStickBoundary();              // Boundary for joystick graphic
    40.     private Vector2 guiTouchOffset;                             // Offset to apply to touch input
    41.     private Vector2 guiCenter;                                  // Center of joystick
    42.    
    43. /* 
    44. #if !UNITY_IPHONE && !UNITY_ANDROID
    45.  
    46.     void Awake () {
    47.         gameObject.active = false; 
    48.     }
    49.  
    50.    
    51. #else
    52.      */
    53.     void Start () {
    54.  
    55.         // Cache this component at startup instead of looking up every frame   
    56.         guiSprite = (GUITexture) GetComponent( typeof(GUITexture) );
    57.    
    58.         // Store the default rect for the gui, so we can snap back to it
    59.         // how do we find the drawing rect for this NGUI GameObject
    60.         defaultRect = guiSprite.pixelInset;
    61.    
    62.        
    63.         defaultRect.x += transform.position.x * Screen.width;// + guiSprite.pixelInset.x; // -  Screen.width * 0.5;
    64.         defaultRect.y += transform.position.y * Screen.height;// - Screen.height * 0.5;
    65.    
    66.         Vector3 initPos = new Vector3(0.0f, 0.0f, transform.position.z);
    67.         transform.position = initPos;
    68.        
    69.         if (touchPad) {
    70.             // If a texture has been assigned, then use the rect ferom the gui as our touchZone
    71.             if (guiSprite.texture)
    72.                 touchZone = defaultRect;
    73.         } else {               
    74.             // This is an offset for touch input to match with the top left
    75.             // corner of the GUI
    76.             guiTouchOffset.x = defaultRect.width * 0.5f;
    77.             guiTouchOffset.y = defaultRect.height * 0.5f;
    78.        
    79.             // Cache the center of the GUI, since it doesn't change
    80.             guiCenter.x = defaultRect.x + guiTouchOffset.x;
    81.             guiCenter.y = defaultRect.y + guiTouchOffset.y;
    82.        
    83.             // Let's build the GUI boundary, so we can clamp joystick movement
    84.             guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
    85.             guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
    86.             guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
    87.             guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;
    88.         }
    89.  
    90.     }
    91.    
    92.     void Disable () {
    93.         gameObject.active = false;
    94.         enumeratedJoysticks = false;
    95.     }
    96.  
    97.  
    98.     void ResetJoystick () {
    99.         // Release the finger control and set the joystick back to the default position
    100.         guiSprite.pixelInset = defaultRect;
    101.         lastFingerId = -1;
    102.         position = Vector2.zero;
    103.         fingerDownPos = Vector2.zero;
    104.         /*
    105.         if (touchPad)
    106.             guiSprite.color.a = 0.025f;
    107.         */
    108.     }
    109.  
    110.     bool IsFingerDown () {
    111.         return (lastFingerId != -1);
    112.     }
    113.    
    114.     void LatchedFinger (int fingerId) {
    115.         // If another joystick has latched this finger, then we must release it
    116.         if (lastFingerId == fingerId)
    117.             ResetJoystick ();
    118.     }
    119.    
    120.     void Update () {   
    121.         if (!enumeratedJoysticks) {
    122.             // Collect all joysticks in the game, so we can relay finger latching messages
    123.             joysticks = FindObjectsOfType(typeof(NGUIjoystick)) as NGUIjoystick[];
    124.            
    125.             enumeratedJoysticks = true;
    126.         }   
    127.        
    128.         int count = Input.touchCount;
    129.    
    130.         // Adjust the tap time window while it still available
    131.         if (tapTimeWindow > 0)
    132.             tapTimeWindow -= Time.deltaTime;
    133.         else
    134.             tapCount = 0;
    135.    
    136.         if (count == 0) {
    137.             ResetJoystick ();
    138.         } else {
    139.             for (int i = 0; i < count; i++) {
    140.                 Touch touch = Input.GetTouch (i);          
    141.                 Vector2 guiTouchPos = touch.position - guiTouchOffset;
    142.    
    143.                 var shouldLatchFinger = false;
    144.                 if (touchPad) {            
    145.                     if (touchZone.Contains (touch.position))
    146.                         shouldLatchFinger = true;
    147.                     } else if (guiSprite.HitTest (touch.position)) {
    148.                         shouldLatchFinger = true;
    149.                     }
    150.    
    151.                     // Latch the finger if this is a new touch
    152.                     if (shouldLatchFinger && (lastFingerId == -1 || lastFingerId != touch.fingerId)) {
    153.                
    154.                     if (touchPad) {
    155.                         Color joystickcolor =  renderer.material.color;
    156.                         joystickcolor.a = 0.15f;
    157.                         guiSprite.color = joystickcolor;
    158.  
    159.                         lastFingerId = touch.fingerId;
    160.                         fingerDownPos = touch.position;
    161.                         fingerDownTime = Time.time;
    162.                     }
    163.                
    164.                     lastFingerId = touch.fingerId;
    165.                
    166.                     // Accumulate taps if it is within the time window
    167.                     if (tapTimeWindow > 0) {
    168.                         tapCount++;
    169.                     } else {
    170.                         tapCount = 1;
    171.                         tapTimeWindow = tapTimeDelta;
    172.                     }
    173.                                            
    174.                     // Tell other joysticks we've latched this finger
    175.                     foreach ( NGUIjoystick j in joysticks ) {
    176.                         if ( j != this )
    177.                             j.LatchedFinger( touch.fingerId );
    178.                     }                      
    179.                 }              
    180.    
    181.                 if (lastFingerId == touch.fingerId) {
    182.                     // Override the tap count with what the iPhone SDK reports if it is greater
    183.                     // This is a workaround, since the iPhone SDK does not currently track taps
    184.                     // for multiple touches
    185.                     if (touch.tapCount > tapCount)
    186.                         tapCount = touch.tapCount;
    187.                
    188.                     if (touchPad) { 
    189.                         // For a touchpad, let's just set the position directly based on distance from initial touchdown
    190.                         position.x = Mathf.Clamp ((touch.position.x - fingerDownPos.x) / (touchZone.width / 2), -1, 1);
    191.                         position.y = Mathf.Clamp ((touch.position.y - fingerDownPos.y) / (touchZone.height / 2), -1, 1);
    192.                     } else {                   
    193.                         // Change the location of the joystick graphic to match where the touch is
    194.                         position.x = (touch.position.x - guiCenter.x) / guiTouchOffset.x;
    195.                         position.y = (touch.position.y - guiCenter.y) / guiTouchOffset.y;
    196.                     }
    197.                
    198.                     if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
    199.                         ResetJoystick ();
    200.                 }          
    201.             }
    202.     }
    203.    
    204.     // Calculate the length. This involves a squareroot operation,
    205.     // so it's slightly expensive. We re-use this length for multiple
    206.     // things below to avoid doing the square-root more than one.
    207.     float length  = position.magnitude;
    208.    
    209.    
    210.     if (length < deadZone) {
    211.         // If the length of the vector is smaller than the deadZone radius,
    212.         // set the position to the origin.
    213.         position = Vector2.zero;
    214.     }
    215.     else {
    216.         if (length > 1) {
    217.             // Normalize the vector if its length was greater than 1.
    218.             // Use the already calculated length instead of using Normalize().
    219.             position = position / length;
    220.         }
    221.         else if (normalize) {
    222.             // Normalize the vector and multiply it with the length adjusted
    223.             // to compensate for the deadZone radius.
    224.             // This prevents the position from snapping from zero to the deadZone radius.
    225.             position = position / length * Mathf.InverseLerp (length, deadZone, 1);
    226.         }
    227.     }
    228.    
    229.     if (!touchPad) {
    230.         // Change the location of the joystick graphic to match the position
    231.         //guiSprite.pixelInset.x = (position.x - 1) * guiTouchOffset.x + guiCenter.x;
    232.         //guiSprite.pixelInset.y = (position.y - 1) * guiTouchOffset.y + guiCenter.y;
    233.     }
    234. }
    235.  
    236. }
    237.  
    238. //#endif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •