AudioAsset
Ease
FastString
FontAsset
NineSlice
PackedSprite
PackedSpriteID
RB
   HardwareSettings
   IRetroBlitGame
RBAsset
Rect2i
ShaderAsset
SoundReference
SpriteGrid
SpriteSheetAsset
TMXMapAsset
   TMXLayer
   TMXLayerLoadState
   TMXObject
   TMXObjectGroup
   TMXProperties
Vector2i

ShaderAsset.Load

Method

public RB.AssetStatus Load(string filename, RB.AssetSource source = RB.AssetSource.Resources)
public RB.AssetStatus Load(Shader existingShader)

Parameters

filename string File name to load from
source RB.AssetSource Asset source type
existingShader Shader Existing Shader object

Returns

RB.AssetStatus

Load status

Description

Load a shader asset which can be used when drawing sprites or applying screen effects. There are various asset sources supported:

  • Resources - Synchronously loaded shader assets from a Resources folder. This was the only asset source supported in RetroBlit prior to 3.0.
  • ResourcesAsync - Asynchronously loaded shader assets from a Resources folder.
  • AddressableAssets - Asynchronously loaded shader assets from Unity Addressable Assets.
  • Existing Assets - Synchronously loaded shader assets from an existing Unity Shader.

If the asset is loaded via a synchronous method then Load will block until the loading is complete. If the asset is loaded via an asynchronous method then Load will immediately return and the asset loading will continue in a background thread. The status of an asynchronous loading asset can be check by looking at RBAsset.status, or by using the event system with RBAsset.OnLoadComplete to get a callback when the asset is done loading.

Note that unlike other asset types, WWW does not support loading shaders, this is a limitation of Unity.

Example

ShaderAsset shaderFancy = new ShaderAsset();

public void Initialize()
{
    // Load asset from Resources asynchronously. This method call will immediately return without blocking.
    shaderFancy.Load("fancy_shader"RB.AssetSource.ResourcesAsync);
}

public void Render()
{
    if (shaderFancy.status == RB.AssetStatus.Ready)
    {
        RB.ShaderSet(shaderFancy);
    }

    // Draw a sprite with the shader applied if the shader has finished loading.
    RB.DrawSprite("hero/walk1", playerPos);
}

See Also

RB.Result
RB.AssetStatus
RB.AssetSource

See Docs

Features - Shaders (Advanced Topic)
Features - Asynchronous Asset Loading