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

Pages: [1] 2
1
NGUI 3 Support / Re: OnClick and private methods
« on: January 09, 2014, 06:09:41 AM »
I do like your approach ShinyMark. I actually think it makes more sense because your approach is more in line with the Observer pattern. There would still be inspector work to be done as the easiest way to find "_targetButton" would be to create an inspector field that you can drag and drop. The one pro I can see from my system is that anyone can find the button and look at its OnClick handlers in the inspector and instantly know what it's calling, whereas your method would require someone to find the class that receives the has the listener, which may not always be clear (it should be if you set up a consistent scene hierarchy). Your technique though has the advantage of not needing to modify NGUI, so it's not a pain in the butt to upgrade NGUI each time. I say it's a pain in the butt, but it's pretty easy with git, however, it would be nice if it were streamlined anyway.

2
NGUI 3 Support / Re: OnClick and private methods
« on: January 08, 2014, 02:54:02 AM »
I've been using it thus far and it seems to be working out pretty nicely. I'll probably use some linq to make it prettier though.

3
NGUI 3 Support / OnClick and private methods
« on: January 07, 2014, 05:09:44 AM »
I noticed that the reflection for generating methods in the OnClick handler for UIButton only has the flags BindingFlags.Instance | BindingFlags.Public  in them. I think I understand why this was done; in order to make things easier for the user. However, I usually find myself making my events private, to properly hide away such things from other classes. Sure, it's not a big deal, but I take my encapsulation in Unity very seriously, going as far as to using SerializeField all the time so I can hide away all those inspector fields from other classes.

So what I came up with was a simple empty attribute. For those who don't care, they can continue making them public. For those who care, they can use the NGUIEvent I created;

  1. [System.AttributeUsageAttribute(System.AttributeTargets.Method)]
  2. public class NGUIEvent : System.Attribute
  3. {
  4.         // Used to allow private methods in the Methods dropdown for OnClicks in the inspector
  5. }
  6.  

I added the BindingFlags.NonPublic flag, then I added this code on line 40 or something;

  1. if (!mi.IsPublic) {
  2.         System.Object[] nguiEventMethods = mi.GetCustomAttributes(typeof(NGUIEvent), false);
  3.         bool hasAttribute = false;
  4.         if (nguiEventMethods.Length > 0) {
  5.                 foreach (var nguiEventMethod in nguiEventMethods) {
  6.                         if (nguiEventMethod.GetType() == typeof(NGUIEvent)) {
  7.                                 hasAttribute = true;
  8.                         }
  9.                 }
  10.         }
  11.         if (!hasAttribute) continue;
  12. }
  13.  

That would probably look prettier with some link which can be processed on the original mi collection. What do you guys think?

I especially like this because it makes the code even more legible, because now [NGUIEvent] will clearly tell you what a method is being used for, generally.

4
NGUI 3 Support / Re: NGUI replaced my shortcut but I can't find it...
« on: March 20, 2013, 01:55:31 AM »
Thanks a lot, that did the trick. That should probably be filed as a bug so ArenMook can fix it. Should I do that somewhere?

5
NGUI 3 Support / Re: NGUI replaced my shortcut but I can't find it...
« on: March 17, 2013, 11:05:45 PM »
Thanks for the reply. I tried that before coming here, that's why I said I couldn't find it. Only my shortcut shows up.

6
NGUI 3 Support / NGUI replaced my shortcut but I can't find it...
« on: March 15, 2013, 10:48:07 PM »
Hello, first of all, I updated NGUI to the latest version today (new project) after being on 2.0.8 for the longest time. Love the new features!

Now, I had a shortcut for a custom editor script I created that allowed me to do batch renaming of gameobjects in the scene view using alt + r. Now with NGUI, it attaches a DragDropContainer script onto it. I tried searching for the shortcut but I couldn't find it, how could I edit this shortcut so I can keep alt + r for renaming (since I use that way more)?

Thanks!

7
NGUI 3 Support / Re: Help understanding memory leaks.
« on: October 16, 2012, 11:54:10 AM »
Answer is negative. Unless I'm missing something. My loading class basically loads a buffer scene, then loads a cutscene, then loads the buffer scene again (thats where the code in my second post is being called), then finally loads the game. I have one GameObject that might be the culprit, and that's my Settings class, which is a singleton and is not destroyed between scenes. I need to try and test that out, maybe that's keeping a reference lingering. However, the odd thing is that all references are destroyed between scenes. So even if in the inspector it says "Missing", would that still keep an atlas from destorying itself, if that "Missing" reference is a gameobject with a class that is inside the atlas hierarchy?

