using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class ShowMsgOperateEditor : IOperateEditor
{
    public string Name => "显示弹窗";

    public Type Component => typeof(ShowMsgComponent);

    private GameObject showPoint;
    ShowMsgData Data;
    public void Dispose()
    {
        
    }

    public void Init(string json)
    {
        Data = string.IsNullOrEmpty(json)?new ShowMsgData():JsonMapper.ToObject<ShowMsgData>(json);
        if (!string.IsNullOrEmpty(Data.showPointName))
        {
            showPoint = GameObject.Find(Data.showPointName);
            if (showPoint == null)
            {
                Debug.Log($"在场景中未找到 {Data.showPointName} 物体,请检查!");
                return;
            }
        }
    }

    public void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        Data.pos = EditorGUILayout.Vector3Field("UI位置", Data.pos);
        Data.rot = EditorGUILayout.Vector3Field("UI旋转", Data.rot);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("显示位置点:", GUILayout.Width(95));
        showPoint = (GameObject)EditorGUILayout.ObjectField(showPoint, typeof(GameObject), true);
        if (showPoint != null)
        {
            Data.pos = showPoint.transform.position;
            Data.rot = showPoint.transform.localRotation.eulerAngles;
        }
        Data.time = EditorGUILayout.FloatField("弹窗时间:", Data.time);
        //Data.AudioName = EditorGUILayout.TextField("音频", Data.AudioName);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.LabelField("弹窗信息",GUILayout.Width(55));
        Data.msg = EditorGUILayout.TextField(Data.msg);

    }

    public string ToData()
    {
        Data.showPointName = showPoint != null ? EditorHelper.GetTransformParentPath(showPoint.transform) : "";
        return JsonMapper.ToJson(Data);
    }
}
