dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.58k stars 465 forks source link

Timeline Inspector Button #385

Open fawad0dev opened 7 months ago

fawad0dev commented 7 months ago

here is my Code for Time timeline Track

using NaughtyAttributes;
using UnityEngine;
using UnityEngine.Playables;

[System.Serializable]
public class CustomDialogBehaviour : PlayableBehaviour
{
    [ResizableTextArea] public string dialogText; // working fine
    [Button("ToUpper")] // not even displaying Btn
    public void ToUpper()
    {
        dialogText = dialogText.ToUpper();
    }
    public Color textColor;
    public Color cloudColor;
#if UNITY_EDITOR
    [UnityEditor.CustomEditor(typeof(CustomDialogBehaviour)), UnityEditor.CanEditMultipleObjects]
    public class CustomDialogBehaviourEditor : UnityEditor.Editor
    {
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("ToUpperCase")) //this also not displaying btn
            {
                var customDialogBehaviour = serializedObject.FindProperty("dialogText");
                customDialogBehaviour.stringValue = customDialogBehaviour.stringValue.ToUpper();
                serializedObject.ApplyModifiedProperties();
            }
            DrawDefaultInspector();
        }
    }
#endif
}
fawad0dev commented 7 months ago
using NaughtyAttributes;
using Timeline.Samples;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
public class CustomDialogPlayableAsset : PlayableAsset, ITimelineClipAsset
{
    [NoFoldOut]
    [NotKeyable]
    public CustomDialogBehaviour template = new()
    {
        cloudColor = Color.white,
        textColor = Color.white,
        dialogText = ""
    };
    [Button("ToUpper")] // this also not displaying any btn
    void ToUpper()
    {
        UnityEditor.Undo.RecordObject(this, "ToUpperCase");
        template.dialogText = template.dialogText.ToUpper();
        UnityEditor.EditorUtility.SetDirty(this);
    }
    public ClipCaps clipCaps
    {
        get { return ClipCaps.Blending; }
    }
    public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    {
        return ScriptPlayable<CustomDialogBehaviour>.Create(graph, template);
    }
}
#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(CustomDialogPlayableAsset)), UnityEditor.CanEditMultipleObjects]
public class CustomDialogPlayableAssetEditor : UnityEditor.Editor
{
    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("ToUpperCase")) // this is displaying Btn
        {
            var customDialogBehaviour = target as CustomDialogPlayableAsset;
            customDialogBehaviour.template.dialogText = customDialogBehaviour.template.dialogText.ToUpper();
            serializedObject.ApplyModifiedProperties();
        }
        DrawDefaultInspector();
    }
}
#endif