using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using HighlightPlus;
///
/// 所有的方法脚本
///
public class Manager : MonoBehaviour
{
public static Manager Instance;
public List ShowPanel; //展示的界面
public List Allqy; //所有企业的toggle
public LookAtCameraName MyLookAtCameraNamel;
#region 驾驶舱
[Header("驾驶舱")]
public List UpAllToggle; //下方toggle
public GameObject EnterpriseInformation_image; //企业信息图片
public TextMeshProUGUI EnterpriseInformationName_text; //企业信息名称
public Button QYCloseButton; //关闭按钮
public Image targetImage; // 企业信息替换图片
public bool isClick; //第一次展示第二次隐藏
public Button PipelineBtn; //点击展示管道按钮
public List Pipeline; //展示管道
public Button ExamBtn; //考试按钮
private string websiteUrl; //文本
[Header("要读取的文件名(放在 StreamingAssets 文件夹内)")]
public string fileName; // 可以在 Inspector 里改,比如 "site1.txt"
public Tween Tween;
#endregion
#region 企业信息管理
[Header("企业信息管理")]
public List secendToggle; //二级菜单
public GameObject middleTable_Image; //表2-2全厂项目工程类别及产品方案
public Image tableImage; //中间的表图片
public TextMeshProUGUI middleTable_Text; //
public Button ForDetailsBtn; // 企业信息管理企业产品产能的详情按钮
public bool isForDetails; //判断是否点击了详情按钮
public Sprite[] ToggleSprites;//下拉
public List toggleObj;
public bool isxiala;
#endregion
#region 环保手续情况
[Header("环保手续情况")]
public List WRZLSSYXGLToggle; //污染治理设施运行管理信息
public GameObject HBSXXXTogObj; //环保手续信息子物体Toggle
public Transform HBSXXXParent; //环保手续信息生成的父物体
#endregion
#region 环保治理现状
[Header("环保治理现状")]
public List bookPages = new List(); //台账翻页
public int currentPage = 1; //当前页数
public GameObject LedgerObj; //台账界面
public Button LedgerCloseBtn; //台账关闭按钮
public Image LedgerImage; //台账image
public Button[] NextOrPrevBtn; //上一页下一页按钮
public List HBGLTZToggle; //环保管理台账
#endregion
#region 园区在线检测
[Header("园区在线检测")]
public List YQSPJKBtn; //园区视频监控按钮
public List PFJKSPBtn; //排放监视频
public GameObject GSYQSPJKObj; //公司园区视频监控
public RawImage GSYQSPJKRawImg;
public TextMeshProUGUI GSYQSPJKTopText; //公司园区视频监控顶部文字
public TextMeshProUGUI PFXZTopTitleText; //(企业/园区)现状标题
public TextMeshProUGUI PFXZGSBTText; //(企业/园区)现状标题
private List allToggles = new List();
#endregion
#region 污染排放管理
[Header("污染排放管理")]
public Button[] FSFQBtn; //右侧废水废气按钮
public GameObject[] FQObj; //高亮废气
public GameObject FQ3DCanvas; //废气canvas
public GameObject FSObj; //高亮废水
#endregion
private void Awake()
{
Instance = this;
Init();
}
private void OnEnable()
{
currentPage = 1;
UpDatePageDisplay();
}
///
/// 初始化
///
public void Init()
{
for (int i = 0; i < ShowPanel.Count; i++)
{
ShowPanel[i].SetActive(false);
ShowPanel[i].SetActive(i==0);
}
}
private void Start()
{
UpDatePageDisplay();
LoadWebsiteUrl(fileName);
NextOrPrevBtn[0].onClick.AddListener(PrevPage);
NextOrPrevBtn[1].onClick.AddListener(NextPage);
}
///
/// 物体高亮(闪来闪去)
///
public void ObjOfHiglight(HighlightEffect HighlightObj)
{
Tween = DOVirtual.Float(1, 0f, 1f, t =>
{
HighlightObj.innerGlow = t;
HighlightObj.outline = t;
}).SetLoops(-1, LoopType.Yoyo);
HighlightObj?.SetHighlighted(true);
}
///
/// 弹框
///
/// 所要展示的页面
/// 中间的画面
/// 上方的标题文字
/// 中间图片的路径
public void LoadImageFromResources(GameObject ShowImage,Image targetImages,TextMeshProUGUI text,
Button closeBtn, List allToggles,string path)
{
ShowImage.SetActive(true);
Sprite sprite = Resources.Load(path);
Debug.Log(sprite.name);
text.text = sprite.name;
if (sprite != null)
{
targetImages.sprite = sprite;
Debug.Log("Sprite 加载成功!");
}
else
{
Debug.LogError("Sprite 加载失败,请检查路径和文件名");
}
foreach (Toggle toggle in allToggles)
{
closeBtn.onClick.AddListener(() =>
{
toggle.isOn = false;
ShowImage.SetActive(toggle.isOn);
});
}
}
///
/// 监控弹框
///
/// 所要展示的页面
/// 中间的画面
/// 上方的标题文字
/// 中间图片的路径
public void LoadRawImageFromResources(GameObject ShowImage,RawImage targetImages,TextMeshProUGUI text,string path)
{
ShowImage.SetActive(true);
Sprite sprite = Resources.Load(path);
text.text = sprite.name;
if (sprite != null)
{
targetImages.texture = sprite.texture;
Debug.Log("Sprite 加载成功!");
}
else
{
Debug.LogError("Sprite 加载失败,请检查路径和文件名");
}
}
# region 台账界面
///
/// 加载台账界面
///
///
///
///
public void LoadLedgerFromResources(GameObject ShowImage ,Image LedgerImage ,Button CloesBtn,string path)
{
ShowImage.SetActive(true);
Sprite[] loadedSprites = Resources.LoadAll(path);
if (loadedSprites == null || loadedSprites.Length == 0)
{
Debug.LogError($"路径 {path} 中未找到任何Sprite文件夹中没图片!");
ShowImage.SetActive(false);
return;
}
// 将加载的Sprite直接存入bookPages列表
bookPages = new List(loadedSprites);
Debug.Log($"成功将 {bookPages.Count} 个Sprite存入bookPages列表");
UpDatePageDisplay();
// 使用第一个Sprite(从bookPages中获取)
if (bookPages.Count > 0 && bookPages[0] != null)
{
LedgerImage.sprite = bookPages[0];
Debug.Log("从bookPages中获取Sprite成功!");
}
CloesBtn.onClick.RemoveAllListeners();
CloesBtn.onClick.AddListener(() =>
{
bookPages?.Clear();
ShowImage.SetActive(false);
Debug.Log("台账面板已关闭,bookPages 列表已清空");
});
}
///
/// 上一页
///
public void PrevPage()
{
Debug.Log("上一页");
if (currentPage > 1)
{
currentPage--;
UpDatePageDisplay();
// if (currentPage == 1)
// {
// NextOrPrevBtn[0].gameObject.SetActive(false);
// NextOrPrevBtn[1].gameObject.SetActive(true);
// }
}
}
///
/// 下一页
///
public void NextPage()
{
Debug.Log("下一页");
if (currentPage < bookPages.Count)
{
currentPage++;
UpDatePageDisplay();
// if (currentPage == bookPages.Count)
// {
// NextOrPrevBtn[0].gameObject.SetActive(true);
// NextOrPrevBtn[1].gameObject.SetActive(false);
// }
}
}
///
/// 更新页数
///
public void UpDatePageDisplay()
{
Debug.Log(bookPages.Count);
if (currentPage >= 1 && currentPage <= bookPages.Count)
{
LedgerImage.sprite = bookPages[currentPage - 1];
LedgerImage.gameObject.SetActive(true);
Debug.Log($"显示第 {currentPage} 页,共 {bookPages.Count} 页");
}
else
{
Debug.Log("当前文件夹内为空");
LedgerImage.gameObject.SetActive(false);
}
NextOrPrevBtn[0].gameObject.SetActive(currentPage > 1); // 上一页
NextOrPrevBtn[1].gameObject.SetActive(currentPage < bookPages.Count); // 下一页
}
#endregion
///
/// 网址加载
///
/// 文件名字
void LoadWebsiteUrl(string fileName)
{
string path = Path.Combine(Application.streamingAssetsPath, fileName);
if (File.Exists(path))
{
websiteUrl = File.ReadAllText(path).Trim();
Debug.Log($"网址加载成功: {websiteUrl}");
}
else
{
Debug.LogError($"未找到配置文件: {path}");
}
}
public void OpenWebsite()
{
if (!string.IsNullOrEmpty(websiteUrl))
{
Application.OpenURL(websiteUrl);
}
else
{
Debug.LogWarning("网站地址为空!");
}
}
public void GenerateToggles(string folderPath)
{
// 确认路径存在
if (!Directory.Exists(folderPath))
{
Debug.LogError("路径不存在:" + folderPath);
return;
}
// 只获取该目录下文件
List files = Directory.GetFiles(folderPath, "*.*", SearchOption.TopDirectoryOnly).ToList();
for (int i = 0; i < files.Count; i++)
{
Debug.Log(files[i]);
if (files[i].Contains("meta"))
{
files.RemoveAt(i);
}
}
if (files.Count == 0)
{
Debug.Log($"目录 {folderPath} 下没有文件。");
return;
}
// 可选:清空旧的Toggle
foreach (Transform child in HBSXXXParent)
Destroy(child.gameObject);
allToggles.Clear();
Debug.Log($"在 {folderPath} 下找到 {files.Count} 个文件。");
ToggleGroup group = HBSXXXParent.GetComponent();
foreach (string filePath in files)
{
string fileName = Path.GetFileName(filePath);
string path = filePath; // ? 重要:防止闭包问题
GameObject newToggle = Instantiate(HBSXXXTogObj, HBSXXXParent);
Toggle toggle = newToggle.GetComponent();
allToggles.Add(toggle);
if (group != null)
toggle.group = group;
// 设置文字
TextMeshProUGUI text = newToggle.GetComponentInChildren();
if (text != null)
text.text = fileName;
// 点击事件
toggle.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
// 重置其他Toggle
foreach (var t in allToggles)
{
if (t != toggle)
t.isOn = false;
}
// 打开文件
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
System.Diagnostics.Process.Start(path);
#elif UNITY_STANDALONE_OSX
System.Diagnostics.Process.Start("open", path);
#elif UNITY_STANDALONE_LINUX
System.Diagnostics.Process.Start("xdg-open", path);
#endif
Debug.Log($"打开文件:{path}");
}
});
}
}
}