[Player.cs]
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폴더에 존재
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 |



