Unity has a powerful feature that helps us to modify values in the Inspector without any programming at all. This article covers everything we need to know in order to show our variables and our custom classes in the Unity Inspector. Showing Variables Just a Variable Let's create a little ...
public int DelayedField; //ShowInInspector用于将属性显示到界面上 [ShowInInspector] [OnValueChanged("OnValueChanged")] public string DelayedProperty { get; set; } private void OnValueChanged() { Debug.Log("Value changed!"); } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 3.颜色 //字...
[CustomPropertyDrawer(typeof(DisplayScriptableObjectPropertiesAttribute))]publicclassDisplayScriptableObjectPropertiesDrawer:PropertyDrawer{boolshowProperty=false;floatDrawerHeight=0;stringbutton="-";// Draw the property inside the given rectpublicoverridevoidOnGUI(Rectposition,SerializedPropertyproperty,GUIContentlabel)...
class in UnityEngine 描述 使变量不显示在 Inspector 中,但进行序列化。 using UnityEngine; public class Example :MonoBehaviour{ // Make the variable p not show up in the inspector // but be serialized. [HideInInspector] int p = 5; }
public class CustomDrawerExample : MonoBehaviour { public MyStruct MyStruct; [ShowInInspector] public static float labelWidth = 10; } // 自定义数据结构,用于演示。 [Serializable] public struct MyStruct { public float X; public float Y;
有一个System.Serializable的class,平时作为public成员,可以直接在Inspector上显示和编辑。 我有成员变量比如float类型时,需要当某个属性被打开时,才在编辑器上显示,则将其设置成[HideInInspector],再在Editor代码中使用if(xxx){PropertyField(...)}的形式就可以实现了。
在Unity的标准界面布局中,我用红色线条示意的右半区域就是Inspector面板。面板的左上角会有个小标签里面写着名字,应该找得到吧。我们把这张图的右下角放大一点看:这个是已经完成的CameraControl代码,红框里显示了这个脚本里所有的公共变量。如果在这里改动变量的数值,游戏运行时会按这里的数值走,而不是代码里的。
●ColorUsageAttribute 用于指定颜色字段的属性,以便在 Inspector 窗口中显示颜色拾取器,允许用户选择颜色。 ●ColorUsageAttribute 的参数有两个: ○Show Alpha: 这是一个布尔值,用于指定是否显示颜色拾取器中的 Alpha 透明度通道。如果设置为 true,则颜色拾取器将包括 Alpha 透明度通道,允许用户选择带有透明度的颜色。
public class TextEditor : Editor { public override void OnInspectorGUI() { DrawDefaultInspector(); CustomTextFunction(); } private void CustomTextFunction() { if (GUILayout.Button("清空内容")) { Text text = (Text)target; text.text = string.Empty; ...
Everything you add is a Component and they all show up in the Inspector window. There are MeshRender and SpriteRender Components; Components for audio and camera functionality; physics-related Components (colliders and rigidbodies), particle systems, path-finding systems, third-party custom ...