ShowInInspector

  06. Attributes No Comments

Attribute that can be used to make class member that follows the attribute be shown in the inspector.

Unlike Unity’s built-in SerializeField attribute, this can also be used to display non-serialized fields.

It also supports properties and methods in addition to fields.

Many types that the default inspector can’t display can be shown in Power Inspector with this attribute.

For more information see the display anything feature page.

Attribute Target

Field, property, method or indexer.

Example

using UnityEngine;
using Sisus.Attributes;

public class TestShowInInspector : MonoBehaviour
{
	[ShowInInspector]
	private bool nonSerializedFieldSupport = true;

	[ShowInInspector]
	public bool PropertySupport
	{
		get
		{
			return true;
		}

		set
		{
			Debug.Log((value ? "Correct." : "Incorrect.") + " Properties are supported.");
		}
	}

	[ShowInInspector]
	public bool GetOnlyPropertySupport { get; } = true;

	[ShowInInspector]
	public bool SetOnlyPropertySupport
	{
		set
		{
			Debug.Log((value ? "Correct." : "Incorrect.") + " Set Only Properties are supported.");
		}
	}

	[ShowInInspector]
	private bool Method()
	{
		return true;
	}

	[ShowInInspector]
	private static bool ExposedStaticMethod()
	{
		return true;
	}

	[ShowInInspector]
	private static bool ExposedMethodWithParameters(bool isSupported = true)
	{
		Debug.Log((isSupported ? "Correct." : "Incorrect.") + " Methods with parameters are supported.");
		return true;
	}
}

Example Result

 

See Also: Button