Browse Source

点未绑定接口变更,加载信息放在配置文件加载完

develop
杨栋梁 12 months ago
parent
commit
72d03050d9
  1. 22
      Assets/Scripts/ANet/DeviceObjManager.cs
  2. 17
      Assets/Scripts/ANet/DevicePanelManager.cs
  3. 18
      Assets/Scripts/Common/GameManager.cs

22
Assets/Scripts/ANet/DeviceObjManager.cs

@ -1,3 +1,4 @@
using AX.MessageSystem;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections; using System.Collections;
@ -22,8 +23,21 @@ public class DeviceObjManager : MonoBehaviour
private void Awake() private void Awake()
{ {
MessageDispatcher.AddListener("ConfigLoadOver", ConfigLoadOver);
Instance = this; Instance = this;
} }
private void Start()
{
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("ConfigLoadOver", ConfigLoadOver);
}
private void ConfigLoadOver(IMessage obj)
{
LoadDeviceObjs();
}
private void Update() private void Update()
{ {
if (Input.GetKey(KeyCode.Q)) if (Input.GetKey(KeyCode.Q))
@ -48,10 +62,6 @@ public class DeviceObjManager : MonoBehaviour
} }
} }
} }
private void Start()
{
LoadDeviceObjs();
}
public DeviceObj GetDeviceByName(string dname) public DeviceObj GetDeviceByName(string dname)
{ {
DeviceObj result = null; DeviceObj result = null;
@ -118,7 +128,7 @@ public class DeviceObjManager : MonoBehaviour
public void SaveObjs() public void SaveObjs()
{ {
var json = JsonConvert.SerializeObject(NowPointList); var json = JsonConvert.SerializeObject(NowPointList);
string url = string.Format(HttpManager.Instance.PostBreakPointsById, objId); string url = string.Format(HttpManager.Instance.PostIOilTankById, objId);
if (Application.platform == RuntimePlatform.WebGLPlayer) if (Application.platform == RuntimePlatform.WebGLPlayer)
{ {
url = url.Substring(url.IndexOf("api") - 1); url = url.Substring(url.IndexOf("api") - 1);
@ -133,7 +143,7 @@ public class DeviceObjManager : MonoBehaviour
{ {
try try
{ {
string url = string.Format(HttpManager.Instance.GetBreakPointsById, objId); string url = string.Format(HttpManager.Instance.GetOilTankById, objId);
Debug.Log($"the url is :{ url}"); Debug.Log($"the url is :{ url}");
if (Application.platform == RuntimePlatform.WebGLPlayer) if (Application.platform == RuntimePlatform.WebGLPlayer)
{ {

17
Assets/Scripts/ANet/DevicePanelManager.cs

@ -9,6 +9,7 @@ using System.Security.Cryptography;
using System.IO; using System.IO;
using UnityEngine.Networking; using UnityEngine.Networking;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using AX.MessageSystem;
#region 接口数据类型 #region 接口数据类型
#pragma warning disable IDE1006 // 命名样式 #pragma warning disable IDE1006 // 命名样式
@ -263,13 +264,23 @@ public class DevicePanelManager : MonoBehaviour
#endregion #endregion
void Awake() void Awake()
{ {
MessageDispatcher.AddListener("ConfigLoadOver", ConfigLoadOver);
Instance = this; Instance = this;
} }
private void Start() private void Start()
{
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("ConfigLoadOver", ConfigLoadOver);
}
private void ConfigLoadOver(IMessage obj)
{ {
LoadDeciceData(); LoadDeciceData();
LoadDeviceObjConfig(); LoadDeviceObjConfig();
} }
public void RefreshData() public void RefreshData()
{ {
StopAllCoroutines(); StopAllCoroutines();
@ -626,7 +637,7 @@ public class DevicePanelManager : MonoBehaviour
{ {
try try
{ {
string url = string.Format(HttpManager.Instance.GetBreakPointsById, objId); string url = string.Format(HttpManager.Instance.GetOilTankById, objId);
Debug.Log($"the url is :{ url}"); Debug.Log($"the url is :{ url}");
if (Application.platform == RuntimePlatform.WebGLPlayer) if (Application.platform == RuntimePlatform.WebGLPlayer)
{ {
@ -673,7 +684,7 @@ public class DevicePanelManager : MonoBehaviour
DeviceObjManager.Instance.AddObj(bindName); DeviceObjManager.Instance.AddObj(bindName);
} }
var json = JsonConvert.SerializeObject(BindObjectList); var json = JsonConvert.SerializeObject(BindObjectList);
string url = string.Format(HttpManager.Instance.PostBreakPointsById, objId); string url = string.Format(HttpManager.Instance.PostIOilTankById, objId);
if (Application.platform == RuntimePlatform.WebGLPlayer) if (Application.platform == RuntimePlatform.WebGLPlayer)
{ {
url = url.Substring(url.IndexOf("api") - 1); url = url.Substring(url.IndexOf("api") - 1);
@ -687,7 +698,7 @@ public class DevicePanelManager : MonoBehaviour
public void SaveDeviceObjConfig() public void SaveDeviceObjConfig()
{ {
var json = JsonConvert.SerializeObject(BindObjectList); var json = JsonConvert.SerializeObject(BindObjectList);
string url = string.Format(HttpManager.Instance.PostBreakPointsById, objId); string url = string.Format(HttpManager.Instance.PostIOilTankById, objId);
if (Application.platform == RuntimePlatform.WebGLPlayer) if (Application.platform == RuntimePlatform.WebGLPlayer)
{ {
url = url.Substring(url.IndexOf("api") - 1); url = url.Substring(url.IndexOf("api") - 1);

18
Assets/Scripts/Common/GameManager.cs

@ -1,6 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
using AX.MessageSystem;
public class GameManager : Singleton<GameManager> public class GameManager : Singleton<GameManager>
{ {
@ -14,12 +15,12 @@ public class GameManager : Singleton<GameManager>
} }
public static void SaveConfig() public static void SaveConfig()
{ {
ConfigWebGL webConfig = new ConfigWebGL() {ServerAddress = Config.ServerAddress, BucketName = Config.BucketName, AreaName = Config.AreaName, CompanyName = Config.CompanyName }; ConfigWebGL webConfig = new ConfigWebGL() { ServerAddress = Config.ServerAddress, BucketName = Config.BucketName, AreaName = Config.AreaName, CompanyName = Config.CompanyName };
string json = JsonConvert.SerializeObject(webConfig, Formatting.Indented); string json = JsonConvert.SerializeObject(webConfig, Formatting.Indented);
string path = Path.Combine(Application.streamingAssetsPath, "Config.json"); string path = Path.Combine(Application.streamingAssetsPath, "Config.json");
using (StreamWriter streamWriter = File.CreateText(path)) using (StreamWriter streamWriter = File.CreateText(path))
{ {
streamWriter.Write(json); streamWriter.Write(json);
@ -32,7 +33,7 @@ public class GameManager : Singleton<GameManager>
{ {
if (b) if (b)
{ {
Debug.Log("================================================================"+json); Debug.Log("================================================================" + json);
} }
else else
{ {
@ -49,11 +50,12 @@ public class GameManager : Singleton<GameManager>
Config.Interval = webConfig.Interval; Config.Interval = webConfig.Interval;
Config.AlarmServer = webConfig.AlarmServer; Config.AlarmServer = webConfig.AlarmServer;
Config.AlarmInterval = webConfig.AlarmInterval; Config.AlarmInterval = webConfig.AlarmInterval;
Debug.Log("ServerAddress:" + Config.ServerAddress+" Interval:"+Config.Interval+" Range:"+Config.Range); Debug.Log("ServerAddress:" + Config.ServerAddress + " Interval:" + Config.Interval + " Range:" + Config.Range);
MessageDispatcher.SendMessage("ConfigLoadOver");
} }
}); });
} }
} }

Loading…
Cancel
Save