using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace FVS
{
    /// <summary>
    /// 一个简单的可直接使用的点击事件脚本
    /// 可以指定事件名与需要传递的数据, 当点击物体时, 会把事件和数据传递给外层.
    /// </summary>
    public class FVSClickable: MonoBehaviour
    {
        // 当前点击物体的唯一标识
        public static string currentClickedName;

        // 点击物体是否响应相机缩放事件
        public static bool zoomObserverEnabled = false;

        /// <summary>
        /// 点击事件对应的事件名
        /// </summary>
        public string eventName;

        /// <summary>
        /// 点击时需要传递的数据, 格式为序列化后的JSON字符串, 如 '{ "name": "xxx" }'
        /// </summary>
        public string eventData;

        private void OnMouseUpAsButton()
        {
            zoomObserverEnabled = true;
            currentClickedName = eventName + eventData;
            Debug.Log("clicked");
            FVSUnityReact.Instance.SendUnityEvent(eventName, eventData);
        }

        private void OnMouseOver()
        {
            Debug.Log("mouseover");
            FVSUnityReact.Instance.FireMouseOver();
        }

        private void OnMouseExit()
        {
            Debug.Log("mouseexit");
            FVSUnityReact.Instance.FireMouseExit();
        }

        public bool IsSelected()
        {
            return currentClickedName != null && currentClickedName == eventName + eventData;
        }
    }
}
