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 - andrejvojtas

Pages: [1] 2
1
NGUI 3 Support / Re: Sprite Atlas Transparency Issues
« on: January 19, 2018, 11:26:27 AM »
I'm also having issues with transparency in atlas creation. The resulting image is a 24-bit PNG instead of a 32-bit one, so the alpha is completely discarded. Furthermore, the "Alpha Is Transparency" toggle gets unchecked on all the textures that are added to an atlas, which disables their transparency. This means if they're used elsewhere in the project, they lose their transparency and this also breaks Unity's preview of some textures - for instance completely white icons, where only alpha channel varies become completely white and it's impossible to visually tell them apart.

Using Unity 2017.3.0f3 + NGUI 3.11.4. Attaching the actual output and the source images I arranged in what would be a desired result (checkerboard added for emphasis).

2
Thank you for your answers, I really appreciate it :)

3
Hi,

I have read trough quite a few performance related posts here, but came up empty.

My setup: I have a 1 drawcall UI, as I use 1 panel and 1 atlas for everything. On Start() I generate lists of widgets representing the various part of the UI. Then as needed I manually enable and disable widgets via NGUITools.SetActive() to show and hide parts of the GUI. The panel reaches up to 100 widgets, enabling and disabling groups of about 20-50 at a time.

The question: would it perform better, if I added a UIPanel to each group? If I understand it correctly adding more panels adds drawcalls, but they would be probably batched, as they use 1 atlas right? The reason I ask is, I read the UIPanel buffer rebuilds everytime a widget is enabled / disabled and the more widgets it has, the slower the rebuild. What is more expensive: adding 2-3 drawcalls or rebuilding 2-3 times a panel with ~ 100 widgets?

Thank you for your time.

4
Thank you, this is pure gold!

5
Thank you for you reply, it's been very useful.

6
Thank you, I will check those out.

What is the benefit of using the advanced C# messenger over the one inbuilt in NGUI?

7
NGUI 3 Support / Re: Tutorial questions from a new user.
« on: May 01, 2013, 11:00:48 PM »
I run into the same thing: hitting 'Make Pixel Perfect' did re-size the sprite, but the result in my Game View was much smaller then expected.

This was because I didn't delete the Main Camera and didn't run the NGUI > Open the UI Wizard option and the scene was not set up properly. Instead I just run NGUI > Create a Texture. And the scene looks pretty much the same, the trick is which camera is setup to display the textures/sprite. If you don't run the wizard, the main camera is showing NGUI elemments and the main camera is not in the correct position, so the make pixel perfect results into not correct size on screen.

It's all about setting ONLY the camera that is parented to UI Root (2D) to display the NGUI elements. You can achieve this with camera mask culling options and adding the NGUI elements to a layer, that is visible only by the correct camera.

8
Thanks, what I was after is something else, I didn't explain it very well.

What is the best practice for communicating between the UIwidgets. e.g. I have 20 UI buttons clicks that change rpg stats in a central game object (lets call it "hero") and then I need the stats from the "hero" object to display in the 20 UI Labels.

What do I do for the buttons? Add scripts that will on click go use GameObject.Find, then set the script component, then adjust the variables?
Again what do I do for the labels? Do they also need to go find the "hero" object, the correct component and read the variables?

Or should I use listeners and messaging, as in e.g.: the notification center: http://wiki.unity3d.com/index.php?title=NotificationCenter

What is efficient performance wise? Is there a best practice for NGUI / Unity to do this?

9
Ok, I figured out the last bits. For the sake another newbie comes this way I will post the solution here.

Btw. the step by step tutorials are a great help how to get a grasp on how things are setup in nGUI. Too bad I was like 50 times on the nGUI page and never noticed them. I just though they were another unity web player examples. It would save me a lot of pain and make a much better start impression if I knew from the start that they exist.

- So I used the NGUI > Open the UI Wizard this time, it creates the UI Root > Camera etc. hierarchy and voila no need to set up camera culling masks and layers etc.
- Also the jpg and png needs to be power of two to work with the 'Make Pixel Perfect' correctly. Otherwise they were still blurry as they were stretched. Maybe it's enough to specify the exact size when creating the Texture2D? Does anybody know a different solution then preparing the images in power of two dimensions?
- To avoid white edges on the result, the jpgs must be prepared correctly. One way how to do it is to use the free Flaming Pear plugins, specifically Solidify. As a side effect they compress much better than with the white background.

