2025-05-12 10:25:52 +09:00
|
|
|
using UnityEngine;
|
2025-05-14 18:07:07 +09:00
|
|
|
using System;
|
2025-05-12 10:25:52 +09:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
public class DataManager : UnitySingleton<DataManager>
|
|
|
|
|
{
|
2025-05-26 18:06:25 +09:00
|
|
|
public bool isPlaying = false;
|
2025-05-12 10:25:52 +09:00
|
|
|
List<SimulationModel> models = new List<SimulationModel>();
|
2025-05-14 18:07:07 +09:00
|
|
|
|
2025-05-28 13:54:59 +09:00
|
|
|
public event Action<List<SimulationModel>> onModelsUpdated;
|
2025-05-12 10:25:52 +09:00
|
|
|
public void AddModel(SimulationModel model)
|
|
|
|
|
{
|
|
|
|
|
if (models.Any(x => x == model))
|
2025-05-12 18:00:37 +09:00
|
|
|
return;
|
|
|
|
|
int objCount = models.FindAll(x => x.modelName.Contains(model.modelName)).Count;
|
|
|
|
|
model.modelName = model.modelName + "_" + objCount.ToString();
|
2025-05-12 10:25:52 +09:00
|
|
|
models.Add(model);
|
2025-05-28 13:54:59 +09:00
|
|
|
onModelsUpdated?.Invoke(models);
|
2025-05-12 10:25:52 +09:00
|
|
|
}
|
|
|
|
|
public void RemoveModel(SimulationModel model)
|
|
|
|
|
{
|
|
|
|
|
if (models.Any(x => x == model))
|
|
|
|
|
return;
|
|
|
|
|
models.Remove(model);
|
2025-05-28 13:54:59 +09:00
|
|
|
onModelsUpdated?.Invoke(models);
|
2025-05-14 18:07:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SimulationModel> GetModels()
|
|
|
|
|
{
|
|
|
|
|
return models;
|
2025-05-12 10:25:52 +09:00
|
|
|
}
|
2025-05-26 18:06:25 +09:00
|
|
|
public SimulationModel GetModel(string nodeID)
|
|
|
|
|
{
|
2025-05-27 14:53:01 +09:00
|
|
|
if (nodeID == null) return null;
|
2025-05-26 18:06:25 +09:00
|
|
|
SimulationModel model = models.Find(x => x.nodeID.Equals(nodeID));
|
|
|
|
|
return model;
|
|
|
|
|
}
|
2025-05-12 10:25:52 +09:00
|
|
|
}
|