Unity Inspector Customization (Beginner Level)
Unity Inspector Customization (Beginner Level)
Hello everyone, in this post I will talk about how you can customize the Inspector window of the Scripts you write in Unity. The information in this post will be very beginner level and will be the first level of Inspector window customization.
At the next level, we will discuss how to create a fully customized Inspector window, but for now, let's learn how we can edit it at a basic level.
When you learn the Inspector customization commands below, you will be able to design more organized Inspector windows as seen in the screenshot.
Unity Inspector Customization
We use the commands we use to customize the Inspector part of our scripts by writing them just above our variables.
SerializeField
Allows variables that are not defined as public to be visible in the Inspector window in the editor.
[SerializeField]
HideInInspector
Allows variables set as public or made visible in the editor with SerializeField to be hidden in the editor.
[HideInInspector]
Header
Allows us to enter a description text above our variables.
[Header("You can create informational text with Header")]Range
Allows the determination of the maximum and minimum values of our integer (int) and float variables.
[Range(0f, 100f)]
// Range can be used to limit float and int variables.
float rangeFloatExample;Tooltip
Allows us to write informational text that appears when we hover the mouse over our variables in the Inspector window.
[Tooltip("Information shown when hovering over the object")]
// Used to add visible info text when hovering over the object.
Vector3 toolTipExample;Space
Allows us to leave space between variables.
[Space(50)]
ContextMenu
Allows us to add a button in the component menu of our script. After using it, the function you write just below is called.
[ContextMenu("Customized Button")]
// Used to add a button that will appear when you click the three dots of the script component in the Inspector window and calls the function written just below it.
void doSomething()
{
Debug.Log("Customized Button Clicked");
}Let's review all our code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StandartScript : MonoBehaviour
{
[Header("You can create informational text with Header")]
// Header is used to add text to the editor.
[Space(50)]
[Header("Our float value created with SerializeField.")]
[SerializeField]
// SerializeField is used to display the variable in the editor without making it public.
float seriliazeFieldCreatedFloat;
[Header("Our float value created by the public method.")]
public float _publicCreatedFloat;
[Space(50)]
[Header("With Range you can set ranges for numbers through the editor.")]
[SerializeField]
[Range(0f, 100f)]
// Range can be used to limit float and int variables.
float rangeFloatExample;
[Space(50)]
[Header("You can add space with Space.")]
[Space(50)]
// Space is used to add space in between.
[SerializeField]
[Range(0, 10)]
int rangeIntegerExample;
[Header("With Tooltip, you can make info text appear when hovering over objects.")]
[SerializeField]
[Tooltip("Information shown when hovering over the object")]
// Used to add visible info text when hovering over the object.
Vector3 toolTipExample;
[SerializeField]
[HideInInspector]
// Hides the visible inspector object.
Vector3 hideInInspectorExample;
[ContextMenu("Customized Button")]
// Used to add a button that will appear when you click the three dots of the script component in the Inspector window and calls the function written just below it.
void doSomething()
{
Debug.Log("Customized Button Clicked");
}
}
I tried to explain to you as simply as possible how you can customize your Unity Inspector window at a basic level. I wish you a good day.






Yorum Gönder