- 5
- 0
- 约8.54千字
- 约 7页
- 2017-01-05 发布于贵州
- 举报
unity3D技术之PerformanceOptimization性能优化unity3D技术之PerformanceOptimization性能优化
1. Use Static Typing使用静态类型When using JavaScript the most important optimization is to use static typing instead of dynamic typing. Unity uses a technique called type inference to automatically convert JavaScript constructs to statically typed code without you having to do any work.使用JavaScript很重要的优化是使用静态类型替代动态类型。Unity使用一种叫做类型推理的技术来自动转换JavaScript为静态类型而无需你做任何工作。【狗刨学习网】C# JavaScript using UnityEngine;using System.Collections;public class example : MonoBehaviour {public int foo = 5;}var foo = 5;In the above example foo will automatically be inferred to be an integer value. Thus Unity can apply a lot of compile time optimizations, without costly dynamic name variable lookups etc. This is one of the reasons why Unitys JavaScript is on average around 20 times faster than other JavaScript implementations. 上面例子中的foo将自动推断为一个整数值。因此Unity能节约大量时间,而不使用动态名称变量查找等耗时的计算。这就是为什么Unity的执行平均速度比其他JavaScript快20倍的原因之一。The only problem is that sometimes not everything can be type inferred, thus Unity will fall back to dynamic typing for those variables. By falling back to dynamic typing, writing JavaScript code is simpler. However it also makes the code run slower. 唯一的问题是,有时不是所有的东西都能被类型推断,因此Unity会对这些变量重新使用动态类型.通过这样,书写JavaScript代码会很简单。不过他也使代码执行变慢。Lets see some examples.我们来看一些例子.C# JavaScript using UnityEngine;using System.Collections;public class example : MonoBehaviour {void Start() {duck foo = GetComponentMyScript();foo.DoSomething();}}function Start () {var foo = GetComponent(MyScript);foo.DoSomething();}Here foo will be dynamically typed, thus calling the function DoSomething takes longer than necessary - because the type of foo is unknown, it has to figure out whether it supports DoSomething function, and if it does, invoke that function. 这里foo将是动态类型,因此调用函数DoSomething必须要更长时间 – 因为foo的类型未知,它必须弄明白是否支持DoSomething函数,如果支持,就调用那个函数。C# JavaScript using UnityEngine;using System.Collections;public class example : MonoBehaviour {void Start() {MyScript foo = GetComponentMyScript();foo.DoSomething();}}f
您可能关注的文档
- Unit 7 介绍性口译.docx
- Unit 7 Lesson 4 Sea Stories学案.doc
- unit 7语言点.doc
- Unit 8 The Great Minds.doc
- unit 8 quiz.doc
- Unit 8 教案.doc
- Unit 9 The Damned Human race.doc
- unit 9 A words.doc
- Unit 9 About Yourself.doc
- Unit 9 Have you ever been to a museum 教案.doc
- 2026年预防为主,生命至上安全培训课件.pptx
- 2026年三级安全教育.pptx
- 2026年检测业务安全培训.pptx
- 2026年消防动火培训.pptx
- 2026年重大事故隐患专项排查整治行动清单.pdf
- 2026年健康义普急救.pptx
- 2025—2026学年度四川省广元市苍溪县九年级上学期期末考试历史试题(含答案).docx
- 2025—2026学年度四川省泸州市合江县马街中学校九年级上学期期末历史试题(含答案)(九上_九下第二单元).docx
- 2025—2026学年度云南省曲靖市宣威市民族中学等校联考九年级上学期期末模拟历史试题(含答案).docx
- 2025-2026学年科普版七年级下册英语Unit7 Being a Smart Shopper素养测评卷(含答案).docx
最近下载
- 焦炭单位产品能源消耗限额-编制说明.pdf VIP
- 人教版八年级生物下册全册教学设计.pdf VIP
- 大家的日本语_第一版_单词表(默写版).pdf VIP
- 轧钢工序单位产品能源消耗限额及计算方法.pdf VIP
- 同步练习(附答案) 寒假预习人教版七年级下册数学之内错角、同位角、同旁内角测试卷.docx VIP
- 2026年常州纺织服装职业技术学院单招职业技能考试题库必考题.docx VIP
- 烧结工序单位产品能源消耗限额及计算方法.pdf VIP
- 2026年常州纺织服装职业技术学院单招职业技能考试参考题库及答案解析.docx VIP
- TJSGT-转炉炼钢工序单位产品能源消耗限额及计算方法编制说明.pdf VIP
- 2026年常州纺织服装职业技术学院单招职业技能笔试参考题库及答案解析.docx VIP
原创力文档

文档评论(0)