Page 1 of 1

Serializable about inheriting StandardUISubtitlePanel

Posted: Mon Sep 13, 2021 7:50 am
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.

Re: Serializable about inheriting StandardUISubtitlePanel

Posted: Mon Sep 13, 2021 8:12 am
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();
    }
}