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

Pages: [1]
1
NGUI 3 Support / Re: Performance Suggestion
« on: July 23, 2014, 05:55:22 AM »
itween??, are you talking about performance and itween?, god help us all......

If you really want a decent tween system, use hotween or gokit, but itween......

Hey. Thanks for sharing this. I tried it immediatly and it looks quite nice.

GoKit uses actions as callbacks, fluent interfaces and a good code structure.
Hotween uses delegates and has also a good code structure.

Indeed well better coded than itween. :)

I think i go for GoKit first :D
 
What are your experience with GoKit and Hotween?

2
NGUI 3 Support / Re: Performance Suggestion
« on: July 21, 2014, 07:06:06 PM »
The statics.... here we go.

Unity is running the Mono Runtime Enviroment and due to licening of this Enviroment, Unity is always behind the current Mono Version.

Since Unity exists there are bugs in the Garbage Collector of Mono, not Unity! Static cant be cleared automatically and big amount of allocated memory making trouble. I had big projects and it was really a headbang till we found a solution. So. Since this i just advice guys not to use statics, especially in MonoBehaviours, which have no constructor and destructor. Dont point me to Start and Destroy, thats still something else.



For example in NGUI. The Scrollview.

If you have a simple scrollview with 100 entries. Adding and Removing costs alot of memory. Moving the entries is not possible on mobile devices. So thats why i searched for reasons in NGUI. And i found statics and huge calls of Unity methods. My balls alerted me, thats something wrong.

So. Well. Ive built my own Scrollview by altering the entries and not adding, removing or moving them. So i can scroll endless entries without having a performance loss.

If NGUI wants to be significant the best ui system, go for a new hierachy and get rid of GetComponent and Unitys method invocation. :)

Hope that brought light into the tunnel :D.


PS: Use "Visual C# + Resharper Plugin" and it will tell you alot about the code quality. And again. I dont attack NGUI. Its still good work but it really needs a refactoring. Simple solutions are indeed the best, if they have a good result.


3
NGUI 3 Support / Re: Performance Suggestion
« on: July 21, 2014, 03:01:27 AM »
1. Well. There are several ways to archieve this.

1.1 The best thing would be to use Unity as a graphicial interface and a code generator exports the designed user interface.
Well. I like Windows Forms. I would kill for such a user interface in Unity.

1.2 In the current version i would suggest something like the following. The parent and root are just assigned in the Start method. On Instantiate it will be assigned automatically and on Parenting you can assign it by code.

  1. public class NGUIComponent : MonoBehaviour {
  2.  
  3.         private NGUIComponent root;
  4.         private NGUIComponent parent;
  5.  
  6.         // Use this for initialization
  7.         void Start () {
  8.                 parent = Find(transform.parent);
  9.                 root = Find (transform.root);
  10.                 Debug.Log (string.Format ("[NGUIComponent, Source: {0}, Parent: {1}, Root: {2}] ", transform, parent, root));
  11.         }
  12.  
  13.         private NGUIComponent Find (Transform source) {
  14.                 if (null == source) {
  15.                         return null;
  16.                 }
  17.                 return source.GetComponent<NGUIComponent> ();
  18.         }
  19.  
  20.         public void OnDestroy () {
  21.                 parent = null;
  22.                 root = null;
  23.         }
  24. }
  25.  

The NGUIComponent contains the calculated Bounds as well. I would say to ensure theres no much invocation, i suggest to process any NGUIComponent in one Update method.
Any component is registered to this NGUIManager itsself and is processed in one Update. Even the Tweens, moves  etc. Anything else should be handled by delegates or interfaces.

  1. public class GuiManager {
  2.  
  3.         public void Update () {
  4.                 NGUIManager.Instance.Update();
  5.         }
  6. }
  7.  

This approach is like the Java Component Model. Component is anything. Panel is a collection of components. Windows is a collection of panels.

But well. I cant ensure anything for this. I just know theres no need to call GetComponent so often. It really kills this great framework.


2. The Statics?
I found the following code in nearly any NGUI file. I replaced it with <T> to visualize that any class has it. Because of the massive code duplication, i think its a surrounding for something.
Well statics are not bad. Yesssssch. :)

  1. static public T current;
  2.  
  3. current = this;
  4. .
  5. .
  6. .
  7. current = null;
  8.  

3. Well. I think theres no need for a static class like EventDelegate. In most cases statics are a lazy way to solve problems. Separate Events for each NGUI Tool would be an approvement as well.

