Skip to content

Commit

Permalink
Static implicit operators removed
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed Dec 16, 2023
1 parent 9125749 commit 36be7c7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 46 deletions.
2 changes: 0 additions & 2 deletions Editor/Files/PreloadedAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace Depra.Assets.Editor.Files
{
public sealed class PreloadedAsset<TAsset> : IAssetFile<TAsset>, IDisposable where TAsset : Object
{
public static implicit operator TAsset(PreloadedAsset<TAsset> self) => self.Load();

private readonly Type _assetType;
private readonly IAssetFile<TAsset> _asset;

Expand Down
2 changes: 0 additions & 2 deletions Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace Depra.Assets.Files.Bundles
{
public sealed class AssetBundleAssetFile<TAsset> : IAssetFile<TAsset>, IDisposable where TAsset : Object
{
public static implicit operator TAsset(AssetBundleAssetFile<TAsset> self) => self.Load();

private readonly AssetBundle _assetBundle;
private TAsset _loadedAsset;

Expand Down
6 changes: 2 additions & 4 deletions Runtime/Files.Bundles/Files/AssetBundleFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Depra.Assets.Files.Bundles
{
public sealed class AssetBundleFile : IAssetFile<AssetBundle>, IDisposable
{
public static implicit operator AssetBundle(AssetBundleFile self) => self.Load();

private readonly AssetBundleUri _uri;
private readonly IAssetBundleSource _source;

Expand All @@ -42,7 +40,7 @@ public AssetBundle Load()
}

var loadedAssetBundle = _source.Load(by: _uri.AbsolutePathWithoutExtension);
Guard.AgainstNull(loadedAssetBundle, () => new AssetBundleNotLoaded(_uri.AbsolutePath));
Guard.AgainstNull(loadedAssetBundle, () => new AssetBundleNotLoaded(_uri.Absolute));

_loadedAssetBundle = loadedAssetBundle;
Metadata.Size = _source.Size(of: _loadedAssetBundle);
Expand All @@ -62,7 +60,7 @@ public async Task<AssetBundle> LoadAsync(DownloadProgressDelegate onProgress = n
var loadedAssetBundle = await _source
.LoadAsync(_uri.AbsolutePathWithoutExtension, OnProgress, cancellationToken);

Guard.AgainstNull(loadedAssetBundle, () => new AssetBundleNotLoaded(_uri.AbsolutePath));
Guard.AgainstNull(loadedAssetBundle, () => new AssetBundleNotLoaded(_uri.Absolute));

_loadedAssetBundle = loadedAssetBundle;
onProgress?.Invoke(DownloadProgress.Full);
Expand Down
15 changes: 2 additions & 13 deletions Runtime/Files.Bundles/Files/AssetBundleUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using Depra.Assets.Extensions;
using Depra.Assets.ValueObjects;
using JetBrains.Annotations;

namespace Depra.Assets.Files.Bundles
{
Expand All @@ -27,32 +26,22 @@ public AssetBundleUri(string path)
? _fileInfo.Name
: _fileInfo.Name.Replace(Extension, string.Empty);

AbsolutePathWithoutExtension = AbsolutePath.Replace(EXTENSION, string.Empty);
AbsolutePathWithoutExtension = Absolute.Replace(EXTENSION, string.Empty);
}

public AssetBundleUri(string name, string directory = null) : this(name, directory, EXTENSION) { }

public AssetBundleUri(string name, string directory, string extension = null) : this(
Path.Combine(directory, name + extension)) { }

[UsedImplicitly]
public string Name { get; }

[UsedImplicitly]
public string Extension => EXTENSION;

[UsedImplicitly]
public string NameWithExtension => Name + Extension;

[UsedImplicitly]
public string AbsolutePath => _fileInfo.FullName;

[UsedImplicitly]
public string Absolute => _fileInfo.FullName;
public string AbsoluteDirectoryPath => _fileInfo.DirectoryName;

public string AbsolutePathWithoutExtension { get; }

string IAssetUri.Relative => Name;
string IAssetUri.Absolute => AbsolutePath;
}
}
8 changes: 3 additions & 5 deletions Runtime/Files.Database/DatabaseAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace Depra.Assets.Files.Database
{
public sealed class DatabaseAsset<TAsset> : IAssetFile<TAsset>, IDisposable where TAsset : ScriptableObject
{
public static implicit operator TAsset(DatabaseAsset<TAsset> self) => self.Load();

private readonly Type _assetType;
private readonly DatabaseAssetUri _uri;

Expand All @@ -43,7 +41,7 @@ public TAsset Load()
#if UNITY_EDITOR
if (_uri.Exists())
{
loadedAsset = AssetDatabase.LoadAssetAtPath<TAsset>(_uri.RelativePath);
loadedAsset = AssetDatabase.LoadAssetAtPath<TAsset>(_uri.Relative);
}
#endif
if (loadedAsset == null)
Expand All @@ -67,7 +65,7 @@ public void Unload()
}

#if UNITY_EDITOR
AssetDatabase.DeleteAsset(_uri.RelativePath);
AssetDatabase.DeleteAsset(_uri.Relative);
#endif
_loadedAsset = null;
}
Expand Down Expand Up @@ -101,7 +99,7 @@ private Object ActivateAsset(Object asset)
_uri.Directory.CreateIfNotExists();

asset.name = _uri.Name;
AssetDatabase.CreateAsset(asset, _uri.RelativePath);
AssetDatabase.CreateAsset(asset, _uri.Relative);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

Expand Down
26 changes: 8 additions & 18 deletions Runtime/Files.Database/DatabaseAssetUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.IO;
using Depra.Assets.ValueObjects;
using JetBrains.Annotations;

namespace Depra.Assets.Files.Database
{
Expand All @@ -21,31 +20,22 @@ public DatabaseAssetUri(string relativeDirectory, string name, string extension)
Name = name;
Extension = extension;
NameWithExtension = Name + Extension;
RelativePath = Path.Combine(relativeDirectory, NameWithExtension).Replace(@"\", "/");
AbsolutePath = Path.GetFullPath(RelativePath).Replace(@"\", "/");
AbsoluteDirectoryPath = Path.GetFullPath(relativeDirectory).Replace(@"\", "/");
Directory = new DirectoryInfo(AbsoluteDirectoryPath);
Relative = Path.Combine(relativeDirectory, NameWithExtension).Replace(@"\", "/");
Absolute = Path.GetFullPath(Relative).Replace(@"\", "/");
AbsoluteDirectory = Path.GetFullPath(relativeDirectory).Replace(@"\", "/");
Directory = new DirectoryInfo(AbsoluteDirectory);
}

public string Name { get; }

[UsedImplicitly]
public string Extension { get; }

[UsedImplicitly]
public string NameWithExtension { get; }

public string RelativePath { get; }
public string AbsolutePath { get; }

[UsedImplicitly]
public string AbsoluteDirectoryPath { get; }
public string Relative { get; }
public string Absolute { get; }

public string AbsoluteDirectory { get; }
internal DirectoryInfo Directory { get; }

string IAssetUri.Relative => RelativePath;
string IAssetUri.Absolute => AbsolutePath;

public bool Exists() => File.Exists(AbsolutePath);
public bool Exists() => File.Exists(Absolute);
}
}
2 changes: 0 additions & 2 deletions Runtime/Files.Resource/ResourcesAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Depra.Assets.Files.Resource
{
public sealed class ResourcesAsset<TAsset> : IAssetFile<TAsset>, IDisposable where TAsset : Object
{
public static implicit operator TAsset(ResourcesAsset<TAsset> self) => self.Load();

private TAsset _loadedAsset;

public ResourcesAsset(ResourcesPath path)
Expand Down

0 comments on commit 36be7c7

Please sign in to comment.