fix merge

This commit is contained in:
lwj
2025-06-05 18:00:14 +09:00
45 changed files with 743 additions and 784 deletions

View File

@@ -51,8 +51,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7b5367f9feadcb94f922ceeb148ff63d, type: 3}
m_Name:
m_EditorClassIdentifier:
text_Label: {fileID: 836481912262468791}
text_Value: {fileID: 8842226809247879340}
Text_Label: {fileID: 836481912262468791}
Text_Value: {fileID: 8842226809247879340}
--- !u!222 &4086929857223959196
CanvasRenderer:
m_ObjectHideFlags: 0

View File

@@ -5955,6 +5955,10 @@ PrefabInstance:
propertyPath: projectMenuButton
value:
objectReference: {fileID: 205755441}
- target: {fileID: 4739726380097546759, guid: 6c1ed824d30fe8848957d865919227a0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5366961481726599031, guid: 6c1ed824d30fe8848957d865919227a0, type: 3}
propertyPath: m_LocalPosition.x
value: -1.2462957
@@ -6011,6 +6015,14 @@ PrefabInstance:
propertyPath: LogicContent
value:
objectReference: {fileID: 384003842}
- target: {fileID: 8164125700257988699, guid: 6c1ed824d30fe8848957d865919227a0, type: 3}
propertyPath: _apiConfigResourcePath
value: APIEndPointsConfig
objectReference: {fileID: 0}
- target: {fileID: 8164125700257988699, guid: 6c1ed824d30fe8848957d865919227a0, type: 3}
propertyPath: _webConfigResourcePath
value: WebConfig
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []

View File