Unity and UI is since version 1.0 a mess and i have respect for any improvement and ui developing. This framework is really an improvement but it has edges need to be rounded. :)


4
NGUI 3 Support / Performance Suggestion
« on: July 20, 2014, 12:45:52 AM »
Hey,

i looked in the source code of ngui and i would like to suggest some performance boosts.

1. Own Hirachy. Dont use Unitys GameObject Tree and GetComponent.
Even AbsoluteBounds is easy calculated with non recursive methods. Relative Coordinates should be calculated within ONE Update Method.
Dont use Broadcast or method invokecation from Unity. Its reflection based and its really slow.

I noticed one of the expensive methods is "CalculateRelativeWidgetBounds". The GetComponent calls are incredible expensive and in scrollviews and other ui stuff
its called very very often. Alot other methods are using GetComponent.

  1. class NGUIComponent {
  2.     private NGUIComponent root;
  3.     private NGUIComponent parent;
  4.    
  5.     public Rect GetAbsoluteBounds() {
  6.             Rect absoluteBounds = bounds;
  7.             NGUIComponent nextParent = parent;
  8.             while (nextParent != null) {
  9.                 absoluteBounds.x += nextParent.Bounds.x;
  10.                 absoluteBounds.y += nextParent.Bounds.y;
  11.                 nextParent = nextParent.Parent;
  12.             }
  13.             return absoluteBounds;
  14.         }
  15. }
  16.  

2. Statics
Remove any static of this project, especially the "current" one. Statics and MonoBehaviours are a mess for the garbage collector.

3. Delegates
A very good base. Your delegates working fine but it has to be in the object space. A Static class with passing lists by reference can not be a good way and
costs a lot.

4. Tweens
Get in Touch with ITween.


Greetz retn




5
NGUI 3 Support / Re: EventDelegate causing infinite loop
« on: July 13, 2014, 01:55:26 PM »
Huiuiui...

Thanks for reply. I dont wanna talk about that anymore. In my opinion its senseless.

@Mook
1. The Tween is not active. Its a button which triggers the tween. Even if its triggered, it should spam the scene not
causing an infinite loop. The tween has a time of 5 second and i can fire the button once!
2. Destroy, Instantiate and Find will work in a row in the next frame.
3. A new instance means also a new separate eventqueue.

@Nicki
The GetComponent thing is a good idea but it works with FindWithTag as well.

Maybe i should desribe it more detailed. The lobby has 3 buttons. Any button forces a tween. The tween moves the container outside the viewport. So if i have a new ui instance, i just put the delegate on the tween object, which is not  triggered automatically. By pressing the Button, the tween is activated and the roll goes on.

My code works like a cham without the eventdelegate method. Its not a fault in my code. I have a lot experience in such projects and i know how unity works.

Thanks for your help anyway. I have to reference it in scene diretly. Well.... Thats what it made for i think.

ciao

6
NGUI 3 Support / Re: EventDelegate causing infinite loop
« on: July 12, 2014, 05:21:52 AM »
Hey ArenMook,

thanks for your reply. Even if i use NGUITools.AddChild i run into an infinite loop. If i use a prefab and put it into the scene or i instantiate it like this, it doesnt matter.

If i have a new instance of a gui and i add an event, it may not be executed or may not run into an infinite loop. Its a bug in the NGUI framework. Take it or leave it. I paid for this framework. I wanna help to make it better. In my opinion its not usability. Best practise or not, it has to work.

Kind regards
retn



7
NGUI 3 Support / Re: EventDelegate causing infinite loop
« on: July 09, 2014, 10:48:03 AM »
Still causing problems....

Why is this code snippet causing an infinite loop?


  1. public class ngui {
  2.  
  3.     private GameObject lobbyGameObject;
  4.  
  5.     public void start () {
  6.         // instanciate new gui nui root
  7.         GameObject g1 = Resources.Load ("Gui/Lobby/Lobby") as GameObject;
  8.         lobbyGameObject = GameObject.Instantiate (g1) as GameObject;   
  9.  
  10.         GameObject letsPlayGameObject = GameObject.FindWithTag (TagManager.GUI_LOBBY_LETSPLAY_BUTTON);
  11.         UIPlayTween[] letsPlayTween = letsPlayGameObject.GetComponents<UIPlayTween> ();
  12.  
  13.         Debug.Log (letsPlayTween [1].GetHashCode());
  14.         EventDelegate.Add (letsPlayTween [1].onFinished, Fin);
  15.     }          
  16.        
  17.     public void close () {
  18.         UnityEngine.Object.Destroy(lobbyGameObject);
  19.     }
  20.  
  21.     public void Fin () {
  22.         close ();
  23.         ngui m = new ngui();
  24.         m.start();
  25.     }
  26. }
  27.  

