I looked up the creation of custom widget classes on the net and stumbled on the following thread:
http://www.tasharen.com/forum/index.php?topic=3640.0You can create a custom widget if you want -- just derive from UISprite or UIWidget, and override the OnFill function.
I have just tried to do precisely that, and unfortunately encountered the following error:
Assets/SupportScripts/UI/UISpriteInverse.cs(42,30): error CS0115: `UISpriteInverse.OnFill(UIWidget, int, BetterList<UnityEngine.Vector3>, BetterList<UnityEngine.Vector2>, BetterList<UnityEngine.Color32>)' is marked as an override but no suitable method found to override
As far as I understand, the issue pops up because UISprite overrides the OnFill itself, instead of having it as a virtual method. I admit I'm not very familiar with how override methods in C# are supposed to work when the method of a parent class is actually an override of another method of yet another parent class (UIWidget, in this case) instead of a virtual method, but I guess that's the cause of the error. After all, you can't make a method both virtual and override, which makes it not possible to override the OnFill.
Is that a relatively recent change in NGUI that was made after the answer I have quoted above? Or maybe I misunderstand the quote and should declare the OnFill method in my inheriting class as "new" instead of "override"?_____________________________________________
Edit: Scratch that, looks like I have overlooked the arguments in my override method and left an UIWidget reference among them, which was not there in actual OnFill method in UISprite and was only used by the delegate method. Intellisense won't highlight that, but that breaks the override. Fixed the arguments to match the UISprite OnFill and errors disappeared - looks like override chains are allowed in C# after all.
Now, another question is - how can I add a new property drawer to the UISpriteInverse inspector in a similar way you handle Widget and Anchor drawers? I have looked at the custom editor code you use and I'm not sure I'm familiar with the way you do it, me being only experienced with traditional one class/one custom inspector approach which your code doesn't look similar to (you don't even use OnInspectorGUI). Is there some straightforward way of doing it, similar to, let's say, DrawDefaultInspector, that will allow me to add new EditorGUILayout elements to the sprite inspector without breaking or hiding your complex editors?
Not sure if I worded it clearly, but in essense my question is: how can I add new custom inspector elements to the custom inspector of a class that inherits from a class that already has a custom inspector?
_____________________________________________
Edit 2: Solved the custom inspector problem by duplicating all contents of UISpriteInspector class into new custom editor and adding OnInspectorGUI into it like this:
public override void OnInspectorGUI ()
{
base.OnInspectorGUI ();
UISpriteInverse s = target as UISpriteInverse;
UISpriteInverse.OffsetStyle style = (UISpriteInverse.OffsetStyle)EditorGUILayout.EnumPopup ("Mode", s.style);
float offsetLeft = EditorGUILayout.Slider ("L", s.offsetLeft, 0f, 128f);
float offsetRight = EditorGUILayout.Slider ("R", s.offsetRight, 0f, 128f);
float offsetTop = EditorGUILayout.Slider ("T", s.offsetTop, 0f, 128f);
float offsetBottom = EditorGUILayout.Slider ("B", s.offsetBottom, 0f, 128f);
if (GUI.changed)
{
NGUIEditorTools.RegisterUndo ("Sliced sprite changed", s.gameObject);
s.style = style;
s.offsetLeft = offsetLeft;
s.offsetRight = offsetRight;
s.offsetTop = offsetTop;
s.offsetBottom = offsetBottom;
s.MarkAsChanged ();
NGUITools.SetDirty (target);
}
}
Not sure if it's the cleanest way and is sure doesn't look as fancy as the property drawers you have created for widget and anchor variables, but it works.

And now, here's the new sprite type in action.
