Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Euthyphro

Pages: [1]
1
No matter what I do, I keep running into this problem when raycasting with the uicamera on a separate layer. I have Event Type set to 3D UI, in physics settings I have "Queries Hit Triggers" turned on as was suggested by someone who had a similar problem in a different thread. Still though, I can never get anything returned by UI Root.

The only way I've been able to raycast beyond UI Root is by removing the Rigidbody from UI Root, however, removing rigidbody is not a permanent fix as it is required and the UI Root just adds it back every time the scene starts anyway.

Here's the code:

  1. void Update()
  2. {
  3.     Ray ray = uiCamera.ScreenPointToRay (Input.mousePosition);
  4.     Debug.DrawLine (uiCamera.ScreenPointToRay(Input.mousePosition).GetPoint(0f), uiCamera.ScreenPointToRay(Input.mousePosition).GetPoint(0f)+Vector3.forward*100f,Color.red, 1000f);
  5.     RaycastHit[] hit;
  6.     hit = Physics.RaycastAll (ray, 400f);
  7.     for (int i = 0; i < hit.Length; i++)
  8.     {
  9.         Debug.Log ("Hit " + hit[i].transform.gameObject.name);
  10.         if (hit [i].transform.gameObject.layer == 8)
  11.         {
  12.                 selectedModel = hit[i].transform.gameObject.name;
  13.                 InstantiateSelectedModelInUI (selectedModel);
  14.         }
  15.     }
  16. }
  17.  

Any suggestions? I'm trying to raycast to a non NGUI model that is being displayed on the UI.

Thanks.

2
NGUI 3 Support / UIButton not firing on mouse 40% of the time
« on: September 08, 2015, 01:01:49 AM »
Problem:
Pretty simple question, could someone tell me why this button in the image below doesn't fire when two identical buttons do fire on mouse collision? It does work 60% of the time, but 40% of mouse hovers dont fire off and the user has to wiggle and juggle the mouse a few times over it for the button to detect mouse intersect with button collider. Any suggestions on why this might be happening? Yes collider is on, yes collider is the same size as the button, no there is no spike in the profiler that would stutter, the scene remains at 59FPS - those were the first things to check - the problem still persists.

Set up:
UI set up as 3D UI. Using the Control - Simple Button prefab that comes with NGUI and absolutely no modifications to the button at all. The Control - Button is the child of a UI Panel and the UI Panel is child to UI Root.

The only thing I can think of was that I copy/pasted the button within the editor but I'm hesitant to call that the problem as I cant reproduce this as the point of this problem.

Edit: I would like a point of clarification. For UIPanels that I'm not using and I want to hide, I am calling uiPanel.enabled = false; Is this incorrect? I'm noticing that the panel is still active but renderer disabled. Nonetheless, I can see for panels that are stacking it is causing issues with button clicks. What is the proper way to hide a UIPanel not being used? What is the point of having UIPanel.enabled = false if it causes issues with overlays?


UI Button:


UI Panel (Parent of button):


UI Root:


UI Camera:

3
I don't recommend placing a tween on the same object as a button. Do this instead:

UIWidget (tween alpha)
- UIButton (your normal button)

I didn't place a tween on the button, this is how it comes by  default with NGUI using 3.7.6 for the Control - Simple Button prefab.

If you want to test it yourself, set a button to disable/active with NGUI.SetActive(), then lerp the alpha from 0 to 1 on the button UISprite. The button will work until your mouse hovers it, then the button alpha goes from 1 to 0 instead of staying at 1.

4
I have some UIButtons with NGUI, I'm lerping the alpha from zero to one after NGUI.SetActive, however, when the mouse is hovered the button alpha goes back to zero on it's own. It's pretty frustrating, any suggestions other than rewriting some of UIButton?

