เริ่มกันเลย
1. ให้ทำการสร้าง C# Script (จากตัวอย่างตั้งชื่อ ItemData) แล้วทำการเพิ่ม
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomPropertyDrawer(typeof(ItemData))]
public class ItemDataDrawer : PropertyDrawer
{
const int fieldWidth = 50;
const int fieldSpace = 5;
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
// ทำการ override property
label = EditorGUI.BeginProperty(position, label, property);
// วาด label และกำหนดไม่ให้มี Indent
Rect contentPosition = EditorGUI.PrefixLabel(position, label);
EditorGUI.indentLevel = 0;
EditorGUIUtility.labelWidth = 35f;
// กำหนดความกว้างของ itemName
contentPosition.width *= 0.5f;
// วาด Field itemName
EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("itemName"),
new GUIContent("Name"));
contentPosition.x += contentPosition.width;
// กำหนดความกว่าและวาด Field type และ maxAmount
Rect amountRect = contentPosition;
amountRect.width *= .5f;
EditorGUI.PropertyField(amountRect, property.FindPropertyRelative("type"),
new GUIContent("Type"));
amountRect.x += amountRect.width;
EditorGUI.PropertyField(amountRect, property.FindPropertyRelative("maxAmount"),
new GUIContent("Max"));
EditorGUI.EndProperty();
}
}
ปล. มีไรแนะนำมาได้นะครับ