More coming
I seriously miss the profiling feature in Unity, so I decided to create a little facility of my own. Obviously, there’s serious limitations to that, but at the same time, this approach also adds some freedom
Very simply put, the little “profiling framework” I’m offering here is used as follows:
-
Add JCsProfiler to any of your game objects (ideally, make it so that it’s never destroyed!)
-
In whichever method you need profiling, add the following code-pattern:
void Update() {
JCsProfilerMethod pm = JCsProfiler.Instance.StartCallStopWatch(
"ProfilingExample", gameObject.name, "Update");
--- code to be profiled
pm.CallIsFinished();
}
That’s it… there’s a few settings. I’m a bit in a rush now, want to continue with my game But I’ve attached a little sample project, which also includes a little Unity package that should contain all you need. You CAN use this with log4net, but I’ve commented that out so you don’t HAVE TO.
The profiling itself shouldn’t consume too much performance, rendering its GUI obviously does. That can be switched off, though (then, profiling only goes into the logfile). Also, if you make sure the statements are always in only one line (JCsProfilerMethod pm = … and pm.CallIsFinished()) you can very easily completely remove all profiling code. With VS.NET that’s two trival search / replace operations on all files in the project, takes about 10 seconds or so (for commenting everything in, or commenting everything out) … again, preprocessor directives would be COOL to make this even simpler and quicker (and easily available to everyone, not just those that use a code editor with full “project support”).
I haven’t even tried this with JavaScript but would be very happy to add a JavaScript sample, too, if someone takes the time to write it up (you just need to convert the sample I have created from C# to JavaScript… shouldn’t be too hard but I just don’t like JavaScript). It should be possible, actually, it should be easy
If people find this useful, I’ll put it to the UnifyWiki… See the screenshot for the little “addon” in action…
Jashan
PS: Oh, btw - the GUI code was the first UnityGUI 2.0 code I ever wrote. That sure could be optimized very easily (e.g. using CalcSize wisely instead of hardcoding heights that may or may not work with a given skin). Consider this “open source” and feel free to optimize, enhance and return the optimized version to the community, if you wish… I just did this because I couldn’t resist the pleasure of doing it
EDIT: In the original posting, I had uploaded a sample project which was missing the example scene. This should be fixed now