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 26 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

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Translating Number Wizard UI to BooDon’t forget that the project is attached to this lecture!. In translating Number Wizard UI from C# to Boo, we encounter no new features of the Boo lan

Trang 1

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, theNumberWizardBoo 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, theLevelManagerclass 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.UInamespace is straight-forward

Worth noticing is that we correct a slight typo in the class naming from the C# codebase by changingNumberWizards

in the C# project toNumberWizard

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 guessText 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 theNumberWizard.booand LevelManager.boofiles:

NumberWizard

import UnityEngine

import UnityEngine.UI

public class NumberWizard(MonoBehaviour):

public guessText as Text

private max = 1000

private min = 1

private guess as int

def Start():

StartGame()

def StartGame():

max = (max + 1)

NextGuess()

public def GuessHigher():

min = guess

NextGuess()

Learn more atwww.CompleteUnityDeveloper.com

Trang 2

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 atwww.CompleteUnityDeveloper.com

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

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm