chore: 외부 에셋 권한 및 줄바꿈 재기록 반영
- Assets/External 하위 샘플 및 서드파티 에셋 파일의 실행 비트 변경을 별도 커밋으로 분리 - PolygonGeneric, SidekickCharacters, Synty 도구 자산 전반의 줄바꿈 및 재직렬화 차이를 그대로 보존 - 프로젝트 고유 로직 변경과 분리해 이후 히스토리에서 외부 에셋 노이즈 범위를 식별하기 쉽게 정리
This commit is contained in:
242
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DatabaseManager.cs
vendored
Normal file → Executable file
242
Assets/External/Models/SidekickCharacters/Scripts/Runtime/Database/DatabaseManager.cs
vendored
Normal file → Executable file
@@ -12,9 +12,7 @@
|
||||
using SQLite;
|
||||
using Synty.SidekickCharacters.Database.DTO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
@@ -23,18 +21,11 @@ namespace Synty.SidekickCharacters.Database
|
||||
/// </summary>
|
||||
public class DatabaseManager
|
||||
{
|
||||
private const string _DATABASE_FILE_NAME = "Side_Kick_Data.db";
|
||||
private const string _LEGACY_PACKAGE_ROOT = "Assets/Synty/SidekickCharacters";
|
||||
private const string _LEGACY_TOOLS_PACKAGE_ROOT = "Assets/Synty/Tools/SidekickCharacters";
|
||||
private const string _WORKING_DATABASE_DIRECTORY = "SidekickCharacters";
|
||||
private static readonly string _DATABASE_PATH = "Assets/External/Models/SidekickCharacters/Database/Side_Kick_Data.db";
|
||||
private readonly string _CURRENT_VERSION = "1.0.2";
|
||||
|
||||
private static SQLiteConnection _connection;
|
||||
private static int _connectionHash;
|
||||
private static string _databasePath;
|
||||
private static string _seedDatabasePath;
|
||||
private static string _packageRootAbsolutePath;
|
||||
private static string _packageRootAssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DB connection with the given connection details.
|
||||
@@ -48,13 +39,7 @@ namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
if (_connection == null)
|
||||
{
|
||||
string databasePath = GetDatabasePath();
|
||||
if (string.IsNullOrEmpty(databasePath))
|
||||
{
|
||||
throw new FileNotFoundException("Unable to locate Sidekick database file in this Unity project.");
|
||||
}
|
||||
|
||||
_connection = new SQLiteConnection(databasePath, true);
|
||||
_connection = new SQLiteConnection(_DATABASE_PATH, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -115,12 +100,12 @@ namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
Species = new SidekickSpecies { ID = -1, Name = "None" },
|
||||
Name = "Default",
|
||||
SourceColorPath = GetPackageAssetPath("Resources", "Textures", "T_ColorMap.png"),
|
||||
SourceMetallicPath = GetPackageAssetPath("Resources", "Textures", "T_MetallicMap.png"),
|
||||
SourceSmoothnessPath = GetPackageAssetPath("Resources", "Textures", "T_SmoothnessMap.png"),
|
||||
SourceReflectionPath = GetPackageAssetPath("Resources", "Textures", "T_ReflectionMap.png"),
|
||||
SourceEmissionPath = GetPackageAssetPath("Resources", "Textures", "T_EmissionMap.png"),
|
||||
SourceOpacityPath = GetPackageAssetPath("Resources", "Textures", "T_OpacityMap.png"),
|
||||
SourceColorPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_ColorMap.png",
|
||||
SourceMetallicPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_MetallicMap.png",
|
||||
SourceSmoothnessPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_SmoothnessMap.png",
|
||||
SourceReflectionPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_ReflectionMap.png",
|
||||
SourceEmissionPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_EmissionMap.png",
|
||||
SourceOpacityPath = "Assets/External/Models/SidekickCharacters/Resources/Textures/T_OpacityMap.png",
|
||||
};
|
||||
|
||||
newSet.Save(this);
|
||||
@@ -221,216 +206,5 @@ namespace Synty.SidekickCharacters.Database
|
||||
{
|
||||
return new Version(GetCurrentDbConnection()?.Table<SidekickDBVersion>().FirstOrDefault().SemanticVersion ?? "0.0.1ea");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute filesystem path to the Sidekick database file.
|
||||
/// </summary>
|
||||
/// <returns>The absolute path to the DB file, if found.</returns>
|
||||
public static string GetDatabasePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_databasePath) && File.Exists(_databasePath))
|
||||
{
|
||||
return _databasePath;
|
||||
}
|
||||
|
||||
string seedDatabasePath = GetSeedDatabasePath();
|
||||
if (string.IsNullOrEmpty(seedDatabasePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string projectRoot = Directory.GetParent(Application.dataPath)?.FullName;
|
||||
if (string.IsNullOrEmpty(projectRoot))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string workingDirectory = Path.Combine(projectRoot, "Library", _WORKING_DATABASE_DIRECTORY);
|
||||
Directory.CreateDirectory(workingDirectory);
|
||||
|
||||
_databasePath = Path.Combine(workingDirectory, _DATABASE_FILE_NAME);
|
||||
if (!File.Exists(_databasePath))
|
||||
{
|
||||
File.Copy(seedDatabasePath, _databasePath, false);
|
||||
}
|
||||
|
||||
_databasePath = Path.GetFullPath(_databasePath);
|
||||
CleanupLegacyDatabaseArtifacts(seedDatabasePath);
|
||||
return _databasePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute filesystem path to the Sidekick package root.
|
||||
/// </summary>
|
||||
/// <returns>The absolute path to the package root, if found.</returns>
|
||||
public static string GetPackageRootAbsolutePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_packageRootAbsolutePath) && Directory.Exists(_packageRootAbsolutePath))
|
||||
{
|
||||
return _packageRootAbsolutePath;
|
||||
}
|
||||
|
||||
string seedDatabasePath = GetSeedDatabasePath();
|
||||
if (string.IsNullOrEmpty(seedDatabasePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string databaseDirectory = Path.GetDirectoryName(seedDatabasePath);
|
||||
if (string.IsNullOrEmpty(databaseDirectory))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_packageRootAbsolutePath = Path.GetDirectoryName(databaseDirectory);
|
||||
if (!string.IsNullOrEmpty(_packageRootAbsolutePath))
|
||||
{
|
||||
_packageRootAbsolutePath = Path.GetFullPath(_packageRootAbsolutePath);
|
||||
}
|
||||
|
||||
return _packageRootAbsolutePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the project-relative asset path to the Sidekick package root.
|
||||
/// </summary>
|
||||
/// <returns>The asset path to the package root, if found.</returns>
|
||||
public static string GetPackageRootAssetPath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_packageRootAssetPath))
|
||||
{
|
||||
return _packageRootAssetPath;
|
||||
}
|
||||
|
||||
string packageRootAbsolutePath = GetPackageRootAbsolutePath();
|
||||
if (string.IsNullOrEmpty(packageRootAbsolutePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_packageRootAssetPath = ToAssetPath(packageRootAbsolutePath);
|
||||
return _packageRootAssetPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a project-relative asset path under the Sidekick package root.
|
||||
/// </summary>
|
||||
/// <param name="relativeSegments">Path segments under the package root.</param>
|
||||
/// <returns>The combined asset path, if the package root could be found.</returns>
|
||||
public static string GetPackageAssetPath(params string[] relativeSegments)
|
||||
{
|
||||
string packageRootAssetPath = GetPackageRootAssetPath();
|
||||
if (string.IsNullOrEmpty(packageRootAssetPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string combinedPath = packageRootAssetPath;
|
||||
foreach (string segment in relativeSegments)
|
||||
{
|
||||
combinedPath = Path.Combine(combinedPath, segment);
|
||||
}
|
||||
|
||||
return NormalizePathSeparators(combinedPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes legacy Sidekick asset paths so moved packages still load correctly.
|
||||
/// </summary>
|
||||
/// <param name="assetPath">The asset path to normalize.</param>
|
||||
/// <returns>The remapped path if it pointed at an old root; otherwise the original path.</returns>
|
||||
public static string NormalizeLegacyAssetPath(string assetPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(assetPath))
|
||||
{
|
||||
return assetPath;
|
||||
}
|
||||
|
||||
string normalizedPath = NormalizePathSeparators(assetPath);
|
||||
string packageRootAssetPath = GetPackageRootAssetPath();
|
||||
if (string.IsNullOrEmpty(packageRootAssetPath))
|
||||
{
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
if (normalizedPath.StartsWith(_LEGACY_TOOLS_PACKAGE_ROOT, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return packageRootAssetPath + normalizedPath.Substring(_LEGACY_TOOLS_PACKAGE_ROOT.Length);
|
||||
}
|
||||
|
||||
if (normalizedPath.StartsWith(_LEGACY_PACKAGE_ROOT, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return packageRootAssetPath + normalizedPath.Substring(_LEGACY_PACKAGE_ROOT.Length);
|
||||
}
|
||||
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
private static string ToAssetPath(string fullPath)
|
||||
{
|
||||
string normalizedFullPath = NormalizePathSeparators(Path.GetFullPath(fullPath));
|
||||
string normalizedAssetsPath = NormalizePathSeparators(Path.GetFullPath(Application.dataPath));
|
||||
|
||||
if (!normalizedFullPath.StartsWith(normalizedAssetsPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return normalizedFullPath;
|
||||
}
|
||||
|
||||
return "Assets" + normalizedFullPath.Substring(normalizedAssetsPath.Length);
|
||||
}
|
||||
|
||||
private static string NormalizePathSeparators(string path)
|
||||
{
|
||||
return path?.Replace('\\', '/');
|
||||
}
|
||||
|
||||
private static string GetSeedDatabasePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_seedDatabasePath) && File.Exists(_seedDatabasePath))
|
||||
{
|
||||
return _seedDatabasePath;
|
||||
}
|
||||
|
||||
string[] databaseFiles = Directory.GetFiles(Application.dataPath, _DATABASE_FILE_NAME, SearchOption.AllDirectories);
|
||||
_seedDatabasePath = databaseFiles
|
||||
.OrderBy(path => path.Contains($"{Path.DirectorySeparatorChar}SidekickCharacters{Path.DirectorySeparatorChar}Database{Path.DirectorySeparatorChar}") ? 0 : 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (!string.IsNullOrEmpty(_seedDatabasePath))
|
||||
{
|
||||
_seedDatabasePath = Path.GetFullPath(_seedDatabasePath);
|
||||
}
|
||||
|
||||
return _seedDatabasePath;
|
||||
}
|
||||
|
||||
private static void CleanupLegacyDatabaseArtifacts(string seedDatabasePath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(seedDatabasePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteIfExists(seedDatabasePath + "-journal");
|
||||
DeleteIfExists(seedDatabasePath + "-journal.meta");
|
||||
DeleteIfExists(seedDatabasePath + "-wal");
|
||||
DeleteIfExists(seedDatabasePath + "-wal.meta");
|
||||
DeleteIfExists(seedDatabasePath + "-shm");
|
||||
DeleteIfExists(seedDatabasePath + "-shm.meta");
|
||||
}
|
||||
|
||||
private static void DeleteIfExists(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user