using HighlightingSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
//============================================================
//支持中文,文件使用UTF-8编码
//@author	#AUTHOR#
//@create	#CREATEDATE#
//@company	#COMPANY#
//
//@description:
//============================================================

public enum Attribute
{
    /// <summary>
    /// 默认
    /// </summary>
    defaultModel,
    /// <summary>
    /// 安全工器具
    /// </summary>
    SafetyToolsAndInstruments,
    /// <summary>
    /// 工器具
    /// </summary>
    ToolsAndInstruments
}

public enum RightAndWrong
{
    /// <summary>
    /// 默认
    /// </summary>
    defaultModel,
    /// <summary>
    /// 对
    /// </summary>
    right,
    /// <summary>
    /// 错
    /// </summary>
    wrong
}

public class ToolModelClick : MonoBehaviour
{
    public Attribute attribute = Attribute.defaultModel;
    public RightAndWrong rightAndWrong = RightAndWrong.defaultModel;

    public UnityEvent onEnter = new UnityEvent();
    public UnityEvent onDown = new UnityEvent();
    public UnityEvent onDrag = new UnityEvent();
    public UnityEvent onExit = new UnityEvent();

    public GameObject line;
    public GameObject Higth;

    public Highlighter selfHighlighter;


    private void Awake()
    {
        if (line != null)
            line.SetActive(false);
        if (Higth != null)
        {
            Higth.SetActive(false);

        }
        selfHighlighter = GetComponent<Highlighter>();
        selfHighlighter.ConstantOff();
    }

    private void OnMouseEnter()
    {
        if (EventSystem.current.IsPointerOverGameObject())
            return;
        onEnter?.Invoke();
        var current = SceneManager.GetActiveScene();
        if (current.name == "工具间场景")
            UIManager.Instance.SetThreeDTip(gameObject.name);
    }

    private void OnMouseDown()
    {
        if (EventSystem.current.IsPointerOverGameObject())
            return;
        var current = SceneManager.GetActiveScene();
        if (current.name != "工具间场景") return;
        onDown?.Invoke();
        Vector3 pos = transform.localPosition;
        Vector3 rot = transform.localEulerAngles;
        ToolsItemManager.Instance.CreatToolItem(gameObject,pos,rot);
        UIManager.Instance.SetThreeDTip("");
        Destroy(gameObject);
    }


    private void OnMouseDrag()
    {
        if (EventSystem.current.IsPointerOverGameObject())
            return;
        onDrag?.Invoke();
    }

    private void OnMouseExit()
    {
        if (EventSystem.current.IsPointerOverGameObject())
            return;
        var current = SceneManager.GetActiveScene();
        if (current.name != "工具间场景") return;
        onExit?.Invoke();
        UIManager.Instance.SetThreeDTip("");
    }
}