5
I have a panel which includes a UISprite and UITable. From a different panel I deactivate it on Start() and then activate it when a button is clicked. The problem is that it will not enable unless the button is clicked twice. There is no error message. First click the button recognizes the button is clicked (printed to debug log to make sure) but the panel is not enabled, second click it does enable the panel. Just to screw around I even tried "NGUITools.SetActive(connectToServerUI, true);" twice in a row and still it did not activate. It only activated if the button was clicked a second time even though the first click is clearly registered given the counter increases with all clicks accounted for.

  1.  
  2.         GameObject connectToServerUI;
  3.         UIButton button;
  4.         void Start ()
  5.         {
  6.                 connectToServerUI = GameObject.Find("Container - Connect to Server Box");
  7.                 button = (UIButton)this.GetComponent(typeof(UIButton));
  8.             //  StartCoroutine(Disable());
  9.         NGUITools.SetActive(connectToServerUI, false);
  10.         }
  11.  
  12.         //tried quick coroutine for testing purposes to see if this has any effect, which it doesn't.
  13.         IEnumerator Enable()
  14.         {
  15.  
  16.                 NGUITools.SetActive(connectToServerUI, true);
  17.                 yield return null;
  18.         }
  19.         IEnumerator Disable()
  20.         {
  21.                 NGUITools.SetActive(connectToServerUI, false);
  22.                 yield return null;
  23.         }
  24.         int clicks = 0;
  25.         public void OnClick()
  26.         {
  27.                 clicks ++;
  28.         //      StartCoroutine(Enable());
  29.                 NGUITools.SetActive(connectToServerUI, true);
  30.         Debug.Log("Clicks "+clicks);
  31.         }
  32.  

Any suggestions on this? It's driving me crazy. I tried a coroutine because of another thread on this forum suggested it, however, I can't see how that would make any difference. I also tried NGUITools.SetActiveChildren and NGUITools.SetActiveSelf but both had no effect.

Using Unity 4.5.3 and NGUI 3.5.x. Unless there is a dire reason to upgrade to 3.7 which would fix huge bugs, I do not want to upgrade given that last time I upgraded NGUI tools it broke half my project and resulted in days extra work just to reconfigure everything.

6
NGUI 3 Support / (Solved) Making table elements pixel perfect
« on: August 08, 2014, 05:05:56 PM »
I'm trying to make my UILabel's pixel perfect however I'm running into problems with positioning the gameobject to a rounded number under a UITable.

My problem is 1) the UITable itself keeps repositioning after and 2) the table elements keep repositioning to a non-pixel perfect position. In my code below I go through all the children gameobjects to make sure they are set to the proper positioning.

  1. uiTable.repositionNow = true;
  2. //get all children and set to pixel perfect position.
  3. Transform[] allChildrenInContainer = GetComponentsInChildren<Transform>();
  4. foreach (Transform child in allChildrenInContainer) {
  5.         child.localPosition = new Vector3(Mathf.RoundToInt(child.localPosition.x),
  6.                                                    Mathf.RoundToInt(child.localPosition.y)+0.5f,
  7.                                                    Mathf.RoundToInt(child.localPosition.z));
  8.  
  9.        //NGUITools.MakePixelPerfect(child); same problem as above when trying this.
  10. }
  11.  

Any suggestions?

*EDIT* Solved it myself, hopefully this helps someone else. The solution is to call the "onRepositoin" invoker and it will invoke the method you create when the table is reposition. In my case, I created RepositionPixelPerfect() to be invoked once repositionNow does occur. This method is then invoked after and in my case I wrote this method to set each element to pixel perfect positioning.

Solution:

  1. void YourMethodForAddingTableElements()
  2. {
  3.     uiTable.onReposition += RepositionPixelPerfect; //onReposition wil invoke RepositionPixelPerfect method when UITable is repositioned.
  4.     uiTable.repositionNow = true;
  5. }
  6.  
  7. void RepositionPixelPerfect()
  8. {
  9.     Transform[] allChildrenInContainer  = GetComponentsInChildren<Transform>();
  10.     foreach (Transform child in allChildrenInContainer) {
  11.          NGUITools.MakePixelPerfect(child);
  12.     }
  13. }
  14.  
  15.  

7
I've been trying to get my fonts to become pixel perfect with NGUI but so far have not been able to. As a result, they are fuzzy.



I've tried the following:
- Creating NGUI font with NGUI font maker.
- UIRoot set to PixelPerfect scaling style.
- When trying wtih Unity - Font, set to "Keep crisp: Always".
- Played with font sizes and tried altering the size.

