private T GetAssetRelativeToAssetPath <T>(string assetPath, string relPath) where T : Object { string directory = Path.GetDirectoryName(assetPath); string assetsPath = $"{directory}/{relPath}"; assetsPath = LDtkPathUtility.CleanPath(assetsPath); //basic find T assetAtPath = (T)AssetDatabase.LoadMainAssetAtPath(assetsPath); if (assetAtPath != null) { return(assetAtPath); } /*//try a reimport as it may fix it * if (File.Exists(assetsPath)) * { * AssetDatabase.ImportAsset(assetsPath, ImportAssetOptions.ForceUpdate); * * AssetDatabase.Refresh(); * assetAtPath = AssetDatabase.LoadAssetAtPath<T>(assetsPath); * if (assetAtPath != null) * { * return assetAtPath; * } * } * * //if the asset is null, try an asset database refresh (the refresh costs time so try try only if it was unsuccessful) * AssetDatabase.Refresh(); * assetAtPath = AssetDatabase.LoadAssetAtPath<T>(assetsPath); * if (assetAtPath != null) * { * return assetAtPath; * }*/ //if we couldn't load it but the file indeed exists, spit a different error if (File.Exists(assetsPath)) { Debug.LogError($"LDtk: File does exist but could not load the asset at \"{assetsPath}\". " + $"Is the asset imported yet?"); return(null); } Debug.LogError($"LDtk: Could not find an asset in the path relative to \"{assetPath}\": \"{relPath}\". " + $"Is the asset also locatable by LDtk, and is the asset located in the Unity Project?"); return(null); }
public void Generate() { string filePath = GetFilePath(_ctx); LDtkPathUtility.CleanPath(filePath); LDtkPathUtility.TryCreateDirectoryForFile(filePath); LDtkEnumFactory factory = new LDtkEnumFactory(_templates, filePath, _enumScriptNamespace); if (factory.CreateEnumFile()) { EditorApplication.delayCall += AssetDatabase.Refresh; } }