fix:代码提交

This commit is contained in:
zhangjiajia
2026-03-03 11:30:53 +08:00
parent adf60cc8df
commit 21ebd4c951
2520 changed files with 178964 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAt : MonoBehaviour
{
private GameObject Player;
private CameraRover cameraRover;
void Awake()
{
Player = GameObject.Find("Player");
if (Player != null)
{
// 获取 Player 上挂载的 CameraRover 脚本实例
cameraRover = Player.GetComponent<CameraRover>();
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnMouseDown() {
cameraRover.WebCallOpenItem("iconCameraBlue_1");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 457ab5f9ce79cc3489ce5e76abaf8cc5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,341 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Newtonsoft.Json;
public class IconDataHolder : MonoBehaviour
{
public IconData Data;
}
public class PnlIcon : ActionBase
{
private Dictionary<PageType, List<GameObject>> iconLists = new Dictionary<PageType, List<GameObject>>
{
{ PageType.Icon01, new List<GameObject>() },
{ PageType.Icon02, new List<GameObject>() },
{ PageType.Icon03, new List<GameObject>() },
{ PageType.Icon04, new List<GameObject>() },
// { PageType.Icon05, new List<GameObject>() }
};
private Dictionary<PageType, List<IconData>> appCacheLists;
private void InitializeAppCacheLists()
{
appCacheLists = new Dictionary<PageType, List<IconData>>
{
{ PageType.Icon01, AppCache.iconPointList01 },
{ PageType.Icon02, AppCache.iconPointList02 },
{ PageType.Icon03, AppCache.iconPointList03 },
{ PageType.Icon04, AppCache.iconPointList04 },
};
}
private Dictionary<PageType, string> textPrefixes = new Dictionary<PageType, string>
{
{ PageType.Icon01, "gnss监测" },
{ PageType.Icon02, "水位" },
{ PageType.Icon03, "雨量监测" },
{ PageType.Icon04, "渗压计监测" },
};
private Dictionary<PageType, string> prefabPaths = new Dictionary<PageType, string>
{
{ PageType.Icon01, "Icon2D/iconPrefab" },
{ PageType.Icon02, "Icon2D/iconPrefab" },
{ PageType.Icon03, "Icon2D/iconPrefab" },
{ PageType.Icon04, "Icon2D/iconPrefab" },
};
private static readonly Dictionary<PageType, string> IconMapping = new Dictionary<PageType, string>
{
{ PageType.Icon01, "MT014" },
{ PageType.Icon02, "MT011" },
{ PageType.Icon03, "MT002" },
{ PageType.Icon04, "MT032" }
};
private GameObject Player;
private CameraRover cameraRover;
void Awake()
{
Player = GameObject.Find("Player");
if (Player != null)
{
// 获取 Player 上挂载的 CameraRover 脚本实例
cameraRover = Player.GetComponent<CameraRover>();
}
}
void Update()
{
}
public override void Init()
{
gameObject.SetActive(true);
}
public override void RegisterAction()
{
GameEvent.OpenPage += Open;
GameEvent.ClosePage += Close;
}
public override void RemoveAction()
{
GameEvent.OpenPage -= Open;
GameEvent.ClosePage -= Close;
}
void Open(PageType type)
{
// Debug.Log(type);
OpenIcon(type);
}
void Close(PageType type)
{
CloseIcon(type);
}
// void OpenIcon(PageType type)
// { // 确保 AppCache 列表已初始化
// if (!IsAppCacheInitialized())
// {
// // Debug.LogError("AppCache 列表未初始化!");
// return;
// }
// // 确保 appCacheLists 已初始化
// if (appCacheLists == null)
// {
// InitializeAppCacheLists();
// }
// if (!appCacheLists.ContainsKey(type) || appCacheLists[type] == null)
// {
// // Debug.LogError($"类型 {type} 的列表为空或不存在!");
// return;
// }
// List<IconData> iconDataList = appCacheLists[type];
// string prefabPath = prefabPaths[type];
// string textPrefix = textPrefixes[type];
// // Debug.Log(IconMapping[type]);
// for (int i = 0; i < iconDataList.Count; i++)
// {
// IconData iconData = iconDataList[i];
// // 确保数据有效
// if (iconData == null || iconData.iconTransform == null)
// continue;
// // 预制体对象
// GameObject prefab = Resources.Load<GameObject>(prefabPath);
// GameObject icon = PoolManager.Instance.Spawn(prefab);
// // 使用 iconTransform 的 name 和 position
// icon.name = iconData.iconName;
// icon.transform.SetParent(transform);
// icon.transform.localScale = Vector3.one * 0.8f;
// icon.GetComponent<IconFollow2D>().targetPos = iconData.iconTransform.position;
// Transform txtMsgTransform = FindChildRecursive(icon.transform, "txtMsg");
// Text textComponent = txtMsgTransform.GetComponent<Text>();
// textComponent.text = icon.name;
// Transform iconBgTransform = FindChildRecursive(icon.transform, "iconBg");
// Image iconBgImage = iconBgTransform.GetComponent<Image>();
// Sprite sprite = Resources.Load<Sprite>($"icons/{IconMapping[type]}");
// iconBgImage.sprite = sprite;
// iconLists[type].Add(icon);
// EventListener.AddPointerClickListener(icon, (clickEventData) => OnIconClick(iconData)); ;
// }
// }
void OpenIcon(PageType type)
{
if (!IsAppCacheInitialized())
{
// Debug.LogError("AppCache 列表未初始化!");
return;
}
// 确保 appCacheLists 已初始化
if (appCacheLists == null)
{
InitializeAppCacheLists();
}
if (!appCacheLists.ContainsKey(type) || appCacheLists[type] == null)
{
// Debug.LogError($"类型 {type} 的列表为空或不存在!");
return;
}
List<IconData> iconDataList = appCacheLists[type];
string prefabPath = prefabPaths[type];
// 1. 提前加载预制体和精灵资源,避免重复加载
GameObject prefab = Resources.Load<GameObject>(prefabPath);
Sprite iconSprite = Resources.Load<Sprite>($"icons/{IconMapping[type]}");
// 检查资源是否成功加载
if (prefab == null || iconSprite == null)
{
Debug.LogError($"资源加载失败: Prefab={prefabPath}, Sprite=icons/{IconMapping[type]}");
return;
}
// 2. 初始化列表(如果需要)
if (iconLists[type] == null)
iconLists[type] = new List<GameObject>();
// 3. 使用协程分帧创建对象,减少单帧压力
StartCoroutine(CreateIconsOverTime(type, iconDataList, prefab, iconSprite));
}
IEnumerator CreateIconsOverTime(PageType type, List<IconData> iconDataList, GameObject prefab, Sprite iconSprite)
{
int batchSize = 5; // 每帧创建的对象数量
int framesBetweenBatches = 1; // 创建批次之间的帧数
for (int i = 0; i < iconDataList.Count; i++)
{
IconData iconData = iconDataList[i];
if (iconData == null || iconData.iconTransform == null)
continue;
// 从对象池生成图标
GameObject icon = PoolManager.Instance.Spawn(prefab);
SetupIcon(icon, iconData, iconSprite);
iconLists[type].Add(icon);
// 控制创建速率
if ((i + 1) % batchSize == 0)
{
// 每创建batchSize个对象后等待几帧
for (int f = 0; f < framesBetweenBatches; f++)
yield return null;
}
}
// 4. 加载完成后强制垃圾回收
yield return new WaitForSeconds(0.5f);
Resources.UnloadUnusedAssets();
System.GC.Collect();
}
void SetupIcon(GameObject icon, IconData iconData, Sprite iconSprite)
{
// 设置图标基本属性
icon.name = iconData.iconName;
icon.transform.SetParent(transform);
icon.transform.localScale = Vector3.one * 0.8f;
icon.GetComponent<IconFollow2D>().targetPos = iconData.iconTransform.position;
// 获取并设置文本组件
Transform txtMsgTransform = FindChildRecursive(icon.transform, "txtMsg");
Text textComponent = txtMsgTransform.GetComponent<Text>();
textComponent.text = icon.name;
// 设置图标背景
Transform iconBgTransform = FindChildRecursive(icon.transform, "iconBg");
Image iconBgImage = iconBgTransform.GetComponent<Image>();
iconBgImage.sprite = iconSprite;
// 添加点击事件
EventListener.AddPointerClickListener(icon, (clickEventData) => OnIconClick(iconData));
}
private bool IsAppCacheInitialized()
{
return AppCache.iconPointList01 != null &&
AppCache.iconPointList02 != null &&
AppCache.iconPointList03 != null &&
AppCache.iconPointList04 != null;
}
void CloseIcon(PageType type)
{
if (!iconLists.ContainsKey(type))
{
return;
}
for (int i = 0; i < iconLists[type].Count; i++)
{
PoolManager.Instance.Unspawn(iconLists[type][i]);
}
iconLists[type].Clear();
}
private Transform FindChildRecursive(Transform parent, string name)
{
foreach (Transform child in parent)
{
if (child.name == name)
return child;
// 递归查找子对象的子对象
Transform found = FindChildRecursive(child, name);
if (found != null)
return found;
}
return null;
}
void OnIconClick(IconData iconData)
{
if (iconData != null && cameraRover != null)
{
cameraRover.StartCoroutine(cameraRover.CallOpenItem(iconData.cameraTransform));
cameraRover.SetTargetPosition(iconData.iconTransform.position);
// Debug.Log($"点击的图标信息:");
// Debug.Log($"device_sn: {iconData.device_sn}");
// Debug.Log($"iconName: {iconData.iconName}");
// Debug.Log($"identifier: {iconData.identifier}");
// Debug.Log($"iconTransform: {iconData.iconTransform}");
// Debug.Log($"cameraName: {iconData.cameraName}");
// Debug.Log($"cameraTransform: {iconData.cameraTransform.position}");
// Debug.Log(iconData.iconTransform.position);
StartCoroutine(WaitForFlightCompletion(iconData));
cameraRover.StartCoroutine(cameraRover.CallOpenItem(iconData.cameraTransform));
}
else
{
Debug.LogWarning("点击的图标没有关联的 IconData");
}
}
private IEnumerator WaitForFlightCompletion(IconData iconData)
{
// 等待飞行结束
while (!cameraRover.isFlightCompleted)
{
yield return null;
}
// 飞行结束,执行网络请求和数据发送操作
string BASE_URL = "/api.php/Device/deviceDetail?device_sn=" + iconData.device_sn + "&identifier=" + iconData.identifier;
string url = WebService.IsRunningInWebGL() ? BASE_URL : AppCache.url + BASE_URL;
WebService.Instance.Get<JsonDetails>(url, delegate (JsonDetails details)
{
var dataToSend = new DataToSend
{
dataItem = details.result,
iconName = iconData.iconName
};
string jsonData = JsonConvert.SerializeObject(dataToSend);
// Debug.Log("序列化后的JSON: " + jsonData);
Application.ExternalCall("sendDataToVue", jsonData);
cameraRover.SetFlightCompleted(false);
});
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b2d4fefc0e1a17941b74b60a5e05e76f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,158 @@
using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PnlMain : ActionBase
{
private const int ButtonCount = 5;
private List<Button> buttons = new List<Button>();
private List<Action> clickActions = new List<Action>();
// 定义一个结构体来存储动态参数
private struct PageActionParams
{
public List<PageType> closePageTypes; // 存储需要关闭的所有页面类型
public List<PageType> openPageType; // 存储需要打开的所有页面类型
public PageType actionPageType;
public float openDelay;
public string buttonName; // 存储按钮名称,避免复杂的条件判断
}
private List<PageActionParams> pageActionParamsList = new List<PageActionParams>
{
new PageActionParams
{
closePageTypes = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04 },
openPageType = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04 },
actionPageType = PageType.Camera1,
openDelay = 1f,
buttonName = "all"
},
new PageActionParams
{
closePageTypes = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04 },
openPageType = new List<PageType> { PageType.Icon01 },
actionPageType = PageType.Camera1,
openDelay = 1f,
buttonName = "gnss"
},
new PageActionParams
{
closePageTypes = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04 },
openPageType = new List<PageType> { PageType.Icon02 },
actionPageType = PageType.Camera2,
openDelay = 1f,
buttonName = "水位"
},
new PageActionParams
{
closePageTypes = new List<PageType> { PageType.Icon01, PageType.Icon02,PageType.Icon03, PageType.Icon04 },
openPageType = new List<PageType> { PageType.Icon03 },
actionPageType = PageType.Camera1,
openDelay = 1f,
buttonName = "雨量监测"
},
new PageActionParams
{
closePageTypes = new List<PageType> { PageType.Icon01, PageType.Icon02, PageType.Icon03,PageType.Icon04 },
openPageType = new List<PageType> { PageType.Icon04 },
actionPageType = PageType.Camera1,
openDelay = 1f,
buttonName = "渗压计监测"
}
};
public override void Init()
{
for (int i = 1; i <= ButtonCount; i++)
{
string buttonName = $"btnPage{i}";
Button button = transform.Find(buttonName).GetComponent<Button>();
// Debug.Log($"找到按钮{buttonName}");
buttons.Add(button);
int index = i - 1;
button.onClick.AddListener(() => OnButtonClick(index));
}
for (int i = 0; i < ButtonCount; i++)
{
int index = i;
clickActions.Add(() =>
{
// Debug.Log($"我点击了按钮{pageActionParamsList[index].buttonName}");
OnButtonClickCommon(index);
});
}
gameObject.SetActive(true);
}
void OnButtonClick(int index)
{
for (int i = 0; i < buttons.Count; i++)
{
buttons[i].interactable = i != index;
}
if (index < clickActions.Count)
{
clickActions[index].Invoke();
}
}
void OnButtonClickCommon(int index)
{
if (index < pageActionParamsList.Count)
{
var paramsData = pageActionParamsList[index];
// 关闭所有需要关闭的页面
if (paramsData.closePageTypes != null && paramsData.closePageTypes.Count > 0)
{
foreach (var pageType in paramsData.closePageTypes)
{
AppCache.ClosePage(pageType);
}
}
// 打开所有需要打开的页面
if (paramsData.openPageType != null && paramsData.openPageType.Count > 0)
{
foreach (var pageType in paramsData.openPageType)
{
AppCache.OpenPageDelay(pageType, paramsData.openDelay);
}
}
if (paramsData.actionPageType != default(PageType))
{
ActionCenter.Instance.DoAction(GameEvent.OpenPage, paramsData.actionPageType);
}
}
}
public void TriggerButtonClick(string buttonName)
{
for (int i = 0; i < pageActionParamsList.Count; i++)
{
if (pageActionParamsList[i].buttonName == buttonName)
{
OnButtonClick(i);
break;
}
}
}
public override void RegisterAction()
{
}
public override void RemoveAction()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 95a397fbdc452114986777f431e4b707
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: