1.委托有匿名委托,不是必须带有委托名
委托可以把一个方法作为参数代入另一个方法;
事件可以看做是一种特殊的委托
委托可以理解为指向一个函数的引用(指针)
2.IK动画不是只有人型动画才能设置,只要有avarar都可以设置IK动画
3.RectTransform是Transform 的子物体,有Transform 的全部特征,Unity UI系统使用Rectform实现基本的布局和层次控制,在Inspector界面上,为了更方便的调节RectTransform的属性,锚点的两个点重合时会显示位置和宽高.RectTransform组件负责组织GameObject的层级关系.
4.使用IK动画要实现系统自带函数OnAnimatorIK(int LayerIndex)
5.Blend Tree:1D一个方向整合
2D Freeform Directional,同一方向上可以有多个动画,不建议有动作相似的动画。
2D Freedform Cartesian,可以在X轴和Y轴使用不同的定义,自有定义动作
Direct融合表情
6.动画遮罩和IK:可以给全身添加IK,不是只有人形动画才能设置IK,只要有avator都能设置IK
7.声音视频资源不能作为预设体,图片转为精灵之后可以作为预设体
8.四元数相对于欧拉角的有点:1)能进行增量旋转(插值,缓动旋转)
2)避免万向节锁
3)给定方位的表达方式有两种,互为负(欧拉角有无数种表达方式)
任意选择⼀一个场景(如果电脑性能不不佳, 直接使⽤用Plane及Cube等搭建⼀一个简单场景),选择⼀一个⻆角⾊色,⼩小地图(可显示场景,玩家,及可拾拾取和不不可拾拾取物品),随机产⽣生可拾拾取物品和不不可拾拾取物品,玩家通过⿏鼠标点击控制⻆角⾊色移动(使⽤用导航);(20)可拾拾取物品:拾拾取后玩家能看到实时的显示(显示⽅方式⾃自定)(10);不不可拾拾取物品,拾拾取后减少玩家剩余游戏时间(游戏以时间为计时,减少数值⾃自定义);(10)游戏结束显示结束界⾯面,显示玩家最终得分(以拾拾取到的物体数为基准,⾃自定义等分规则)(5)玩家游戏时间结束,播放玩家死亡动画,(5)
(⽂文件管理理,代码规范);
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);
}
}
//加载游戏结束场景
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 () {
}
}
网友评论