// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 namespace AWS.GameKit.Editor.Utils { /// /// A lazy loading wrapper for a pair of dark-theme and light-theme assets stored in a "Resources" folder. /// /// The Get() method returns the correct asset based on the Unity Editor theme. /// /// The assets are loaded and cached the first time Get() is called. /// /// For details on Unity's special "Resources" folders and how to load data from them, please read: https://docs.unity3d.com/ScriptReference/Resources.Load.html /// /// The type to load the assets as. public class LazyLoadedEditorThemeAwareResource : IGettable where T : UnityEngine.Object { private readonly EditorThemeAware> _cachedResources; /// /// Create a new LazyLoadedEditorThemeAwareResource for the specified resource paths. /// /// See official docs for details on the resource paths: https://docs.unity3d.com/ScriptReference/Resources.Load.html /// /// The path to the Dark-themed resource relative to any Resources folder. /// The path to the Light-themed resource relative to any Resources folder. public LazyLoadedEditorThemeAwareResource(string darkThemeResourcePath, string lightThemeResourcePath) { _cachedResources = new EditorThemeAware>( new LazyLoadedResource(darkThemeResourcePath), new LazyLoadedResource(lightThemeResourcePath) ); } /// /// Create a new LazyLoadedEditorThemeAwareResource for the specified resource paths. /// /// See official docs for details on the resource paths: https://docs.unity3d.com/ScriptReference/Resources.Load.html /// /// An IGetter for the dark theme resource. /// An IGetter for the light theme resource. public LazyLoadedEditorThemeAwareResource(IGettable darkThemeResourceGetter, IGettable lightThemeResourceGetter) { _cachedResources = new EditorThemeAware>(darkThemeResourceGetter, lightThemeResourceGetter); } /// /// Get the asset matching the current Unity Editor theme. /// /// The dark-themed asset if the Unity Editor theme is "Dark", otherwise the light-themed asset. public T Get() { return _cachedResources.Get().Get(); } } }