脚本API
主要介绍3D平台二开时常用的接口、API、类以及常量等内容。
# Interface
主要包括场景、设备、设备图标、UI控件以及UI弹窗/面板接口。
# ISceneNode
业务场景接口
public interface ISceneNode
{
/// <summary>
/// 场景的UI控件节点
/// </summary>
DeviceNodeBase UiPageRoot { get; }
/// <summary>
/// 场景的设备节点
/// </summary>
DeviceNodeBase DeviceRoot { get; }
/// <summary>
/// 场景是否已加载
/// </summary>
bool Loaded { get; }
/// <summary>
/// 场景名称
/// </summary>
string SceneName { get; }
/// <summary>
/// 场景Id
/// </summary>
string SceneId { get; }
/// <summary>
/// 添加设备节点
/// </summary>
/// <param name="SceneRoot">设备节点</param>
void AddDeviceRoot(SceneRoot deviceRoot);
}
# IDevice
设备接口
设备接口:IDevice
public interface IDevice
{
/// <summary>
/// 设备当前状态
/// </summary>
EquipState EquipState { get; }
/// <summary>
/// 设备模板数据
/// </summary>
DeviceResData DeviceResData { get; set; }
/// <summary>
/// IoT设备信息
/// </summary>
EquipBaseData IoTEquipInfo { get; }
/// <summary>
/// IoT遥测数据
/// </summary>
List<YcItemData> IoTYcDatas { get; }
/// <summary>
/// IoT遥信数据
/// </summary>
List<YxItemData> IoTYxDatas { get; }
/// <summary>
/// 设备状态发生变化事件,需关联IoT设备号。
/// </summary>
UnityEvent<EquipState> OnEquipChanged { get; }
/// <summary>
/// 设备视角
/// </summary>
Transform CameraView { get; }
/// <summary>
/// 设备是否在摄像头聚焦状态
/// </summary>
bool IsCameraMoved { get; set;}
/// <summary>
/// 当前设备实体
/// </summary>
DeviceLogic DeviceLogic { get; }
/// <summary>
/// 播放动画
/// </summary>
/// <param name="aniName"></param>
void AnimationPlay(string aniName);
/// <summary>
/// 摄像头取消聚焦设备时调用
/// </summary>
void CameraLeaved();
/// <summary>
/// 摄像头聚焦设备时调用
/// </summary>
void CameraMoved();
/// <summary>
/// 显示设备
/// </summary>
void Show();
/// <summary>
/// 隐藏设备
/// </summary>
void Hide();
/// <summary>
/// 设备初始化
/// </summary>
void Init();
/// <summary>
/// 点击设备
/// </summary>
/// <param name="cameraSpeed">动画速度</param>
void Click(float cameraSpeed = 1f);
/// <summary>
/// 定位设备
/// </summary>
void OnLocat();
/// <summary>
/// 选中设备
/// </summary>
void Select();
/// <summary>
/// 取消选中
/// </summary>
void UnSelect();
/// <summary>
/// 更新设备实时快照
/// </summary>
/// <param name="realTimeEventItem"></param>
void UpdateRealTimeEvent(RealTimeEventItem realTimeEventItem);
}
# IDeviceIcon
设备图标接口
设备图标接口:IDeviceIcon
public interface IDeviceIcon
{
/// <summary>
/// 图标初始化
/// </summary>
/// <param name="userData"></param>
void OnInit(object userData);
/// <summary>
/// 图标点击时
/// </summary>
void OnIconClick();
/// <summary>
/// 图标状态刷新
/// </summary>
void SetState();
/// <summary>
/// 鼠标进入时
/// </summary>
void MouseEnter();
/// <summary>
/// 鼠标离开时
/// </summary>
void MouseExit();
/// <summary>
/// 选中时
/// </summary>
void OnSelect();
/// <summary>
/// 取消选中时
/// </summary>
void UnSelect();
/// <summary>
/// 禁用时
/// </summary>
void OnDisable();
/// <summary>
/// 显示时
/// </summary>
void Show();
/// <summary>
/// 隐藏时
/// </summary>
void Hide();
}
# IUIControl
UI控件接口
UI控件接口:IUIControl
public interface IUIControl
{
/// <summary>
/// 初始化
/// </summary>
void OnInit();
/// <summary>
/// UI显示时
/// </summary>
void OnOpen();
/// <summary>
/// UI关闭时
/// </summary>
void OnClose();
}
# IUIForm
UI弹窗/面板接口
UI控件接口:IUIForm
/// <summary>
/// 界面接口。
/// </summary>
public interface IUIForm
{
/// <summary>
/// 获取界面序列编号。
/// </summary>
int SerialId
{
get;
}
/// <summary>
/// 获取界面资源名称。
/// </summary>
string UIFormAssetName
{
get;
}
/// <summary>
/// 获取界面实例。
/// </summary>
object Handle
{
get;
}
/// <summary>
/// 获取界面所属的界面组。
/// </summary>
IUIGroup UIGroup
{
get;
}
/// <summary>
/// 获取界面在界面组中的深度。
/// </summary>
int DepthInUIGroup
{
get;
}
/// <summary>
/// 获取是否暂停被覆盖的界面。
/// </summary>
bool PauseCoveredUIForm
{
get;
}
/// <summary>
/// 初始化界面。
/// </summary>
/// <param name="serialId">界面序列编号。</param>
/// <param name="uiFormAssetName">界面资源名称。</param>
/// <param name="uiGroup">界面所属的界面组。</param>
/// <param name="pauseCoveredUIForm">是否暂停被覆盖的界面。</param>
/// <param name="isNewInstance">是否是新实例。</param>
/// <param name="userData">用户自定义数据。</param>
void OnInit(int serialId, string uiFormAssetName, IUIGroup uiGroup, bool pauseCoveredUIForm, bool isNewInstance, object userData);
/// <summary>
/// 界面回收。
/// </summary>
void OnRecycle();
/// <summary>
/// 界面打开。
/// </summary>
/// <param name="userData">用户自定义数据。</param>
void OnOpen(object userData);
/// <summary>
/// 界面关闭。
/// </summary>
/// <param name="isShutdown">是否是关闭界面管理器时触发。</param>
/// <param name="userData">用户自定义数据。</param>
void OnClose(bool isShutdown, object userData);
/// <summary>
/// 界面暂停。
/// </summary>
void OnPause();
/// <summary>
/// 界面暂停恢复。
/// </summary>
void OnResume();
/// <summary>
/// 界面遮挡。
/// </summary>
void OnCover();
/// <summary>
/// 界面遮挡恢复。
/// </summary>
void OnReveal();
/// <summary>
/// 界面激活。
/// </summary>
/// <param name="userData">用户自定义数据。</param>
void OnRefocus(object userData);
/// <summary>
/// 界面轮询。
/// </summary>
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
void OnUpdate(float elapseSeconds, float realElapseSeconds);
/// <summary>
/// 界面深度改变。
/// </summary>
/// <param name="uiGroupDepth">界面组深度。</param>
/// <param name="depthInUIGroup">界面在界面组中的深度。</param>
void OnDepthChanged(int uiGroupDepth, int depthInUIGroup);
}
# API
IoTCenter3D提供的可调用接口。包括DeviceModule、RPCModule、SceneModule以及UIModule。
使用以上接口时需添加IoT3D.Framework
引用
using IoT3D.Framework
# DeviceModule
DeviceModule
可访问已部署三维设备接口 /// <summary>
/// 获取设备模块的管理器
/// </summary>
static IDeviceManager manager
namespace IoT3D.Framework
{
public interface IDeviceManager
{
/// <summary>
/// 设备选中发生变化事件
/// </summary>
event Action<DeviceLogic> DeviceSelectChanged;
/// <summary>
/// 选中的设备
/// </summary>
public DeviceLogic SelectionDevice { get; set; }
/// <summary>
/// 当前设备
/// </summary>
public DeviceLogic CurrentDevice { get; set; }
/// <summary>
/// 获取所有已部署的设备
/// </summary>
/// <returns></returns>
public List<DeviceLogic> GetAllDevice();
void SetDeviceResData(Dictionary<string, DeviceResData> datas);
/// <summary>
/// 获取设备模板数据
/// </summary>
/// <param name="resId"></param>
/// <returns></returns>
public DeviceResData GetDeviceResData(string resId);
/// <summary>
/// 设置设备图标
/// </summary>
/// <param name="deviceIcon">图标对象</param>
/// <param name="canvas">canvas</param>
void SetDeviceIcon(GameObject deviceIcon, Canvas canvas);
/// <summary>
/// 选中一个设备
/// </summary>
/// <param name="device">设备</param>
void SetSelection(DeviceLogic device,float cameraSpeed = 1f);
/// <summary>
/// 注册一个设备
/// </summary>
/// <param name="device"></param>
void Register(DeviceLogic device);
/// <summary>
/// 取消注册一个设备
/// </summary>
/// <param name="device"></param>
void UnRegister(DeviceLogic device);
/// <summary>
/// 取消选中一个设备
/// </summary>
/// <param name="device"></param>
void UnSelect(DeviceLogic device);
// void SetDeviceRoot(Transform root);
// void SetLocat(DeviceLogic device);
/// <summary>
/// 通过设备号获取一个设备
/// </summary>
/// <param name="equipNo"></param>
/// <returns></returns>
DeviceLogic GetDeviceByEquipNo(int equipNo);
/// <summary>
/// 实例化设备图标
/// </summary>
/// <param name="deviceIcon">自定义图标</param>
/// <returns></returns>
GameObject InstantiateIcon(IDeviceIcon deviceIcon);
/// <summary>
/// 实例化默认设备图标
/// </summary>
/// <returns></returns>
GameObject InstantiateIcon();
}
}
# RPCModule
RPCModule
通过 IRpcHelper Rpc 访问IoT数据GetYcValueData
/// <summary> /// 获取遥测数据 /// </summary> /// <param name="equipNo">设备号</param> /// <param name="ycNo">遥测号</param> /// <returns>string</returns> Task<string> GetYcValueData(int equipNo, int ycNo);
示例
//获取1000号设备的1号测点数据 _ = await RPCModule.Rpc.GetYcValueData(1000, 1);
GetYxValueData
/// <summary> /// 获取遥信数据 /// </summary> /// <param name="equipNo">设备号</param> /// <param name="ycNo">遥信号</param> /// <returns>string</returns> Task<string> GetYxValueData(int equipNo, int ycNo);
示例
//获取1000号设备的1号遥信数据 _ = await RPCModule.Rpc.GetYxValueData(1000, 1);
GetYcpListItemAsync
/// <summary> /// 获取设备所有遥测列表 /// </summary> /// <param name="equipNo">设备号</param> /// <returns>List<YcItemData></returns> Task<List<YcItemData>> GetYcpListItemAsync(int equipNo);
示例
//获取1000号设备 _ = await RPCModule.Rpc.GetYcpListItemAsync(1000);
GetYxpListItemAsync
/// <summary> /// 获取设备所有遥信列表 /// </summary> /// <param name="equipNo">设备号</param> /// <returns>List<YxItemData></returns> Task<List<YxItemData>> GetYxpListItemAsync(int equipNo);
示例
//获取1000号设备 _ = await RPCModule.Rpc.GetYcpListItemAsync(1000);
GetAsyncSQLData
/// <summary> /// 获取数据库表数据 /// </summary> /// <typeparam name="T">Json 序列化类</typeparam> /// <param name="sql">查询Sql语句</param> /// <returns></returns> Task<T> GetAsyncSQLData<T>(string sql);
示例
List<Model> Models = await RPCModule.Rpc.GetAsyncSQLData<List<Model>>("select ID,Name from GW_Models"); public class Model { public string ID; public string Name; }
SetParam
/// <summary> /// 执行设备控制命令 /// </summary> /// <param name="s_no">设备号</param> /// <param name="n_no">控制命令号</param> void SetParam(int s_no, int n_no); /// <summary> /// 执行设备控制命令 /// </summary> /// <param name="s_no">设备号</param> /// <param name="n_no">控制命令号</param> /// <param name="s_value">参数</param> void SetParam(int s_no, int n_no, string s_value);
示例
RPCModule.Rpc.SetParam(1000,1,"value");
GetDataFromCurveAsync
/// <summary> /// 获取测点历史数据 /// </summary> /// <param name="dateTimes">时间数组</param> /// <param name="eqNo">设备号</param> /// <param name="ycNo">遥测号</param> /// <param name="type">测点类型</param> /// <returns></returns> Task<List<myCurveData>> GetDataFromCurveAsync(List<DateTime> dateTimes, int eqNo, int ycNo, string type = "C");
GetChangedDataFromCurveAsync
/// <summary> /// 获取已变化的测点历史数据 /// </summary> /// <param name="bgn">开始时间</param> /// <param name="end">结束时间</param> /// <param name="eqNo">设备号</param> /// <param name="ycNo">遥测号</param> /// <param name="type">测点类型</param> /// <returns></returns> Task<List<myCurveData>> GetChangedDataFromCurveAsync(DateTime bgn, DateTime end, int eqNo, int ycNo, string type = "C");
- GetEquipEvent
/// <summary> /// 获取设备事件 /// </summary> /// <param name="equipNos">设备号列表</param> /// <param name="startTime">开始时间</param> /// <param name="endTime">结束时间</param> /// <param name="eventType">事件类型</param> /// <param name="pageSize">每页数据</param> /// <param name="pageIndex">页码</param> /// <returns></returns> Task<IoTEquipEventData> GetEquipEvent(List<int> equipNos,DateTime startTime,DateTime endTime, int pageSize = 20, int pageIndex = 1, IoTEquipEventType eventType = IoTEquipEventType.Equip_Event);
# SceneModule
SceneModule 场景管理器
CurrentSceneNode属性。
/// <summary> /// 当前场景 /// </summary> public static SceneNode CurrentSceneNode { get; }
示例
//打印当前场景名称 Debug.log(SceneModule.CurrentSceneNode.name);
LoadScene方法
/// <summary> /// 加载场景 /// </summary> /// <param name="sceneName">场景名称</param> public static void LoadScene(string sceneName);
示例
//加载首页场景 SceneModule.LoadScene("首页");
GetSceneNode方法
/// <summary> /// 获取指定场景 /// </summary> /// <param name="sceneName">场景名称</param> /// <returns></returns> public static SceneNode GetSceneNode(string sceneName);
示例
//获取首页所有设备 var devs = SceneModule.GetSceneNode("首页").DeviceRoot.GetDevices<DeviceLogic>();
SetCameraActive方法
/// <summary> /// 控制摄像机是否可以交互 /// 如 鼠标控制缩放、旋转、平移等 /// </summary> /// <param name="active"></param> public static void SetCameraActive(bool active);
示例
//取消交互画面会固定住 SceneModule.SetCameraActive(false);
SetCameraPoint方法
/// <summary> /// 设置摄像头位置 /// </summary> /// <param name="pos">坐标</param> /// <param name="rot">旋转角度</param> /// <param name="centerpoint">中心点位置</param> /// <param name="speed">速度</param> public static void SetCameraPoint(Vector3 pos, Vector3 rot, Vector3 centerpoint, float speed = 0)
AddSceneChangedListener
/// <summary> /// 切换场景时回调 /// </summary> /// <param name="unityAction">回调方法</param> public static void AddSceneChangedListener(UnityAction<SceneNode> unityAction);
示例
SceneModule.AddSceneChangedListener(OnSceneEnterChanged); void OnSceneEnterChanged(SceneNode sceneNode) { Debug.log(sceneNode.name); }
# UIModule
UIModule
UI面板管理器 1. OpenUIForm。 /// <summary>
/// 打开指定UI面板
/// </summary>
/// <param name="uiFormAssetName">UI名称</param>
/// <param name="groupName">UI层级</param>
/// <returns>IUIForm</returns>
public static IUIForm OpenUIForm(string uiFormAssetName, string groupName)
/// <summary>
/// 打开指定UI面板
/// </summary>
/// <param name="uiFormAssetName">UI名称</param>
/// <param name="groupName">UI层级</param>
/// <param name="userData">UI面板接收的数据</param>
/// <returns>IUIForm</returns>
public static IUIForm OpenUIForm(string uiFormAssetName, string groupName, object userData)
示例
//打开TimeselectorForm界面,层级为Dialog,传输数据为当前脚本对象
IUIForm uIForm = UIModule.OpenUIForm("TimeselectorForm", "Dialog", this);
CloseUIForm。
/// <summary> /// 关闭指定页面 /// </summary> /// <param name="uIForm">要关闭的UI</param> public static void CloseUIForm(IUIForm uIForm)
示例
IUIForm uIForm = UIModule.OpenUIForm("TimeselectorForm", "Dialog", this); if (uIForm != null) UIModule.CloseUIForm(uIForm);
# Class
在编写脚本时可能需要使用的一些最常用和最重要的IoTCenter3D内置类。
# SceneRoot
SceneRoot
创建新三维场景时要需要继承这个脚本,然后添加到场景中,以此IoT3D可识别和保存此场景内容。public abstract class SceneRoot : MonoBehaviour, ISceneRoot
{
/// <summary>
/// 场景灯光列表
/// </summary>
public List<Light> SceneLights;
/// <summary>
/// 场景meta数据
/// </summary>
public abstract MetaDataComponent metaDataComponent { get; set; }
/// <summary>
/// 获取设备节点
/// </summary>
public List<DeviceLogic> GetDeviceNodes { get; }
/// <summary>
/// 获取所有设备
/// </summary>
/// <returns></returns>
public abstract List<DeviceLogic> GetDevices();
/// <summary>
/// 获取所有设备MetaData数据
/// </summary>
/// <returns></returns>
public abstract List<MetaDataComponent> GetMetaDataComponents();
/// <summary>
/// 场景加载是回调
/// </summary>
public virtual void OnLoad();
/// <summary>
/// 场景保存时回调
/// </summary>
public virtual void OnSave();
}
# SceneNode
SceneNode
业务场景的节点public abstract class SceneNode : MonoBehaviour, ISceneNode
{
/// <summary>
/// 场景选中时事件
/// </summary>
public UnityAction<bool> SceneSelectChanged;
/// <summary>
/// UI控件节点
/// </summary>
public abstract DeviceNodeBase UiPageRoot { get; }
/// <summary>
/// 设备节点
/// </summary>
public abstract DeviceNodeBase DeviceRoot { get; }
/// <summary>
/// 场景配置数据
/// </summary>
public abstract SceneNodeData SceneData { get; }
/// <summary>
/// 场景是否已加载
/// </summary>
public abstract bool Loaded { get; }
/// <summary>
/// 场景是否已选中
/// </summary>
public abstract bool IsSelect { get; }
/// <summary>
/// 场景名称
/// </summary>
public abstract string SceneName { get; }
/// <summary>
/// 场景Id
/// </summary>
public abstract string SceneId { get; }
/// <summary>
/// 是否显示导航按钮
/// </summary>
public abstract bool ShowNavButton { get; }
/// <summary>
/// 添加设备节点
/// </summary>
/// <param name="deviceRoot">设备节点</param>
public abstract void AddDeviceRoot(SceneRoot deviceRoot);
/// <summary>
/// 隐藏场景
/// </summary>
public virtual void Hide();
}
# SceneNodeData
SceneNode
场景的配置数据模型public class SceneNodeData
{
/// <summary>
/// 场景的所呈现设备标签配置
/// </summary>
public List<EquipTagData> EquipTags { get; set; }
/// <summary>
/// 场景的图标资源,一般配合导航按钮使用
/// </summary>
public TextureAssetItem IconAssetItem { get; set; }
/// <summary>
/// 任务栏的位置设置
/// </summary>
public Vector2 TaskBarOffset { get; set; }
/// <summary>
/// 场景的保留值配置
/// </summary>
public string ValueCmd { get; set; }
/// <summary>
/// 场景风格名称
/// </summary>
public string StyleName { get; set; }
/// <summary>
/// 导航按钮的方向
/// </summary>
public NavigaOrientation NavigaOrientation { get; set; }
/// <summary>
/// 场景的类型
/// </summary>
public SceneType SceneType { get; set; }
/// <summary>
/// 场景摄像机的参数配置
/// </summary>
public CameraControlData CameraData { get; set; }
/// <summary>
/// 是否显示当前场景的导航按钮
/// </summary>
public bool ShowNavButton { get; set; }
/// <summary>
/// 场景镜头切换曲线
/// </summary>
public Ease CameraAniEase { get; set; }
/// <summary>
/// 场景切换速度
/// </summary>
public float CameraSpeed { get; set; }
/// <summary>
/// 场景的视角位置
/// </summary>
public Vector3 SceneRot { get; set; }
/// <summary>
/// 场景的视角角度
/// </summary>
public Vector3 ScenePos { get; set; }
/// <summary>
/// 场景节点类型
/// </summary>
public SceneNodeType NodeType { get; set; }
/// <summary>
/// 场景id
/// </summary>
public string Id { get; set; }
/// <summary>
/// 场景名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 场景三维文件
/// </summary>
public SceneAssetItem SceneItem { get; set; }
/// <summary>
/// 是否显示遮罩
/// </summary>
public bool MaskEnabled { get; set; }
}
# DeviceLogic
DeviceLogic
设备基类,所有设备须显式派生DeviceLogic类。public abstract class DeviceLogic : MonoBehaviour
{
/// <summary>
/// 是否告警
/// </summary>
public bool IsWar;
/// <summary>
/// 设备图标
/// </summary>
public DeviceIconBase deviceIcon;
/// <summary>
/// 设备图标资源
/// </summary>
public Sprite m_Icon;
/// <summary>
/// 是否创建设备图标
/// </summary>
public bool IsCreatIcon;
/// <summary>
/// 聚焦动画速度
/// </summary>
public float MovedSpeed;
/// <summary>
/// 定制化设备图标模板
/// </summary>
public DeviceIconBase DeviceIconTemplate;
/// <summary>
/// 设备动画
/// </summary>
public Animation m_Animation;
/// <summary>
/// 取消设备聚焦距离
/// </summary>
public float ExceedDistance;
/// <summary>
/// 是否允许定位
/// </summary>
public bool CanLocat;
/// <summary>
/// 是否显示
/// </summary>
public bool IsShow;
/// <summary>
/// 设备模型Transform
/// </summary>
public Transform Root;
/// <summary>
/// 设备MeteData 数据
/// </summary>
public MetaDataComponent MetaData { get; }
/// <summary>
/// 设备模板数据
/// </summary>
public DeviceResData DeviceResData { get; }
/// <summary>
/// 设备
/// </summary>
public IDevice Device { get; }
/// <summary>
/// IoT遥信数据
/// </summary>
public List<YxItemData> YxItemDatas { get; }
/// <summary>
/// IoT遥测数据
/// </summary>
public List<YcItemData> YcItemDatas { get; }
/// <summary>
/// 设备状态
/// </summary>
public EquipState EquipState { get; set; }
[SerializeProperty]
public DeviceDataModel DeviceData { get; set; }
/// <summary>
/// 是否已经聚焦
/// </summary>
public bool IsFocus { get; set; }
/// <summary>
/// 播放设备动画
/// </summary>
/// <param name="aniName">名称</param>
public virtual void AnimationPlay(string aniName);
/// <summary>
/// 摄像头取消聚焦设备时调用
/// </summary>
public virtual void CameraLeaved();
/// <summary>
/// 摄像头聚焦设备时调用
/// </summary>
public virtual void CameraMoved();
/// <summary>
/// 获取设备子项对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="includeInactive"></param>
/// <returns></returns>
public List<T> GetChildren<T>(bool includeInactive = false) where T : DeviceLogic;
/// <summary>
/// 获取父类设备
/// </summary>
/// <returns></returns>
public DeviceLogic GetParent();
/// <summary>
/// 是否有子设备
/// </summary>
/// <returns></returns>
public bool HasChildren();
/// <summary>
/// 隐藏设备
/// </summary>
public virtual void Hide();
/// <summary>
/// 定位回调
/// </summary>
public virtual void OnLocat();
/// <summary>
/// IoT3D平台序列化后
/// </summary>
public virtual void OnSerialized();
/// <summary>
/// 设备状态发生变化回调
/// </summary>
/// <param name="state"></param>
public virtual void OnStateChanged(EquipState state);
/// <summary>
/// 选中设备
/// </summary>
public virtual void Select();
/// <summary>
/// 设置报警回调
/// </summary>
/// <param name="isWar"></param>
public virtual void SetAlarm(bool isWar);
/// <summary>
/// 显示设备
/// </summary>
public virtual void Show();
/// <summary>
/// 取消选中
/// </summary>
public virtual void UnSelect();
/// <summary>
/// 关闭平台告警界面
/// </summary>
protected void CloseAlarmUIForm();
/// <summary>
/// 设备点击回调
/// </summary>
protected virtual void OnClick();
/// <summary>
/// 设备初始化回调
/// </summary>
protected virtual void OnInit();
/// <summary>
/// 打开平台告警界面
/// </summary>
protected void OpenAlarmUIForm();
}
# DeviceBase
DeviceBase
设备自定义基类,设备的基本功能实现,所有自定义设备都可以派生自该类,二次开发也可以重写实现逻辑。继承自DeviceLogic类。 这里说明它的特有属性
/// <summary>
/// 设备聚焦界面ID
/// </summary>
[SerializeProperty]
public DeviceFormId DeviceFormId { get; set; }
/// <summary>
/// 设备界面
/// </summary>
protected IUIForm m_DeviceForm;
/// <summary>
/// 设备告警弹窗界面
/// </summary>
[HideInInspector]
public DeviceAlarmUIForm m_DeviceAlarmForm;
/// <summary>
/// 设备是否在建筑/楼层统计界面中显示分类
/// </summary>
public bool ClassifyShow = true;
/// <summary>
/// 是否显示设备光影
/// </summary>
public bool ShowShadow = true;
# DeviceDataModel
DeviceDataModel
三维设备的数据模型public class DeviceDataModel
{
/// <summary>
/// 设备类型
/// </summary>
public string Type { get; set; }
/// <summary>
/// 设备名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 设备描述
/// </summary>
public string Desc { get; set; }
/// <summary>
/// 设备的IoT类型
/// </summary>
public EquipDataType DataType { get; set; }
/// <summary>
/// 设备号
/// </summary>
public int EquipNo { get; set; }
/// <summary>
/// 遥测/遥信号
/// </summary>
public int YcyxNo { get; set; }
/// <summary>
/// 设备视角位置
/// </summary>
public Vector3 ViewPos { get; set; }
/// <summary>
/// 设备视角角度
/// </summary>
public Vector3 ViewRot { get; set; }
/// <summary>
/// 设备保留值
/// </summary>
public string ValueCMD { get; set; }
/// <summary>
/// 设备发生告警时是否自动定位
/// </summary>
public bool AutoLocal { get; set; }
/// <summary>
/// 设备关联视频:rtsp或设备号
/// </summary>
public string RelatedVideo { get; set; }
/// <summary>
/// 设备id
/// </summary>
public string Id { get; set; }
/// <summary>
/// 设备标签
/// </summary>
public string[] Tags { get; set; }
}
# DeviceIconBase
DeviceIconBase
设备图标基类,继承MonoBehaviour类,并实现了IDeviceIcon接口。
public abstract class DeviceIconBase : MonoBehaviour, IDeviceIcon
{
/// <summary>
/// 设备图片资源
/// </summary>
public Image Icon;
/// <summary>
/// 当前设备
/// </summary>
protected DeviceLogic Device { get; }
/// <summary>
/// 隐藏图标
/// </summary>
public abstract void Hide();
/// <summary>
/// 当鼠标在图标上
/// </summary>
public abstract void MouseEnter();
/// <summary>
/// 当鼠标退出图标上
/// </summary>
public abstract void MouseExit();
/// <summary>
/// 当图标点击时
/// </summary>
public abstract void OnIconClick();
/// <summary>
/// 初始化图标
/// </summary>
/// <param name="userData"></param>
public virtual void OnInit(object userData);
/// <summary>
/// 图标选中
/// </summary>
public abstract void OnSelect();
/// <summary>
/// 设置图标状态
/// </summary>
public abstract void SetState();
/// <summary>
/// 显示图标
/// </summary>
public abstract void Show();
/// <summary>
/// 取消图标选中
/// </summary>
public abstract void UnSelect();
}
# DeviceUIFormBase
DeviceUIFormBase
UI弹窗基类,继承`UIFormLogic`类。# UIControl
SceneNode
UI控件基类,所有UI控件须显式派生自UIControl类。
public abstract class UIControl : MonoBehaviour, IUIControl
{
/// <summary>
/// 控件所在的Canvas
/// </summary>
protected Canvas canvas;
/// <summary>
/// 是否已经显示
/// </summary>
public bool IsOpen { get; set; }
/// <summary>
/// 当前Canvas
/// </summary>
public Canvas RectCanvas { get; set; }
/// <summary>
/// 当前RectTransform
/// </summary>
public RectTransform rectTransform { get; }
/// <summary>
/// 资源类型
/// </summary>
public abstract UIResEnum uIResEnum { get; }
/// <summary>
/// 资源名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 资源ID
/// </summary>
public string ResId { get; }
/// <summary>
/// 控件反序列化后调用
/// </summary>
public virtual void OnSerialized();
/// <summary>
/// 控件初始化时调用
/// </summary>
public virtual void OnInit();
/// <summary>
/// 控件显示时调用
/// </summary>
public virtual void OnOpen();
/// <summary>
/// 控件关闭时调用
/// </summary>
public virtual void OnClose();
/// <summary>
/// 控件每个10秒刷新一次回调
/// </summary>
public virtual void RefreshData();
/// <summary>
/// 保存控件信息
/// </summary>
public virtual void SetAllDirty();
/// <summary>
/// 更新控件UI
/// </summary>
public virtual void UpdateUI();
}
# UIResEnum
UIResEnum
UI控件的类型。# UIFormLogic
UIFormLogic
UI面板基类,所有UI弹窗必须显式派生自UIFormLogic public abstract class UIFormLogic : MonoBehaviour
{
protected UIFormLogic();
/// <summary>
/// 获取已缓存的 Transform。
/// </summary>
public Transform CachedTransform { get; }
/// <summary>
/// 获取界面是否可用。
/// </summary>
public bool Available { get; }
/// <summary>
/// 获取或设置界面名称。
/// </summary>
public string Name { get; set; }
/// <summary>
/// 获取界面。
/// </summary>
public IUIForm UIForm { get; }
/// <summary>
/// 获取或设置界面是否可见。
/// </summary>
public bool Visible { get; set; }
/// <summary>
/// 界面初始化。
/// </summary>
/// <param name="userData">用户自定义数据。</param>
public virtual void OnInit(object userData);
/// <summary>
/// 界面打开。
/// </summary>
/// <param name="userData">用户自定义数据。</param>
public virtual void OnOpen(object userData);
/// <summary>
/// 设置界面的可见性。
/// </summary>
/// <param name="visible">界面的可见性。</param>
public virtual void InternalSetVisible(bool visible);
/// <summary>
/// 界面关闭。
/// </summary>
/// <param name="isShutdown">是否是关闭界面管理器时触发。</param>
/// <param name="userData">用户自定义数据。</param>
public virtual void OnClose(bool isShutdown, object userData);
/// <summary>
/// 界面遮挡。
/// </summary>
public virtual void OnCover();
/// <summary>
/// 界面深度改变。
/// </summary>
/// <param name="uiGroupDepth">界面组深度。</param>
/// <param name="depthInUIGroup">界面在界面组中的深度。</param>
public virtual void OnDepthChanged(int uiGroupDepth, int depthInUIGroup);
/// <summary>
/// 界面暂停。
/// </summary>
public virtual void OnPause();
/// <summary>
/// 界面回收。
/// </summary>
public virtual void OnRecycle();
/// <summary>
/// 界面激活。
/// </summary>
/// <param name="userData">用户自定义数据。</param>
public virtual void OnRefocus(object userData);
/// <summary>
/// 界面暂停恢复。
/// </summary>
public virtual void OnResume();
/// <summary>
/// 界面遮挡恢复。
/// </summary>
public virtual void OnReveal();
/// <summary>
/// 界面轮询。
/// </summary>
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
public virtual void OnUpdate(float elapseSeconds, float realElapseSeconds);
}
# UIGroup
YcItemData
public enum UIGroup
{
/// <summary>
/// UI层
/// </summary>
UI = 1,
/// <summary>
/// 设备层
/// </summary>
DeviceUI = 2,
/// <summary>
/// 编辑器层
/// </summary>
Editor = 3,
/// <summary>
/// 设备图标层
/// </summary>
DeviceIconUI = 4,
/// <summary>
/// 弹窗层
/// </summary>
Dialog = 5
}
# YcItemData
YcItemData
IoT设备的遥测数据public class YcItemData : INotifyPropertyChanged
{
/// <summary>
/// 设备号
/// </summary>
public int EquipNo { get; set; }
/// <summary>
/// 是否布防
/// </summary>
public bool Bufang { get; set; }
/// <summary>
/// 遥测号
/// </summary>
public int YcNo { get; set; }
/// <summary>
/// 遥测名称
/// </summary>
public string YcName { get; set; }
/// <summary>
/// 单位
/// </summary>
public string Unit { get; set; }
/// <summary>
/// 关联视频
/// </summary>
public string RelatedVideo { get; set; }
/// <summary>
/// 关联图片
/// </summary>
public string RelatedPic { get; set; }
/// <summary>
/// 资产id
/// </summary>
public string ZiChanID { get; set; }
/// <summary>
/// 预案号
/// </summary>
public string PlanNo { get; set; }
/// <summary>
/// 是否告警
/// </summary>
public bool IsAlarm { get; set; }
/// <summary>
/// 报警时的处理意见
/// </summary>
public string AdviceMsg { get; set; }
/// <summary>
/// 是否有历史记录
/// </summary>
public bool HasHistoryCcurve { get; set; }
/// <summary>
/// 设备状态
/// </summary>
public int EquipState { get; set;}
/// <summary>
/// 测点实时值
/// </summary>
public RealTimeValue YcValue { get; set; } }
/// <summary>
/// 属性发生变化时事件
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
}
# YxItemData
YxItemData
IoT设备的遥信数据public class YxItemData : INotifyPropertyChanged
{
/// <summary>
/// 设备号
/// </summary>
public int EquipNo { get; set; }
/// <summary>
/// 是否布防
/// </summary>
public bool Bufang { get; set; }
/// <summary>
/// 遥信号
/// </summary>
public int YxNo { get; set; }
/// <summary>
/// 遥信名称
/// </summary>
public string YxName { get; set; }
/// <summary>
/// 关联视频
/// </summary>
public string RelatedVideo { get; set; }
/// <summary>
/// 关联图片
/// </summary>
public string RelatedPic { get; set; }
/// <summary>
/// 资产id
/// </summary>
public string ZiChanID { get; set; }
/// <summary>
/// 预案号
/// </summary>
public string PlanNo { get; set; }
/// <summary>
/// 是否告警
/// </summary>
public YXAlarm IsAlarm = new YXAlarm();
/// <summary>
/// 报警时的处理意见
/// </summary>
public string AdviceMsg { get; set; }
/// <summary>
/// 是否有历史记录
/// </summary>
public bool HasHistoryCcurve { get; set; }
/// <summary>
/// 设备状态
/// </summary>
public int EquipState { get; set; }
/// <summary>
/// 遥测状态值
/// </summary>
public string State { get; set; }
/// <summary>
/// 遥测实时值
/// </summary>
public RealTimeValue YxValue { get; set; }
/// <summary>
/// 属性发生变化时事件
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
}
# RealTimeValue
RealTimeValue
遥测/遥信的实时值,根据IoT平台配置可能是以下几种类型,需要开发者自行判断。public class RealTimeValue : INotifyPropertyChanged
{
/// <summary>
/// 测点字符串值
/// </summary>
public string StringValue { get; set; }
/// <summary>
/// 测点双精度类型值
/// </summary>
public double? DoubleValue { get; set; }
/// <summary>
/// 测点Int类型值
/// </summary>
public int? Temp { get; set; }
/// <summary>
/// 测点布尔值
/// </summary>
public bool BoolValue { get; set; }
/// <summary>
/// 属性值发生变化时事件
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
}
# EquipState
设备状态
EquipState
设备的IoT通讯状态,可以通过通讯状态进行设备数量的统计。
public enum EquipState
{
/// <summary>
/// 不通讯或者通讯故障
/// </summary>
NoCommunication = 0,
/// <summary>
/// 通讯正常
/// </summary>
CommunicationOK = 1,
/// <summary>
/// 有报警发生
/// </summary>
HaveAlarm = 2,
/// <summary>
/// 有设置在处理
/// </summary>
HaveSetParm = 3,
/// <summary>
/// 初始化
/// </summary>
Initial = 4,
/// <summary>
/// 撤防
/// </summary>
CheFang = 5,
/// <summary>
/// 未知状态
/// </summary>
None
}
# MetaDataComponent
MetaDataComponent
IoT3D场景编辑器中可以序列化的内容标记脚本,一般设备上必须添加此脚本才能被IoT3D编辑器识别和保存数据。public class MetaDataComponent : MonoBehaviour
{
/// <summary>
/// 资源id
/// </summary>
public string Id { get; }
/// <summary>
/// 资源类型 一般使用两种,Resource:资源设备,Instance:静态设备
/// </summary>
public AssetType AssetType { get; set; }
/// <summary>
/// meta数据
/// </summary>
public MetaData Metadata { get; set; }
/// <summary>
/// 生成静态id
/// </summary>
public void BuildInstanceID();
/// <summary>
/// 生成资源id
/// </summary>
public void BuildResourceID();
}
上次更新: 2024/10/11 14:01:13