// Copyright (c) Wojciech Figat. All rights reserved.
using System;
using System.Runtime.CompilerServices;
namespace FlaxEngine
{
partial class Content
{
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
///
/// Asset unique ID.
/// Type of the asset to load. Includes any asset types derived from the type.
/// Asset instance if loaded, null otherwise.
public static T LoadAsync(Guid id) where T : Asset
{
return (T)LoadAsync(id, typeof(T));
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
///
/// Asset unique ID.
/// Asset instance if loaded, null otherwise
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Asset LoadAsync(Guid id)
{
return LoadAsync(id);
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
///
/// Path to the asset.
/// Type of the asset to load. Includes any asset types derived from the type.
/// Asset instance if loaded, null otherwise.
public static T LoadAsync(string path) where T : Asset
{
return (T)LoadAsync(path, typeof(T));
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
///
/// Path to the asset.
/// Asset instance if loaded, null otherwise
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Asset LoadAsync(string path)
{
return LoadAsync(path, typeof(Asset));
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
///
/// Internal path to the asset. Relative to the Engine startup folder.
/// Type of the asset to load. Includes any asset types derived from the type.
/// Asset instance if loaded, null otherwise.
[HideInEditor]
public static T LoadAsyncInternal(string internalPath) where T : Asset
{
return (T)LoadAsyncInternal(internalPath, typeof(T));
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
///
/// Internal path to the asset. Relative to the Engine startup folder.
/// Asset instance if loaded, null otherwise
[HideInEditor]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Asset LoadAsyncInternal(string internalPath)
{
return LoadAsyncInternal(internalPath, typeof(Asset));
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async. The current thread execution is blocked until asset is loaded.
/// Waits until asset will be loaded. It's equivalent to LoadAsync + WaitForLoaded.
///
/// Asset unique ID.
/// Custom timeout value in milliseconds.
/// Asset instance if loaded, null otherwise
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Asset Load(Guid id, double timeoutInMilliseconds = 30000.0)
{
return Load(id, timeoutInMilliseconds);
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async. The current thread execution is blocked until asset is loaded.
/// Waits until asset will be loaded. It's equivalent to LoadAsync + WaitForLoaded.
///
/// Path to the asset.
/// Custom timeout value in milliseconds.
/// Asset instance if loaded, null otherwise
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Asset Load(string path, double timeoutInMilliseconds = 30000.0)
{
return Load(path, timeoutInMilliseconds);
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
/// Waits until asset will be loaded. It's equivalent to LoadAsync + WaitForLoaded.
///
/// Internal path to the asset. Relative to the Engine startup folder.
/// Custom timeout value in milliseconds.
/// Asset instance if loaded, null otherwise
[HideInEditor]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Asset LoadInternal(string internalPath, double timeoutInMilliseconds = 30000.0)
{
return LoadInternal(internalPath, timeoutInMilliseconds);
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
/// Waits until asset will be loaded. It's equivalent to LoadAsync + WaitForLoaded.
///
/// Asset unique ID.
/// Custom timeout value in milliseconds.
/// Type of the asset to load. Includes any asset types derived from the type.
/// Asset instance if loaded, null otherwise
public static T Load(Guid id, double timeoutInMilliseconds = 30000.0) where T : Asset
{
var asset = LoadAsync(id);
if (asset && asset.WaitForLoaded(timeoutInMilliseconds) == false)
return asset;
return null;
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
/// Waits until asset will be loaded. It's equivalent to LoadAsync + WaitForLoaded.
///
/// Path to the asset.
/// Custom timeout value in milliseconds.
/// Type of the asset to load. Includes any asset types derived from the type.
/// Asset instance if loaded, null otherwise
public static T Load(string path, double timeoutInMilliseconds = 30000.0) where T : Asset
{
var asset = LoadAsync(path);
if (asset && asset.WaitForLoaded(timeoutInMilliseconds) == false)
return asset;
return null;
}
///
/// Loads asset to the Content Pool and holds it until it won't be referenced by any object. Returns null if asset is missing. Actual asset data loading is performed on a other thread in async.
/// Waits until asset will be loaded. It's equivalent to LoadAsync + WaitForLoaded.
///
/// Internal path to the asset. Relative to the Engine startup folder and without an asset file extension.
/// Custom timeout value in milliseconds.
/// Type of the asset to load. Includes any asset types derived from the type.
/// Asset instance if loaded, null otherwise
[HideInEditor]
public static T LoadInternal(string internalPath, double timeoutInMilliseconds = 30000.0) where T : Asset
{
var asset = LoadAsyncInternal(internalPath);
if (asset && asset.WaitForLoaded(timeoutInMilliseconds) == false)
return asset;
return null;
}
///
/// Creates temporary and virtual asset of the given type.
/// Virtual assets have limited usage but allow to use custom assets data at runtime.
/// Virtual assets are temporary and exist until application exit.
///
/// Type of the asset to create. Includes any asset types derived from the type.
/// Asset instance if created, null otherwise. See log for error message if need to.
public static T CreateVirtualAsset() where T : Asset
{
return (T)Internal_CreateVirtualAsset(typeof(T));
}
}
}