1. Trang chủ
  2. » Giáo án - Bài giảng

Lecture 228 number wizard UI BOO translation tủ tài liệu training

2 25 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 2
Dung lượng 94,31 KB

Nội dung

Translating Number Wizard UI to Boo Don’t forget that the project is attached to this lecture! What’s new? In translating Number Wizard UI from C# to Boo, we encounter no new features of the Boo language In particular, the NumberWizard Boo class is almost identical to the previous section’s solution We simply remove a few logging statements and re-order some of the execution to avoid some pitfalls Similarly, the LevelManager class we introduce in this section translates to Boo in a straight forward manner The only thing worth noting is how we have access to the complete UnityEngine APIs from Boo, so the logic of the code is almost identical For example, accessing the UnityEngie.UI namespace is straight-forward Worth noticing is that we correct a slight typo in the class naming from the C# codebase by changing NumberWizards in the C# project to NumberWizard That said, the effort to translate the project was not in the code translation, but in recreating the connections made in the editor, using drag and drop in the inspector For example, reconnecting the guess Text object to the NumberWizard script in the Game scene Doing this methodically required going through every object in the scenes and checking for their missing scripts manually This is error prone and the compiler will rarely catch missing objects and null references for us This workload can potentially be reduced in two ways: • Link and reference scripts programmatically instead of using the editor’s drag and drop • Use Prefabs, which would allow scripts to be changed only on the prefab itself without the need to reconnect scene objects individually In practice, translating an entire project is a rare undertaking, as most projects will use one main language or will keep old files as they are when switching to a new language and only translate them when they are being edited for another reason anyway, so the problems with scripts needing to be reconnected will be dealt with piecemeal or not at all For completeness, here are the NumberWizard.boo and LevelManager.boo files: NumberWizard import UnityEngine import UnityEngine.UI public class NumberWizard(MonoBehaviour): public guessText as Text private max = 1000 private = private guess as int def Start(): StartGame() def StartGame(): max = (max + 1) NextGuess() public def GuessHigher(): = guess NextGuess() Learn more at www.CompleteUnityDeveloper.com Translating Number Wizard UI to Boo public def GuessLower(): max = guess NextGuess() public def GuessCorrect(): StartGame() private def NextGuess(): guess = Random.Range(min, max) print(('Next guess is ' + guess)) guessText.text = guess.ToString() LevelManager import UnityEngine public class LevelManager(MonoBehaviour): public def LoadLevel(name as string): Debug.Log(('New Level load: ' + name)) Application.LoadLevel(name) public def QuitRequest(): Debug.Log('Quit requested') Application.Quit() Learn more at www.CompleteUnityDeveloper.com ...Translating Number Wizard UI to Boo public def GuessLower(): max = guess NextGuess() public def GuessCorrect(): StartGame()... Debug.Log(('New Level load: ' + name)) Application.LoadLevel(name) public def QuitRequest(): Debug.Log('Quit requested') Application.Quit() Learn more at www.CompleteUnityDeveloper.com

Ngày đăng: 17/11/2019, 07:35