Files
Simulation/Assets/Scripts/Manager/DataManager.cs

39 lines
1.1 KiB
C#
Raw Normal View History

using UnityEngine;
2025-05-14 18:07:07 +09:00
using System;
using System.Collections.Generic;
using System.Linq;
public class DataManager : UnitySingleton<DataManager>
{
2025-05-26 18:06:25 +09:00
public bool isPlaying = false;
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;
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();
models.Add(model);
2025-05-28 13:54:59 +09:00
onModelsUpdated?.Invoke(models);
}
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-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;
}
}