When i start a new instance of my ngui class and call start.. it MUST work! But why not? It looks like the delegate is executed by adding an event.
greetz

8
NGUI 3 Support / Re: EventDelegate causing infinite loop
« on: July 09, 2014, 08:39:47 AM »
Hey grofie,

thanks for reply. Your suggestion is good.
It sovled the problem. Unity doesnt crash anymore.

Indeed, adding the delegate in my way before, caused the execution loop inside ngui to an infinite loop.

  1. public class ngui {
  2.  
  3.         private GameObject lobbyGameObject;
  4.  
  5.         public void start () {
  6.                 // instanciate new gui nui root
  7.                 GameObject g1 = Resources.Load ("Gui/Lobby/Lobby") as GameObject;
  8.                 lobbyGameObject = GameObject.Instantiate (g1) as GameObject;   
  9.  
  10.                 GameObject letsPlayGameObject = GameObject.FindWithTag (TagManager.GUI_LOBBY_LETSPLAY_BUTTON);
  11.                 UIPlayTween[] letsPlayTween = letsPlayGameObject.GetComponents<UIPlayTween> ();
  12.  
  13.                 Debug.Log (letsPlayTween [1].GetHashCode());
  14.                 EventDelegate.Add (letsPlayTween [1].onFinished, Fin);
  15.         }              
  16.                
  17.         public void close () {
  18.                 UnityEngine.Object.Destroy(lobbyGameObject);
  19.         }
  20.  
  21.         public void Fin () {
  22.                 close ();
  23.                 start ();
  24.         }
  25. }
  26.  

My intention is to keep the things in memory which i really need. I dont create and destroy the lobby endless times. Sometimes its better to
destroy and renew anything instead of resetting a lot of states.

Btw. This code snippet ist just a reduction to a minimum of the real code.
Thanks.

greetz retn


9
NGUI 3 Support / EventDelegate causing infinite loop
« on: July 08, 2014, 08:04:45 PM »
Hey Guys,

i have NGUI version. 3.6.7

My problem is the following. If i use EventDelegates on a UIPlayTween script, its causing an infinite loop and unity crashs.


  1. using UnityEngine;
  2. using System.Collections;
  3. using Net.MobileGame1.Core.Application;
  4.  
  5. public class ngui {
  6.  
  7.         private GameObject lobbyGameObject;
  8.         private UIPlayTween[] letsPlayTween;
  9.  
  10.         public ngui () {
  11.         }
  12.  
  13.         public void start () {
  14.                 // instanciate new gui nui root
  15.                 GameObject g1 = Resources.Load ("Gui/Lobby/Lobby") as GameObject;
  16.                 lobbyGameObject = GameObject.Instantiate (g1) as GameObject;           
  17.                 // lets get the tween script, from the button to be pressed
  18.                 GameObject letsPlayGameObject = GameObject.FindGameObjectWithTag (TagManager.GUI_LOBBY_LETSPLAY_BUTTON);
  19.                 letsPlayTween = letsPlayGameObject.GetComponents<UIPlayTween> ();
  20.                 // lets add a function to the eventhandler
  21.                 letsPlayTween[1].onFinished.Add (new EventDelegate(OnFinished));
  22.         }              
  23.                
  24.         public void close () {
  25.                 UnityEngine.Object.Destroy(lobbyGameObject);
  26.         }
  27.  
  28.         // callback
  29.         public void OnFinished () {
  30.                 //close previous
  31.                 close ();              
  32.                 start();
  33.         }
  34. }
  35.  

When i call the function outside of the ngui spec, its working like a cham.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class test : MonoBehaviour {
  5.  
  6.         // global ngui instance, changes on click
  7.         public static ngui n;
  8.  
  9.         // Use this for initialization
  10.         void Start () {
  11.                 n = new ngui ();
  12.                 n.start ();
  13.         }
  14.                
  15.         public void OnGUI () {
  16.                 // this works like a cham
  17.                 if (GUI.Button (new Rect(0, 0, 200, 20), "refresh")) {
  18.                         n.OnFinished();
  19.                 }
  20.         }
  21. }
  22.  


Kind regards
retn

Pages: [1]