My problem is that the font is never crisp. I've played with the unity settings for the font, I've tried making the font an NGUI font, nothing seems to work. I've tried several different fonts, this is the same problem for all of them.

Does anyone have any suggestions? Both on how to make it crisp and then keep it persistently crisp among different resolutions?


EDIT: Solved.

For some reason the atlas reverted back to trilinear filtering. Changed it back to point and problem was instantly solved. If anyone else has this issue and stumbles on this thread, look up your atlas image in the unity folder tree, set Filter Mode to Point and that will resolve your problem hopefully.


Thanks.

8
NGUI 3 Support / Re: How to use half pixel offset?
« on: October 25, 2013, 06:09:38 PM »
Use localPosition instead of position - position is global in the scene, while local is inside the hierarchy and the one shown in the inspector.

Perfect, got it. Thanks! Now working properly.

I had to write my own offset method:

  1. void OnDrag (Vector2 delta)
  2. {
  3.         [...]
  4.         transf.localPosition += (Vector3)delta * rootElement.pixelSizeAdjustment;
  5.         transf.localPosition = new Vector3(HalfPixelOffset(transf.localPosition.x), HalfPixelOffset(transf.localPosition.y), transf.localPosition.z);
  6. }
  7.  
  8. float HalfPixelOffset(float input)
  9. {
  10.                 float r = 0;
  11.                 int i = (int)input;
  12.                 int result = (int)((input - (int)input) * 100);
  13.                 if(i > 0)
  14.                 {
  15.                         if(result > 50)
  16.                         {
  17.                                 r = i + 1 + 0.5f;
  18.                         }
  19.                         else if(result <= 50)
  20.                         {
  21.                                 r = i + 0.5f;
  22.                         }
  23.                 }
  24.                 else if(i < 0)
  25.                 {
  26.                         if(result > 50)
  27.                         {
  28.                                 r = i - 1 - 0.5f;
  29.                         }
  30.                         else if(result <= 50)
  31.                         {
  32.                                 r = i - 0.5f;
  33.                         }
  34.                 }
  35.                 return r;
  36. }
  37.  

9
NGUI 3 Support / Re: How to use half pixel offset?
« on: October 25, 2013, 02:03:14 PM »
It's not the half-pixel offset.

The sprite is an odd width (67) then because it is centered, it has to "land" on a .5 value to be crisp. The same applies with the height.

I noticed that in the editor, the transform position is x -28,y 36, z 0, but when I print out "this.transform.position.x, y, z"  the position is not even a whole number, instead it is coming out as:
-0.1230769 0.1516484 0 UnityEngine.MonoBehaviour:print(Object) ItemScript:Update() (at Assets/ItemScript.cs:35)

I think this is the source of my problem when repositioning. Any idea how to get the actual position, not a small unwhole number? I'm simply using "this.transform.position" to get the position from within the UITexture gameobject.

10
NGUI 3 Support / Re: How to use half pixel offset?
« on: October 25, 2013, 01:08:35 AM »
Things can lose their crispness when you drag them due to the fact that it's done via floats rather than ints. When you release the drag, it should even out to an integer value though.


  1.  
  2. Vector3 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  3. this.transform.position = p;
  4.  

The following code results in the fuzzy image. When I try to round p to either 0.5 or a full number, movement will not occur when dragging the image.

For example,  this.transform.position = new Vector3(Mathf.Round (p.x), Mathf.Round(p.y), p.z); does not move the image because rounding will keep rounding the number down before it can move, making it impossible to move. Likewise, usint Mathf.CeilToInt has the same problem, and FloorToInt also same problem.

My brain is fried right now after a long day of moving, any suggestions on how to overcome this issue?

11
NGUI 3 Support / How to use half pixel offset?
« on: October 23, 2013, 10:09:51 PM »
I'm having trouble with a UITexture. it seems that the texture loses its crispness after I move it. I've created a script that drags a UITexture gameobject around when I click on it, but as soon as its moved, the crispness is lost. I'm certain it is the half texture offset, but my question is, how do I correct this in c#?


Thanks.

Pages: [1]