47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using CounterDrone.Core;
|
|
using CounterDrone.Core.Models;
|
|
using CounterDrone.Core.Repository;
|
|
using CounterDrone.Core.Services;
|
|
using UnityEngine;
|
|
|
|
namespace CounterDrone.Unity
|
|
{
|
|
/// <summary>模型管理桥接 — 导入/删除/查询 3D 模型元数据</summary>
|
|
public class ModelManager : MonoBehaviour
|
|
{
|
|
private IModelService _service;
|
|
private IPathProvider _paths;
|
|
private SQLite.SQLiteConnection _db;
|
|
|
|
public IModelService Service => _service;
|
|
|
|
public void Awake()
|
|
{
|
|
_paths = new UnityPathProvider();
|
|
_db = new DatabaseManager(_paths).OpenMainDb();
|
|
SqliteConnectionTracker.Track(_db);
|
|
_service = new ModelService(new ModelRepository(_db), _paths);
|
|
}
|
|
|
|
void OnDisable() { SqliteConnectionTracker.Untrack(_db); _db?.Dispose(); _db = null; }
|
|
|
|
public ModelInfo Import(string filePath, string name) => _service.ImportModel(filePath, name);
|
|
public ModelInfo Import(string filePath, string name, int entityType, string desc)
|
|
=> _service.ImportModel(filePath, name, entityType, desc);
|
|
public ModelInfo Add(ModelInfo model) => _service.AddModel(model);
|
|
public void Delete(string id) => _service.DeleteModel(id);
|
|
public List<ModelInfo> GetAll() => _service.GetAllModels();
|
|
public ModelInfo Get(string id) => _service.GetModel(id);
|
|
public ModelInfo UpdateModel(ModelInfo model) => _service.UpdateModel(model);
|
|
|
|
[ContextMenu("Verify")]
|
|
void Verify()
|
|
{
|
|
Awake();
|
|
Debug.Log($"ModelManager OK. DB: {_paths.GetMainDbPath()}");
|
|
}
|
|
}
|
|
}
|