Skip to content

Instantly share code, notes, and snippets.

@Aaron8052
Last active January 5, 2024 21:25
Show Gist options
  • Save Aaron8052/4996a98e6bd84269c55b0e612cf9e626 to your computer and use it in GitHub Desktop.
Save Aaron8052/4996a98e6bd84269c55b0e612cf9e626 to your computer and use it in GitHub Desktop.
Unity游戏优化(一)GetComponent变体

Unity游戏优化(一)GetComponent变体

GetComponent主要有三种变体:

  1. GetComponent("string")
  2. GetComponent<Type>()以及
  3. GetComponent(typeof(Type))

经过1000000次的循环测试后,第二种执行最快,仅89ms; 其次是第三种,95ms,仅相差6ms; 第一种最慢,耗时6413ms,是第二种方法的72倍多。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment