当前位置:网站首页>Some thoughts on callback
Some thoughts on callback
2022-06-09 03:26:00 【The cat is not here】
List of articles
UI problem
- In recent months, I have also made several small games , There are some problems .
- I didn't do anything at first UI frame , But each UI Interfaces need to be opened , such as
Start interfaceOfStart buttonClick to openChoose the levelInterface . - Select the level button in the interface and click it to open the game interface .
- When I didn't write a framework , Every UI There should be one inside the interface
Open()andCloseMethod , And in order to call these methods , I need them to quote each other , namely StartPanelSave theSelectPanelReferences to ,SelectPanelSave theGamePanelThe interface of 【 I didn't set oneUICenterGeneral control class of 】- And each UI It needs an initialization process ,
Init(),UI The interface needs to be initializedButton bindingThe function of , Generally speakingButton binding only needs to be done once - also ,UI Interface
Callback
- There are three forms of callback ,
- Set the callback function as
ParametersIn the form of ,
void DoSomeThing(int param, Action callback)
{
callback.Invoke();
}
- Subscriber pattern
public Event OnValueChanged;
publiv void ChangeGravity(int val){
OnValueChanged.Invoke(val)
}
The difference between the above two is , The subscriber model is for more people , The callback only faces one ,
I also have such a puzzle .
// When I wrote the code, I already knew that the game interface should be opened after the function is executed
// So I have two ways to deal with it
void DoSomething(){
...
UICenter.Inst.OpenGamePanel();
}
Action callback = ()=>{
UICenter.Inst.OpenGamePanel();
}
void DoSomething(callback){
...
callback.Invoke();
}
- The form of transfer function is mostly used in a well encapsulated class , Interfaces exposed when used by others . That means you don't know what other people want , But keep such an interface for others to use .
- If you write your own code , Know what to do next , Just write it directly in the function . This can also avoid
GC
Interface confusion
- The interface itself is a contract for others , It is for others to use .
- It has the same effect as virtual function rewriting
interface IPoolContext
{
void OnSpawn();
void OnCreate();
}
abstract class Pool{
virtual OnSpawn(){
}
void Spawn(IPoolContext context)
{
OnSpawn();
context.OnSpawn();
}
}
- You can see above ,
OnSpawnThe function itself is used inPoolSelf , namelyThe moment he created the object, One is used to generate objectsGenerated time, These are two events .
边栏推荐
- Implementation of hash table of Telephone Query System for C language project (project requirements + operation interface + code analysis + complete code)
- 2022年短期理财产品排行榜
- [detailed explanation of kubernetes 13] - dashboard deployment
- Ccf-csp 201903-2 24:00
- 并发操作之——ReenTrantLock和synchronized的区别
- What's the matter with online stock account opening? Is it safe to open an account online?
- 技术分享 | 调整 max-write-buffer-size 优化 pika 性能10倍的案例
- Elderly fall prevention alarm system based on stm32+ Huawei cloud IOT [play with Huawei cloud]
- Ccf-csp 202203-2 travel plan 100 points difference
- [reinforcement learning notes] V value and Q value in reinforcement learning
猜你喜欢

SQL审核 | 这里有 MySQL/Oracle 最常用的 SQL 开发规则
![Generation of random numbers in C language [detailed explanation]](/img/a7/a7530074efa3e9bd92b9f049556f2a.png)
Generation of random numbers in C language [detailed explanation]

FPGA初次尝试

Neural network learning (V) -- comparison of common network structures

Do you know the specifications of e-commerce background permission settings!

Leetcode 238. Product of arrays other than itself

Ccf-csp 201803-4 chess game evaluation +dfs

"Baget" takes you one minute to set up your own private nuget server

Redis6学习笔记-第一章-Redis的介绍与环境搭建
![[machinetranslation] a training of multilingual machinetranslation model](/img/42/39f020b0e38c93c66885077f9addeb.png)
[machinetranslation] a training of multilingual machinetranslation model
随机推荐
Ccf-csp 201503-3 Festival
Leetcode 871. Minimum refuelling times priority queue
Ccf-csp 202109-3 pulse neural network, sometimes 100 points..
Ccf-csp 202012-5 Star Trek 80 points
is_ Numeric SQL bypass
[play with Huawei cloud] functions and features of Kunpeng code migration tool
À propos de JS console. Log () est un problème de synchronisation ou asynchrone
并发操作之——ReentrantReadWriteLock
Ccf-csp 202203-2 travel plan 100 points difference
Ccp-csp 201909-3 character drawing 100
SQL审核 | 这里有 MySQL/Oracle 最常用的 SQL 开发规则
故障分析 | MySQL 中新建用户无法登陆的一种特殊场景
[reinforcement learning notes] V value and Q value in reinforcement learning
Android 程序常用功能《清除缓存》
Now VB6.0 has been connected to SQL, but when using the query function, you can't query with any conditions. The situation on the Internet is not consistent with mine. How can you implement it?
postgresql判断数据库的主从关系
[machinetranslation] a training of multilingual machinetranslation model
What taxes do Tami dogs need to pay for equity transfer? What are the possible tax risks?
opencv学习笔记一
word+正则表达式==快速批量添加图注题注(保姆级图文)