對這文章發表回應
發表限制: 非會員 可以發表
發表者: 冷日 發表時間: 2014/12/10 10:04:03
AddComponentMenu 添加組件菜單項
Posted on 2013年07月22日 by U3d /在編輯器添加一個用於添加組件的菜單項,將擁有該屬性的腳本添加到選中的物體上。(用法:[AddComponentMenu(「Duan/Script_Mobile/BreakAndEnd」)])
例:在當前腳本中加入AddComponentMenu屬性,選中某物體後,將擁有該屬性的腳本添加到選中的物體上。
using UnityEngine;
using System.Collections;
///
/// 按返回退出应用
///
[AddComponentMenu("Duan/Script_Mobile/BreakAndEnd")]
public class BreakAndEnd : MonoBehaviour {
// Update is called once per frame
void Update () {
endGame();
//Unity3D教程手册:www.unitymanual.com
void endGame(){
if ( Application.platform == RuntimePlatform.Android &&
(Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home)) )
{
//Home键好像不一定能用。。默认就是把程序挂到后台,并不是退出。
Application.Quit();
}
}
}
原文出處:AddComponentMenu 添加组件菜单项 | Unity3D教程手册