using LitJson;
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using WS;

public class ShowViewOperateEditor : IOperateEditor
{
    public string Name => "引导UI";

    public Type Component => typeof(ShowViewOperateComponent);

    ShowViewOperateData Data;
    ///<summary>UI类型索引</summary>
    private int UITypeIndex;
    ///<summary>显示的图片</summary>
    private Texture2D texture;

    public void Dispose()
    {

    }

    public void Init(string json)
    {
        Data = string.IsNullOrEmpty(json) ? new ShowViewOperateData() : JsonMapper.ToObject<ShowViewOperateData>(json);
        if (!string.IsNullOrEmpty(Data.imageName))
        {
            texture = Resources.Load<Texture2D>("Texture/" + Data.imageName);
        }
    }

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

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("显示图片", GUILayout.Width(55));
        texture = EditorGUILayout.ObjectField(texture, typeof(Texture2D), false) as Texture2D;
        GUILayout.Label("音频名称", GUILayout.Width(55));
        Data.audioName = EditorGUILayout.TextField(Data.audioName);
        GUILayout.Label("流程结束：", GUILayout.Width(60));
        Data.isEnd = EditorGUILayout.Toggle(Data.isEnd);
        EditorGUILayout.EndHorizontal();
    }

    public string ToData()
    {
        Data.imageName =  texture.name ;
        return JsonMapper.ToJson(Data);
    }
}