8
NGUI 3 Support / Re: Help understanding memory leaks.
« on: October 16, 2012, 11:49:59 AM »
Do you have any widgets in the scene that are referencing them?

I can recheck, now that I think about it, the skip button for the cutscenes might be the culprit. Let me check that right now.

9
NGUI 3 Support / Re: Help understanding memory leaks.
« on: October 16, 2012, 10:34:51 AM »
As long as anything references the asset, it will not get unloaded by Resources.UnloadUnusedAssets()

See, I figured that that was my problem with the NGUI atlases, but how in the world am I supposed to find out what's keeping those references alive? Any tips for that? I guess I can set up some test scenes and see what happens...

10
NGUI 3 Support / Re: Help understanding memory leaks.
« on: October 15, 2012, 07:52:58 PM »
It's in a gameObject that doesn't get destroyed between levels. So this just keeps running in-between levels. It's just a test block as well, I turn it off during gameplay.

11
NGUI 3 Support / Re: Help understanding memory leaks.
« on: October 14, 2012, 09:52:21 PM »
Hopefully this will also help shed some light into the matter. I'm running this in a Buffer scene that I always load between the main menu, cutscenes, and the levels. During this time, I'm just showing a loading screen.

  1.         void Start()
  2.         {
  3.                 System.GC.Collect();
  4.                 Resources.UnloadUnusedAssets();
  5.                 StartCoroutine(WaitToLoadLevel());
  6.         }
  7.  
  8.         IEnumerator WaitToLoadLevel()
  9.         {
  10.                 yield return new WaitForSeconds(2.5f);
  11.                 AsyncOperation load = Application.LoadLevelAsync(LevelLoading.Instance.levelToLoad);
  12.                 LevelLoading.Instance.WaitForLoadDone(load);
  13.         }

12
NGUI 3 Support / Help understanding memory leaks.
« on: October 14, 2012, 09:47:28 PM »
Hi guys, I'm running this code and apparently, my Menu atlas isn't getting destroyed between scenes. Please forgive me if I come off as a novice in this area, I know very little about memory leaks or general memory management. I know just the basics. So here's what I'm doing;

  1.         IEnumerator TextureCheck() {
  2.                 yield return new WaitForSeconds(2);
  3.                 while (true) {
  4.                         Object[] textures = Resources.FindObjectsOfTypeAll(typeof(Texture));
  5.                         Object[] materials = Resources.FindObjectsOfTypeAll(typeof(Material));
  6.                         Object[] atlas = Resources.FindObjectsOfTypeAll(typeof(GameObject));
  7.                         List<Object> objects = new List<Object>();
  8.                         objects.AddRange(textures);
  9.                         objects.AddRange(materials);
  10.                         objects.AddRange(atlas);
  11.                         foreach (Object menuAtlas in objects) {
  12.                                 if (menuAtlas.name == "Menu") {
  13.                                         print (menu.GetType());
  14.                                 }
  15.                         }
  16.                         textures = null;
  17.                         materials = null;
  18.                         atlas = null;
  19.                         objects = null;
  20.                         yield return new WaitForSeconds(2);
  21.                 }
  22.         }
  23.  

As I move into other levels, this keeps spitting out in the console those 3 objects (The UIAtlas gameObject, the Material, and the Texture). I tried destroying them but I get the "Destroying assets is not permitted" error. This is a massive 8mb texture that is really eating a lot of memory. I really need help in solving this because we need to get this working on the 3GS. Thank you for your help.

13
Nevermind, I fixed it. There was a UIRoot pulled off way to the side and items were reaching that camera and the reason I wasn't able to replicate it is because that UIRoot persists between levels and its position was different in the scene where it starts on the iOS device.

14
I changed the category of some of the items to "none" and the following behavior is somewhat consistent; the shorter the list is from right to left, the more the ghost colliders are pushed to the right. Meaning that the ghost colliders start further at the end of list of items. Could this be some far off camera that's capturing some of this data or something?

15
Ok, I tried updating and the problem persists. Still getting the exact same behavior. Any ideas?

Pages: [1] 2