Posted January 21, 2024 by wiggums
[CustomPropertyDrawer(typeof(DocumentTextData))] public class DocumentTextDataDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //draw custom field! } }
The DocumentTextData is the class that holds the lists of words and enums, and is a serialized field in my DocumentTextElement monobehavior. Now inside OnGUI() we get the lists, and pass it to this method that draws the important bits:
The CleanseRuleId is the flag for the censorship rule, which has a None field by default. the if(changed) check is the logic that triggers when I click on the button in the inspector. Using a static value set elsewhere, I can easily change the rule that I assign.
So now with this all set up I now see a new view in my DocumentTextElement component:
14 is just the number of words, which might not be terribly useful to display, but its there. Then you can see the words from our document in ordered buttons and all greyed out. That is the color I set for CleanseRuleID.None. I can change my current rule to assign in another component, and now when I click on the words it will change their rule enum value.
It works! Some quick debug logging shows that the flags are indeed being set correctly.
I can probably format the buttons a bit better, as you can see some words don't quite fit, but this works well enough for now. I have each rule color coded so that I can easily distinguish between them. So that should handle all the text components in my documents. The only other case will be images, which will be much simpler as I will be using individual components for each image, meaning it will be a simple enum dropdown box to select which censorship rule applies if any to the given image. No custom property drawers necessary!
My next post will be about how I handle the censoring interaction on documents, where I will dive a bit into the handy features of TextMeshPro.