1.委托有匿名委托吸祟,不是必須帶有委托名
委托可以把一個(gè)方法作為參數(shù)代入另一個(gè)方法;
事件可以看做是一種特殊的委托
委托可以理解為指向一個(gè)函數(shù)的引用(指針)
2.IK動(dòng)畫(huà)不是只有人型動(dòng)畫(huà)才能設(shè)置璃哟,只要有avarar都可以設(shè)置IK動(dòng)畫(huà)
3.RectTransform是Transform 的子物體,有Transform 的全部特征枣耀,Unity UI系統(tǒng)使用Rectform實(shí)現(xiàn)基本的布局和層次控制,在Inspector界面上,為了更方便的調(diào)節(jié)RectTransform的屬性,錨點(diǎn)的兩個(gè)點(diǎn)重合時(shí)會(huì)顯示位置和寬高.RectTransform組件負(fù)責(zé)組織GameObject的層級(jí)關(guān)系.
4.使用IK動(dòng)畫(huà)要實(shí)現(xiàn)系統(tǒng)自帶函數(shù)OnAnimatorIK(int LayerIndex)
5.Blend Tree:1D一個(gè)方向整合
??????????????? 2D Freeform Directional,同一方向上可以有多個(gè)動(dòng)畫(huà),不建議有動(dòng)作相似的動(dòng)畫(huà)踩寇。
? ? ? ? ? ? ? ? ? ? ? ? 2D Freedform Cartesian,可以在X軸和Y軸使用不同的定義六水,自有定義動(dòng)作
??????????????????????? Direct融合表情
6.動(dòng)畫(huà)遮罩和IK:可以給全身添加IK俺孙,不是只有人形動(dòng)畫(huà)才能設(shè)置IK,只要有avator都能設(shè)置IK
7.聲音視頻資源不能作為預(yù)設(shè)體掷贾,圖片轉(zhuǎn)為精靈之后可以作為預(yù)設(shè)體
8.四元數(shù)相對(duì)于歐拉角的有點(diǎn):1)能進(jìn)行增量旋轉(zhuǎn)(插值睛榄,緩動(dòng)旋轉(zhuǎn))
????????????????????????????????????????????????? 2)避免萬(wàn)向節(jié)鎖
????????????????????????????????????????????????? 3)給定方位的表達(dá)方式有兩種,互為負(fù)(歐拉角有無(wú)數(shù)種表達(dá)方式)
任意選擇?一個(gè)場(chǎng)景(如果電腦性能不不佳,? 直接使?用Plane及Cube等搭建?一個(gè)簡(jiǎn)單場(chǎng)景),選擇?一個(gè)?角?色,?小地圖(可顯示場(chǎng)景,玩家,及可拾拾取和不不可拾拾取物品),隨機(jī)產(chǎn)?生可拾拾取物品和不不可拾拾取物品,玩家通過(guò)?鼠標(biāo)點(diǎn)擊控制?角?色移動(dòng)(使?用導(dǎo)航);(20)可拾拾取物品:拾拾取后玩家能看到實(shí)時(shí)的顯示(顯示?方式?自定)(10);不不可拾拾取物品,拾拾取后減少玩家剩余游戲時(shí)間(游戲以時(shí)間為計(jì)時(shí),減少數(shù)值?自定義);(10)游戲結(jié)束顯示結(jié)束界?面,顯示玩家最終得分(以拾拾取到的物體數(shù)為基準(zhǔn),?自定義等分規(guī)則)(5)玩家游戲時(shí)間結(jié)束,播放玩家死亡動(dòng)畫(huà),(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;//游戲剩余時(shí)間
public float gameScore;//游戲成績(jī)
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的計(jì)時(shí)
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) {
//播放死亡動(dòng)畫(huà)
GameObject.Find ("Ethan").GetComponent<Animator>().SetTrigger (Animator.StringToHash ("DeadParams"));
isDead = true;}
//并且彈出游戲失敗界面
//獲取動(dòng)畫(huà)時(shí)長(zhǎng)
float clipLength = GameObject.Find ("Ethan").GetComponent<Animator>( )
.GetCurrentAnimatorClipInfo (0)[0].clip.length;
Invoke ("LoadGameOverScene", clipLength + 0.5f);
PlayerPrefs.SetFloat ("Score", gameScore);
}
}
//加載游戲結(jié)束場(chǎng)景
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 = "剩余時(shí)間 :" + 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 () {
}
}