Skip to content

Commit 8c108cf

Browse files
committed
Make the background image panel images load from the cache
1 parent 0c49d9a commit 8c108cf

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Assets/Scripts/GUI/LoadBackgroundImageButton.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ override protected void OnButtonPressed()
4747
{
4848
return;
4949
}
50-
SceneSettings.m_Instance.LoadCustomSkybox(ReferenceImage.FileName);
50+
if (ReferenceImage.NotLoaded)
51+
{
52+
// Load-on-demand.
53+
ReferenceImage.SynchronousLoad();
54+
}
55+
56+
57+
SceneSettings.m_Instance.LoadCustomSkyboxFromCache(ReferenceImage.FileName);
5158
}
5259

5360
override public void ResetState()

Assets/Scripts/SceneSettings.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,32 @@ public void LoadCustomSkybox(string filename)
250250
}
251251
}
252252

253+
public void LoadCustomSkyboxFromCache(string filename)
254+
{
255+
Texture2D tex = ImageCache.LoadImageCache(filename);
256+
257+
if (tex == null)
258+
{
259+
LoadCustomSkybox(filename);
260+
}
261+
else
262+
{
263+
float aspectRatio = tex.width / tex.height;
264+
if (aspectRatio > 1.5)
265+
{
266+
m_CustomSkyboxMaterial = Resources.Load<Material>("Environments/CustomSkybox");
267+
}
268+
else
269+
{
270+
m_CustomSkyboxMaterial = Resources.Load<Material>("Environments/CustomStereoSkybox");
271+
}
272+
m_CustomSkyboxMaterial.mainTexture = tex;
273+
m_CustomSkyboxMaterial.SetColor("_Tint", Color.gray);
274+
RenderSettings.skybox = m_CustomSkyboxMaterial;
275+
RenderSettings.ambientMode = AmbientMode.Skybox;
276+
}
277+
}
278+
253279
public Quaternion GradientOrientation
254280
{
255281
get { return m_GradientSkew; }

0 commit comments

Comments
 (0)