Unity Edit need MonoBehaviour apply gameobjcet, so create script extends MonoBehaviour can use.
建立新的腳本,並且要繼承 MonoBehaviour,否則 Unity Editor 腳本不能套用在物件身上。
TestEdit (C#) :
using UnityEngine;
using System.Collections;
using UnityEditor;
/**
* Unity Edit need MonoBehaviour apply gameobjcet,
so create script extends MonoBehaviour can use.
*/
[CustomEditor(typeof(PlayerTest))]
public class TestEdit : Editor {
Color color;
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
// Color setting windows
color = EditorGUILayout.ColorField("color",color);
if (GUILayout.Button("color Setting")) {
PlayerTest obj = target as PlayerTest;
obj.GetComponent<Renderer>().material.color = color;
}
}
}
結果圖:
沒有留言:
張貼留言