johnatm / itween

Automatically exported from code.google.com/p/itween
1 stars 2 forks source link

Patch to allow delegates to be used in callbacks (oncomplete) #133

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
Please find attached both a patch to allow delegates to be passed to callbacks 
and some example usages.

Notes:
 - The patch is against asset store version 2.0.46 (from version number in its code; it's called 2.0.46.1 in Asset store; The Google Code version says it's 2.0.45).
 - There's no extra documentation (all oncomplete, onstart, etc all need updating).
 - It'd be better to remove need to cast labmda expression delegates to Action but I don't know it [yet] (suggestions?)
 - If one wished to avoid naming it "System.Action" cast, iTween could include a delegate type definition to cast to, E.g:
     public delegate void CB();
   Then the cast would read:
     iT.MoveTo.oncomplete, (iTween.CB) myInScopeMethod

Please let me know if there are any changes desired/required for acceptance!

Thanks for the lovely library & HTH!
Rupert.

Original issue reported on code.google.com by Rupert....@gmail.com on 7 Dec 2013 at 1:23

Attachments:

GoogleCodeExporter commented 8 years ago
Whoops, patch contained next fix I was going to submit as well 
(requirereceiver).  Attached is solely delegates change.

Original comment by Rupert....@gmail.com on 7 Dec 2013 at 1:30

Attachments:

GoogleCodeExporter commented 8 years ago
Improved patch attached.  Common-case optimization: checks whether delegate is 
System.Action and uses direct invocation (as opposed to all the redundant 
argument unwrapping apparently involved in DynamicInvoke()).  (I'm not a 
delegates guru!)  If one were happy with the restriction, one could probably 
elide the old if branch (if (callback is Delegate, etc).
HTH, Rupert.

Original comment by Rupert....@gmail.com on 7 Dec 2013 at 9:34

Attachments: