5.15考試試題

1.委托有匿名委托,不是必須帶有委托名

委托可以把一個方法作為參數(shù)代入另一個方法;

事件可以看做是一種特殊的委托

委托可以理解為指向一個函數(shù)的引用(指針)

2.IK動畫不是只有人型動畫才能設(shè)置,只要有avarar都可以設(shè)置IK動畫

3.RectTransform是Transform 的子物體,有Transform 的全部特征,Unity UI系統(tǒng)使用Rectform實(shí)現(xiàn)基本的布局和層次控制,在Inspector界面上,為了更方便的調(diào)節(jié)RectTransform的屬性,錨點(diǎn)的兩個點(diǎn)重合時會顯示位置和寬高.RectTransform組件負(fù)責(zé)組織GameObject的層級關(guān)系.

4.使用IK動畫要實(shí)現(xiàn)系統(tǒng)自帶函數(shù)OnAnimatorIK(int LayerIndex)

5.Blend Tree:1D一個方向整合

??????????????? 2D Freeform Directional,同一方向上可以有多個動畫,不建議有動作相似的動畫。

? ? ? ? ? ? ? ? ? ? ? ? 2D Freedform Cartesian,可以在X軸和Y軸使用不同的定義,自有定義動作

??????????????????????? Direct融合表情

6.動畫遮罩和IK:可以給全身添加IK,不是只有人形動畫才能設(shè)置IK,只要有avator都能設(shè)置IK

7.聲音視頻資源不能作為預(yù)設(shè)體,圖片轉(zhuǎn)為精靈之后可以作為預(yù)設(shè)體

8.四元數(shù)相對于歐拉角的有點(diǎn):1)能進(jìn)行增量旋轉(zhuǎn)(插值,緩動旋轉(zhuǎn))

????????????????????????????????????????????????? 2)避免萬向節(jié)鎖

????????????????????????????????????????????????? 3)給定方位的表達(dá)方式有兩種,互為負(fù)(歐拉角有無數(shù)種表達(dá)方式)

任意選擇?一個場景(如果電腦性能不不佳,? 直接使?用Plane及Cube等搭建?一個簡單場景),選擇?一個?角?色,?小地圖(可顯示場景,玩家,及可拾拾取和不不可拾拾取物品),隨機(jī)產(chǎn)?生可拾拾取物品和不不可拾拾取物品,玩家通過?鼠標(biāo)點(diǎn)擊控制?角?色移動(使?用導(dǎo)航);(20)可拾拾取物品:拾拾取后玩家能看到實(shí)時的顯示(顯示?方式?自定)(10);不不可拾拾取物品,拾拾取后減少玩家剩余游戲時間(游戲以時間為計時,減少數(shù)值?自定義);(10)游戲結(jié)束顯示結(jié)束界?面,顯示玩家最終得分(以拾拾取到的物體數(shù)為基準(zhǔn),?自定義等分規(guī)則)(5)玩家游戲時間結(jié)束,播放玩家死亡動畫,(5)

(?文件管理理,代碼規(guī)范);

using UnityEngine;

using System.Collections;

public class PlayerScript : MonoBehaviour {

public delegate void PlayerTriggerDelegate (bool isGood);

public event PlayerTriggerDelegate playerTriggerEvent;

Animator animator;

NavMeshAgent agent;

void Start ( ) {

animator = GetComponent<Animator>( );

agent = GetComponent<NavMeshAgent>( );

}

void Update ( ) {

if (Input.GetMouseButtonDown (0)) {

RaycastHit hit;

if (Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit)) {

if (hit.collider.tag == "Walkable") {

transform.LookAt (hit.point);

animator.SetBool (Animator.StringToHash ("WalkParams"), true);

agent.destination = new Vector3 (hit.point.x, transform.position.y, hit.point.z);

}

}

}

if (agent.remainingDistance <= 0.1) {

if (animator.GetCurrentAnimatorStateInfo (0).IsName ("HumanoidWalk")) {

animator.SetBool (Animator.StringToHash ("WalkParams"), false);

}

}

}