Then I use this code to load and display the art pixel perfect, in best quality, with smallest install and download size. The only cost of this method is vRAM cost, but it my game I display only a couple of these at once.

  1.         void Start () {                
  2.                                
  3.                 //load the prepared image data
  4.                 TextAsset colortxt;
  5.                 TextAsset alphatxt;
  6.                                
  7.                 Texture2D colorjpg = new Texture2D(4, 4);
  8.                 Texture2D alphapng = new Texture2D(4, 4);
  9.                                
  10.                 colortxt = Resources.Load("1024cloak01") as TextAsset;
  11.                 alphatxt = Resources.Load ("1024cloak01A") as TextAsset;
  12.                
  13.                 colorjpg.LoadImage(colortxt.bytes);            
  14.                 alphapng.LoadImage(alphatxt.bytes);                                            
  15.                
  16.                 //load the prepared Shader asset
  17.                 Shader rgbplusa;       
  18.                 rgbplusa = Shader.Find("RGBplusA");
  19.                
  20.                 //use NGUI to display the image pixel-perfect, make use of the camera setup created with NGUI > Open the UI Wizard
  21.                 UITexture perfect = NGUITools.AddWidget<UITexture>(GameObject.Find ("Panel"));                         
  22.                 perfect.material =  new Material (rgbplusa);
  23.                 perfect.material.SetTexture("_MainTex", colorjpg);
  24.                 perfect.material.SetTexture("_Mask", alphapng);
  25.                 perfect.MakePixelPerfect();
  26.                                        
  27.         }
  28.  

10
@Nicki: yes, thank you that's a good tip

@ArenMook: thank you, it's a place to start. Is there perhaps a place in one of the NGUI examples I imported into my project a place where this is used so I can understand the scene  setup better? What is the best practice for communicating between game object in Unity?

11
How do I hook a variable (e.g. an int) to a Label created in Editor? To display score and such.

How do I create an UITexture on runtime?

Thank you.

EDIT: I changed the title to better reflect what I meant.

12
Ok, just in case someone googles this, I figured it out, I don't need another shader, I am fine with the first one. I ended up using a 32 bit for the alpha, with RGB all turned to 0,0,0. This way the png compresses to almost the same size as a greyscale png. I used the original png32 art and reduced the Luminance in a Image editing program.

13
Thank you, that's a life saver. But how do I create an UITexture from code, please?

Also there is one last step I miss with the shader. It only works if the Texture has the Greyscale from Alpha checked. This is not possible to do when I load the png on the fly, via TextAsset. But it should be possible to use the greyscale RGB value in a shader in a blending mode and affect the alpha channel with it only.

EDIT: I figured a way that works with the shader I have and meets the size optimization requirements, see post below.

14
NGUI 3 Support / atlas maker trimming bug?
« on: April 30, 2013, 01:40:40 PM »
See attachment. The trimming doesn't work correctly. It cuts the character art. Or is there something I need to select?
Thank you for your time.

15
NGUI 3 Support / Re: Gui directly in front of the main camera?
« on: April 30, 2013, 01:16:26 PM »
I ran into the same thing. I am on Unity 3.5.7 and nGUI 2.5.1, Win 7.

I tried to follow the new NGUI Basic Tutorial at http://www.youtube.com/watch?v=rI1vjXgKVTU

After adding a UITexture via the NGUI menu > Add Texture, and actually adding a texture from the resource to the component the texture is nowhere to be seen in the Game View. Also 'Make Pixel Perfect' doesn't work correctly.

This is all because the camera culling layers, and the created NGUI objects are not added to any layer as well (respectively the are added to an Unamed31 layer, and the camera under the UI Root is not set up to display that layer). The bottom line, to make it work as supposed to, you need to select the nGUI object (Texture/Sprite) and add them to a layer in the inspector. I clicked Add a Layer and named it NGUI. Then in the Main Camera in the Culling Mask dialogue disable the NGUI layer and in the camera that is under UI Root (2D) for culling mask select the NGUI layer only.

I don't know if that's how it supposed to work, but it seems to work ok now. It really got me confused for a while.

Pages: [1] 2