@@ -5,9 +5,7 @@ using UnityEngine;
using System.Collections;
using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
using RTG;
using Unity.VisualScripting;
using Best.HTTP.JSON;
using Octopus.Simulator.Networks;
public class SimulationModelConveyor : SimulationModel
{

View File

@@ -3,8 +3,9 @@ using UnityEngine;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine.Events;
using Octopus.Simulator.Networks;
public class SimulationModelMove : SimulationModel
{
public string eventLoading = "transporter_loading";

View File

@@ -4,6 +4,8 @@ using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine.Events;
using Octopus.Simulator.Networks;
public class SimulationModelProcess : SimulationModel
{
public string eventUsingQueue = "processor_using_queue";

View File

@@ -2,6 +2,7 @@ using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
using UnityEngine;
using System.Collections;
using Octopus.Simulator.Networks;
public class SimulationModelSink : SimulationModel
{

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using Newtonsoft.Json.Linq;
using Best.HTTP.JSON;
using Octopus.Simulator.Networks;
public class SimulationModelSource : SimulationModel
{

View File

@@ -6,14 +6,14 @@ namespace Octopus.Simulator
public class LogicDataInfoItem : MonoBehaviour
{
[SerializeField]
TMP_Text text_Label;
TMP_Text Text_Label;
[SerializeField]
TMP_Text text_Value;
TMP_Text Text_Value;
public void Set(string label, string value)
{
text_Label.text = label;
text_Value.text = value;
Text_Label.text = label;
Text_Value.text = value;
}
}
}

View File

@@ -2,6 +2,7 @@ using UnityEngine;
using System;
using System.Collections.Generic;
using Octopus.Simulator.Networks;
using UVC.Networks;
using Newtonsoft.Json;
using UnityEngine.UI;
using System.Collections;
@@ -27,35 +28,14 @@ namespace Octopus.Simulator
public Dictionary<string, Button> dataMap = new Dictionary<string, Button>();
public Dictionary<string, Button> idMap = new Dictionary<string, Button>();
Panel_LogicData panelLogicData;
Panel_ConnectedObject panelConnectedObject;
Panel_PlacedObject panelPlacedObject;
public event Action<ILogicItem> onLogicButtonClicked;
public event Action onLogicDeSelected;
private void Awake()
{
panelLogicData = FindAnyObjectByType<Panel_LogicData>();
panelConnectedObject = FindAnyObjectByType<Panel_ConnectedObject>();
panelPlacedObject = FindAnyObjectByType<Panel_PlacedObject>();
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
onLogicButtonClicked += panelLogicData.OnLogicDataSelected;
onLogicButtonClicked += panelConnectedObject.OnLogicDataSelected;
onLogicButtonClicked += panelPlacedObject.OnLogicDataSelected;
onLogicDeSelected += panelLogicData.DataDeSelected;
onLogicDeSelected += panelConnectedObject.DataDeSelected;
onLogicDeSelected += panelPlacedObject.DataDeSelected;
backGround.onClick.AddListener(() => onLogicDeSelected?.Invoke());
panelPlacedObject.onPlacedObjectSelected += panelConnectedObject.OnLogicDataSelected;
FindAnyObjectByType<Panel_SimulationUI>().onLogicBTNClicked += SetActive;
panelLogicData.gameObject.SetActive(false);
panelConnectedObject.gameObject.SetActive(false);
panelPlacedObject.gameObject.SetActive(false);
//LogicWindow.gameObject.SetActive(false);
FindAnyObjectByType<WebReceiver>().onParameterRecived += RequestInfo;
FindAnyObjectByType<MQTTManager>().onLogicUpdated += RequestInfo;
}
@@ -80,7 +60,7 @@ namespace Octopus.Simulator
public void RequestInfo()
{
ClearLogicBTN();
WebManager.webManager.Request_Get($"{WebManager.webManager.apiConfig.logic}/{WebParameters.config.logicId}", (flag, value) =>
WebManager.Instance.Request_Get($"{WebManager.Instance.apiConfig.logic}/{WebParameters.config.logicId}", (flag, value) =>
{
if (flag)
{

View File

@@ -1,40 +1,41 @@
using Octopus.Simulator;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class LogicItemButton : MonoBehaviour
namespace Octopus.Simulator
{
[Header("UI References")]
[SerializeField] private Image iconImage;
[SerializeField] private TMP_Text nameText;
[SerializeField] private Button button;
[Header("Type Icons")]
[SerializeField] private Sprite resourceIcon;
[SerializeField] private Sprite storeIcon;
[SerializeField] private Sprite queueIcon;
[SerializeField] private Sprite productGeneratorIcon;
[SerializeField] private Sprite processorIcon;
[SerializeField] private Sprite transporterIcon;
[SerializeField] private Sprite shipmentIcon;
// 타입→아이콘 매핑
private Dictionary<LogicItemType, Sprite> IconMap;
private Dictionary<ComponentType, Sprite> componentMap;
/// <summary>
/// 외부에서 이 버튼을 초기화할 때 호출
/// </summary>
public void Setup(ILogicItem item)
public class LogicItemButton : MonoBehaviour
{
IconMap = new Dictionary<LogicItemType, Sprite>()
[Header("UI References")]
[SerializeField] private Image iconImage;
[SerializeField] private TMP_Text nameText;
[SerializeField] private Button button;
[Header("Type Icons")]
[SerializeField] private Sprite resourceIcon;
[SerializeField] private Sprite storeIcon;
[SerializeField] private Sprite queueIcon;
[SerializeField] private Sprite productGeneratorIcon;
[SerializeField] private Sprite processorIcon;
[SerializeField] private Sprite transporterIcon;
[SerializeField] private Sprite shipmentIcon;
// 타입→아이콘 매핑
private Dictionary<LogicItemType, Sprite> IconMap;
private Dictionary<ComponentType, Sprite> componentMap;
/// <summary>
/// 외부에서 이 버튼을 초기화할 때 호출
/// </summary>
public void Setup(ILogicItem item)
{
IconMap = new Dictionary<LogicItemType, Sprite>()
{
{ LogicItemType.Queue, queueIcon },
{ LogicItemType.Resource, resourceIcon },
{LogicItemType.Store,storeIcon }
};
componentMap = new Dictionary<ComponentType, Sprite>()
componentMap = new Dictionary<ComponentType, Sprite>()
{
{ ComponentType.Product_Generator,productGeneratorIcon },
{ ComponentType.Processor,processorIcon },
@@ -44,14 +45,15 @@ public class LogicItemButton : MonoBehaviour
};
if (item.ItemType != LogicItemType.Component)
{
iconImage.sprite = IconMap[item.ItemType];
if (item.ItemType != LogicItemType.Component)
{
iconImage.sprite = IconMap[item.ItemType];
}
else
{
iconImage.sprite = componentMap[(item as ILogicComponent).Type];
}
nameText.text = item.Label;
}
else
{
iconImage.sprite = componentMap[(item as ILogicComponent).Type];
}
nameText.text = item.Label;
}
}

View File

@@ -1,17 +0,0 @@
using UnityEngine;
using Octopus.Simulator;
using TMPro;
namespace Octopus.Simulator
{
public class LogicPlacedObjectButton : MonoBehaviour
{
[SerializeField]
TMP_Text text_Label;
public void Set(string name)
{
text_Label.text = name;
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: fcb433a8a5a1cb9499b04771da71feda

View File

@@ -1,14 +0,0 @@
using UnityEngine;
using TMPro;
public class ObjectPopup : MonoBehaviour
{
public TMP_Text label;
public TMP_Text data;
public void Set(string label,string data)
{
this.label.text = label;
this.data.text = data;
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 11558110f89df71498fc76c786f4dd9f

View File

@@ -19,12 +19,22 @@ namespace Octopus.Simulator
{ "위치","" },
{ "ID","" }
};
float panelPadding = 25f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Awake()
{
rect = GetComponent<RectTransform>();
}
private void Start()
{
var logicDataManager = FindAnyObjectByType<LogicDataManager>();
logicDataManager.onLogicButtonClicked += SetLogicDataItem;
logicDataManager.onLogicDeSelected += UnsetConnectedDataItem;
gameObject.SetActive(false);
}
void ClearItem()
{
foreach (var infoItem in infoItems)
@@ -51,15 +61,14 @@ namespace Octopus.Simulator
}
}
public void OnLogicDataSelected(ILogicItem item)
public void SetLogicDataItem(ILogicItem item)
{
gameObject.SetActive(true);
ClearItem();
GetObjectByName(item.Name);
float itemHeight = logicItem.GetComponent<RectTransform>().rect.height;
float panelHeight = dataMap.Count * itemHeight+25f;
rect.sizeDelta = new Vector2(rect.sizeDelta.x, panelHeight);
SetRectHeight(itemHeight);
int i = 0;
foreach (var p in dataMap)
{
@@ -74,15 +83,14 @@ namespace Octopus.Simulator
LayoutRebuilder.ForceRebuildLayoutImmediate(contentRect);
}
public void OnLogicDataSelected(string itemName)
public void SetConnectedDataItem(string itemName)
{
gameObject.SetActive(true);
ClearItem();
GetObjectByName(itemName);
float itemHeight = logicItem.GetComponent<RectTransform>().rect.height;
float panelHeight = dataMap.Count * itemHeight+25f;
rect.sizeDelta = new Vector2(rect.sizeDelta.x, panelHeight);
SetRectHeight(itemHeight);
int i = 0;
foreach (var p in dataMap)
{
@@ -97,7 +105,13 @@ namespace Octopus.Simulator
LayoutRebuilder.ForceRebuildLayoutImmediate(contentRect);
}
public void DataDeSelected()
void SetRectHeight(float itemHeight)
{
float panelHeight = dataMap.Count * itemHeight + panelPadding;
rect.sizeDelta = new Vector2(rect.sizeDelta.x, panelHeight);
}
public void UnsetConnectedDataItem()
{
gameObject.SetActive(false);
}

View File

@@ -14,12 +14,22 @@ namespace Octopus.Simulator
RectTransform rect;
[SerializeField]
RectTransform contentRect;
float panelPadding = 25f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
private void Awake()
{
rect = GetComponent<RectTransform>();
}
private void Start()
{
var logicDataManager = FindAnyObjectByType<LogicDataManager>();
logicDataManager.onLogicButtonClicked += SetLogicDataItem;
logicDataManager.onLogicDeSelected += UnsetLogicDataItem;
gameObject.SetActive(false);
}
void ClearItem()
{
foreach (var infoItem in infoItems)
@@ -29,7 +39,7 @@ namespace Octopus.Simulator
infoItems.Clear();
}
public void OnLogicDataSelected(ILogicItem item)
public void SetLogicDataItem(ILogicItem item)
{
gameObject.SetActive(true);
ClearItem();
@@ -49,8 +59,7 @@ namespace Octopus.Simulator
}
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
float itemHeight = logicItem.GetComponent<RectTransform>().rect.height;
float panelHeight = fields.Length * itemHeight+25f;
rect.sizeDelta = new Vector2(rect.sizeDelta.x, panelHeight);
SetRectHeight(fields.Length, itemHeight);
for (int i = 0; i < fields.Length; i++)
{
var rawValue = fields[i].GetValue(item);
@@ -63,7 +72,13 @@ namespace Octopus.Simulator
LayoutRebuilder.ForceRebuildLayoutImmediate(contentRect);
}
public void DataDeSelected()
void SetRectHeight(int count,float itemHeight)
{
float panelHeight = count * itemHeight + panelPadding;
rect.sizeDelta = new Vector2(rect.sizeDelta.x, panelHeight);
}
public void UnsetLogicDataItem()
{
gameObject.SetActive(false);
}

View File

@@ -8,10 +8,8 @@ namespace Octopus.Simulator
{
public class Panel_PlacedObject : MonoBehaviour
{
List<Button> buttons = new List<Button>();
[SerializeField]
Button ButtonPrefab;
RectTransform rect;
[SerializeField]
RectTransform contentRect;
[SerializeField]
@@ -22,10 +20,17 @@ namespace Octopus.Simulator
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Awake()
{
rect = GetComponent<RectTransform>();
DataManager.I.onModelsUpdated += (value)=>SetDropdown();
}
private void Start()
{
var logicDataManager = FindAnyObjectByType<LogicDataManager>();
logicDataManager.onLogicButtonClicked += SetPlacedObjectDataItem;
logicDataManager.onLogicDeSelected += UnsetPlacedObjectDataItem;
gameObject.SetActive(false);
}
public void SetDropdown(string mappingKey)
{
mappingkey = mappingKey;
@@ -87,8 +92,6 @@ namespace Octopus.Simulator
public void SetDropdown()
{
//gameObject.SetActive(true);
var models = DataManager.I.GetModels();
dropdown.onValueChanged.RemoveAllListeners();
@@ -142,22 +145,12 @@ namespace Octopus.Simulator
});
}
void ClearButton()
public void SetPlacedObjectDataItem(ILogicItem item)
{
foreach (var button in buttons)
{
Destroy(button.gameObject);
}
buttons.Clear();
}
public void OnLogicDataSelected(ILogicItem item)
{
ClearButton();
SetDropdown(item.Name);
}
public void DataDeSelected()
public void UnsetPlacedObjectDataItem()
{
mappingkey = "";
gameObject.SetActive(false);

View File

@@ -1,16 +0,0 @@
using UnityEngine;
public class ObjectPopupQueue : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 0bf03ce20dd84f0418dc4cff2bc2b37b

View File

@@ -1,24 +0,0 @@
using UnityEngine;
using System.Collections.Generic;
using Octopus.Simulator;
public class ObjectPopupSource : MonoBehaviour
{
Dictionary<string, string> UIList;
[SerializeField]
ObjectPopup prefab;
private void Start()
{
UIList = new Dictionary<string, string>()
{
{ "Input", "" },
{"최대 용량",""},
{"불량","" }
};
}
public void Set(ILogicItem queue)
{
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: b78637c5fbc37034cb641a2d77a37b4d

View File

@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine.UIElements;
using Octopus.Simulator.Networks;
namespace Octopus.Simulator

View File

@@ -1,48 +1,51 @@
using UnityEngine;
using System.Collections.Generic;
public class LogicMappingDataBase : MonoBehaviour
namespace Octopus.Simulator
{
static Dictionary<string, SimulationModel> mappingObjectDict = new Dictionary<string, SimulationModel>();
public static void SetMapping(string name, SimulationModel target)
public class LogicMappingDataBase : MonoBehaviour
{
if (mappingObjectDict.ContainsKey(name))
static Dictionary<string, SimulationModel> mappingObjectDict = new Dictionary<string, SimulationModel>();
public static void SetMapping(string name, SimulationModel target)
{
if (target)
if (mappingObjectDict.ContainsKey(name))
{
mappingObjectDict[name] = target;
target.nodeID = name;
target.SetPopupData();
if (target)
{
mappingObjectDict[name] = target;
target.nodeID = name;
target.SetPopupData();
}
else
{
mappingObjectDict[name].DeletePopupData();
mappingObjectDict.Remove(name);
}
}
else
{
mappingObjectDict[name].DeletePopupData();
mappingObjectDict.Remove(name);
target.SetPopupData();
mappingObjectDict.Add(name, target);
target.nodeID = name;
}
}
else
{
target.SetPopupData();
mappingObjectDict.Add(name, target);
target.nodeID = name;
}
}
public static SimulationModel GetGameObject(string name)
{
if (mappingObjectDict.ContainsKey(name))
public static SimulationModel GetGameObject(string name)
{
return mappingObjectDict[name];
if (mappingObjectDict.ContainsKey(name))
{
return mappingObjectDict[name];
}
else
{
return null;
}
}
else
{
return null;
}
}
public static void LoadDataBase(Dictionary<string, SimulationModel> db)
{
mappingObjectDict = db;
public static void LoadDataBase(Dictionary<string, SimulationModel> db)
{
mappingObjectDict = db;
}
}
}

View File

@@ -4,46 +4,35 @@ using System.Collections.Concurrent;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class MQTTDataBase : MonoBehaviour
namespace Octopus.Simulator.Networks
{
public static MQTTDataBase Instance;
public ConcurrentDictionary<string, ConcurrentQueue<Dictionary<string, object>>> mqttDataBase;
public ConcurrentDictionary<string, ConcurrentQueue<JObject>> mqttData = new ConcurrentDictionary<string, ConcurrentQueue<JObject>>();
private void Awake()
public class MQTTDataBase : MonoBehaviour
{
mqttDataBase = new ConcurrentDictionary<string, ConcurrentQueue<Dictionary<string, object>>>();
Instance = this;
}
public static MQTTDataBase Instance;
public ConcurrentDictionary<string, ConcurrentQueue<Dictionary<string, object>>> mqttDataBase;
public ConcurrentDictionary<string, ConcurrentQueue<JObject>> mqttData = new ConcurrentDictionary<string, ConcurrentQueue<JObject>>();
public void AddDict(string key, string value)
{
Debug.Log("#### : " + key + " : " + value);
JObject json = JObject.Parse(value);
var queue = mqttData.GetOrAdd(key, _ => new ConcurrentQueue<JObject>());
queue.Enqueue(json);
//var dicts = JsonConvert.DeserializeObject<Dictionary<string, object>>(value);
//
//// 해당 key가 없으면 새 큐를 생성하고, 이미 있으면 기존 큐를 반환
//var queue = mqttDataBase.GetOrAdd(key, _ => new ConcurrentQueue<Dictionary<string, object>>());
//queue.Enqueue(dicts);
}
//public ConcurrentQueue<Dictionary<string, object>> GetDataQueue(string id)
//{
// if (mqttDataBase.TryGetValue(id, out ConcurrentQueue<Dictionary<string, object>> dataQueue))
// {
// return dataQueue;
// }
// return null;
//}
public ConcurrentQueue<JObject> GetDataQueue(string id)
{
if (mqttData.TryGetValue(id, out ConcurrentQueue<JObject> dataQueue))
private void Awake()
{
return dataQueue;
mqttDataBase = new ConcurrentDictionary<string, ConcurrentQueue<Dictionary<string, object>>>();
Instance = this;
}
public void AddDict(string key, string value)
{
Debug.Log("#### : " + key + " : " + value);
JObject json = JObject.Parse(value);
var queue = mqttData.GetOrAdd(key, _ => new ConcurrentQueue<JObject>());
queue.Enqueue(json);
}
public ConcurrentQueue<JObject> GetDataQueue(string id)
{
if (mqttData.TryGetValue(id, out ConcurrentQueue<JObject> dataQueue))
{
return dataQueue;
}
return null;
}
return null;
}
}

View File

@@ -3,14 +3,9 @@ using Best.MQTT;
using Best.MQTT.Packets;
using Best.MQTT.Packets.Builders;
using Newtonsoft.Json;
using System.IO;
using System;
using System.Collections.Generic;
using System.Text;
using TMPro;
using System.Collections;
using Octopus.Simulator;
using Best.HTTP.JSON;
namespace Octopus.Simulator.Networks
{
@@ -53,14 +48,6 @@ namespace Octopus.Simulator.Networks
public void SetMqttConfig()
{
/*
string path = Application.streamingAssetsPath + MQTTpath;
string json;
using (StreamReader reader = new StreamReader(path))
{
json = reader.ReadToEnd();
}
*/
TextAsset json = Resources.Load<TextAsset>(MQTTpath);
MQTTConfigList ConfigList = JsonConvert.DeserializeObject<MQTTConfigList>(json.text);
var config = ConfigList.configs[0];
@@ -73,16 +60,6 @@ namespace Octopus.Simulator.Networks
public void SetMqttConfig(string json)
{
/*
string path = Application.streamingAssetsPath + MQTTpath;
string json;
using (StreamReader reader = new StreamReader(path))
{
json = reader.ReadToEnd();
}
TextAsset json = Resources.Load<TextAsset>(MQTTpath);
Debug.Log(json.text);
*/
MQTTConfigList ConfigList = JsonConvert.DeserializeObject<MQTTConfigList>(json);
var config = ConfigList.configs[0];
string clientName = config.name;
@@ -146,7 +123,6 @@ namespace Octopus.Simulator.Networks
private void OnMessage(MQTTClient client, SubscriptionTopic topic, string topicName, ApplicationMessage message)
{
var payload = Encoding.UTF8.GetString(message.Payload.Data, message.Payload.Offset, message.Payload.Count);
//Debug.Log(payload);
if (topicName.Contains("completed"))
{
return;
@@ -155,8 +131,6 @@ namespace Octopus.Simulator.Networks
{
basemessage = JsonConvert.DeserializeObject<BaseSimulationMessage>(payload);
MQTTDataBase.Instance.AddDict(basemessage.component_id, payload);
//LogicMappingDataBase.GetGameObject(basemessage.component_id).UpdatePopupData(payload);
//onMessageReceived?.Invoke(basemessage.component_id, payload);
}
if (topicName.Contains("middleware"))
{

View File

@@ -64,14 +64,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 128c906b71c22fb428a05e13831af396, type: 3}
m_Name:
m_EditorClassIdentifier:
_webConfigResourcePath: WebConfig
_apiConfigResourcePath: APIEndPointsConfig
apiConfig:
history:
model:
logic:
project:
analyses:
WebPath: WebConfig
ApiPath: APIEndPointsConfig
--- !u!114 &6191105916327120908
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -85,9 +85,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
currentData:
id: 0
projectId: 0
userId: 0
name:
simulationCode:
data:
@@ -97,7 +94,6 @@ MonoBehaviour:
resources: []
stores: []
components: []
simulation_time: 0
webConfig:
nodes: []
edges: []
@@ -106,11 +102,13 @@ MonoBehaviour:
createdAt:
updatedAt:
deletedAt:
ModelFiles: []
config:
nodes: []
edges: []
logicPrefab: {fileID: 2210399282865539074, guid: 72314043a41090846a8c16ad04f3c028, type: 3}
LogicWindow: {fileID: 0}
LogicContent: {fileID: 0}
linePrefab: {fileID: 6254276411767355245, guid: c899c98324602eb4fbe900753508f64d, type: 3}
backGround: {fileID: 0}
references:
@@ -141,6 +139,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
text: {fileID: 0}
projectMenuButton: {fileID: 0}
menuPanel: {fileID: 0}
--- !u!1 &2069922514250663687
GameObject:
m_ObjectHideFlags: 0
@@ -192,6 +192,7 @@ MonoBehaviour:
projectId:
logicId:
simulationId:
modelId:
--- !u!1 &6518512601816170710
GameObject:
m_ObjectHideFlags: 0

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using Octopus.Simulator.Networks;
using Newtonsoft.Json;
using TMPro;
using UVC.Networks;
namespace Octopus.Simulator
{
@@ -35,7 +36,7 @@ namespace Octopus.Simulator
private void Start()
{
webmanager = WebManager.webManager;
webmanager = WebManager.Instance;
Button_Play.onClick.AddListener(OnClickPlayBTN);
Button_FastForward.onClick.AddListener(OnclickFastForwardBTN);
Button_Logic.onClick.AddListener(OnclickLogicBTN);

View File

@@ -1,42 +1,46 @@
using Octopus.Simulator.Networks;
using UVC.Networks;
using UnityEngine;
using Newtonsoft.Json;
using UnityEngine.UI;
using TMPro;
using Octopus.Simulator.Networks;
public class ProjectDataManager : MonoBehaviour
namespace Octopus.Simulator
{
[SerializeField]
TMP_Text text;
[SerializeField]
Button projectMenuButton;
[SerializeField]
RectTransform menuPanel;
public class ProjectDataManager : MonoBehaviour
{
[SerializeField]
TMP_Text text;
[SerializeField]
Button projectMenuButton;
[SerializeField]
RectTransform menuPanel;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
FindAnyObjectByType<WebReceiver>().onParameterRecived += RequestInfo;
projectMenuButton.onClick.AddListener(SetActive);
}
public void RequestInfo()
{
WebManager.webManager.Request_Get($"{WebManager.webManager.apiConfig.project}/{WebParameters.config.projectId}", (flag, value) =>
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
if (flag)
FindAnyObjectByType<WebReceiver>().onParameterRecived += RequestInfo;
projectMenuButton.onClick.AddListener(SetActive);
}
public void RequestInfo()
{
WebManager.Instance.Request_Get($"{WebManager.Instance.apiConfig.project}/{WebParameters.config.projectId}", (flag, value) =>
{
var info = JsonConvert.DeserializeObject<ProjectInfo>(value);
SetText(info.data.name);
}
});
}
if (flag)
{
var info = JsonConvert.DeserializeObject<ProjectInfo>(value);
SetText(info.data.name);
}
});
}
void SetText(string data)
{
text.text = data;
}
void SetActive()
{
menuPanel.gameObject.SetActive(!menuPanel.gameObject.activeSelf);
void SetText(string data)
{
text.text = data;
}
void SetActive()
{
menuPanel.gameObject.SetActive(!menuPanel.gameObject.activeSelf);
}
}
}

View File

@@ -1,43 +1,45 @@
using UnityEngine;
using System;
using System.Collections.Generic;
[Serializable]
public class ProjectInfo
{
public ProjectInfoData data;
}
[Serializable]
public class WebModelClass
namespace Octopus.Simulator.Networks
{
public int logicId;
public string name;
public string description;
public WebModelData data=new WebModelData();
}
[Serializable]
public class ProjectInfo
{
public ProjectInfoData data;
}
[Serializable]
public class WebModelData
{
public string info;
}
[Serializable]
public class WebModelClass
{
public int logicId;
public string name;
public string description;
public WebModelData data = new WebModelData();
}
[Serializable]
public class WebModelReturnClass
{
public WebModelReturnData data;
}
[Serializable]
public class WebModelData
{
public string info;
}
[Serializable]
public class WebModelReturnData
{
public int insertedId;
}
[Serializable]
public class WebModelReturnClass
{
public WebModelReturnData data;
}
[Serializable]
[SerializeField]
public class ProjectInfoData
{
public string name;
[Serializable]
public class WebModelReturnData
{
public int insertedId;
}
[Serializable]
public class ProjectInfoData
{
public string name;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 347b34afd66f57e4f8bc6c51f500cb5a
guid: 1084d0846d0215548a4eb3759dba7460
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using UnityEngine;
using Octopus.Simulator.Networks;
namespace UVC.Networks
{
public class ApiConfigLoader
{
public APIEndPointsConfig ApiConfig { get; private set; }
public APIEndPointsConfig LoadFromResources(string resourcePath)
{
TextAsset jsonAsset = Resources.Load<TextAsset>(resourcePath);
if (jsonAsset == null)
{
Debug.LogError($"ApiConfig 리소스를 찾을 수 없습니다: {resourcePath}");
return null;
}
ApiConfig = JsonConvert.DeserializeObject<APIEndPointsConfig>(jsonAsset.text);
return ApiConfig;
}
public APIEndPointsConfig LoadFromJsonString(string json)
{
ApiConfig = JsonConvert.DeserializeObject<APIEndPointsConfig>(json);
return ApiConfig;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b35b558cb96a7cc4885672f67a56c149

View File

@@ -2,7 +2,7 @@ using UnityEngine;
using System;
using System.Collections.Generic;
namespace Octopus.Simulator.Networks
namespace UVC.Networks
{
[Serializable]
public class WebConfigList
@@ -10,6 +10,16 @@ namespace Octopus.Simulator.Networks
public List<WebConfig> configs = new List<WebConfig>();
}
[Serializable]
public class WebConfig
{
public string host;
public int port;
public string accessToken;
}
}
namespace Octopus.Simulator.Networks
{
[Serializable]
public class SimulatorConfig
{
@@ -20,14 +30,6 @@ namespace Octopus.Simulator.Networks
public string modelId;
}
[Serializable]
public class WebConfig
{
public string host;
public int port;
public string accessToken;
}
[Serializable]
public class APIEndPointsConfig
{

View File

@@ -0,0 +1,37 @@
using UnityEngine;
using Newtonsoft.Json;
namespace UVC.Networks
{
public class WebConfigLoader
{
public string Host { get; private set; }
public int Port { get; private set; }
public string Token { get; private set; }
public string BaseUrl => $"{Host}:{Port}";
public void LoadFromResources(string resourcePath)
{
TextAsset jsonAsset = Resources.Load<TextAsset>(resourcePath);
if (jsonAsset == null)
{
Debug.LogError($"WebConfig 리소스를 찾을 수 없습니다: {resourcePath}");
return;
}
WebConfigList configList = JsonConvert.DeserializeObject<WebConfigList>(jsonAsset.text);
var config = configList.configs[0];
Host = config.host;
Port = config.port;
Token = config.accessToken;
}
public void LoadFromJsonString(string json)
{
WebConfigList configList = JsonConvert.DeserializeObject<WebConfigList>(json);
var config = configList.configs[0];
Host = config.host;
Port = config.port;
Token = config.accessToken;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 811a195eb21a7e9449e289071b70bcc2

View File

@@ -1,16 +1,12 @@
using Newtonsoft.Json;
using Octopus.Simulator.Networks;
using System.Collections;
using Octopus.Simulator.Networks;
using System.Collections.Generic;
using System.IO;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
using UnityEngine.Networking;
using Octopus.Simulator;
using TMPro;
using Best.HTTP.JSON.LitJson;
namespace Octopus.Simulator.Networks
namespace UVC.Networks
{
//API를 통해 서버와 통신하기 위한 함수들이 내장되어 있습니다.
//Post, Get. Put을 사용하며, Post의 경우엔 Class를 입력으로 받아 Json형식으로 변환하여 업로드합니다.
@@ -18,77 +14,48 @@ namespace Octopus.Simulator.Networks
//정상적으로 API가 입력, 결과가 출력되었는지를 확인할 수 있습니다.
public class WebManager : MonoBehaviour
{
public static WebManager webManager;
static WebManager webManager;
public static WebManager Instance
{
get
{
if (webManager == null)
{
GameObject go = new GameObject("[WebManager]");
webManager = go.AddComponent<WebManager>();
DontDestroyOnLoad(go);
}
return webManager;
}
}
[SerializeField] private string _webConfigResourcePath= "WebConfig";
[SerializeField] private string _apiConfigResourcePath= "APIEndPointsConfig";
private WebConfigLoader _webConfigLoader = new WebConfigLoader();
private ApiConfigLoader _apiConfigLoader = new ApiConfigLoader();
public APIEndPointsConfig apiConfig;
[SerializeField]
string WebPath = "";
[SerializeField]
string ApiPath = "";
string host = "";
string token = "";
int port;
string http;
void Awake()
{
if (webManager != null && webManager != this)
{
Destroy(gameObject);
return;
}
webManager = this;
FindAnyObjectByType<WebReceiver>().onWebConfigReceived += SetWebConfig;
SetWebConfig();
SetApiConfig();
DontDestroyOnLoad(gameObject);
#if UNITY_EDITOR
_webConfigLoader.LoadFromResources(_webConfigResourcePath);
#else
WebReceiver receiver = FindAnyObjectByType<WebReceiver>();
receiver.onWebConfigReceived += HandleWebConfigFromReceiver;
#endif
apiConfig = _apiConfigLoader.LoadFromResources(_apiConfigResourcePath);
}
private void SetWebConfig(string json)
private void HandleWebConfigFromReceiver(string json)
{
/*
string path = Application.streamingAssetsPath + WebPath;
string json;
using (StreamReader reader = new StreamReader(path))
{
json = reader.ReadToEnd();
}
var json = Resources.Load<TextAsset>(WebPath);
*/
WebConfigList ConfigList = JsonConvert.DeserializeObject<WebConfigList>(json);
var config = ConfigList.configs[0];
host = config.host;
port = config.port;
token = config.accessToken;
http = $"{host}:{port}";
}
private void SetWebConfig()
{
/*
string path = Application.streamingAssetsPath + WebPath;
string json;
using (StreamReader reader = new StreamReader(path))
{
json = reader.ReadToEnd();
}
*/
var json = Resources.Load<TextAsset>(WebPath);
WebConfigList ConfigList = JsonConvert.DeserializeObject<WebConfigList>(json.text);
var config = ConfigList.configs[0];
host = config.host;
port = config.port;
token = config.accessToken;
http = $"{host}:{port}";
}
private void SetApiConfig()
{
/*
string path = Application.streamingAssetsPath + ApiPath;
string json;
Debug.Log($"fromunity :{path}");
using (StreamReader reader = new StreamReader(path))
{
json = reader.ReadToEnd();
}
*/
TextAsset json = Resources.Load<TextAsset>(ApiPath);
apiConfig = JsonConvert.DeserializeObject<APIEndPointsConfig>(json.text);
_webConfigLoader.LoadFromJsonString(json);
}
//Post동작을 실행하는 함수입니다
@@ -96,7 +63,7 @@ namespace Octopus.Simulator.Networks
{
//입력된 클래스를 json데이터로 변환합니다.
string json = JsonConvert.SerializeObject(inputclass);
StartCoroutine(Web_Post(http + type, json, (result, text) =>
StartCoroutine(Web_Post(_webConfigLoader.BaseUrl + type, json, (result, text) =>
{
ResultCallback(result, text);
}));
@@ -105,7 +72,7 @@ namespace Octopus.Simulator.Networks
//Get동작을 실행하는 함수입니다.
public void Request_Get(string type, System.Action<bool, string> ResultCallback)
{
StartCoroutine(Web_Get(http + type, (result, text) =>
StartCoroutine(Web_Get(_webConfigLoader.BaseUrl + type, (result, text) =>
{
ResultCallback(result, text);
}));
@@ -114,7 +81,7 @@ namespace Octopus.Simulator.Networks
//Put동작을 실행하는 함수입니다.
public void Request_Put(string type, System.Action<bool, string> ResultCallback)
{
StartCoroutine(Web_Put(http + type, (result, text) =>
StartCoroutine(Web_Put(_webConfigLoader.BaseUrl + type, (result, text) =>
{
ResultCallback(result, text);
}));
@@ -123,7 +90,7 @@ namespace Octopus.Simulator.Networks
public void Request_Put(object inputclass, string type, System.Action<bool, string> ResultCallback)
{
string json = JsonConvert.SerializeObject(inputclass);
StartCoroutine(Web_Put(http + type, json, (result, text) =>
StartCoroutine(Web_Put(_webConfigLoader.BaseUrl + type, json, (result, text) =>
{
ResultCallback(result, text);
}));
@@ -139,7 +106,7 @@ namespace Octopus.Simulator.Networks
request.uploadHandler = new UploadHandlerRaw(jsonToSend);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("Authorization", "Bearer " + token);
request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token);
yield return request.SendWebRequest();
Debug.Log(json);
@@ -165,7 +132,7 @@ namespace Octopus.Simulator.Networks
using (UnityWebRequest request = UnityWebRequest.Get(URL))
{
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Authorization", "Bearer " + token);
request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token);
yield return request.SendWebRequest();
@@ -192,7 +159,7 @@ namespace Octopus.Simulator.Networks
using (UnityWebRequest request = UnityWebRequest.Put(URL, data))
{
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Authorization", "Bearer " + token);
request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token);
yield return request.SendWebRequest();
@@ -224,7 +191,7 @@ namespace Octopus.Simulator.Networks
request.uploadHandler = new UploadHandlerRaw(jsonToSend);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("Authorization", "Bearer " + token);
request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token);
yield return request.SendWebRequest();

View File

@@ -0,0 +1,14 @@
using UnityEngine;
using System;
namespace Octopus.Simulator.Networks
{
[Serializable]
public static class WebParameters
{
public static int speed = 1;
public static int id = 1;
public static string code = "";
public static SimulatorConfig config = new SimulatorConfig();
}
}

View File

@@ -0,0 +1,50 @@
using Newtonsoft.Json;
using UnityEngine;
using System;
namespace Octopus.Simulator.Networks
{
public class WebReceiver : MonoBehaviour
{
public SimulatorConfig config;
public event Action onParameterRecived;
public event Action<string> onMqttConfigReceived;
public event Action<string> onWebConfigReceived;
public void Start()
{
#if UNITY_EDITOR
config.projectId = "1";
//config.simulationId = "15";
config.logicId = "1";
WebParameters.config = config;
onParameterRecived += FindAnyObjectByType<ProjectDataManager>().RequestInfo;
onParameterRecived += FindAnyObjectByType<LogicDataManager>().RequestInfo;
onParameterRecived?.Invoke();
#else
Application.ExternalCall("loadingComplete");
#endif
}
public void ReceiveWebParameterJson(string json)
{
config = JsonConvert.DeserializeObject<SimulatorConfig>(json);
WebParameters.config = config;
onParameterRecived?.Invoke();
Debug.Log($"webparam:{json}");
}
public void ReceiveMQTTConfigJson(string json)
{
onMqttConfigReceived?.Invoke(json);
Debug.Log($"mqttconfig:{json}");
}
public void ReceiveWebConfigJson(string json)
{
onWebConfigReceived?.Invoke(json);
Debug.Log($"webconfig:{json}");
}
}
}

View File

@@ -1,12 +0,0 @@
using UnityEngine;
using System;
using Octopus.Simulator.Networks;
[Serializable]
public static class WebParameters
{
public static int speed=1;
public static int id=1;
public static string code="";
public static SimulatorConfig config = new SimulatorConfig();
}

View File

@@ -1,48 +0,0 @@
using Newtonsoft.Json;
using UnityEngine;
using System;
using TMPro;
using Octopus.Simulator.Networks;
using Octopus.Simulator;
using System.Runtime.InteropServices;
public class WebReceiver : MonoBehaviour
{
public SimulatorConfig config;
public event Action onParameterRecived;
public event Action<string> onMqttConfigReceived;
public event Action<string> onWebConfigReceived;
public void Start()
{
Application.ExternalCall("loadingComplete");
config.projectId = "17";
//config.simulationId = "15";
config.logicId = "71";
WebParameters.config = config;
onParameterRecived += FindAnyObjectByType<ProjectDataManager>().RequestInfo;
onParameterRecived += FindAnyObjectByType<LogicDataManager>().RequestInfo;
onParameterRecived?.Invoke();
}
public void ReceiveWebParameterJson(string json)
{
config = JsonConvert.DeserializeObject<SimulatorConfig>(json);
WebParameters.config = config;
onParameterRecived?.Invoke();
Debug.Log($"webparam:{json}");
}
public void ReceiveMQTTConfigJson(string json)
{
onMqttConfigReceived?.Invoke(json);
Debug.Log($"mqttconfig:{json}");
}
public void ReceiveWebConfigJson(string json)
{
onWebConfigReceived?.Invoke(json);
Debug.Log($"webconfig:{json}");
}
}

View File

@@ -5,43 +5,45 @@ using Newtonsoft.Json;
using System.IO;
using System.Linq;
using System.Text;
using Octopus.Simulator.Networks;
using UVC.Networks;
public class SaveLoadmanager : MonoBehaviour
namespace Octopus.Simulator.Networks
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
public class SaveLoadmanager : MonoBehaviour
{
}
// Update is called once per frame
void Update()
{
if ( Input.GetKey(KeyCode.K))
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
Onclick_Save_Local();
}
if ( Input.GetKey(KeyCode.L))
// Update is called once per frame
void Update()
{
Onclick_Load_Local();
if (Input.GetKey(KeyCode.K))
{
Onclick_Save_Local();
}
if (Input.GetKey(KeyCode.L))
{
Onclick_Load_Local();
}
}
}
public void Onclick_Save_Local()
{
var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", "");
var simulationModels = FindObjectsByType<SimulationModel>(FindObjectsSortMode.None);
List<SimulationModelInfo> saveInfos = new List<SimulationModelInfo>();
foreach (var item in simulationModels)
public void Onclick_Save_Local()
{
var tmpSimulationModelInfo = new SimulationModelInfo();
var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", "");
var simulationModels = FindObjectsByType<SimulationModel>(FindObjectsSortMode.None);
List<SimulationModelInfo> saveInfos = new List<SimulationModelInfo>();
foreach (var item in simulationModels)
{
var tmpSimulationModelInfo = new SimulationModelInfo();
tmpSimulationModelInfo.prefabName = item.gameObject.name.Replace("(Clone)", "");
tmpSimulationModelInfo.modelName = item.modelName;
@@ -52,72 +54,72 @@ public class SaveLoadmanager : MonoBehaviour
tmpSimulationModelInfo.rotation = item.transform.rotation.ToString();
tmpSimulationModelInfo.scale = item.transform.localScale.ToString();
saveInfos.Add(tmpSimulationModelInfo);
saveInfos.Add(tmpSimulationModelInfo);
}
string jsonObject = JsonConvert.SerializeObject(saveInfos, Formatting.Indented);
FileStream fileStream = new FileStream(string.Format("{0}.json", path), FileMode.Create);
byte[] buffer = Encoding.UTF8.GetBytes(jsonObject);
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Close();
}
string jsonObject = JsonConvert.SerializeObject(saveInfos, Formatting.Indented);
FileStream fileStream = new FileStream(string.Format("{0}.json", path), FileMode.Create);
byte[] buffer = Encoding.UTF8.GetBytes(jsonObject);
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Close();
}
public void Onclick_Load_Local()
{
var path = StandaloneFileBrowser.OpenFilePanel("Open Layout", "", "", false);
FileStream fileStream = new FileStream(string.Format("{0}", path), FileMode.Open);
byte[] data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Close();
string jsonData = Encoding.UTF8.GetString(data);
List<SimulationModelInfo> loadInfos = new List<SimulationModelInfo>();
loadInfos = JsonConvert.DeserializeObject<List<SimulationModelInfo>>(jsonData);
string resourcePath = "ModelsUpdated";
Dictionary<string, SimulationModel> loadModels = new Dictionary<string, SimulationModel>();
foreach (var item in loadInfos)
public void Onclick_Load_Local()
{
var path = StandaloneFileBrowser.OpenFilePanel("Open Layout", "", "", false);
var simulationModel = Resources.Load<GameObject>(string.Format("{0}/{1}", resourcePath, item.prefabName));
var spawnItem = Instantiate(simulationModel).GetComponent<SimulationModel>();
FileStream fileStream = new FileStream(string.Format("{0}", path), FileMode.Open);
byte[] data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Close();
string jsonData = Encoding.UTF8.GetString(data);
List<SimulationModelInfo> loadInfos = new List<SimulationModelInfo>();
loadInfos = JsonConvert.DeserializeObject<List<SimulationModelInfo>>(jsonData);
string resourcePath = "ModelsUpdated";
Dictionary<string, SimulationModel> loadModels = new Dictionary<string, SimulationModel>();
foreach (var item in loadInfos)
{
var simulationModel = Resources.Load<GameObject>(string.Format("{0}/{1}", resourcePath, item.prefabName));
var spawnItem = Instantiate(simulationModel).GetComponent<SimulationModel>();
spawnItem.modelName = item.modelName;
//spawnItem.modelType = item.modelType;
spawnItem.modelID = item.modelID;
spawnItem.nodeID = item.nodeID;
spawnItem.gameObject.transform.position = ParseVector3(item.position);
spawnItem.gameObject.transform.localScale = ParseVector3(item.scale);
spawnItem.gameObject.transform.rotation = ParseQuaternion(item.rotation);
spawnItem.gameObject.transform.position = ParseVector3(item.position);
spawnItem.gameObject.transform.localScale = ParseVector3(item.scale);
spawnItem.gameObject.transform.rotation = ParseQuaternion(item.rotation);
if (!string.IsNullOrEmpty(item.nodeID))
loadModels.Add(item.nodeID, spawnItem);
if (!string.IsNullOrEmpty(item.nodeID))
loadModels.Add(item.nodeID, spawnItem);
}
LogicMappingDataBase.LoadDataBase(loadModels);
}
LogicMappingDataBase.LoadDataBase(loadModels);
}
public void Onclick_Save()
{
//var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", "");
var simulationModels = FindObjectsByType<SimulationModel>(FindObjectsSortMode.None);
List<SimulationModelInfo> saveInfos = new List<SimulationModelInfo>();
foreach (var item in simulationModels)
public void Onclick_Save()
{
var tmpSimulationModelInfo = new SimulationModelInfo();
//var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", "");
var simulationModels = FindObjectsByType<SimulationModel>(FindObjectsSortMode.None);
List<SimulationModelInfo> saveInfos = new List<SimulationModelInfo>();
foreach (var item in simulationModels)
{
var tmpSimulationModelInfo = new SimulationModelInfo();
tmpSimulationModelInfo.prefabName = item.gameObject.name.Replace("(Clone)", "");
tmpSimulationModelInfo.modelName = item.modelName;
@@ -128,243 +130,244 @@ public class SaveLoadmanager : MonoBehaviour
tmpSimulationModelInfo.rotation = item.transform.rotation.ToString();
tmpSimulationModelInfo.scale = item.transform.localScale.ToString();
saveInfos.Add(tmpSimulationModelInfo);
}
saveInfos.Add(tmpSimulationModelInfo);
}
string jsonObject = JsonConvert.SerializeObject(saveInfos, Formatting.Indented);
string jsonObject = JsonConvert.SerializeObject(saveInfos, Formatting.Indented);
var modelClass = new WebModelClass();
modelClass.logicId = int.Parse(WebParameters.config.logicId);
modelClass.name = "new model";
modelClass.description = "new model";
modelClass.data.info = jsonObject;
var modelClass = new WebModelClass();
modelClass.logicId = int.Parse(WebParameters.config.logicId);
modelClass.name = "new model";
modelClass.description = "new model";
modelClass.data.info = jsonObject;
string requestAPI = $"{WebManager.webManager.apiConfig.model}";
Debug.Log(requestAPI);
if (string.IsNullOrEmpty(WebParameters.config.modelId))
{
WebManager.webManager.Request_Post(modelClass, requestAPI, (flag, value) =>
string requestAPI = $"{WebManager.Instance.apiConfig.model}";
Debug.Log(requestAPI);
if (string.IsNullOrEmpty(WebParameters.config.modelId))
{
if (flag)
WebManager.Instance.Request_Post(modelClass, requestAPI, (flag, value) =>
{
var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
}
});
}
else
{
WebManager.webManager.Request_Put(modelClass, $"{requestAPI}/{WebParameters.config.modelId}", (flag, value) =>
if (flag)
{
var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
}
});
}
else
{
if (flag)
WebManager.Instance.Request_Put(modelClass, $"{requestAPI}/{WebParameters.config.modelId}", (flag, value) =>
{
var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
}
});
if (flag)
{
var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
}
});
}
/*
FileStream fileStream = new FileStream(string.Format("{0}.json", path), FileMode.Create);
byte[] buffer = Encoding.UTF8.GetBytes(jsonObject);
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Close();
*/
}
/*
FileStream fileStream = new FileStream(string.Format("{0}.json", path), FileMode.Create);
byte[] buffer = Encoding.UTF8.GetBytes(jsonObject);
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Close();
*/
}
public void Onclick_Load(string jsonData)
{
/*
var path = StandaloneFileBrowser.OpenFilePanel("Open Layout", "", "", false);
FileStream fileStream = new FileStream(string.Format("{0}", path), FileMode.Open);
byte[] data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Close();
string jsonData = Encoding.UTF8.GetString(data);
*/
List<SimulationModelInfo> loadInfos = new List<SimulationModelInfo>();
loadInfos = JsonConvert.DeserializeObject<List<SimulationModelInfo>>(jsonData);
string resourcePath = "ModelsUpdated";
Dictionary<string, SimulationModel> loadModels = new Dictionary<string, SimulationModel>();
foreach (var item in loadInfos)
public void Onclick_Load(string jsonData)
{
/*
var path = StandaloneFileBrowser.OpenFilePanel("Open Layout", "", "", false);
var simulationModel = Resources.Load<GameObject>(string.Format("{0}/{1}", resourcePath, item.prefabName));
var spawnItem = Instantiate(simulationModel).GetComponent<SimulationModel>();
FileStream fileStream = new FileStream(string.Format("{0}", path), FileMode.Open);
byte[] data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Close();
string jsonData = Encoding.UTF8.GetString(data);
*/
List<SimulationModelInfo> loadInfos = new List<SimulationModelInfo>();
loadInfos = JsonConvert.DeserializeObject<List<SimulationModelInfo>>(jsonData);
string resourcePath = "ModelsUpdated";
Dictionary<string, SimulationModel> loadModels = new Dictionary<string, SimulationModel>();
foreach (var item in loadInfos)
{
var simulationModel = Resources.Load<GameObject>(string.Format("{0}/{1}", resourcePath, item.prefabName));
var spawnItem = Instantiate(simulationModel).GetComponent<SimulationModel>();
spawnItem.modelName = item.modelName;
//spawnItem.modelType = item.modelType;
spawnItem.modelID = item.modelID;
spawnItem.nodeID = item.nodeID;
spawnItem.gameObject.transform.position = ParseVector3(item.position);
spawnItem.gameObject.transform.localScale = ParseVector3(item.scale);
spawnItem.gameObject.transform.rotation = ParseQuaternion(item.rotation);
spawnItem.gameObject.transform.position = ParseVector3(item.position);
spawnItem.gameObject.transform.localScale = ParseVector3(item.scale);
spawnItem.gameObject.transform.rotation = ParseQuaternion(item.rotation);
if (!string.IsNullOrEmpty(item.nodeID))
loadModels.Add(item.nodeID, spawnItem);
if (!string.IsNullOrEmpty(item.nodeID))
loadModels.Add(item.nodeID, spawnItem);
}
LogicMappingDataBase.LoadDataBase(loadModels);
}
LogicMappingDataBase.LoadDataBase(loadModels);
}
//public void Onclick_Save()
//{
// var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", "");
// var simulationModels = FindObjectsByType<SimulationModel>(FindObjectsSortMode.None);
//public void Onclick_Save()
//{
// var path = StandaloneFileBrowser.SaveFilePanel("Save Layout", "", "", "");
// var simulationModels = FindObjectsByType<SimulationModel>(FindObjectsSortMode.None);
// List<SimulationModelInfo> saveInfos = new List<SimulationModelInfo>();
// List<SimulationModelInfo> saveInfos = new List<SimulationModelInfo>();
// foreach (var item in simulationModels)
// {
// if (item is SimulationModelProduct)
// continue;
// foreach (var item in simulationModels)
// {
// if (item is SimulationModelProduct)
// continue;
// var tmpSimulationModelInfo = new SimulationModelInfo();
// var tmpSimulationModelInfo = new SimulationModelInfo();
// tmpSimulationModelInfo.prefabName = item.gameObject.name.Replace("(Clone)", "");
// tmpSimulationModelInfo.modelName = item.modelName;
// tmpSimulationModelInfo.modelType = item.modelType;
// tmpSimulationModelInfo.modelID = item.modelID;
// tmpSimulationModelInfo.nodeID = item.nodeID;
// tmpSimulationModelInfo.position = item.transform.position.ToString();
// tmpSimulationModelInfo.rotation = item.transform.rotation.ToString();
// tmpSimulationModelInfo.scale = item.transform.localScale.ToString();
// tmpSimulationModelInfo.prefabName = item.gameObject.name.Replace("(Clone)", "");
// tmpSimulationModelInfo.modelName = item.modelName;
// tmpSimulationModelInfo.modelType = item.modelType;
// tmpSimulationModelInfo.modelID = item.modelID;
// tmpSimulationModelInfo.nodeID = item.nodeID;
// tmpSimulationModelInfo.position = item.transform.position.ToString();
// tmpSimulationModelInfo.rotation = item.transform.rotation.ToString();
// tmpSimulationModelInfo.scale = item.transform.localScale.ToString();
// saveInfos.Add(tmpSimulationModelInfo);
// }
// saveInfos.Add(tmpSimulationModelInfo);
// }
// string jsonObject = JsonConvert.SerializeObject(saveInfos, Formatting.Indented);
// string jsonObject = JsonConvert.SerializeObject(saveInfos, Formatting.Indented);
// var modelClass = new WebModelClass();
// modelClass.logicId = int.Parse(WebParameters.config.logicId);
// modelClass.name = "new model";
// modelClass.description = "new model";
// modelClass.data.info = jsonObject;
// var modelClass = new WebModelClass();
// modelClass.logicId = int.Parse(WebParameters.config.logicId);
// modelClass.name = "new model";
// modelClass.description = "new model";
// modelClass.data.info = jsonObject;
// string requestAPI = $"{WebManager.webManager.apiConfig.model}";
// Debug.Log(requestAPI);
// if (string.IsNullOrEmpty(WebParameters.config.modelId))
// {
// WebManager.webManager.Request_Post(modelClass, requestAPI, (flag, value) =>
// {
// if (flag)
// {
// var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
// WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
// }
// });
// }
// else
// {
// WebManager.webManager.Request_Put(modelClass, $"{requestAPI}/{WebParameters.config.modelId}", (flag, value) =>
// {
// if (flag)
// {
// var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
// WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
// }
// });
// }
// /*
// FileStream fileStream = new FileStream(string.Format("{0}.json", path), FileMode.Create);
// string requestAPI = $"{WebManager.webManager.apiConfig.model}";
// Debug.Log(requestAPI);
// if (string.IsNullOrEmpty(WebParameters.config.modelId))
// {
// WebManager.webManager.Request_Post(modelClass, requestAPI, (flag, value) =>
// {
// if (flag)
// {
// var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
// WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
// }
// });
// }
// else
// {
// WebManager.webManager.Request_Put(modelClass, $"{requestAPI}/{WebParameters.config.modelId}", (flag, value) =>
// {
// if (flag)
// {
// var webreturnClass = JsonConvert.DeserializeObject<WebModelReturnClass>(value);
// WebParameters.config.modelId = webreturnClass.data.insertedId.ToString();
// }
// });
// }
// /*
// FileStream fileStream = new FileStream(string.Format("{0}.json", path), FileMode.Create);
// byte[] buffer = Encoding.UTF8.GetBytes(jsonObject);
// fileStream.Write(buffer, 0, buffer.Length);
// fileStream.Close();
// byte[] buffer = Encoding.UTF8.GetBytes(jsonObject);
// fileStream.Write(buffer, 0, buffer.Length);
// fileStream.Close();
//}
//}
//public void Onclick_Load(string jsonData)
//{
// /*
// var path = StandaloneFileBrowser.OpenFilePanel("Open Layout", "", "", false);
//public void Onclick_Load(string jsonData)
//{
// /*
// var path = StandaloneFileBrowser.OpenFilePanel("Open Layout", "", "", false);
// FileStream fileStream = new FileStream(string.Format("{0}", path), FileMode.Open);
// byte[] data = new byte[fileStream.Length];
// fileStream.Read(data, 0, data.Length);
// fileStream.Close();
// FileStream fileStream = new FileStream(string.Format("{0}", path), FileMode.Open);
// byte[] data = new byte[fileStream.Length];
// fileStream.Read(data, 0, data.Length);
// fileStream.Close();
// string jsonData = Encoding.UTF8.GetString(data);
// */
// string jsonData = Encoding.UTF8.GetString(data);
// */
// List<SimulationModelInfo> loadInfos = new List<SimulationModelInfo>();
// List<SimulationModelInfo> loadInfos = new List<SimulationModelInfo>();
// loadInfos = JsonConvert.DeserializeObject<List<SimulationModelInfo>>(jsonData);
// loadInfos = JsonConvert.DeserializeObject<List<SimulationModelInfo>>(jsonData);
// string resourcePath = "Models";
// string resourcePath = "Models";
// Dictionary<string, SimulationModel> loadModels = new Dictionary<string, SimulationModel>();
// Dictionary<string, SimulationModel> loadModels = new Dictionary<string, SimulationModel>();
// foreach(var item in loadInfos)
// {
// foreach(var item in loadInfos)
// {
// var simulationModel = Resources.Load<GameObject>(string.Format("{0}/{1}", resourcePath, item.prefabName));
// var spawnItem = Instantiate(simulationModel).GetComponent<SimulationModel>();
// var simulationModel = Resources.Load<GameObject>(string.Format("{0}/{1}", resourcePath, item.prefabName));
// var spawnItem = Instantiate(simulationModel).GetComponent<SimulationModel>();
// spawnItem.modelName = item.modelName;
// spawnItem.modelType = item.modelType;
// spawnItem.modelID = item.modelID;
// spawnItem.nodeID = item.nodeID;
// spawnItem.modelName = item.modelName;
// spawnItem.modelType = item.modelType;
// spawnItem.modelID = item.modelID;
// spawnItem.nodeID = item.nodeID;
// spawnItem.gameObject.transform.position = ParseVector3(item.position);
// spawnItem.gameObject.transform.localScale = ParseVector3(item.scale);
// spawnItem.gameObject.transform.rotation = ParseQuaternion(item.rotation);
// spawnItem.gameObject.transform.position = ParseVector3(item.position);
// spawnItem.gameObject.transform.localScale = ParseVector3(item.scale);
// spawnItem.gameObject.transform.rotation = ParseQuaternion(item.rotation);
// if ( !string.IsNullOrEmpty(item.nodeID))
// loadModels.Add(item.nodeID, spawnItem);
// }
// if ( !string.IsNullOrEmpty(item.nodeID))
// loadModels.Add(item.nodeID, spawnItem);
// }
// LogicMappingDataBase.LoadDataBase(loadModels);
//}
// LogicMappingDataBase.LoadDataBase(loadModels);
//}
public Vector3 ParseVector3(string input)
{
Vector3 returnValue;
public Vector3 ParseVector3(string input)
{
Vector3 returnValue;
input = input.Replace("(", "");
input = input.Replace(")", "");
input = input.Replace("(", "");
input = input.Replace(")", "");
var nakedString = input.Split(",");
var nakedString = input.Split(",");
returnValue.x = float.Parse(nakedString[0]);
returnValue.y = float.Parse(nakedString[1]);
returnValue.z = float.Parse(nakedString[2]);
returnValue.x = float.Parse(nakedString[0]);
returnValue.y = float.Parse(nakedString[1]);
returnValue.z = float.Parse(nakedString[2]);
return returnValue;
return returnValue;
}
}
public Quaternion ParseQuaternion(string input)
{
Quaternion returnValue;
public Quaternion ParseQuaternion(string input)
{
Quaternion returnValue;
input = input.Replace("(", "");
input = input.Replace(")", "");
input = input.Replace("(", "");
input = input.Replace(")", "");
var nakedString = input.Split(",");
var nakedString = input.Split(",");
returnValue.x = float.Parse(nakedString[0]);
returnValue.y = float.Parse(nakedString[1]);
returnValue.z = float.Parse(nakedString[2]);
returnValue.w = float.Parse(nakedString[3]);
returnValue.x = float.Parse(nakedString[0]);
returnValue.y = float.Parse(nakedString[1]);
returnValue.z = float.Parse(nakedString[2]);
returnValue.w = float.Parse(nakedString[3]);
return returnValue;
return returnValue;
}
}
}