09. Modifying Existing Drawers

  09. Extending Power Inspector No Comments

If you want to modify an existing drawer that ships with Power Inspector, it is not recommended to do this by directly editing the class file. This could result in conflicts if future updates to Power Inspector should change the same file.

Instead you should create your own class that extends the drawer you want to modify, and implement your modifications by way of overriding methods and properties.

To get Power Inspector to start using your drawer instead of the original one, you’ll also need to copy the DrawerFor* attribute from the base class declaration, except omitting the last “setIsFallback” parameter.

Example

using UnityEngine;
using Sisus;
using Sisus.Attributes;

[DrawerForComponent(typeof(Transform), false)]
public class ExtendedTransformDrawer : TransformDrawer
{
		/// <inheritdoc/>
		protected override void BuildContextMenu(ref Menu menu, bool extendedMenu)
		{
			base.BuildContextMenu(ref menu, extendedMenu);
			menu.AddSeparatorIfNotRedundant();
			menu.Add("Print Name To Console", ()=>Debug.Log(Name));
		}
}