using AX.MessageSystem;
using UnityEngine;
using UnityEngine.AddressableAssets;

public class MainMenu : MonoSingleton<MainMenu>
{
    public MainMenuMode MenuMode;
    public BuildingType BuildType;
    public FloorViewMode ViewMode;
    //防火分区
    public static bool ShowFireCompartments;
    //防火门
    public static bool ShowFireDoors;
    //防火卷帘
    public static bool ShowFireShutters;
    //室内消火栓
    public static bool ShowIndoorHydrants;
    private void Awake()
    {
        GameManager.Instance.Initialize();
    }

    #region MainMenu
    public void OnHome()
    {
        UIManager.Instance.Show<MainButtonsPanel>();
        switch (MenuMode)
        {
            case MainMenuMode.人员定位:
                UIManager.Instance.Hide<PersonnelLocationPanel>();
                UIManager.Instance.Hide<PersonnelLocationMenuPanel>();
                break;
            case MainMenuMode.单位简介:
                UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
                UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.gameObject.SetActive(false);
                UIManager.Instance.Hide<IntroductionMenuPanel>();
                break;
            case MainMenuMode.消控室:
                MessageDispatcher.SendMessage("FIRECONTROL", false, "FireControlRoom");
                MessageDispatcher.SendMessage("FIRECONTROLCENTERCOLOR", false);
                EquipmentManager.Instance.CreationType = EquipmentType.None;
                UIManager.Instance.Hide<EquipmentRoomAttributePanel>();
                break;
            case MainMenuMode.防火设计:
                UIManager.Instance.Hide<FireDesignMenuPanel>();
                break;
            case MainMenuMode.防排烟系统:
                UIManager.Instance.Hide<SmokeSystemMenuPanel>();
                break;
            case MainMenuMode.供水系统:
                UIManager.Instance.Hide<WaterSystemMenuPanel>();
                break;
            case MainMenuMode.疏散系统:
                UIManager.Instance.Hide<EvacuationSystemMenuPanel>();
                AssetManager.Instance.ZhuTi.SetActive(true);
                AssetManager.Instance.ShiNei.SetActive(true);
                AssetManager.Instance.Transparent.SetActive(false);
                UIManager.Instance.Show<FloorButtonsPanel>();
                break;
            case MainMenuMode.体验漫游:
                AssetManager.Instance.MainCamera.SetActive(true);
                UIManager.Instance.Show<CompassPanel>();
                AssetManager.Instance.RoamingAssets.SetActive(false);

                //卸载全景图
                EquipmentManager.Instance.UnLoadAsset();
                UIManager.Instance.Hide<EquipmentAttributePanel>();
                SelectionManager.Instance.Sets.Clear();
                break;
            case MainMenuMode.周边水源:
                UIManager.Instance.Hide<WaterSourceMenuPanel>();
                switch (BuildType)
                {
                    case BuildingType.单体:
                        UIManager.Instance.Show<FloorButtonsPanel>();
                        break;
                    case BuildingType.群楼:

                        break;
                }
                AssetManager.Instance.MainCamera.SetActive(true);
                //AssetManager.Instance.WaterSourceAssets.SetActive(false);
                WaterSource.Instance.Hide();
                break;
            case MainMenuMode.行车路线:
                UIManager.Instance.Hide<RouteMapMenuPanel>();
                switch (BuildType)
                {
                    case BuildingType.单体:
                        UIManager.Instance.Show<FloorButtonsPanel>();
                        break;
                    case BuildingType.群楼:

                        break;
                }
                AssetManager.Instance.MainCamera.SetActive(true);
                DriveRoute.Instance.Hide();
                //AssetManager.Instance.RouteMapAssets.SetActive(false);
                break;
            case MainMenuMode.态势标绘:
                PowerManager.Instance.ClearAll();
                UIManager.Instance.Hide<SituationPlottingMenuPanel>();
                UIManager.Instance.Hide<PlottingTablesPanel>();
                PowerManager.Instance.Hide();
                break;
        }

        UIManager.Instance.Hide<SecondMenuPanel>();
    }

