Last active
May 6, 2020 22:09
-
-
Save mukaschultze/9381dda1a4905feea70a0a5adcb3065b to your computer and use it in GitHub Desktop.
Change Unity preview background to a nicer color!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
namespace EnhancedHierarchy { | |
[InitializeOnLoad] | |
static class PreviewBackgroundColor { | |
private static readonly Color backgroundColor = new Color(1f, 0f, 1f); // Change this color | |
static PreviewBackgroundColor() { | |
Camera.onPreRender += (Camera cam) => { | |
if (cam && cam.name.Contains("Preview")) { | |
cam.backgroundColor = backgroundColor; | |
} | |
}; | |
After.Frames(1, () => { | |
var texture = CreateTexture(backgroundColor); | |
GUIStyle preBackground = "PreBackground"; | |
GUIStyle preBackgroundSolid = "PreBackgroundSolid"; | |
preBackground.normal.background = texture; | |
preBackgroundSolid.normal.background = texture; | |
}); | |
} | |
private static Texture2D CreateTexture(Color c) { | |
var texture = new Texture2D(16, 16); | |
for (var x = 0; x < texture.width; x++) | |
for (var y = 0; y < texture.height; y++) | |
texture.SetPixel(x, y, c); | |
texture.Apply(); | |
texture.hideFlags = HideFlags.HideAndDontSave; | |
return texture; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And a few more interesting links
https://timaksu.com/post/126337219047/spruce-up-your-custom-unity-inspectors-with-a
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/Inspector/PreviewRenderUtility.cs