wjdakf aksgdmsdlfemfdl dlTDJTdj
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Octopus.Simulator.Networks;
|
||||
|
||||
public class SimulationModelSource : SimulationModel
|
||||
{
|
||||
public string eventGenerateProduct = "product_generated";
|
||||
public string eventGenerateDefect = "product_defective";
|
||||
public string eventQueueProduct = "product_queued";
|
||||
public GameObject productPrefab;
|
||||
public GameObject defectPrefab;
|
||||
public List<GameObject> listProducts = new List<GameObject>();
|
||||
public List<GameObject> listDefects = new List<GameObject>();
|
||||
public Transform productPos;
|
||||
public Vector3 productDistance = new Vector3(0, 0.321f, 0);
|
||||
//ConcurrentQueue<Dictionary<string, object>> dataQueue;
|
||||
ConcurrentQueue<JObject> dataQueue;
|
||||
int productCount = 0;
|
||||
int defectCount = 0;
|
||||
void Update()
|
||||
{
|
||||
int interval = 0;
|
||||
if (productCount != listProducts.Count)
|
||||
{
|
||||
productCount = listProducts.Count;
|
||||
for (int i = 0; i < productCount; i++)
|
||||
{
|
||||
GameObject gb = listProducts[i];
|
||||
gb.transform.localPosition = productDistance * interval;
|
||||
interval++;
|
||||
}
|
||||
}
|
||||
if (defectCount != listDefects.Count)
|
||||
{
|
||||
defectCount = listDefects.Count;
|
||||
for (int i = 0; i < defectCount; i++)
|
||||
{
|
||||
GameObject gb = listDefects[i];
|
||||
gb.transform.localPosition = productDistance * interval;
|
||||
interval++;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override IEnumerator RunSimulationCoroutine()
|
||||
{
|
||||
yield return new WaitUntil(() => !string.IsNullOrEmpty(nodeID));
|
||||
while (dataQueue == null)
|
||||
{
|
||||
dataQueue = MQTTDataBase.Instance.GetDataQueue(nodeID);
|
||||
if (dataQueue == null)
|
||||
yield return null;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
if (dataQueue.IsEmpty)
|
||||
{
|
||||
yield return null;
|
||||
continue;
|
||||
}
|
||||
if (dataQueue.TryDequeue(out JObject currentData))
|
||||
{
|
||||
string eventKey = "_event";
|
||||
if (currentData.ContainsKey(eventKey))
|
||||
{
|
||||
string value = currentData[eventKey].ToString();
|
||||
if (value.Contains(eventGenerateProduct))
|
||||
{
|
||||
GameObject gb = Instantiate(productPrefab, productPos);
|
||||
listProducts.Add(gb);
|
||||
}
|
||||
else if (value.Contains(eventGenerateDefect))
|
||||
{
|
||||
GameObject gb = Instantiate(defectPrefab, productPos);
|
||||
listProducts.Add(gb);
|
||||
}
|
||||
else if (value.Contains(eventQueueProduct))
|
||||
{
|
||||
string[] queueIDKey = { "data", "queue" };
|
||||
string[] capacityKey = { "data", "queue_length" };
|
||||
string[] storeTypeKey = { "data", "queue_type" };
|
||||
string queueID = GetJsonValue(currentData, queueIDKey)?.ToString();
|
||||
int queueCapacity = GetJsonIntValue(currentData, capacityKey);
|
||||
string storeType = GetJsonValue(currentData, storeTypeKey)?.ToString();
|
||||
SimulationModel model = DataManager.I.GetModel(queueID);
|
||||
GameObject product = null;
|
||||
if (listProducts.Count > 0)
|
||||
{
|
||||
product = listProducts[0];
|
||||
listProducts.Remove(product);
|
||||
}
|
||||
else if (listDefects.Count > 0)
|
||||
{
|
||||
product = listDefects[0];
|
||||
listDefects.Remove(product);
|
||||
}
|
||||
if (model != null && product != null)
|
||||
{
|
||||
SimulationModelStore storeModel = (SimulationModelStore)model;
|
||||
storeModel.maxCapacity = queueCapacity;
|
||||
storeModel.storeType = storeType;
|
||||
storeModel.StoreProduct(product);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user