    /// <summary>
    /// 人员定位
    /// </summary>
    public void OnPersonnelLocation()
    {
        MenuMode = MainMenuMode.人员定位;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<PersonnelLocationPanel>();
        UIManager.Instance.Show<PersonnelLocationMenuPanel>();
    }
    //单位简介
    public void OnIntroduction()
    {
        MenuMode = MainMenuMode.单位简介;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.gameObject.SetActive(true);
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<IntroductionMenuPanel>();
    }
    //消控室
    public void OnFireControlRoom()
    {
        if (AssetManager.Instance.DeviceList.XiaoKongShi.Value)
        {
            OnInterialClose();
            OnResetCamera();
            MenuMode = MainMenuMode.消控室;
            UIManager.Instance.Hide<MainButtonsPanel>();
            UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
            EquipmentManager.Instance.CreationType = EquipmentType.FireControlRoom;
            MessageDispatcher.SendMessage("FIRECONTROL", true, "FireControlRoom");
            MessageDispatcher.SendMessage("FIRECONTROLCENTERCOLOR", true);
        }
        else
        {
            MessageBox.Show(AssetManager.Instance.DeviceList.XiaoKongShi.Describe, Color.white, 1f);
        }
        

    }
    //防火设计
    public void OnFireDesign()
    {
        MenuMode = MainMenuMode.防火设计;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<FireDesignMenuPanel>();
    }
    //防排烟系统
    public void OnSmokeControl()
    {
        MenuMode = MainMenuMode.防排烟系统;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<SmokeSystemMenuPanel>();
    }
    //供水系统
    public void OnWaterSystem()
    {
        MenuMode = MainMenuMode.供水系统;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<WaterSystemMenuPanel>();
    }
    //疏散系统
    public void OnEvacuationSystem()
    {
        MenuMode = MainMenuMode.疏散系统;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<EvacuationSystemMenuPanel>();
        AssetManager.Instance.ZhuTi.SetActive(false);
        AssetManager.Instance.ShiNei.SetActive(false);
        UIManager.Instance.Hide<FloorButtonsPanel>();
        if (AssetManager.Instance.Transparent)
            AssetManager.Instance.Transparent.SetActive(true);
        else
            AssetManager.Instance.GetTransparent();

    }
    //体验漫游
    public void OnRoaming()
    {
        MenuMode = MainMenuMode.体验漫游;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        AssetManager.Instance.MainCamera.SetActive(false);
        UIManager.Instance.Hide<CompassPanel>();
        if (AssetManager.Instance.RoamingAssets == null)
        {
            AssetManager.Instance.SetLoadingPanel(true);
            Addressables.InstantiateAsync("RoamingAssets").Completed += Loaded=> 
            {
                AssetManager.Instance.RoamingAssets = Loaded.Result;
                AssetManager.Instance.SetLoadingPanel(false);
            };
        }
        else
        {
            AssetManager.Instance.RoamingAssets.SetActive(true);
        }
        

        //加载全景图
        //EquipmentManager.Instance.CreationType = EquipmentType.ImageMarked;
        //EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllImageMarkers;
        //EquipmentManager.Instance.LoadData(EquipmentManager.Instance.Equipments.Find(go => go.name == "ImageMarked"), false);
    }
    //周边水源
    public void OnWaterSource()
    {
        MenuMode = MainMenuMode.周边水源;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<WaterSourceMenuPanel>();
        switch (BuildType)
        {
            case BuildingType.单体:
                UIManager.Instance.Hide<FloorButtonsPanel>();
                break;
            case BuildingType.群楼:
                
                break;
        }
       
        //AssetManager.Instance.WaterSourceAssets.SetActive(true);
        WaterSource.Instance.Show();
        UIManager.Instance.GetView<CompassPanel>().GetComponent<RectTransform>().localEulerAngles = new Vector3(0, 0, 180);
        AssetManager.Instance.MainCamera.SetActive(false);
    }
    //行车路线
    public void OnRouteMap()
    {
        MenuMode = MainMenuMode.行车路线;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<RouteMapMenuPanel>();
        switch (BuildType)
        {
            case BuildingType.单体:
                UIManager.Instance.Hide<FloorButtonsPanel>();
                break;
            case BuildingType.群楼:

                break;
        }
        AssetManager.Instance.MainCamera.SetActive(false);
        DriveRoute.Instance.Show();
        UIManager.Instance.GetView<CompassPanel>().GetComponent<RectTransform>().localEulerAngles = new Vector3(0, 0, 180);
    }
    //态势标绘
    public void OnSituationPlotting()
    {
        MenuMode = MainMenuMode.态势标绘;
        UIManager.Instance.Hide<MainButtonsPanel>();
        UIManager.Instance.Show<SecondMenuPanel>(OnSecondMenuLoaded);
        UIManager.Instance.Show<SituationPlottingMenuPanel>();
        UIManager.Instance.Show<PlottingTablesPanel>();
        PowerManager.Instance.Show();
    }

