AGV 정보 창
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Collections;
|
||||
using Studio.AssetLibraryTree;
|
||||
using Studio;
|
||||
using System.Drawing.Printing;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
|
||||
namespace Studio.AssetTool
|
||||
{
|
||||
@@ -122,7 +123,7 @@ namespace Studio.AssetTool
|
||||
|
||||
public GameObject CreateAsset(string name)
|
||||
{
|
||||
AssetLibraryItem item = assetScrollView.FindItem("Palletrobot", AssetLibraryItemType.file);
|
||||
AssetLibraryItem item = assetScrollView.FindItem(name, AssetLibraryItemType.file);
|
||||
|
||||
OnAssetSelected(item);
|
||||
GameObject obj = selectRenderObject.gameObject;
|
||||
@@ -281,9 +282,17 @@ namespace Studio.AssetTool
|
||||
internal void OnSelectObjects(string name, List<GameObject> selectedObjects)
|
||||
{
|
||||
var canvas_Popup = EventConnector.instance.GetCanvas<Canvas_Popup>();
|
||||
canvas_Popup.panel_dynamicobjectinfo.SetObjectInfo(name, selectedObjects);
|
||||
canvas_Popup.panel_dynamicobjectinfo.SetActive(true);
|
||||
canvas_Popup.panel_agv.SetTarget(selectedObjects);
|
||||
if (ManagerHub.instance.Get<RunManager>().curState == RunManager.EState.Run)
|
||||
{
|
||||
canvas_Popup.panel_dynamicobjectinfo.gameObject.SetActive(false);
|
||||
canvas_Popup.panel_agv.SetTarget(selectedObjects);
|
||||
}
|
||||
else
|
||||
{
|
||||
canvas_Popup.panel_dynamicobjectinfo.SetObjectInfo(name, selectedObjects);
|
||||
canvas_Popup.panel_dynamicobjectinfo.SetActive(true);
|
||||
canvas_Popup.panel_agv.gameObject.SetActive(false);
|
||||
}
|
||||
canvas_Popup.panel_objectdistance.SelectObjectFromClick(name, selectedObjects);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Best.MQTT.Packets.Builders;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Studio.Conifg;
|
||||
using Studio.Setting.Connect;
|
||||
using Studio.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@@ -36,7 +37,7 @@ namespace Studio
|
||||
|
||||
public void MQTTCreateConnect(string MQTTDomain,string MQTTPort)
|
||||
{
|
||||
var conntedInfo = $"MQTT Domain : {MQTTDomain} , MQTTPORT :{MQTTPort}";
|
||||
var conntedInfo = CreateConntedInfo(MQTTDomain, MQTTPort);
|
||||
Debug.Log(conntedInfo);
|
||||
var port = int.Parse(MQTTPort);
|
||||
var options = new ConnectionOptionsBuilder()
|
||||
@@ -57,6 +58,23 @@ namespace Studio
|
||||
clients[conntedInfo].OnDisconnect += OnDisconnectedMQTT;
|
||||
clients[conntedInfo].OnError += OnErrorMQTT;
|
||||
}
|
||||
public string CreateConntedInfo(string MQTTDomain, string MQTTPort)
|
||||
{
|
||||
return $"MQTT Domain : {MQTTDomain} , MQTTPORT :{MQTTPort}";
|
||||
}
|
||||
public MQTTClient FindClient(string MQTTDomain, string MQTTPort)
|
||||
{
|
||||
string key = CreateConntedInfo(MQTTDomain, MQTTPort);
|
||||
if (clients.ContainsKey(key))
|
||||
{
|
||||
return clients[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ConnectPacketBuilder ConnectPacketBuilderCallback(MQTTClient client, ConnectPacketBuilder builder)
|
||||
{
|
||||
return builder.WithKeepAlive(60 * 60);//keep alive 1시간으로
|
||||
@@ -100,7 +118,6 @@ namespace Studio
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnStateChangedMQTT(MQTTClient client, ClientStates oldState, ClientStates newState)
|
||||
{
|
||||
Debug.Log($"{oldState} => {newState}");
|
||||
@@ -118,6 +135,17 @@ namespace Studio
|
||||
Debug.Log($"MQTT OnConnected");
|
||||
}
|
||||
|
||||
public void DisConnectMQTT()
|
||||
{
|
||||
foreach (var client in clients)
|
||||
{
|
||||
client.Value?.CreateDisconnectPacketBuilder()
|
||||
.WithReasonCode(DisconnectReasonCodes.NormalDisconnection)
|
||||
.WithReasonString($"{client.Value.Options.Host} Disconnecting")
|
||||
.BeginDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 구독
|
||||
/// </summary>
|
||||
@@ -140,6 +168,19 @@ namespace Studio
|
||||
.BeginUnsubscribe();
|
||||
}
|
||||
|
||||
public void UnSubscibeAll()
|
||||
{
|
||||
List<MQTTConnection> mqttConnections = ConfigConnected.MQTTSettings.mqttConnections;
|
||||
|
||||
foreach (var connection in mqttConnections)
|
||||
{
|
||||
foreach (var topic in connection.topics)
|
||||
{
|
||||
UnSubscibe(FindClient(connection.domain, connection.port), topic.topic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTopic(MQTTClient client, SubscriptionTopic topic, string topicName, ApplicationMessage message)
|
||||
{
|
||||
string payload = Encoding.UTF8.GetString(message.Payload.Data, message.Payload.Offset, message.Payload.Count);
|
||||
@@ -200,5 +241,6 @@ namespace Studio
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace Studio
|
||||
|
||||
public class StudioService : UnitySingleton<StudioService>
|
||||
{
|
||||
private Dictionary<string, Dictionary<string, EventHandler<StudioServiceIdEventArgs>>> listenerIdMap;
|
||||
private Dictionary<string, EventHandler<StudioServiceTypeEventArgs>> listenerTypeMap;
|
||||
private Dictionary<string, Dictionary<string, EventHandler<StudioServiceIdEventArgs>>> listenerIdMap =new();
|
||||
private Dictionary<string, EventHandler<StudioServiceTypeEventArgs>> listenerTypeMap = new();
|
||||
|
||||
private StudioRepoistory repository;
|
||||
private Dictionary<string, float> updateTime = new();
|
||||
@@ -76,24 +76,27 @@ namespace Studio
|
||||
private Dictionary<string, List<Topic>> topicTable = new();
|
||||
public Dictionary<string, List<Topic>> TopciTable { get { return topicTable; } }
|
||||
|
||||
public void ConnectMQTT(string domain, string port, List<Util.Topic> topics)
|
||||
public void Init()
|
||||
{
|
||||
this.repository = new StudioRepoistory();
|
||||
listenerIdMap = new Dictionary<string, Dictionary<string, EventHandler<StudioServiceIdEventArgs>>>();
|
||||
listenerTypeMap = new Dictionary<string, EventHandler<StudioServiceTypeEventArgs>>();
|
||||
|
||||
repository.OnTopicList += OnTopicList;
|
||||
|
||||
}
|
||||
public void ConnectMQTT(string domain, string port, List<Util.Topic> topics)
|
||||
{
|
||||
var conntedInfo = $"MQTT Domain : {domain} , MQTTPORT :{port}";
|
||||
if (!topicTable.ContainsKey(conntedInfo))
|
||||
topicTable.Add(conntedInfo, new());
|
||||
topicTable[conntedInfo] = topics;
|
||||
|
||||
repository.MQTTCreateConnect(domain, port);
|
||||
|
||||
repository.MQTTConnect(conntedInfo);
|
||||
}
|
||||
|
||||
public void DisConnectMQTT()
|
||||
{
|
||||
repository.DisConnectMQTT();
|
||||
}
|
||||
|
||||
private void OnTopicList(string type, Dictionary<string, Dictionary<string, string>> entities)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Studio.Manage
|
||||
Join(new AGVManager());
|
||||
Join(new AssetManager());
|
||||
Join(new SceneStartSettingService());
|
||||
Join(new RunManager());
|
||||
|
||||
foreach(var m in managers)
|
||||
{
|
||||
|
||||
71
Assets/Scripts/Studio/Managers/RunManager.cs
Normal file
71
Assets/Scripts/Studio/Managers/RunManager.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using NUnit.Framework;
|
||||
using Studio.Conifg;
|
||||
using Studio.Manage;
|
||||
using Studio.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Studio.Manage
|
||||
{
|
||||
public class RunManager : Manager
|
||||
{
|
||||
public event Action onRun;
|
||||
public event Action onStop;
|
||||
|
||||
public enum EState
|
||||
{
|
||||
Run,
|
||||
Stop,
|
||||
Exit,
|
||||
}
|
||||
|
||||
public EState curState = EState.Stop;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
StudioService.instance.Init();
|
||||
onRun += Dynamic.M.AGVManager.instance.OnPlayStart;
|
||||
onStop += StudioService.instance.DisConnectMQTT;
|
||||
}
|
||||
|
||||
public void ChangeState()
|
||||
{
|
||||
curState = curState == EState.Stop ? EState.Run : EState.Stop;
|
||||
Debug.Log("curState " + curState);
|
||||
switch (curState)
|
||||
{
|
||||
case EState.Run:
|
||||
Run();
|
||||
break;
|
||||
case EState.Stop:
|
||||
Stop();
|
||||
break;
|
||||
|
||||
case EState.Exit:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
MQTTConeect();
|
||||
onRun?.Invoke();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
onStop?.Invoke();
|
||||
}
|
||||
|
||||
public void MQTTConeect()
|
||||
{
|
||||
var mqttsettings = ConfigConnected.MQTTSettings;
|
||||
|
||||
foreach (var mqtt in mqttsettings.mqttConnections)
|
||||
{
|
||||
StudioService.instance.ConnectMQTT(mqtt.domain, mqtt.port, mqtt.topics);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Studio/Managers/RunManager.cs.meta
Normal file
2
Assets/Scripts/Studio/Managers/RunManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e365cd468c835846860290f5fa3f1aa
|
||||
@@ -23,6 +23,7 @@ namespace Studio.Dynamic.TwinObject
|
||||
Quaternion startRot;
|
||||
Quaternion endRot;
|
||||
|
||||
public Action<Dictionary<string, string>> onDataUpdate;
|
||||
public Dictionary<string, string> CurrentEntity;
|
||||
|
||||
private bool isPlay = false;
|
||||
@@ -82,6 +83,7 @@ namespace Studio.Dynamic.TwinObject
|
||||
s += "}";
|
||||
//Debug.Log(s);
|
||||
SetPos();
|
||||
onDataUpdate?.Invoke(CurrentEntity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Studio.Dynamic.M
|
||||
{
|
||||
public class AGVManager : UnitySingleton<AGVManager>
|
||||
{
|
||||
private GameObject prf_AGV;
|
||||
private CustomAssetRenderObject renderobject;
|
||||
private HashSet<AGV> agvs = new();
|
||||
public float AGVMoveSpeed;
|
||||
public float AGVRotateSpeed;
|
||||
@@ -20,20 +20,19 @@ namespace Studio.Dynamic.M
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
|
||||
//이벤트 걸어둔다..
|
||||
//+= OnPlayStart
|
||||
}
|
||||
public void OnPlayStart()
|
||||
{
|
||||
var type = GetComponent<CustomAssetRenderObject>().addTopic;
|
||||
var assets = ConfigConnected.AssetSettings;
|
||||
prf_AGV = assets[type].loadedObject;
|
||||
if (prf_AGV == null)
|
||||
{
|
||||
//todo::팝업메시지 나주엥 설정....
|
||||
return;
|
||||
}
|
||||
//var type = GetComponent<CustomAssetRenderObject>().addTopic;
|
||||
// var assets = ConfigConnected.AssetSettings;
|
||||
//prf_AGV = assets[type].loadedObject;
|
||||
//var connector = ManagerHub.instance.Get<CustomAssetConnector>();
|
||||
//ConnectedAsset searchAsset = connector.connectedAssets.FirstOrDefault(x => x.renderObject == renderobject);
|
||||
//searchAsset.assetData.assetName
|
||||
var type = "AGV";
|
||||
|
||||
StudioService.instance.AddTypeListener(type, OnDataUpdate);
|
||||
StudioService.instance.AddTypeIdListener(type);
|
||||
}
|
||||
@@ -61,7 +60,7 @@ namespace Studio.Dynamic.M
|
||||
|
||||
private AGV CreateAGV(string type, string id ,Dictionary<string,string> entity)
|
||||
{
|
||||
var agv = ManagerHub.instance.Get<CustomAssetConnector>().CreateAsset("AGV").AddComponent<AGV>();
|
||||
var agv = ManagerHub.instance.Get<CustomAssetConnector>().CreateAsset("Palletrobot").AddComponent<AGV>();
|
||||
//var agv = Instantiate<AGV>(prf_AGV,transform);
|
||||
|
||||
// var agv = Instantiate<GameObject>(prf_AGV,transform).AddComponent<AGV>();
|
||||
|
||||
@@ -26,12 +26,15 @@ namespace Studio.UI
|
||||
var renderObjectHandler = ManagerHub.instance.Get<RenderObjectHandler>();
|
||||
var fbxFileManager = ManagerHub.instance.Get<FBXFileManager>();
|
||||
var projectManager = ManagerHub.instance.Get<ProjectManager>();
|
||||
var runManager = ManagerHub.instance.Get<RunManager>();
|
||||
|
||||
statusPanel.SetMode(ModePanel.ProgramMode.ObjectLayout);
|
||||
|
||||
//panel_studiotopbar.onClickAssetLibraryWindow += fbxFileManager.LoadLocalData;
|
||||
panel_studiotopbar.onClickNewProject += () => CommandInvoker.instance.Invoke(new SaveProjectCommand());
|
||||
panel_studiotopbar.onClickSaveProject += () => CommandInvoker.instance.Invoke(new SaveProjectCommand());
|
||||
|
||||
panel_studiotopbar.onClickPlay += runManager.ChangeState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using XRLib.UI;
|
||||
using System.Linq;
|
||||
using Studio.Core;
|
||||
|
||||
namespace Studio.UI
|
||||
{
|
||||
@@ -12,30 +13,26 @@ namespace Studio.UI
|
||||
{
|
||||
public GameObject itemPrefab;
|
||||
public RectTransform Content;
|
||||
|
||||
private Dictionary<string, TMP_Text> keyToValueTextMap = new();
|
||||
private bool isInitialized = false;
|
||||
|
||||
private Dictionary<string, TMP_Text> textDict = new();
|
||||
private bool itemInit;
|
||||
public Dictionary<string, string> CurrentEntity;
|
||||
|
||||
private string targetId = string.Empty;
|
||||
|
||||
private AGV prevAgv;
|
||||
public override void AfterAwake()
|
||||
{
|
||||
itemPrefab = Resources.Load<GameObject>("Prefabs/UI/PRF_EntityItem");
|
||||
}
|
||||
|
||||
internal void OnUpdateData(object sender, StudioServiceIdEventArgs e)
|
||||
internal void OnUpdateData(Dictionary<string, string> entity)
|
||||
{
|
||||
if (!itemInit)
|
||||
{
|
||||
InstantiateUI(e.Entity);
|
||||
InstantiateUI(entity);
|
||||
itemInit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateUI(e.Entity);
|
||||
UpdateUI(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +41,20 @@ namespace Studio.UI
|
||||
if (selectedObjects.Count == 0)
|
||||
return;
|
||||
|
||||
GameObject selectedObject = selectedObjects[0];
|
||||
GameObject selectedObject = selectedObjects[0];
|
||||
if (prevAgv != null)
|
||||
{
|
||||
prevAgv.onDataUpdate -= InstantiateUI;
|
||||
prevAgv = null;
|
||||
}
|
||||
|
||||
if (selectedObject.TryGetComponent<AGV>(out AGV agv))
|
||||
{
|
||||
StudioService.instance.RemoveTypeIdListener("AGV", targetId);
|
||||
targetId = agv.name;
|
||||
StudioService.instance.AddTypeIdListener("AGV", targetId, OnUpdateData);
|
||||
var dic = agv.Info;
|
||||
SetActive(true);
|
||||
prevAgv = agv;
|
||||
OnUpdateData(dic);
|
||||
agv.onDataUpdate += OnUpdateData;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -66,7 +69,6 @@ namespace Studio.UI
|
||||
GameObject item = Instantiate(itemPrefab, Content);
|
||||
|
||||
var texts = item.GetComponentsInChildren<TMP_Text>();
|
||||
if (texts.Length < 2) continue;
|
||||
|
||||
TMP_Text keyText = texts[0];
|
||||
TMP_Text valueText = texts[1];
|
||||
@@ -74,7 +76,7 @@ namespace Studio.UI
|
||||
keyText.text = kvp.Key;
|
||||
valueText.text = kvp.Value;
|
||||
|
||||
keyToValueTextMap[kvp.Key] = valueText;
|
||||
textDict[kvp.Key] = valueText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,9 +84,9 @@ namespace Studio.UI
|
||||
{
|
||||
foreach (var kvp in entity)
|
||||
{
|
||||
if (keyToValueTextMap.TryGetValue(kvp.Key, out var valueText))
|
||||
if (textDict.TryGetValue(kvp.Key, out var txt))
|
||||
{
|
||||
valueText.text = kvp.Value;
|
||||
txt.text = kvp.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,13 @@ namespace Studio.UI
|
||||
/*Build*/
|
||||
public Button Button_Build;
|
||||
public Button Button_Run;
|
||||
|
||||
|
||||
public Button Button_Play;
|
||||
private Image playImage;
|
||||
public Sprite RunSprite;
|
||||
public Sprite StopSprite;
|
||||
public event Action onClickPlay;
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
Button_NewProject.onClick.AddListener(OnClickNewProject);
|
||||
@@ -52,9 +58,13 @@ namespace Studio.UI
|
||||
Button_AssetLibraryWindow.onClick.AddListener(OnClickAssetLibraryWindow);
|
||||
Button_HierarchyWindow.onClick.AddListener(OnClickHierarchyWindow);
|
||||
|
||||
|
||||
Button_Build.onClick.AddListener(OnClickBuild);
|
||||
Button_Run.onClick.AddListener(OnClickRun);
|
||||
|
||||
Button_Play.onClick.AddListener(OnClickPlay);
|
||||
playImage = Button_Play.GetComponent<Image>();
|
||||
RunSprite = Resources.Load<Sprite>("Images/Run");
|
||||
StopSprite = Resources.Load<Sprite>("Images/Stop");
|
||||
}
|
||||
|
||||
private void OnClickNewProject()
|
||||
@@ -118,5 +128,11 @@ namespace Studio.UI
|
||||
{
|
||||
onClickExit?.Invoke();
|
||||
}
|
||||
|
||||
private void OnClickPlay()
|
||||
{
|
||||
playImage.sprite = playImage.sprite == RunSprite ? StopSprite : RunSprite;
|
||||
onClickPlay?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user