It takes a long time to contact the delegated proxy delegate. Besides viewing APIs, kotoba also gave me a lecture. Speaking of delegation, it is better to take the following small example. (The exercises I spent on in June 26)
Example: Write a method A, define Method B (print Hello), and method C (print world), where I can only call method. Yes. Hello will be printed in 1 second, and world will be printed in 3 seconds.
Let's talk about the benefits of callback:
Some of our code is fixed during development, but some are flexible and easy to change. Let's assume that both B and C are not written by ourselves, but other methods that have been written by others. Therefore, we should try not to modify others' methods without any bugs, in this case, method A is written by ourselves. We need to call Method B in one second and method C in three seconds. This is the current method. Maybe, after my demand increases, more and more similar code will be available. For example, if method D is executed in 4 seconds, but one day you think method A is too slow to execute, you have changed the time to 0.5 seconds, and you have to change all the subsequent methods, this will be troublesome. Then we will make a slight modification, so that the modification time of Method B will not affect the execution of other methods.
Public Delegate void delemethod (); void start () {startcoroutine (FUNA (2, funb); startcoroutine (FUNA (3, func);} ienumerator FUNA (float time, delemethod m) {yield return New waitforseconds (time); m ();} void funb () {print ("hello");} void func () {print ("world ");}