    private void OnSecondMenuLoaded()
    {
        UIManager.Instance.GetView<SecondMenuPanel>().MainText.text = MenuMode.ToString();
    }
    #endregion
    #region SubMenu
    //基本信息
    public void OnInformation(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.Show<BuildingInformationPanel>();
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
        }
        else
        {
            UIManager.Instance.Hide<BuildingInformationPanel>();
        }
    }
    //建筑特点
    public void OnBuildingFeature(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.Show<BuildingFeaturesPanel>();
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
        }
        else
        {
            UIManager.Instance.Hide<BuildingFeaturesPanel>();
        }
    }
    //高度
    public void OnHeight(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            OnInterialClose();
            string url = HttpManager.Instance.GetHeightLocation;
            HttpManager.Instance.Get<CameraLocationData>(url, data =>
            {
                Camera.main.transform.position = data.Position;
                Camera.main.transform.eulerAngles = data.Rotation;
                Camera.main.GetComponent<CameraOrbit>().distance = data.Distance;
                Camera.main.GetComponent<CameraOrbit>().x = data.Xy.x;
                Camera.main.GetComponent<CameraOrbit>().y = data.Xy.y;
                Camera.main.GetComponent<CameraOrbit>().target.position = data.Pivot;

            });
        }
        MessageDispatcher.SendMessage("HEIGHT", isOn);

    }
    //毗邻
    public void OnAdjacent(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            OnInterialClose();
            string url = HttpManager.Instance.GetAdjacentLocation;
            HttpManager.Instance.Get<CameraLocationData>(url, data =>
            {
                Camera.main.transform.position = data.Position;
                Camera.main.transform.eulerAngles = data.Rotation;
                Camera.main.GetComponent<CameraOrbit>().distance = data.Distance;
                Camera.main.GetComponent<CameraOrbit>().x = data.Xy.x;
                Camera.main.GetComponent<CameraOrbit>().y = data.Xy.y;
                Camera.main.GetComponent<CameraOrbit>().target.position = data.Pivot;
            });
            UIManager.Instance.Show<AdjacentInfoPanel>(AdjacentGetInfos);
        }
        else
        {
            UIManager.Instance.Hide<AdjacentInfoPanel>();
            UIManager.Instance.Hide<AdjacentImagePanel>();
        }

        MessageDispatcher.SendMessage("ADJACENT", isOn);
        MessageDispatcher.SendMessage("ADJACENTCONTROLLER", isOn);
    }
    private void AdjacentGetInfos()
    {
        var Parent = AssetManager.Instance.transform.Find("Adjacent");
        foreach(GameObject go in Parent.GetComponent<AdjacentListening>().Adjectnts)
        {
            go.GetComponent<AdjacentController>().GetInfos();
        }
    }
    //登高作业面
    public void OnFireClimbingSurface(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllFireClimbingSites;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllFireClimbingSites;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.FireClimbingSite;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("FireClimbingSurface", true);
        }
        else
        {
            if(EquipmentManager.Instance.CreationType== EquipmentType.FireClimbingSite)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<EquipmentAttributePanel>();
            SelectionManager.Instance.ClearSelection();

        }
    }
    //危险源
    public void OnHazardSource(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllHazardSources;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllHazardSources;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.HazardSource;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("HazardSource", true);
        }
        else
        {
            EquipmentManager.Instance.UnLoadAsset();
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<EquipmentAttributePanel>();
            SelectionManager.Instance.ClearSelection();

        }
    }
    //禁停区
    public void OnNoParking(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllNoParkingAreas;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllNoParkingAreas;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.NoParking;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("NoParking", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.NoParking)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<EquipmentAttributePanel>();
            SelectionManager.Instance.ClearSelection();

        }
    }
    //重点提示
    public void OnKeyPoint(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllImportantLocations;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllImportantLocations;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.KeyArea;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("KeyArea", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.KeyArea)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<EquipmentAttributePanel>();
            SelectionManager.Instance.ClearSelection();

        }
    }
    //图片标注
    public void OnImageMarked(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllImageMarkers;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllImageMarkers;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.ImageMarked;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("ImageMarked", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.ImageMarked)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<EquipmentAttributePanel>();
            SelectionManager.Instance.ClearSelection();

        }
    }
    //逃生窗
    public void OnEscapeWindow(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllEscapeWins;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllEscapeWins;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.EscapeWin;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("EscapeWindow", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.EscapeWin)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<EquipmentAttributePanel>();
            SelectionManager.Instance.ClearSelection();

        }
    }
    //破拆点
    public void OnBreakPoint(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllBreakPoints;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllBreakPoints;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.BreakPoint;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("BreakPoint", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.BreakPoint)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<EquipmentAttributePanel>();
            SelectionManager.Instance.ClearSelection();

        }
    }
    //微型消防站
    public void OnFireStation(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.GetView<ToolBarPanel>().PlaneToggle.isOn = false;
            UIManager.Instance.Show<FireStationPanel>();
        }
        else
        {
            UIManager.Instance.Hide<FireStationPanel>();
        }
    }
    //避难层
    public void OnRefugeFloor(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.BiNanCeng.Value)
        {
            MessageDispatcher.SendMessage("REFUGEFLOOR", isOn);
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.BiNanCeng.Describe, Color.white, 1f);
        }
    }
    //防火分区
    public void OnFireCompartment(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.FangHuoFenQu.Value)
        {
            ShowFireCompartments = isOn;
            MessageDispatcher.SendMessage("FIRECOMPANTMENT", isOn);
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.FangHuoFenQu.Describe, Color.white, 1f);
        }
    }
    //防火门
    public void OnFireDoor(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.FangHuoMen.Value)
        {
            ShowFireDoors = isOn;
            MessageDispatcher.SendMessage("FIREDOOR", isOn);
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.FangHuoMen.Describe, Color.white, 1f);
        }
    }
    //防火卷帘
    public void OnFireShutters(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.FangHuoJuanLian.Value)
        {
            ShowFireShutters = isOn;
            MessageDispatcher.SendMessage("FIRESHUTTER", isOn);
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.FangHuoJuanLian.Describe, Color.white, 1f);
        }
    }
    //送风机
    public void OnForcedDraftFan(bool isOn)
    {
        if (isOn)
        {
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllForcedDraftFans;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllForcedDraftFans;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.ForcedDraftFan;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("ForcedDraftFan", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.ForcedDraftFan)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<SmokeFanPanel>();

        }
    }
    //送风口
    public void OnAirVent(bool isOn)
    {
        if (isOn)
        {
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllAirVents;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllAirVents;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.AirVent;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("AirVent", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.AirVent)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
        }
    }
    //排烟风机
    public void OnSmokeExtractionFan(bool isOn)
    {
        if (isOn)
        {
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllSmokeExtractionFans;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllSmokeExtractionFans;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.SmokeExtractionFan;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("SmokeExtractionFan", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.SmokeExtractionFan)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();
            UIManager.Instance.Hide<SmokeFanPanel>();
        }
    }
    //排烟口
    public void OnSmokeVent(bool isOn)
    {
        if (isOn)
        {
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllSmokeVents;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllSmokeVents;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.SmokeVent;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<CreationPanel>();
            EquipmentManager.Instance.LoadData("SmokeVent", true);
        }
        else
        {
            if (EquipmentManager.Instance.CreationType == EquipmentType.SmokeVent)
            {
                EquipmentManager.Instance.UnLoadAsset();
            }
            UIManager.Instance.Hide<CreationPanel>();

        }
    }
    //泵房水箱
    public void OnPumpRoom(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.BengFang.Value)
        {
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
                EquipmentManager.Instance.CreationType = EquipmentType.PumpRoomAndWaterTank;
            }
            else
            {
                EquipmentManager.Instance.CreationType = EquipmentType.None;
                UIManager.Instance.Hide<EquipmentRoomAttributePanel>();
            }
           
            MessageDispatcher.SendMessage("PUMPROOM", isOn, "PumpRoomAndWaterTank");
            MessageDispatcher.SendMessage("BENGFANGSHUIXIANG", isOn);
            MessageDispatcher.SendMessage("SETS", isOn,EquipmentType.Pump.ToString());
        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.BengFang.Describe, Color.white, 1f);
        }
    }
    //室内消火栓
    public void OnIndoorHydrant(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.ShiNeiXiaoHuoShuan.Value)
        {
            ShowIndoorHydrants = isOn;
            MessageDispatcher.SendMessage("INTERIALHYDRANT", isOn);
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.ShiNeiXiaoHuoShuan.Describe, Color.white, 1f);
        }
    }
    //室外消火栓
    public void OnOutdoorHydrant(bool isOn)
    {
        if (isOn)
        {
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllOutdoorFireHydrants;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllOutdoorFireHydrants;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.OutdoorHydrant;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<HydrantCreationPanel>();
        }
        else
        {
            UIManager.Instance.Hide<HydrantCreationPanel>();
            UIManager.Instance.Hide<OutdoorHydranrAttributePanel>();
            SelectionManager.Instance.ClearSelection();
        }
        MessageDispatcher.SendMessage("ICON", isOn, EquipmentManager.Instance.CreationType.ToString());
        MessageDispatcher.SendMessage("SETS", isOn, EquipmentManager.Instance.CreationType.ToString());
        MessageDispatcher.SendMessage("DRAG", isOn, EquipmentManager.Instance.CreationType.ToString());
    }
    //水泵接合器
    public void OnSiameseConnection(bool isOn)
    {
        if (isOn)
        {
            EquipmentManager.Instance.GetAllUrl = HttpManager.Instance.GetAllSiameseConnections;
            EquipmentManager.Instance.PostAllUrl = HttpManager.Instance.PostAllSiameseConnections;
            OnInterialClose();
            OnResetCamera();
            EquipmentManager.Instance.CreationType = EquipmentType.SiameseConnection;
            SelectionManager.Instance.Sets.Clear();
            UIManager.Instance.Show<SiameseConnectionCreationPanel>();
        }
        else
        {
            UIManager.Instance.Hide<SiameseConnectionCreationPanel>();
            UIManager.Instance.Hide<OutdoorHydranrAttributePanel>();
            SelectionManager.Instance.ClearSelection();
        }
        MessageDispatcher.SendMessage("ICON", isOn, EquipmentManager.Instance.CreationType.ToString());
        MessageDispatcher.SendMessage("SETS", isOn, EquipmentManager.Instance.CreationType.ToString());
        MessageDispatcher.SendMessage("DRAG", isOn, EquipmentManager.Instance.CreationType.ToString());
    }
    //供水关系图
    public void OnDiagram(bool isOn)
    {
        if (isOn)
        {
            UIManager.Instance.Show<WaterDiagramPanel>();
        }
        else
        {
            UIManager.Instance.Hide<WaterDiagramPanel>();
        }
    }

    //安全出口
    public void OnFireEscape(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.AnQuanChuKou.Value)
        {
            MessageDispatcher.SendMessage("ICON", isOn, EquipmentType.FireEscape.ToString());
            MessageDispatcher.SendMessage("SETS", isOn, EquipmentType.FireEscape.ToString());
            MessageDispatcher.SendMessage("LUMOS", isOn, EquipmentType.FireEscape.ToString());
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
            else
            {
                SelectionManager.Instance.ClearSelection();
                UIManager.Instance.Hide<FireEscapeAttributePanel>();
            }

        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.AnQuanChuKou.Describe, Color.white, 1f);
        }
    }
    //疏散楼梯
    public void OnEscapeStiar(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.ShuSanLouTi.Value)
        {

            MessageDispatcher.SendMessage("SETS", isOn, EquipmentType.EscapeStair.ToString());
            MessageDispatcher.SendMessage("LUMOS", isOn, EquipmentType.EscapeStair.ToString());
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
            else
            {
                SelectionManager.Instance.ClearSelection();
                UIManager.Instance.Hide<EscapeStairAttributePanel>();
            }

        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.ShuSanLouTi.Describe, Color.white, 1f);
        }
    }
    //消防电梯
    public void OnFireElevator(bool isOn)
    {
        if (AssetManager.Instance.DeviceList.XiaoFangDianTi.Value)
        {

            MessageDispatcher.SendMessage("SETS", isOn, EquipmentType.FireElevator.ToString());
            MessageDispatcher.SendMessage("LUMOS", isOn, EquipmentType.FireElevator.ToString());
            if (isOn)
            {
                OnInterialClose();
                OnResetCamera();
            }
            else
            {
                SelectionManager.Instance.ClearSelection();
                UIManager.Instance.Hide<FireElevatorAttributePanel>();
            }

        }
        else
        {
            if (isOn)
                MessageBox.Show(AssetManager.Instance.DeviceList.XiaoFangDianTi.Describe, Color.white, 1f);
        }
    }
    #endregion

    public void OnInterialClose()
    {
        MessageDispatcher.SendMessage("INTERIALCOLSED");
    }
    public void OnResetCamera()
    {
        AssetManager.Instance.MainCamera.GetComponent<CameraOrbit>().ResetCamera();
    }
    public Vector2 GetMousePosition(GameObject go)
    {
        var canvas = UIManager.GetCanvas().GetComponent<Canvas>(); 
        RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, canvas.worldCamera, out Vector2 pos);
        float texWidth = go.GetComponent<RectTransform>().sizeDelta.x;
        float texHeight = go.GetComponent<RectTransform>().sizeDelta.y;
        if (Screen.width - pos.x < Screen.width)
        {
            pos.x -= texWidth;
        }
        if (Screen.height - pos.y > Screen.height)
        {
            pos.y += texHeight;
        }
        return pos;
    }
}