You've already forked Commercialization.topon
更新sdk
This commit is contained in:
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using AnyThink.Scripts.IntegrationManager.Editor;
|
||||
using UnityEngine;
|
||||
// #if UNITY_EDITOR //是Unity编辑器才引入
|
||||
using UnityEditor;
|
||||
@@ -21,16 +22,93 @@ public class ATSdkUtil
|
||||
/// <returns>The exported path of the MAX plugin asset or the default export path if the asset is not found.</returns>
|
||||
public static string GetAssetPathForExportPath(string exportPath)
|
||||
{
|
||||
var defaultPath = Path.Combine("Assets", exportPath);
|
||||
var assetLabelToFind = "l:al_max_export_path-" + exportPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
||||
var normalizedExportPath = NormalizeAssetPath(exportPath);
|
||||
var defaultPath = NormalizeAssetPath(Path.Combine("Assets", normalizedExportPath));
|
||||
var assetLabelToFind = "l:al_max_export_path-" + normalizedExportPath;
|
||||
var assetGuids = AssetDatabase.FindAssets(assetLabelToFind);
|
||||
|
||||
return assetGuids.Length < 1 ? defaultPath : AssetDatabase.GUIDToAssetPath(assetGuids[0]);
|
||||
if (assetGuids.Length > 0)
|
||||
{
|
||||
var assetPath = AssetDatabase.GUIDToAssetPath(assetGuids[0]);
|
||||
if (!string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
return assetPath;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var candidatePath in GetCandidateAssetPaths(normalizedExportPath))
|
||||
{
|
||||
if (AssetExists(candidatePath))
|
||||
{
|
||||
return candidatePath;
|
||||
}
|
||||
}
|
||||
|
||||
var assetName = Path.GetFileNameWithoutExtension(normalizedExportPath);
|
||||
if (!string.IsNullOrEmpty(assetName))
|
||||
{
|
||||
var expectedSuffixes = new[]
|
||||
{
|
||||
normalizedExportPath,
|
||||
GetPluginRelativeExportPath(normalizedExportPath)
|
||||
};
|
||||
|
||||
foreach (var guid in AssetDatabase.FindAssets(assetName))
|
||||
{
|
||||
var assetPath = NormalizeAssetPath(AssetDatabase.GUIDToAssetPath(guid));
|
||||
if (expectedSuffixes.Any(suffix =>
|
||||
!string.IsNullOrEmpty(suffix) &&
|
||||
assetPath.EndsWith(suffix, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return assetPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
public static bool Exists(string filePath)
|
||||
{
|
||||
return Directory.Exists(filePath) || File.Exists(filePath);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetCandidateAssetPaths(string normalizedExportPath)
|
||||
{
|
||||
var pluginRelativeExportPath = GetPluginRelativeExportPath(normalizedExportPath);
|
||||
var dynamicRootPath = NormalizeAssetPath(ATConfig.RootPath);
|
||||
|
||||
if (!string.IsNullOrEmpty(dynamicRootPath))
|
||||
{
|
||||
yield return NormalizeAssetPath(Path.Combine(dynamicRootPath, pluginRelativeExportPath));
|
||||
}
|
||||
|
||||
yield return NormalizeAssetPath(Path.Combine("Assets", normalizedExportPath));
|
||||
}
|
||||
|
||||
private static string GetPluginRelativeExportPath(string normalizedExportPath)
|
||||
{
|
||||
const string pluginRootName = "AnyThinkPlugin/";
|
||||
return normalizedExportPath.StartsWith(pluginRootName, StringComparison.OrdinalIgnoreCase)
|
||||
? normalizedExportPath.Substring(pluginRootName.Length)
|
||||
: normalizedExportPath;
|
||||
}
|
||||
|
||||
private static string NormalizeAssetPath(string assetPath)
|
||||
{
|
||||
return string.IsNullOrEmpty(assetPath)
|
||||
? string.Empty
|
||||
: assetPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).TrimStart(Path.AltDirectorySeparatorChar);
|
||||
}
|
||||
|
||||
private static bool AssetExists(string assetPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath) != null || File.Exists(assetPath);
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user