Serializable about inheriting StandardUISubtitlePanel

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Triphail
Posts: 5
Joined: Sat Sep 11, 2021 12:43 pm

Serializable about inheriting StandardUISubtitlePanel

Post by Triphail »

Hi, thank you for your previous reply, it is helpful.
And now I want to inherit StandardUISubtitlePanel to override some function, but I find the pulic field can't be showed in the inspector. I think it's the serializable problem. If the script is not loaded in the gameobject on the scenes, I can find the field by inspector, but when it is loaded in the gameobject the field is hidden. Can you give me some suggests.
Attachments
3.png
3.png (64.66 KiB) Viewed 147 times
2.png
2.png (71.2 KiB) Viewed 147 times
1.png
1.png (11.45 KiB) Viewed 147 times
User avatar
Tony Li
Posts: 21986
Joined: Thu Jul 18, 2013 1:27 pm

Re: Serializable about inheriting StandardUISubtitlePanel

Post by Tony Li »

Hi,

StandardUISubtitlePanel has a custom editor script, so you'll need to create a custom editor script for your subclass. For example, if your subclass looks like this:

Code: Select all

public class MySubtitlePanel : StandardUISubtitlePanel
{
    public bool MyBool;
}
Then, in a folder named Editor, create an editor script:

Code: Select all

using UnityEngine;
using UnityEditor; //<-- Include this line in editor scripts.
using PixelCrushers.DialogueSystem;

[CustomEditor(typeof(MySubtitlePanel), true]
public class MySubtitlePanelEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI(); // Draw the regular StandardUISubtitlePanel fields.
        
        // Draw fields that were added in MySubtitlePanel:
        serializedObject.Update();
        EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(MySubtitlePanel.MyBool)));
        serializedObject.ApplyModifiedProperties();
    }
}
Post Reply