茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1671280 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
PIMG_00012.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

Game Play Maker : [轉貼]unity3D AddComponentMenu 添加組件菜單

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]unity3D AddComponentMenu 添加組件菜單

AddComponentMenu 添加組件菜單

Inherits from Attribute

The AddComponentMenu attribute allows you to place a script anywhere in the "Component" menu, instead of just the "Component->Scripts" menu.

AddComponentMenu屬性允許你在"Component"菜單中放置一個無論在哪的腳本,而不是僅僅在"Component->Scripts"菜單中。

You use this to organize the Component menu better, this way improving workflow when adding scripts. Important notice: You need to restart

你可以用它來更好的組織組件菜單,這種方式可以改善工作流程當你添加腳本的時候。重要提示:你需要重啟


// Javascript example
@script AddComponentMenu ("Transform/Follow Transform")
class FollowTransform extends MonoBehaviour {
}
// C# example:
[AddComponentMenu("Transform/Follow Transform")]
class FollowTransform : MonoBehaviour
{
}

Constructors 構造器

  • AddComponentMenu
    The script will be placed in the component menu according to menuName. menuName is the path to the component
    這個腳本將會被放置在組件菜單根據menuName(菜單名稱)。menuName是組件的路徑。
最後修改:2011年5月18日 Wednesday 16:19

原文出處: AddComponentMenu 添加组件菜单
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]unity3D AddComponentMenu 添加組件菜單項

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教程手册
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]自訂 Unity 工具列選單處理專案內容

自訂 Unity 工具列選單處理專案內容


一般我們使用 Unity 主要是用來製作 Client 內容播放與操作,但製作遊戲或任何系統軟體,比較少被注意到卻很重要的就是編輯或後端工具,雖然 Unity 編輯器本身就很強大且方便了,但有時候還是有些客制化需求,希望能更方便於我們製作及設置遊戲,所以 Unity 的 Script 除了有運作遊戲內容的 Runtime Classes 之外還有 Editor Classes,它其中一個功能就是可以讓我們自訂工具列選單,選單命令的動作就像我們平常撰寫 script 一樣,相當方便。


通常我們自己建立的 class 只要是繼承 MonoBehaviour,都會自動在工具列中的 Component/Scripts 出現,如果為 class 加上 AddComponentMenu 則可以為此 class 定義它在 Component 選單內的路徑,如下所示(也可參考 官網 )..

//Javascript 

class MyUnityScript extends MonoBehaviour {
.....
}

// C#

public class MyCSharpScript : MonoBehaviour{
.....
}

其實 Javascript 部份的寫法不需要特別宣告 class 繼承 MonoBehaviour,因為 Unity 在編譯時會自動為 Javascript 處理這個部份,所以只要在程式檔內找個地方插入 AddComponentMenu 那一行就可以了。

這種自訂工具列選單的方式只是運用在為物件加入 Component,如果我們在編輯遊戲時,常有一連串動作需要常常重複操作,此時就能利用 Editor Classes 的 MenuItem 另外自訂工具列選單做為執行命令,製作重點及步驟如下( 官網說明 )...


  • 在 Project 視窗任意路徑建立名為 Editor 的目錄。
  • 在 Editor 目錄內建立新的 script 檔。
  • 如果是使用 C# 請記得 using UnityEditor;。
  • 給工具列選單呼叫的 method 必須為 static。
  • 在被呼叫執行的 method 上一行加入 MenuItem,Javascript 的寫法為 @MenuItem("選單路徑字串"),C# 的寫法 [MenuItem ("選單路徑字串")]

  • 視需求為自訂選單命令加入快捷鍵,在【選單路徑字串】後空一格加入參數字元,% 符號代表Ctrl鍵,# 符號代表Shift鍵,& 符號代表Alt鍵,_ 符號代表無功能鍵,例如 %&b 代表按住 Ctrl+Alt 再按 B 鍵可執行此選單命令。


static void CustomMenuTest(){
....
}

很簡單的就建立自訂工具列選單,而且如果有指定快捷鍵的話,Unity 也將自動在選單項目的後面加註按鍵名稱;接下來就能依照個人需求在點選選單時對場景中的物件或 Project 視窗中的資源進行各種操作,像是... 在場景中產生新的 GameObject 添加需要的 Component 並調整數據後利用此 GameObject 製作新的 Prefab,或是在 Project 視窗複製多個 Material 並為它們個別調整設定,甚至是在硬碟的其它路徑建立新的資料夾並將在 Project 視窗中所選擇的資源做成 Assetbundle 儲存到該資料夾中,怎麼做就看大家如何運用囉!


原文出處:胡亂說‧隨便寫: 自訂 Unity 工具列選單處理專案內容
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|