Monthly Archives: July 2016

NGUI EventDelegate

I have a button whose function changes depending on which panel is currently being displayed.  When switching panels, this button stays on screen (think a NavBar).  I ran into this unexpected behavior today, that slowed me down.

If you change the contents of an EventDelegate list during a method called from that  EventDelegate list then its probable that your new method will get called right way when control is passed back to the Execute method of EventDelegate.  This looked like the OnClick method of a UIButton was not waiting for a release, so I went down that rabbit hole for a bit.

I ended up adding a short delay to the code that switches the current OnClick action to the new OnClick action, which solved the problem.

	button.onClick.Clear();
	//delay this by a frame, so it happens outside the EventDelegate processing
	callAfterDelay(0.01f,()=>{
		button.onClick.Add(action);
	});

OSX Find command and patterns

I’ve been working on learning to create Joomla modules and plugins, and needed to do some bulk renaming on files, folders and the contents of those files (some of which are .ini, some are .xml and lots are .php).

To rename the files, I ended up using Automator on the mac – this is a nice visualization tool to do bulk rename of folders and files.

For the file content, I used the following command:

find . -type f -name '*.xml' -exec sed -i '' s/OLDNAME/NEWNAME/ {} +

This finds all the .xml files in your current path, passes them to sed, which then replaces the text OLDNAME with NEWNAME.  Because I also had some case variations, I used three other commands:

find . -type f -name '*.xml' -exec sed -i '' s/OLDName/NEWName/ {} +
find . -type f -name '*.xml' -exec sed -i '' s/oldname/newname/ {} +
find . -type f -name '*.xml' -exec sed -i '' s/Old Name/New Name/ {} +

Combine this with all 3 file types and it’s a lot of typing.  A read of the manual file for find says that -name uses the standard ‘pattern’ system, and then after some googling, I discovered you can use [ ] to have it match one character from the list, so I split up the file types and used the following:

find . -type f -name '*.[xpi][mhn][lpi]' -exec sed -i '' s/Old Name/New Name/ {} +

That worked as expected, and I was able to hunt for all 3 extensions with one find command.

Now I’m sure someone out there can probably point out how to use regex to do it correctly, but hey, my method worked, and that’s all I cared about…

I just discovered, I’ve a fourth file type that needed to be updated… ‘.sql’.  So I interleaved that in my line and voila!

find . -type f -name '*.[xpis][mhnq][lpil]' -exec sed -i '' s/Old Name/New Name/ {} +

(I probably don’t need that last ‘l’ but for completeness I left it in…)