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 - Skared Creations

Pages: [1]
1
NGUI 3 Support / UIPanel depth and raycast vs colliders
« on: January 29, 2014, 05:23:14 PM »
Hi,

I'm today switching my code from 2.x to 3.x, I have an empty object with UIStretch set to Both and a collider attached with size 1x1 and it should deny to raise events on underlying elements/interface (at least it worked in 2.x by using different Z in transform). Now if I understand the new guideline I have to maintain the same Z and use "Depth" of UIPanel to bring it back/forth, it works for rendering though it also raises events on underlying elements that reside in lower depth.

Here is an example:


The mouse was where you see "X", so it's intercepting the mouse-over event of the UIImageButton under it, here is the hierarchy:
UIRoot
- Camera
---Window (Z=0, Depth=1)
----GameObject with collider and UIStretch="Both"
----...other...
---Panel underlying (Z=0, Depth=0)
----Button
----Button
----...other...

Am I doing wrong or missing something? btw I also tried to use lower Z for "Window" to try if it worked like in 2.x but it didn't affect anything.

2
NGUI 3 Support / Issue on removing/add texture
« on: August 03, 2012, 05:25:55 AM »
Hi,

I have a 2048x2048 filled atlas textures, now I'm trying to optimize the space and the artist is making cuts on the UI to have more multiusable pieces. But any time I try to remove a sprite from the atlas (through "Atlas maker" window) or add new sprite (which of course would require a larger atlas) the atlas texture packer ends to screw up everything and the other sprites resulted messed after the re-packing.

It is an iOS game for iPad 2 and later, is it possible/performant to use a 4096x4096? And why Atlas maker does not increase to 4096 instead of messing up?

I can send privately the atlas and related texture.

EDIT: here is the screenshots:

Before removing a sprite:


After removing a sprite:


3
NGUI 3 Support / Re: Color Picker
« on: July 12, 2012, 04:53:40 PM »
Yep I fixed everything, I was getting the transform position on Start but the widget is on an animated panel so it got the position when the panel was out of the screen, now it works :)

4
NGUI 3 Support / Re: Color Picker
« on: July 12, 2012, 12:03:38 PM »
In OnPress & OnDrag, calculate the position of the UICamera.lastTouchPosition relative to the widget's origin (the top-left corner). Texture2D.ReadPixels the color at that coordinate.

I'm having some problems to achieve this, probably I'm doing something wrong. To calculate the lastTouchPosition relative to the UITexture I'm subtracting from it the screen point of the widget's transform:

  1. // This code is executed in a script attached to the UITexture which contains the wheel texture
  2. Vector3 textureWheelPos = UICamera.currentCamera.WorldToScreenPoint(transform.position);
  3. Vector2 pos = UICamera.lastTouchPosition - textureWheelPos;
  4.  

I'm almost sure that I'm doing it wrong, can you please help?

5
NGUI 3 Support / Re: Refreshing/repositionning dynamic items in grid
« on: June 08, 2012, 01:37:13 PM »
mh.. I call directly the UIGrid.Reposition method, because repositionNow is a flag checked inside Update so hopefully calling directly the method without waiting the next Update should/could be faster.

6
NGUI 3 Support / Re: Add contents dynamically to Grid
« on: June 08, 2012, 02:45:39 AM »
Oh finally I got rid of it, unchecking the parameter "Static" in the UIDraggablePanel properties did the trick... I didn't understand what it would be used for, since it was checked in the Scroll View example scene.

7
NGUI 3 Support / Re: Add contents dynamically to Grid
« on: June 07, 2012, 06:36:55 PM »
mh.. well, until I'll find an acceptable solution for now I'm using for now the following hack:

  1. // Hack: simulate a drag upwards on the UIDraggablePanel to update the render of deleted item
  2. myPanel.SendMessage("MoveAbsolute", new Vector3(0, 0.001f, 0));
  3.  

Of course I would prefer a fix, also because this little hack scroll the panel to the first item of the grid (it should be better to scroll only very few points before the current content, but at list it avoids now the empty destroyed cells).

8
NGUI 3 Support / Re: Add contents dynamically to Grid
« on: June 07, 2012, 04:23:36 PM »
Unfortunately unparenting it didn't make any difference, here is the code (called from another GameObject called through a SendMessage from the deleting UIDraggablePanelContents):

  1. IEnumerator DeleteMe (GameObject go) {
  2.         go.transform.parent = null;
  3.         DestroyImmediate(go);
  4.         yield return new WaitForEndOfFrame();
  5.         myGrid.Reposition();
  6.         myGrid.transform.parent.GetComponent<UIDraggablePanel>().ResetPosition();
  7. }
  8.  

and it's still the same behavior, here is a screenshot when I try to delete an object in the middle:



and again if I drag the panel to scroll after the destroy then the grid is rendered correctly. Isn't there a function I can call to force the render update?

9
NGUI 3 Support / Re: Add contents dynamically to Grid
« on: June 07, 2012, 01:29:07 PM »
Hello again,

