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

Lecture 229 number wizard UI unityscript 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,34 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 UnityScriptDon’t forget that the project is attached to this lecture!. In translating Number Wizard UI from C# to UnityScript, we encounter no new feature

Trang 1

Translating Number Wizard UI to UnityScript

Don’t forget that the project is attached to this lecture!

What’s new?

In translating Number Wizard UI from C# to UnityScript, we encounter no new features of the UnityScript language In particular, theNumberWizardUnityScript 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 LevelManagerclass we introduce in this section translates to UnityScript in a straight forward manner The only thing worth noting is how we have access to the complete UnityEngine APIs from UnityScript, so the logic of the code is almost identical For example, accessing theUnityEngie.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.jsandLevelManager.js files:

NumberWizard

#pragma strict

import UnityEngine.UI;

public var guessText: Text;

private var max: int = 1000;

private var min: int = 1;

private var guess: int;

private function Start() {

StartGame();

}

private function StartGame() {

max = max + 1;

NextGuess();

}

public function GuessHigher(){

min = guess;

NextGuess();

}

Learn more atwww.CompleteUnityDeveloper.com

Trang 2

Translating Number Wizard UI to UnityScript

public function GuessLower(){

max = guess;

NextGuess ();

}

public function GuessCorrect(){

StartGame ();

}

private function NextGuess() {

guess = Random.Range(min, max);

print ("Next guess is " + guess);

guessText.text = guess.ToString();

}

LevelManager

#pragma strict

public function LoadLevel(name: String){

Debug.Log ("New Level load: " + name);

Application.LoadLevel (name);

}

public function 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