fix:1
This commit is contained in:
239
Assets/Scripts/App/AppCache.cs
Normal file
239
Assets/Scripts/App/AppCache.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class AppCache
|
||||
{
|
||||
|
||||
public enum MonitorType
|
||||
{
|
||||
GNSS,
|
||||
EnvironmentalMonitoring,
|
||||
CrackMonitoring,
|
||||
VibrationMonitoring,
|
||||
SurfaceStrainMonitoring
|
||||
}
|
||||
public static int screenWidth = 1920;
|
||||
public static int screenHeight = 1080;
|
||||
|
||||
public static string url = "https://api.zk.gzckgc.cn";
|
||||
|
||||
//界面
|
||||
public static PageType cameraType = PageType.Camera1;
|
||||
public static PageType pageType = PageType.PnlPage1;
|
||||
//点位gnss
|
||||
public static List<IconData> iconPointList01;
|
||||
//相机点位gnss
|
||||
public static List<Transform> iconCameraList01 = new List<Transform>();
|
||||
//点位环境监测
|
||||
public static List<IconData> iconPointList02;
|
||||
//相机点位环境检测
|
||||
public static List<Transform> iconCameraList02 = new List<Transform>();
|
||||
//点位裂缝监测
|
||||
public static List<IconData> iconPointList03;
|
||||
//相机点位裂缝监测
|
||||
public static List<Transform> iconCameraList03 = new List<Transform>();
|
||||
//点位加速度震动监测
|
||||
public static List<IconData> iconPointList04;
|
||||
//相机点位加速度震动监测
|
||||
public static List<Transform> iconCameraList04 = new List<Transform>();
|
||||
//点位表面应变监测
|
||||
public static List<IconData> iconPointList05;
|
||||
//相机点位表面应变监测
|
||||
public static List<Transform> iconCameraList05 = new List<Transform>();
|
||||
public static List<Vector3> areaPointList01 = new List<Vector3>();
|
||||
public static List<Vector3> areaPointList02 = new List<Vector3>();
|
||||
|
||||
|
||||
//初始化
|
||||
public static void Init()
|
||||
{
|
||||
//分辨率设置
|
||||
if (Application.platform == RuntimePlatform.WindowsPlayer)
|
||||
{
|
||||
float height = Screen.width * (screenHeight / (float)screenWidth);
|
||||
Screen.SetResolution(Screen.width, (int)height, true);
|
||||
|
||||
//Screen.SetResolution(screenWidth, screenHeight, true);
|
||||
}
|
||||
//初始化
|
||||
cameraType = PageType.Camera1;
|
||||
pageType = PageType.PnlPage1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 页面管理
|
||||
|
||||
//已打开页面列表
|
||||
private static List<PageType> pageList = new List<PageType>();
|
||||
|
||||
//打开页面
|
||||
public static void OpenPage(PageType page)
|
||||
{
|
||||
if (page != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.OpenPage, page);
|
||||
if (!pageList.Contains(page))
|
||||
{
|
||||
pageList.Add(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//打开页面
|
||||
public static void OpenDialog<T>(PageType page, T t)
|
||||
{
|
||||
if (page != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.OpenDialog, page, t);
|
||||
if (!pageList.Contains(page))
|
||||
{
|
||||
pageList.Add(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//delay秒后打开页面
|
||||
public static void OpenPageDelay(PageType page, float delay)
|
||||
{
|
||||
ActionCenter.Instance.DoActionDelay(OpenPage, delay, page);
|
||||
}
|
||||
|
||||
//关闭页面
|
||||
public static void ClosePage(PageType page)
|
||||
{
|
||||
|
||||
if (pageList.Contains(page) && page != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, page);
|
||||
pageList.Remove(page);
|
||||
}
|
||||
}
|
||||
|
||||
//关闭页面
|
||||
public static void ClosePage(List<PageType> list)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (pageList.Contains(list[i]) && list[i] != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, list[i]);
|
||||
pageList.Remove(list[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//关闭页面,参数为保留页面
|
||||
public static void CloseAllPage(PageType page = PageType.Null)
|
||||
{
|
||||
for (int i = 0; i < pageList.Count; i++)
|
||||
{
|
||||
if (pageList[i] != page)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, pageList[i]);
|
||||
}
|
||||
}
|
||||
pageList.Clear();
|
||||
if (page != PageType.Null)
|
||||
{
|
||||
pageList.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
//关闭页面,参数为保留页面
|
||||
public static void CloseAllPage(List<PageType> list)
|
||||
{
|
||||
//保留页面
|
||||
List<PageType> saveList = new List<PageType>();
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (list[i] != PageType.Null && pageList.Contains(list[i]))
|
||||
{
|
||||
saveList.Add(list[i]);
|
||||
}
|
||||
}
|
||||
//关闭现有页面
|
||||
for (int i = 0; i < pageList.Count; i++)
|
||||
{
|
||||
if (!saveList.Contains(pageList[i]))
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, pageList[i]);
|
||||
}
|
||||
}
|
||||
pageList.Clear();
|
||||
//当前页面更新
|
||||
for (int i = 0; i < saveList.Count; i++)
|
||||
{
|
||||
pageList.Add(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
// 根据device_sn查找在AppCache.iconCameraList01中的下标
|
||||
public static int FindIndexInIconCameraList(string deviceSn)
|
||||
{
|
||||
if (AppCache.iconCameraList01 == null)
|
||||
return -1;
|
||||
|
||||
// 遍历列表查找匹配的下标
|
||||
for (int i = 0; i < AppCache.iconCameraList01.Count; i++)
|
||||
{
|
||||
// 从name中提取device_sn部分(去掉"_Camera"后缀)
|
||||
string nameWithoutSuffix = AppCache.iconCameraList01[i].name.Split('_')[0];
|
||||
|
||||
if (nameWithoutSuffix == deviceSn)
|
||||
{
|
||||
return i; // 找到匹配的下标
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // 未找到
|
||||
}
|
||||
|
||||
public static List<IconData> GetIconPointListByType(MonitorType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MonitorType.GNSS:
|
||||
return iconPointList01;
|
||||
case MonitorType.EnvironmentalMonitoring:
|
||||
return iconPointList02;
|
||||
case MonitorType.CrackMonitoring:
|
||||
return iconPointList03;
|
||||
case MonitorType.VibrationMonitoring:
|
||||
return iconPointList04;
|
||||
case MonitorType.SurfaceStrainMonitoring:
|
||||
return iconPointList05;
|
||||
default:
|
||||
Debug.LogError("未知的监测类型: " + type);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Transform> GetIconCameraListByType(MonitorType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MonitorType.GNSS:
|
||||
return iconCameraList01;
|
||||
case MonitorType.EnvironmentalMonitoring:
|
||||
return iconCameraList02;
|
||||
case MonitorType.CrackMonitoring:
|
||||
return iconCameraList03;
|
||||
case MonitorType.VibrationMonitoring:
|
||||
return iconCameraList04;
|
||||
case MonitorType.SurfaceStrainMonitoring:
|
||||
return iconCameraList05;
|
||||
default:
|
||||
Debug.LogError("未知的监测类型: " + type);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/App/AppCache.cs.meta
Normal file
11
Assets/Scripts/App/AppCache.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4021aed31c4794419d8b529321a2aad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/Scripts/App/AppMain.cs
Normal file
37
Assets/Scripts/App/AppMain.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AppMain : MonoBehaviour
|
||||
{
|
||||
public static AppMain Instance;
|
||||
|
||||
public List<Transform> pointList = new List<Transform>();
|
||||
|
||||
public Color color1;
|
||||
public Color color2;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
//单例对象
|
||||
Instance = this;
|
||||
//初始化
|
||||
AppCache.Init();
|
||||
ActionCenter.Instance.Init();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
//初始化主页
|
||||
// AppCache.OpenPage(PageType.PnlMain);
|
||||
AppCache.OpenPage(AppCache.cameraType);
|
||||
// AppCache.OpenPageDelay(AppCache.pageType, 0.3f);
|
||||
AppCache.OpenPageDelay(PageType.Icon01, 2f);
|
||||
// AppCache.OpenPageDelay(PageType.Area01, 2f);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/App/AppMain.cs.meta
Normal file
11
Assets/Scripts/App/AppMain.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0601b8b59d626c24ab98ed17184b97df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
305
Assets/Scripts/App/CameraControl.cs
Normal file
305
Assets/Scripts/App/CameraControl.cs
Normal file
@@ -0,0 +1,305 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class CameraControl : MonoBehaviour
|
||||
{
|
||||
[Header("移动速度")]
|
||||
public float moveSpeed = 1.2f;
|
||||
[Header("旋转速度")]
|
||||
public float rotateSpeed = 45f;
|
||||
[Header("缩放速度")]
|
||||
public float zoomSpeed = 0.2f;
|
||||
[Header("最小高度")]
|
||||
public float minHeight = 0.1f;
|
||||
[Header("最大高度")]
|
||||
public float maxHeight = 100f;
|
||||
[Header("地图中心")]
|
||||
public Vector3 mapCenter = Vector3.zero;
|
||||
[Header("最大距离")]
|
||||
public float maxDistance = 3000f;
|
||||
[Header("最小角度")]
|
||||
public float minAngleX = -60f;
|
||||
[Header("最大角度")]
|
||||
public float maxAngleX = 88f;
|
||||
[Header("射线检测提前量")]
|
||||
public float raycastOffset = 0.1f; // 射线检测提前量
|
||||
|
||||
|
||||
//控制变量
|
||||
private Vector3 viewPos_0; //鼠标左键初始坐标
|
||||
private Vector3 viewPos_1; //鼠标右键初始坐标
|
||||
|
||||
private Vector3 startCameraPos; //相机初始位置
|
||||
private Vector3 targetCameraPos; //相机目标位置
|
||||
|
||||
private Vector2 startCameraEuler; //初始角度
|
||||
private Vector2 targetCameraEuler; //目标角度
|
||||
|
||||
//相机控制
|
||||
private Camera mainCamera;
|
||||
private bool isCameraCtrl = true; //相机是否可控制
|
||||
private float screenAdapter = 1f; //屏幕长度比
|
||||
|
||||
//相机操作有效性判断
|
||||
private bool isClickUI = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
screenAdapter = Screen.width / (float)Screen.height;
|
||||
targetCameraPos = transform.position;
|
||||
targetCameraEuler = transform.eulerAngles;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//相机控制
|
||||
if (isCameraCtrl)
|
||||
{
|
||||
//操作有效性判断
|
||||
if (EventSystem.current != null)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
|
||||
{
|
||||
isClickUI = EventSystem.current.IsPointerOverGameObject();
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2))
|
||||
{
|
||||
isClickUI = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isClickUI)
|
||||
{
|
||||
//平移控制
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(2))
|
||||
{
|
||||
viewPos_0 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
startCameraPos = transform.position;
|
||||
startCameraEuler = transform.eulerAngles;
|
||||
}
|
||||
if (Input.GetMouseButton(0) || Input.GetMouseButton(2))
|
||||
{
|
||||
Vector3 currentViewPos = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
Vector3 dis = currentViewPos - viewPos_0;
|
||||
dis = dis * GetMoveSpeed();
|
||||
|
||||
// 获取相机的右向量和上向量
|
||||
Vector3 right = transform.right;
|
||||
Vector3 up = transform.up;
|
||||
|
||||
// 分别计算水平和垂直方向的位移
|
||||
float horizontalDis = -dis.x * screenAdapter;
|
||||
float verticalDis = -dis.y * screenAdapter;
|
||||
|
||||
// 根据相机的右向量和上向量计算最终位移
|
||||
Vector3 finalDis = right * horizontalDis + up * verticalDis;
|
||||
|
||||
// targetCameraPos = startCameraPos + finalDis;
|
||||
Vector3 newTargetPos = startCameraPos + finalDis;
|
||||
newTargetPos = CheckCollisionOnMove(transform.position, newTargetPos);
|
||||
targetCameraPos = newTargetPos;
|
||||
}
|
||||
//旋转控制
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
|
||||
viewPos_1 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
startCameraPos = transform.position;
|
||||
startCameraEuler = transform.eulerAngles;
|
||||
}
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
Vector2 angle = (mainCamera.ScreenToViewportPoint(Input.mousePosition) - viewPos_1) * rotateSpeed;
|
||||
angle = new Vector3(-angle.y, angle.x * screenAdapter);
|
||||
targetCameraEuler = startCameraEuler + angle;
|
||||
}
|
||||
//缩进控制
|
||||
if (Input.mouseScrollDelta != Vector2.zero)
|
||||
{
|
||||
// float moveSpeed = GetMoveSpeed() * 0.2f;
|
||||
// targetCameraPos += transform.forward * moveSpeed * Input.mouseScrollDelta.y;
|
||||
float moveSpeed = GetMoveSpeed() * zoomSpeed;
|
||||
Vector3 newTargetPos = targetCameraPos + transform.forward * moveSpeed * Input.mouseScrollDelta.y;
|
||||
newTargetPos = CheckCollisionOnMove(transform.position, newTargetPos);
|
||||
targetCameraPos = newTargetPos;
|
||||
}
|
||||
|
||||
//相机运动
|
||||
LimitCamera();
|
||||
// CheckCollision(); // 检查碰撞
|
||||
//控制相机运动
|
||||
// 控制相机运动
|
||||
if (Vector3.Distance(transform.position, targetCameraPos) > 0.1f)
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, targetCameraPos, 5f * Time.deltaTime);
|
||||
// Debug.Log("position"+transform.position);
|
||||
}
|
||||
|
||||
// 控制相机旋转
|
||||
if (Quaternion.Angle(transform.rotation, Quaternion.Euler(targetCameraEuler)) > 0.1f)
|
||||
{
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(targetCameraEuler), 5f * Time.deltaTime);
|
||||
// Debug.Log("rotation"+transform.eulerAngles);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//开启相机控制
|
||||
// public void StartCameraControl()
|
||||
// {
|
||||
// isCameraCtrl = true;
|
||||
// isClickUI = false;
|
||||
// viewPos_0 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
// viewPos_1 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
// startCameraPos = transform.position;
|
||||
// startCameraEuler = transform.eulerAngles;
|
||||
// targetCameraPos = transform.position;
|
||||
|
||||
// targetCameraEuler = transform.eulerAngles;
|
||||
// }
|
||||
|
||||
//停止相机控制
|
||||
// public void StopCameraControl()
|
||||
// {
|
||||
// isCameraCtrl = false;
|
||||
// }
|
||||
|
||||
|
||||
//获取相机移动速度
|
||||
float GetMoveSpeed()
|
||||
{
|
||||
|
||||
float highDis = (transform.position.y - minHeight);
|
||||
float speed = moveSpeed + moveSpeed * highDis;
|
||||
speed = Mathf.RoundToInt(speed);
|
||||
return speed;
|
||||
}
|
||||
|
||||
//限制相机位置,角度
|
||||
void LimitCamera()
|
||||
{
|
||||
//位置限制
|
||||
targetCameraPos.y = Mathf.Clamp(targetCameraPos.y, minHeight, maxHeight);
|
||||
|
||||
float dis = Vector3.Distance(targetCameraPos, mapCenter);
|
||||
|
||||
if (dis > maxDistance)
|
||||
{
|
||||
Vector3 dir = (targetCameraPos - mapCenter).normalized;
|
||||
targetCameraPos = mapCenter + dir * maxDistance;
|
||||
}
|
||||
//角度限制
|
||||
if (targetCameraEuler.x > 180) { targetCameraEuler.x -= 360f; }
|
||||
if (targetCameraEuler.x < -180) { targetCameraEuler.x += 360; }
|
||||
if (targetCameraEuler.y > 180) { targetCameraEuler.y -= 360f; }
|
||||
if (targetCameraEuler.y < -180) { targetCameraEuler.y += 360; }
|
||||
targetCameraEuler.x = Mathf.Clamp(targetCameraEuler.x, minAngleX, maxAngleX);
|
||||
}
|
||||
|
||||
// // 检查碰撞
|
||||
// void CheckCollisionOnMove(Vector3 startPos, Vector3 targetPos)
|
||||
// {
|
||||
// RaycastHit hit;
|
||||
// Vector3 direction = targetCameraPos - transform.position;
|
||||
// float distance = direction.magnitude;
|
||||
|
||||
// if (Physics.Raycast(transform.position, direction.normalized, out hit, distance))
|
||||
// {
|
||||
// targetCameraPos = hit.point;
|
||||
// }
|
||||
// }
|
||||
// 修改CheckCollisionOnMove方法,增加垂直方向检测
|
||||
Vector3 CheckCollisionOnMove(Vector3 startPos, Vector3 targetPos)
|
||||
{
|
||||
Vector3 direction = targetPos - startPos;
|
||||
float distance = direction.magnitude;
|
||||
|
||||
// 存储最终的安全位置
|
||||
Vector3 safePosition = targetPos;
|
||||
|
||||
// 1. 检测移动路径上的障碍物(包括水平和垂直方向)
|
||||
if (distance > 0)
|
||||
{
|
||||
float sphereRadius = 0.1f; // 根据相机碰撞体大小调整
|
||||
|
||||
// 计算起点和终点的包围盒
|
||||
Bounds startBounds = new Bounds(startPos, Vector3.one * sphereRadius * 2);
|
||||
Bounds endBounds = new Bounds(targetPos, Vector3.one * sphereRadius * 2);
|
||||
|
||||
// 创建从起点到终点的包围盒移动路径
|
||||
Bounds movementBounds = new Bounds();
|
||||
movementBounds.Encapsulate(startBounds);
|
||||
movementBounds.Encapsulate(endBounds);
|
||||
|
||||
// 使用多个方向的射线检测全方位碰撞
|
||||
bool collisionDetected = false;
|
||||
|
||||
// 主方向检测
|
||||
if (Physics.SphereCast(startPos, sphereRadius, direction.normalized, out RaycastHit hit, distance + raycastOffset))
|
||||
{
|
||||
float safeDistance = hit.distance - raycastOffset - sphereRadius;
|
||||
safePosition = startPos + direction.normalized * Mathf.Max(safeDistance, 0);
|
||||
collisionDetected = true;
|
||||
}
|
||||
|
||||
// 如果是向上移动,增加顶部检测
|
||||
if (direction.y > 0.1f) // 设置一个阈值,只在明显向上移动时检测
|
||||
{
|
||||
Vector3 topStart = startPos + Vector3.up * sphereRadius;
|
||||
Vector3 topDirection = Vector3.up * (endBounds.max.y - startBounds.max.y);
|
||||
|
||||
if (Physics.SphereCast(topStart, sphereRadius, topDirection.normalized, out hit, topDirection.magnitude + raycastOffset))
|
||||
{
|
||||
float verticalSafeDistance = hit.distance - raycastOffset - sphereRadius;
|
||||
safePosition.y = startPos.y + verticalSafeDistance;
|
||||
collisionDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (collisionDetected)
|
||||
{
|
||||
// 声明地面检测变量(移到这里避免作用域冲突)
|
||||
Ray groundRay1;
|
||||
float maxGroundDistance1;
|
||||
RaycastHit groundHit1;
|
||||
|
||||
// 如果检测到碰撞,进行地面高度验证
|
||||
groundRay1 = new Ray(safePosition + Vector3.up, Vector3.down);
|
||||
maxGroundDistance1 = 0.5f;
|
||||
|
||||
if (Physics.Raycast(groundRay1, out groundHit1, maxGroundDistance1))
|
||||
{
|
||||
float minSafeHeight = groundHit1.point.y + minHeight;
|
||||
if (safePosition.y < minSafeHeight)
|
||||
{
|
||||
safePosition.y = minSafeHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return safePosition;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 如果没有检测到碰撞,只进行地面高度验证
|
||||
// 重用之前声明的变量
|
||||
Ray groundRay = new Ray(targetPos + Vector3.up, Vector3.down);
|
||||
float maxGroundDistance = 0.5f;
|
||||
|
||||
if (Physics.Raycast(groundRay, out RaycastHit groundHit, maxGroundDistance))
|
||||
{
|
||||
float minSafeHeight = groundHit.point.y + minHeight;
|
||||
if (targetPos.y < minSafeHeight)
|
||||
{
|
||||
targetPos.y = minSafeHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return targetPos;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/App/CameraControl.cs.meta
Normal file
11
Assets/Scripts/App/CameraControl.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8428addbd23d2d346969c8fd6e13d738
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
263
Assets/Scripts/App/CameraRover.cs
Normal file
263
Assets/Scripts/App/CameraRover.cs
Normal file
@@ -0,0 +1,263 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.AI;
|
||||
using System.Linq;
|
||||
public class CameraRover : ActionBase
|
||||
{
|
||||
private CameraControl cameraCtr2;
|
||||
private ControlMove cameraCtrl;
|
||||
private Vector3 targetPos = Vector3.zero; //视角坐标
|
||||
|
||||
private bool isLookAt = false; //视角是否朝向目标
|
||||
private string currentAnim = "";
|
||||
|
||||
// 私有变量,用于存储飞行完成状态
|
||||
private bool _isFlightCompleted = false;
|
||||
|
||||
// 公共属性,用于获取飞行完成状态
|
||||
public bool isFlightCompleted
|
||||
{
|
||||
get { return _isFlightCompleted; }
|
||||
}
|
||||
|
||||
// 公共方法,用于修改飞行完成状态
|
||||
public void SetFlightCompleted(bool value)
|
||||
{
|
||||
_isFlightCompleted = value;
|
||||
}
|
||||
|
||||
public LayerMask obstacleLayer; // 障碍物层
|
||||
|
||||
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
cameraCtr2 = GetComponent<CameraControl>();
|
||||
cameraCtrl = GetComponent<ControlMove>();
|
||||
|
||||
currentAnim = "";
|
||||
isLookAt = false;
|
||||
}
|
||||
|
||||
public override void RegisterAction()
|
||||
{
|
||||
GameEvent.OpenPage += OpenPage;
|
||||
GameEvent.StartCameraControl += StartCameraCtrl;
|
||||
GameEvent.StopCameraControl += StopCameraCtrl;
|
||||
}
|
||||
|
||||
public override void RemoveAction()
|
||||
{
|
||||
GameEvent.OpenPage -= OpenPage;
|
||||
GameEvent.StartCameraControl -= StartCameraCtrl;
|
||||
GameEvent.StopCameraControl -= StopCameraCtrl;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (isLookAt)
|
||||
{
|
||||
transform.LookAt(targetPos);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenPage(PageType type)
|
||||
{
|
||||
Debug.Log(type);
|
||||
switch (type)
|
||||
{
|
||||
case PageType.Camera1:
|
||||
CameraBreak();
|
||||
StartCoroutine("CameraAnim_1");
|
||||
break;
|
||||
case PageType.Camera2:
|
||||
CameraBreak();
|
||||
StartCoroutine("CameraAnim_2");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void StartCameraCtrl()
|
||||
{
|
||||
cameraCtrl.StartCameraControl();
|
||||
}
|
||||
|
||||
void StopCameraCtrl()
|
||||
{
|
||||
cameraCtrl.StopCameraControl();
|
||||
}
|
||||
|
||||
public void SetTargetPosition(Vector3 position)
|
||||
{
|
||||
cameraCtrl.GetInScriptCore(position);
|
||||
}
|
||||
|
||||
//打断当前相机操作
|
||||
void CameraBreak()
|
||||
{
|
||||
StopCoroutine(currentAnim);
|
||||
isLookAt = false;
|
||||
transform.DOKill();
|
||||
}
|
||||
|
||||
//相机点位-1
|
||||
IEnumerator CameraAnim_1()
|
||||
{
|
||||
currentAnim = "CameraAnim_1";
|
||||
StopCameraCtrl();
|
||||
cameraCtrl.GetInScriptCore();
|
||||
yield return new WaitForEndOfFrame();
|
||||
transform.DOMove(new Vector3(853.45f, 56.79f, 775.12f), 2f);
|
||||
transform.DORotate(new Vector3(10.39f, 184.72f, 0f), 2f);
|
||||
yield return new WaitForSeconds(2f);
|
||||
StartCameraCtrl();
|
||||
}
|
||||
|
||||
//相机点位-2
|
||||
IEnumerator CameraAnim_2()
|
||||
{
|
||||
currentAnim = "CameraAnim_2";
|
||||
StopCameraCtrl();
|
||||
cameraCtrl.GetInScriptCore(new Vector3(849f, 27f, 560f));
|
||||
yield return new WaitForEndOfFrame();
|
||||
transform.DOMove(new Vector3(850.61f, 65.11f, 524.99f), 2f);
|
||||
transform.DORotate(new Vector3(36.65f, 7.09f, 0f), 2f);
|
||||
|
||||
yield return new WaitForSeconds(2f);
|
||||
StartCameraCtrl();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vector3[] GetRoundPath(Vector3 pos, Vector3 pivot)
|
||||
{
|
||||
Vector3[] path = new Vector3[10];
|
||||
Vector3 dir = pos - pivot;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Vector3 rotatedDir = Quaternion.AngleAxis(40f * i, Vector3.up) * dir;
|
||||
path[i] = pivot + rotatedDir;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// 暴露给 JavaScript 的静态方法
|
||||
public void CallOpenPage(int typeIndex)
|
||||
{
|
||||
PageType pageType = (PageType)typeIndex;
|
||||
ActionCenter.Instance.DoAction(GameEvent.OpenPage, pageType);
|
||||
}
|
||||
|
||||
public void WebCallOpenItem(string objectName)
|
||||
{
|
||||
// 定义要搜索的所有相机图标列表
|
||||
List<List<Transform>> allCameraLists = new List<List<Transform>>
|
||||
{
|
||||
AppCache.iconCameraList01,
|
||||
AppCache.iconCameraList02,
|
||||
AppCache.iconCameraList03,
|
||||
AppCache.iconCameraList04,
|
||||
AppCache.iconCameraList05
|
||||
};
|
||||
|
||||
// 在所有列表中查找具有指定名称的 Transform
|
||||
Transform foundTransform = null;
|
||||
|
||||
foreach (var cameraList in allCameraLists)
|
||||
{
|
||||
if (cameraList == null) continue;
|
||||
|
||||
// 查找匹配名称的 Transform
|
||||
foundTransform = cameraList.Find(transform =>
|
||||
transform != null && transform.name == objectName);
|
||||
|
||||
if (foundTransform != null) break;
|
||||
}
|
||||
|
||||
// 如果找到对应的 Transform,则执行飞行逻辑
|
||||
if (foundTransform != null)
|
||||
{
|
||||
StartCoroutine(flyItem(foundTransform));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"未找到名称为 '{objectName}' 的相机图标!");
|
||||
}
|
||||
}
|
||||
|
||||
// 公共协程方法 - 处理相机移动的核心逻辑(带自动避障)
|
||||
private IEnumerator MoveCameraCore(Transform targetTransform, string animName)
|
||||
{
|
||||
currentAnim = animName;
|
||||
StopCameraCtrl();
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
Vector3 targetPosition = targetTransform.position;
|
||||
Vector3 targetRotation = targetTransform.eulerAngles;
|
||||
|
||||
float distance = Vector3.Distance(transform.position, targetPosition);
|
||||
float speed = 5f;
|
||||
float flightTime = distance / speed;
|
||||
float maxFlightTime = 2f;
|
||||
|
||||
flightTime = Mathf.Max(flightTime, 0.1f);
|
||||
flightTime = Mathf.Min(flightTime, maxFlightTime);
|
||||
RaycastHit hit;
|
||||
// 射线检测是否有障碍物
|
||||
if (Physics.Raycast(transform.position, targetPosition - transform.position, out hit, distance, obstacleLayer))
|
||||
{
|
||||
// 有障碍物
|
||||
// Debug.Log("有障碍物,使用绕行路径");
|
||||
|
||||
Vector3 stopPosition = hit.point - (targetPosition - transform.position).normalized * 0.1f;
|
||||
|
||||
float stopDistance = Vector3.Distance(transform.position, stopPosition);
|
||||
float stopFlightTime = stopDistance / speed;
|
||||
stopFlightTime = Mathf.Max(stopFlightTime, 0.1f);
|
||||
stopFlightTime = Mathf.Min(stopFlightTime, maxFlightTime);
|
||||
|
||||
transform.DOMove(stopPosition, stopFlightTime);
|
||||
transform.DORotate(Quaternion.LookRotation(targetPosition - transform.position).eulerAngles, stopFlightTime);
|
||||
yield return new WaitForSeconds(stopFlightTime);
|
||||
transform.position = targetPosition;
|
||||
transform.DORotate(targetRotation, stopFlightTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 无障碍物
|
||||
// Debug.Log("无障碍物,使用直接路径");
|
||||
transform.DOMove(targetPosition, flightTime);
|
||||
transform.DORotate(targetRotation, flightTime);
|
||||
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(flightTime);
|
||||
StartCameraCtrl();
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator flyItem(Transform targetTransform)
|
||||
{
|
||||
return MoveCameraCore(targetTransform, "CameraAnim_4");
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator CallOpenItem(Transform targetTransform)
|
||||
{
|
||||
SetFlightCompleted(false);
|
||||
|
||||
// 执行公共相机移动逻辑
|
||||
yield return StartCoroutine(MoveCameraCore(targetTransform, "CameraAnim_3"));
|
||||
|
||||
SetFlightCompleted(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
11
Assets/Scripts/App/CameraRover.cs.meta
Normal file
11
Assets/Scripts/App/CameraRover.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56eadf24a6164ef4db2623b73dc84937
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
239
Assets/Scripts/App/ControlMove.cs
Normal file
239
Assets/Scripts/App/ControlMove.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class ControlMove : MonoBehaviour
|
||||
{
|
||||
|
||||
private float moveSpeed = 50f; // 右键平移速度
|
||||
|
||||
[Header("滚轮缩放速度系数")]
|
||||
public float zoomSpeed = 10f; // 滚轮缩放速度
|
||||
|
||||
[Header("相机与水库中心的最大距离")]
|
||||
public float maxDistance = 600f; // 最大缩放距离
|
||||
|
||||
[Header("相机的最大高度限制")]
|
||||
public float maxHeight = 220f; // 最大高度限制
|
||||
|
||||
[Header("右键键平移速度衰减系数")]
|
||||
public float rightClickPanSpeed = 100f; // 右键平移速度除数
|
||||
|
||||
private Vector3 inScript; // 引用焦点脚本,提供 core
|
||||
|
||||
[Header("左键拖拽旋转灵敏度系数")]
|
||||
public float rotationSensitivity = 0.5f; // 左键拖拽旋转灵敏度
|
||||
|
||||
private Camera cam; // 主相机引用
|
||||
private bool isRotating = false; // 是否正在旋转标志
|
||||
private Vector2 lastMousePos; // 上次鼠标位置(用于旋转计算)
|
||||
|
||||
[Header("初始距离中心")]
|
||||
public Vector3 reservoirCenter; // 水库中心坐标
|
||||
|
||||
[Header("初始旋转中心")]
|
||||
public Vector3 startinScript; // 初始焦点位置
|
||||
|
||||
private Rigidbody rb; // 刚体组件(如需要物理模拟)
|
||||
private bool isCameraCtrl = true; // 相机是否可控制
|
||||
|
||||
//相机操作有效性判断
|
||||
private bool isClickUI = false;
|
||||
|
||||
private float pitchDelta; // 刚体组件(如需要物理模拟)
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
cam = Camera.main;
|
||||
if (inScript == Vector3.zero)
|
||||
{
|
||||
GetInScriptCore();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isCameraCtrl)
|
||||
{
|
||||
//操作有效性判断
|
||||
if (EventSystem.current != null)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
|
||||
{
|
||||
isClickUI = EventSystem.current.IsPointerOverGameObject();
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2))
|
||||
{
|
||||
isClickUI = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isClickUI)
|
||||
{
|
||||
Vector3 core = inScript;
|
||||
// —— 右键平移 ——
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
moveSpeed = Vector3.Distance(core, transform.position) / 2f;
|
||||
float mx = Input.GetAxis("Mouse X");
|
||||
float my = Input.GetAxis("Mouse Y");
|
||||
|
||||
Vector3 desiredPosition = transform.position + (-transform.right * mx + -transform.up * my) * moveSpeed / rightClickPanSpeed;
|
||||
|
||||
// 判断是否与障碍物发生碰撞
|
||||
if (!WillCollideWithObstacle(desiredPosition))
|
||||
{
|
||||
transform.position = desiredPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// —— 滚轮缩放 ——
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (Mathf.Abs(scroll) > 0.001f)
|
||||
{
|
||||
Vector3 desiredPosition = transform.position + transform.forward * scroll * zoomSpeed;
|
||||
|
||||
// 判断是否与障碍物发生碰撞
|
||||
if (!WillCollideWithObstacle(desiredPosition))
|
||||
{
|
||||
transform.position = desiredPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// —— 左键开始/结束旋转 ——
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
isRotating = true;
|
||||
lastMousePos = Input.mousePosition;
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
isRotating = false;
|
||||
}
|
||||
|
||||
// —— 左键拖拽:RotateAround 实现 + 俯仰限制 ——
|
||||
if (isRotating && Input.GetMouseButton(0))
|
||||
{
|
||||
Vector2 curr = Input.mousePosition;
|
||||
Vector2 delta = (curr - lastMousePos) * rotationSensitivity;
|
||||
lastMousePos = curr;
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
// 1. 水平绕世界 Y 轴旋转
|
||||
//Vector3 desiredPosition = transform.position;
|
||||
//transform.RotateAround(core, Vector3.up, delta.x);
|
||||
|
||||
Vector3 localPosHorizonal = transform.position - core;
|
||||
Quaternion rotationHorizonal = Quaternion.AngleAxis(delta.x, Vector3.up);
|
||||
Vector3 newLocalPosHorizonal = rotationHorizonal * localPosHorizonal;
|
||||
Vector3 newPosHorizonal = core + newLocalPosHorizonal;
|
||||
|
||||
|
||||
// 检查旋转后是否发生碰撞
|
||||
if (!WillCollideWithObstacle(newPosHorizonal))
|
||||
{
|
||||
// 如果没有碰撞,执行旋转
|
||||
transform.RotateAround(core, Vector3.up, delta.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果碰撞了,撤销旋转,恢复到原来的位置
|
||||
|
||||
}
|
||||
|
||||
// 2. 俯仰旋转
|
||||
Vector3 dir = (transform.position - core).normalized;
|
||||
Vector3 flat = new Vector3(dir.x, 0f, dir.z).normalized;
|
||||
float selfFlatX = transform.forward.x;
|
||||
float selfFlatZ = transform.forward.z;
|
||||
Vector3 selfFlat = new Vector3(selfFlatX, 0f, selfFlatZ).normalized;
|
||||
float selfPitch = Vector3.SignedAngle(selfFlat, transform.forward, transform.right);
|
||||
|
||||
|
||||
|
||||
if (selfPitch <= 80f && selfPitch >= 0f)
|
||||
{
|
||||
pitchDelta = delta.y * -1f;
|
||||
|
||||
|
||||
Vector3 localPosVertical = transform.position - core;
|
||||
Quaternion rotationVertical = Quaternion.AngleAxis(pitchDelta, transform.right);
|
||||
Vector3 newPosVertical = core + rotationVertical * localPosVertical;
|
||||
|
||||
|
||||
if (!WillCollideWithObstacle(newPosVertical))
|
||||
{
|
||||
transform.RotateAround(core, transform.right, pitchDelta);
|
||||
}
|
||||
|
||||
}
|
||||
else if (selfPitch > 80f)
|
||||
{
|
||||
pitchDelta = delta.y * -1f;
|
||||
if (pitchDelta < 0f)
|
||||
{
|
||||
transform.RotateAround(core, transform.right, pitchDelta);
|
||||
}
|
||||
}
|
||||
else if (selfPitch < 0f)
|
||||
{
|
||||
pitchDelta = delta.y * -1f;
|
||||
if (pitchDelta > 0f)
|
||||
{
|
||||
transform.RotateAround(core, transform.right, pitchDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 碰撞检测方法
|
||||
bool WillCollideWithObstacle(Vector3 targetPosition)
|
||||
{
|
||||
// 计算从当前位置到目标位置的方向和距离
|
||||
Vector3 moveDir = targetPosition - transform.position;
|
||||
float moveDist = moveDir.magnitude;
|
||||
|
||||
// 使用 SphereCast 检查即将到达的位置是否会与障碍物发生碰撞
|
||||
RaycastHit hit;
|
||||
if (Physics.SphereCast(transform.position, 0.5f, moveDir.normalized, out hit, moveDist, LayerMask.GetMask("Default"), QueryTriggerInteraction.Collide))
|
||||
{
|
||||
// 如果检测到碰撞,返回 true
|
||||
// Debug.Log("collider");
|
||||
return true;
|
||||
}
|
||||
else if (Vector3.Distance(targetPosition, reservoirCenter) < maxDistance && targetPosition.y < maxHeight)
|
||||
{
|
||||
// 如果在范围内,返回 false
|
||||
return false;
|
||||
}
|
||||
else
|
||||
// Debug.Log("outRange");
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void GetInScriptCore()
|
||||
{
|
||||
inScript = startinScript;
|
||||
}
|
||||
public void GetInScriptCore(Vector3 position)
|
||||
{
|
||||
inScript = position;
|
||||
}
|
||||
|
||||
public void StartCameraControl()
|
||||
{
|
||||
isCameraCtrl = true;
|
||||
isClickUI = false;
|
||||
}
|
||||
|
||||
//停止相机控制
|
||||
public void StopCameraControl()
|
||||
{
|
||||
isCameraCtrl = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/App/ControlMove.cs.meta
Normal file
11
Assets/Scripts/App/ControlMove.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a1e76e08ccc2f0488913f8e95f574e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
159
Assets/Scripts/App/GameDto.cs
Normal file
159
Assets/Scripts/App/GameDto.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//界面
|
||||
public enum PageType
|
||||
{
|
||||
Null,
|
||||
//镜头
|
||||
Camera1, //镜头-1
|
||||
Camera2, //镜头-2
|
||||
|
||||
//页面
|
||||
PnlMain, //主界面
|
||||
PnlPage1, //界面-1
|
||||
PnlPage2, //界面-2
|
||||
|
||||
//Icon
|
||||
Icon01,
|
||||
Icon02,
|
||||
Icon03,
|
||||
Icon04,
|
||||
Icon05,
|
||||
|
||||
//Effect
|
||||
Area01,
|
||||
Area02,
|
||||
|
||||
//Dialog
|
||||
DlgInfo01,
|
||||
DlgInfo02,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region 网络数据
|
||||
// 状态信息
|
||||
[System.Serializable]
|
||||
public class Status
|
||||
{
|
||||
public int code;
|
||||
public string msg;
|
||||
}
|
||||
// 设备列表返回数据
|
||||
[System.Serializable]
|
||||
public class JsonData
|
||||
{
|
||||
public Status status;
|
||||
public Result result;
|
||||
}
|
||||
// 设备详情返回数据
|
||||
[System.Serializable]
|
||||
public class JsonDetails
|
||||
{
|
||||
public Status status;
|
||||
public ResultDetails result;
|
||||
}
|
||||
|
||||
// 设备列表结果
|
||||
[System.Serializable]
|
||||
public class Result
|
||||
{
|
||||
public List<Device> device_list;
|
||||
}
|
||||
|
||||
// 设备详情结果
|
||||
[System.Serializable]
|
||||
public class ResultDetails
|
||||
{
|
||||
public int device_id;
|
||||
public string device_sn;
|
||||
public string device_name;
|
||||
public string online_status;
|
||||
public string pic;
|
||||
public string status;
|
||||
public string address;
|
||||
public string location;
|
||||
public DataPoints data_points;
|
||||
}
|
||||
|
||||
|
||||
// 设备信息
|
||||
[System.Serializable]
|
||||
public class Device
|
||||
{
|
||||
public int device_id;
|
||||
public string device_sn;
|
||||
public string device_name;
|
||||
public string online_status;
|
||||
public int project_id;
|
||||
public string pic;
|
||||
}
|
||||
|
||||
// 数据点信息
|
||||
[System.Serializable]
|
||||
public class Timeseries
|
||||
{
|
||||
public string point_id;
|
||||
public string name;
|
||||
public string alias;
|
||||
public string identifier;
|
||||
public string unitName;
|
||||
public string unitIdentifier;
|
||||
public string accessMode;
|
||||
public string dataType;
|
||||
public List<object> propertyEnum;
|
||||
public string value;
|
||||
public string callback_time;
|
||||
}
|
||||
|
||||
// 数据点信息
|
||||
[System.Serializable]
|
||||
public class DataPoints
|
||||
{
|
||||
public List<object> control;
|
||||
public List<Timeseries> timeseries;
|
||||
}
|
||||
|
||||
//传值web。把模型名称传过去
|
||||
[System.Serializable]
|
||||
public class DataToSend
|
||||
{
|
||||
public ResultDetails dataItem;
|
||||
public string iconName;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class IconData
|
||||
{
|
||||
public string device_sn;
|
||||
public string iconName;
|
||||
public string identifier;
|
||||
public Transform iconTransform;
|
||||
|
||||
public string cameraName;
|
||||
public Transform cameraTransform;
|
||||
|
||||
public IconData(string device_sn, string iconName, string identifier, Transform iconTransform,string cameraName,Transform cameraTransform)
|
||||
{
|
||||
this.device_sn = device_sn;
|
||||
this.iconName = iconName;
|
||||
this.identifier = identifier;
|
||||
this.iconTransform = iconTransform;
|
||||
this.cameraName = cameraName;
|
||||
this.cameraTransform = cameraTransform;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
11
Assets/Scripts/App/GameDto.cs.meta
Normal file
11
Assets/Scripts/App/GameDto.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04fa43d151cecb34d88b22f73ec60687
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/App/GameEvent.cs
Normal file
19
Assets/Scripts/App/GameEvent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class GameEvent
|
||||
{
|
||||
//相机控制
|
||||
public static UnityAction StartCameraControl;
|
||||
public static UnityAction StopCameraControl;
|
||||
|
||||
//UI页面控制
|
||||
public static UnityAction<PageType> OpenPage;
|
||||
public static UnityAction<PageType> ClosePage;
|
||||
public static UnityAction RefreshPage;
|
||||
|
||||
public static UnityAction<PageType, object> OpenDialog;
|
||||
|
||||
}
|
||||
11
Assets/Scripts/App/GameEvent.cs.meta
Normal file
11
Assets/Scripts/App/GameEvent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad594012b3427174cabb304db86ce09a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
95
Assets/Scripts/App/SceneUtil.cs
Normal file
95
Assets/Scripts/App/SceneUtil.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class SceneUtil : ActionBase
|
||||
{
|
||||
public Color color01;
|
||||
public Color color02;
|
||||
|
||||
// 辅助方法,用于初始化图标和相机列表
|
||||
private void InitializeIconAndCameraLists(string iconName, string cameraName, List<IconData> iconList, List<Transform> cameraList, string[] deviceSns, string[] iconNames, string[] identifiers)
|
||||
{
|
||||
iconList.Clear();
|
||||
cameraList.Clear();
|
||||
|
||||
Transform icon = transform.Find(iconName);
|
||||
Transform iconCamera = transform.Find(cameraName);
|
||||
|
||||
if (icon != null && iconCamera != null)
|
||||
{
|
||||
int count = Mathf.Min(icon.childCount, deviceSns.Length, iconNames.Length);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Transform currentIcon = icon.GetChild(i);
|
||||
Transform currentCamera = iconCamera.GetChild(i);
|
||||
|
||||
// 获取当前索引对应的设备信息
|
||||
string deviceSn = deviceSns[i];
|
||||
string name = iconNames[i];
|
||||
string identifier = identifiers[i];
|
||||
// 创建 IconData 实例并添加到 iconList
|
||||
IconData iconData = new IconData(deviceSn, name, identifier, currentIcon, currentCamera.name, currentCamera);
|
||||
iconList.Add(iconData);
|
||||
|
||||
cameraList.Add(currentCamera);
|
||||
}
|
||||
|
||||
icon.gameObject.SetActive(false);
|
||||
iconCamera.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
// 确保 AppCache 中的列表类型为 List<IconData>
|
||||
if (AppCache.iconPointList01 == null) AppCache.iconPointList01 = new List<IconData>();
|
||||
if (AppCache.iconPointList02 == null) AppCache.iconPointList02 = new List<IconData>();
|
||||
if (AppCache.iconPointList03 == null) AppCache.iconPointList03 = new List<IconData>();
|
||||
if (AppCache.iconPointList04 == null) AppCache.iconPointList04 = new List<IconData>();
|
||||
if (AppCache.iconPointList05 == null) AppCache.iconPointList05 = new List<IconData>();
|
||||
|
||||
// 初始化 GNSS 相关列表(12个设备)
|
||||
InitializeIconAndCameraLists("GNSS", "GNSS视角", AppCache.iconPointList01, AppCache.iconCameraList01,
|
||||
new string[] { "MS3P1475041092", "MS3P1475041038", "MS3P1475041023", "MS3P1475041053", "MS3P1475041070", "MS3P1475041068", "MS3P1475041098", "MS3P1475041020", "MS3P1475041030", "MS3P1475041014", "MS3P1475041096", "MS3P1475041084" },
|
||||
new string[] { "GNSS基准点1", "GNSS监测点1", "GNSS监测点2", "GNSS监测点3", "GNSS监测点4", "GNSS监测点5", "GNSS监测点6", "GNSS监测点7", "GNSS监测点8", "GNSS监测点9", "GNSS监测点10", "GNSS基准点2" },
|
||||
new string[] { "", "", "", "", "", "", "", "", "", "", "", "" });
|
||||
|
||||
// 初始化环境量监测相关列表(1个设备)
|
||||
InitializeIconAndCameraLists("环境量监测", "环境量监测视角", AppCache.iconPointList02, AppCache.iconCameraList02,
|
||||
new string[] { "2025042109" },
|
||||
new string[] { "环境量监测" },
|
||||
new string[] { "" });
|
||||
|
||||
// 初始化测缝针监测相关列表(9个设备)
|
||||
InitializeIconAndCameraLists("测缝针监测", "测缝计监测视角", AppCache.iconPointList03, AppCache.iconCameraList03,
|
||||
new string[] { "2025042106", "2025042103", "2025042105", "2025042104", "2025042107", "2025042102", "20250421A2", "20250421A1", "2025042101","2025042108" },
|
||||
new string[] { "测缝计1", "测缝计2", "测缝计3", "测缝计4", "测缝计5", "测缝计6", "测缝计7", "测缝计8", "测缝计9","测缝计10" },
|
||||
new string[] { "ff01", "ff01", "ff01", "ff01", "ff01", "ff01", "ff01", "ff01", "ff01","ff01" });
|
||||
|
||||
// 初始化加速度振动监测相关列表(6个设备)
|
||||
InitializeIconAndCameraLists("加速度振动监测", "加速度振动监测视角", AppCache.iconPointList04, AppCache.iconCameraList04,
|
||||
new string[] { "2025042106", "2025042103", "2025042107", "2025042102", "2025042101", "2025042108" },
|
||||
new string[] { "振动加速度1", "振动加速度2", "振动加速度3", "振动加速度4", "振动加速度5", "振动加速度6" },
|
||||
new string[] { "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05" });
|
||||
|
||||
// 初始化应变计监测相关列表(2个设备)
|
||||
InitializeIconAndCameraLists("应变计监测", "应变计监测视角", AppCache.iconPointList05, AppCache.iconCameraList05,
|
||||
new string[] { "20250421A2", "20250421A1", "20250421A2", "20250421A1", "20250421A2", "20250421A1" },
|
||||
new string[] { "6号桥墩表面应变监测", "3号桥墩表面应变监测", "5号桥墩表面应变监测", "2号桥墩表面应变监测", "4号桥墩表面应变监测", "1号桥墩表面应变监测" },
|
||||
new string[] { "ff20,ff21", "ff20,ff21", "ff26,ff27", "ff26,ff27", "ff24,ff25", "ff24,ff25" });
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
public override void RegisterAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void RemoveAction()
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/App/SceneUtil.cs.meta
Normal file
11
Assets/Scripts/App/SceneUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cac2717237eedc240969c5d04866da82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user