I am writing a script to display a book with text in game. I wanted a text area to display in the editor so I would have an easier time editing the text in the books. I created a custom editor script to do so, and placed it in Assets/Editor. If I create a script called testscript.js with text1 and text2 properties, and add the line @CustomEditor(testscript), the custom editor works great, and I see the text areas in the editor as expected.
However, what I am doing is a little bit different. My actual book.js script has an array of "BookPageContent" objects in it. BookPageContent is a class that I defined within Book.js that contains two strings, text1 and text2.
What I thought I could do was add the line @CustomEditor(BookPageContent) into the custom editor code to make the text area show up for each one of these strings within the array inside book.js, but it doesn't seem to work. Instead, the strings just show up in their normal single-line editor. Does anyone know how to correct this?
here is my code for my custom editor called TextAreaEditor.js:
#pragma strict
@CustomEditor(BookPageContent)
@CanEditMultipleObjects
class TextAreaEditor extends Editor {
var text1Prop : SerializedProperty;
var text2Prop : SerializedProperty;
function OnEnable () {
// Setup the SerializedProperties
text1Prop = serializedObject.FindProperty ("text1");
text2Prop = serializedObject.FindProperty ("text2");
}
function OnInspectorGUI() {
// Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
serializedObject.Update ();
text1Prop.stringValue = EditorGUILayout.TextArea(text1Prop.stringValue, GUILayout.MaxHeight(75));
text2Prop.stringValue = EditorGUILayout.TextArea(text2Prop.stringValue, GUILayout.MaxHeight(75));
serializedObject.ApplyModifiedProperties();
}
}
And my Book.js file contains:
class BookPageContent {
var text1 : String;
var text2 : String;
}
var pages : BookPageContent[];
↧