void OnTriggerEnter (Collider other) {

if (other.tag == "Good") {

playerTriggerEvent (true);

Destroy (other.gameObject);

} else if (other.tag == "NotGood") {

playerTriggerEvent (false);

Destroy (other.gameObject);

}

}

}



using UnityEngine;

using System.Collections;

using UnityEngine.SceneManagement;

public class GameController : MonoBehaviour {

public PlayerScript playerScr;

public UIManager uiManager;

public float remainingTime = 60.0f;//游戲剩余時間

public float gameScore;//游戲成績

public GameObject goodPerfabs;

public GameObject notGoodPerfabs;

private float time = 1.0f;

private bool isDead;

void Start ( ) {

playerScr = GameObject.Find ("Ethan").GetComponent<PlayerScript>( );

playerScr.playerTriggerEvent += ChangeData;

uiManager = GameObject.Find ("Canvas").GetComponent<UIManager>( );

}

void Update ( ) {

time += Time.deltaTime;

remainingTime -= Time.deltaTime;

if (remainingTime > 0) {

//刷新UI的計時

uiManager.time = remainingTime;

if (time >= 2f) {

int number = Random.Range (0, 2);

GameObject anything;

if (number == 0) {

anything = Instantiate (goodPerfabs) as GameObject;

Destroy (anything, 4.0f);

} else {

anything = Instantiate (notGoodPerfabs) as GameObject;

Destroy (anything, 6.0f);

}

anything.transform.position = GetAbledPostion ();

anything.transform.rotation = Quaternion.identity;

time = 0.0f;

}

} else {

uiManager.time = 0.0f;

if (!isDead) {

//播放死亡動畫

GameObject.Find ("Ethan").GetComponent<Animator>().SetTrigger (Animator.StringToHash ("DeadParams"));

isDead = true;}

//并且彈出游戲失敗界面

//獲取動畫時長

float clipLength = GameObject.Find ("Ethan").GetComponent<Animator>( )

.GetCurrentAnimatorClipInfo (0)[0].clip.length;

Invoke ("LoadGameOverScene", clipLength + 0.5f);

PlayerPrefs.SetFloat ("Score", gameScore);

}

}

//加載游戲結(jié)束場景

void LoadGameOverScene () {

SceneManager.LoadScene (1);

}

Vector3 GetAbledPostion () {

ArrayList colliders = new ArrayList ();

Vector3 pos;

do {

float x = Random.Range (-4.75f, 4.75f);

float z = Random.Range (-4.75f, 4.75f);

pos = new Vector3 (x, 0.5f, z);

colliders = new ArrayList (Physics.OverlapSphere (pos, 0.3f));

} while (colliders.Count > 0);

return pos;

}

public void ChangeData (bool isGood) {

if (isGood) {

gameScore += 2;

//刷新UI界面

uiManager.score = gameScore;

} else {

remainingTime -= 10.0f;

//刷新UI界面

uiManager.time = remainingTime;

}

}

}



using UnityEngine;

using System.Collections;

using UnityEngine.UI;

public class UIManager : MonoBehaviour {

public float score {

set {

scoreText.text = "得分 :" + value.ToString();

}

}

public float time {

set {

timeText.text = "剩余時間 :" + value.ToString("0.00");

}

}

Text scoreText;

Text timeText;

void Awake () {

scoreText = transform.GetChild (0).GetChild (0).gameObject.GetComponent<Text>();

timeText = transform.GetChild (0).GetChild (1).gameObject.GetComponent<Text>();

}

// Update is called once per frame

void Update () {

}

}



using UnityEngine;

using System.Collections;

using UnityEngine.UI;

public class GetScoreScript : MonoBehaviour {

Text finallScoreText;

void Awake () {

finallScoreText = GetComponentInChildren<Text>();

}

void Start () {

finallScoreText.text = "最終得分為 :" + PlayerPrefs.GetFloat ("Score").ToString("0.0");

}

void Update () {

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容