[Player.cs]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using UnityEngine; public class Player : MonoBehaviour { public int id; public string playerName; public string backStory; public float health; public float damage; public float weapon1Damage, weapon2Damage; public string shoesName; public int shoesSize; public string shoesType; // Use this for initialization void Start () { health = 50; } // Update is called once per frame void Update () { } } |
[PlayerInspector2.cs] - Editor폴더에 존재
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | using UnityEngine; using UnityEditor; [CustomEditor( typeof (Player))] [CanEditMultipleObjects] public class PlayerInspector2 : Editor { Player player; SerializedProperty playerName; SerializedProperty playerHealth; private void OnEnable() { player = (Player)target; playerName = serializedObject.FindProperty( "playerName" ); playerHealth = serializedObject.FindProperty( "health" ); } public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.BeginVertical(); EditorGUILayout.PropertyField(playerName); if (playerHealth.floatValue < 20) { GUI.color = Color.red; } if (playerHealth.floatValue > 80) { GUI.color = Color.green; } EditorGUILayout.PropertyField(playerHealth); GUI.color = Color.white; EditorGUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); } } |
'Unity' 카테고리의 다른 글
FSM 엔진 (0) | 2017.06.11 |
---|---|
Custom Inspector (0) | 2017.05.03 |
EditorWindow 사용예 (0) | 2017.05.02 |
Custom Editor Window - GUI (0) | 2017.05.02 |
Editor Scripting Tip [Built-in Attribute] (0) | 2017.05.02 |