42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using UnityEngine;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Octopus.Simulator;
|
|
|
|
public class DataManager : UnitySingleton<DataManager>
|
|
{
|
|
public bool isPlaying = false;
|
|
List<SimulationModel> models = new List<SimulationModel>();
|
|
|
|
public event Action<List<SimulationModel>> onModelsUpdated;
|
|
public void AddModel(SimulationModel model)
|
|
{
|
|
if (models.Any(x => x == model))
|
|
return;
|
|
int objCount = models.FindAll(x => x.modelName.Contains(model.modelName)).Count;
|
|
model.modelName = model.modelName + "_" + objCount.ToString();
|
|
model.onModelClicked += FindAnyObjectByType<Panel_ConnectedObject>(FindObjectsInactive.Include).SetConnectedDataItem;
|
|
models.Add(model);
|
|
onModelsUpdated?.Invoke(models);
|
|
}
|
|
public void RemoveModel(SimulationModel model)
|
|
{
|
|
if (models.Any(x => x == model))
|
|
return;
|
|
models.Remove(model);
|
|
onModelsUpdated?.Invoke(models);
|
|
}
|
|
|
|
public List<SimulationModel> GetModels()
|
|
{
|
|
return models;
|
|
}
|
|
public SimulationModel GetModel(string nodeID)
|
|
{
|
|
if (nodeID == null) return null;
|
|
SimulationModel model = models.Find(x => x.nodeID.Equals(nodeID));
|
|
return model;
|
|
}
|
|
}
|