As mentioned I managed to add items dynamically to UIDraggablePanel+UIGrid, but I found a problem where I am stuck now: when I destroy an item (e.g. when the player click on an item in the inventory, the real item prefab will spawn and so the UIDraggablePanelContents must be destroyed to not appear again in the inventory panel).

I am using the following code to destroy the content and refresh the list:

  1. // this script is attached to the UIDraggablePanelContents
  2. NGUITools.DestroyImmediate(gameObject);
  3. // myGrid is a reference to the UIGrid
  4. myGrid.Reposition();
  5. myGrid.transform.parent.GetComponent<UIDraggablePanel>().ResetPosition();
  6.  

The problem is that sometimes (not ever, but very often) the item is destroyed but the grid is rendered with an empty space where it was the destroyed cell, even if I can see in the hierarchy that the grid was correctly repositioned because its orange bounds in the editor window are correctly resized and the other items were repositioned correctly but not drawn.

Is it the correct way to remove an item from an UIGrid or I'm doing it wrong?

By the way I'm targeting iOS as output platform (using NGUI 2.0.7c), and this happens also to a modified version of the "Scroll View" example shipped with the library that you can try yourself from the attachment (it will need to be imported in a project where there is already NGUI imported).

This is very urgent, since the release date of the game is very soon and the GUI is the last thing missing.
Thanks

EDIT: I forgot to mention that as soon as I drag the list (or destroy the first element of the grid, after having destroyed another one in the middle) it is again correctly rendered without the empty space in the middle, so I'm guessing if there is a method to force the render update. I also tried to move the destroy script on another GameObject passing the object to be destroyed, but the result is the same, the object is destroyed but the grid is wrongly rendered with an empty space.

10
NGUI 3 Support / Re: Can't set up UIDraggablePanel
« on: June 07, 2012, 01:00:15 PM »
I'm having a similar problem (nothing actually scrolls) using the latest trial version. I don't understand what you mean by:In both the documentation and the package's assets, I can't find a UIDragPanel. There's just UIDraggablePanel and UIDragPanelContents. Can you clarify this?
He meant UIDraggablePanel

11
NGUI 3 Support / Re: Add contents dynamically to Grid
« on: June 06, 2012, 06:02:37 PM »
Ok, I fixed it adding the following code after the "for" loop:

  1. // Wait for the end of frame, else the UIDraggablePanel is still disabled
  2. yield return new WaitForEndOfFrame();
  3. listGridRoot.transform.parent.GetComponent<UIDraggablePanel>().ResetPosition();
  4. listGridRoot.GetComponent<UIGrid>().Reposition();
  5.  

12
NGUI 3 Support / Add contents dynamically to Grid
« on: June 06, 2012, 05:37:37 PM »
Hi,

I have a store and inventory as different UIPanels (both containing their own UIGrid) in my game and now I'm coding the following script to dynamically instantiate items bought from the store into the UIGrid of the inventory:

  1. public class InventoryGUI : MonoBehaviour {
  2.        
  3.         public static InventoryGUI instance;
  4.        
  5.         public UILabel labelLoading;
  6.         public GameObject listGridRoot;
  7.         public GameObject listItemPrefab;
  8.        
  9.         void OnEnable () {
  10.                 instance = this;
  11.                 labelLoading.enabled = true;
  12.                 StartCoroutine(LoadInventory());
  13.         }
  14.         void OnDisable () {
  15.                 instance = null;
  16.                 if (listGridRoot) {
  17.                         foreach (Transform item in listGridRoot.transform) {
  18.                                 Destroy(item.gameObject);
  19.                         }
  20.                 }
  21.         }
  22.        
  23.         IEnumerator LoadInventory() {
  24.                 Debug.Log("Load Inventory: " + Inventory.instance.items.Count);
  25.                 for (int i = 0; i < Inventory.instance.items.Count; i++) {
  26.                         StoreInfo info = Inventory.instance.items[i].info;
  27.                        
  28.                         GameObject item = NGUITools.AddChild(listGridRoot, listItemPrefab);
  29.                         item.name = "InventoryItem" + i;
  30.                         item.transform.FindChild("Name").GetComponent<UILabel>().text = info.displayName;
  31.                         item.transform.FindChild("Description").GetComponent<UILabel>().text = info.description;
  32.                 }
  33.                 yield return new WaitForEndOfFrame();
  34.                 listGridRoot.GetComponent<UIGrid>().Reposition();
  35.                 yield return new WaitForEndOfFrame();
  36.                 labelLoading.enabled = false;
  37.         }
  38. }
  39.  

The two panels are disabled by default and then enabled when clicking their respective buttons on the menu (through the common UIButtonPlayAnimation).

If I open first the store, buy one or more items, close it and finally open the inventory then everything works fine. But if I open first inventory (so its Grid is empty), then open the store, buy one or more items and finally re-open the inventory then it doesn't display anything, even if I saw the instantiated items in the hierarchy on editor. I tried to add the above "WaitForEndOfFrame" to see if it could be a rendering issue in time but it isn't... they are not displayed even if I play with transform's Z on either object in the UI root.

Any suggestion on what could it be the problem?

Thanks

Pages: [1]