Initial commit
This commit is contained in:
+92
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
namespace GradientSkybox
|
||||
{
|
||||
public class CircularMultipleColorGradientSkyboxGUI : ShaderGUI
|
||||
{
|
||||
private GradientObject gradientObject = null;
|
||||
private bool isGradientSaved = false;
|
||||
|
||||
public override void OnGUI(MaterialEditor editor, MaterialProperty[] properties)
|
||||
{
|
||||
MaterialProperty norm = FindProperty("_Norm", properties);
|
||||
editor.ShaderProperty(norm, norm.displayName);
|
||||
|
||||
Material material = editor.target as Material;
|
||||
string materialRelativePath = AssetDatabase.GetAssetPath(material);
|
||||
|
||||
if (gradientObject == null)
|
||||
{
|
||||
string objectRelativePath = materialRelativePath + ".asset";
|
||||
gradientObject = AssetDatabase.LoadAssetAtPath<GradientObject>(objectRelativePath);
|
||||
if (gradientObject == null)
|
||||
{
|
||||
gradientObject = ScriptableObject.CreateInstance<GradientObject>();
|
||||
AssetDatabase.CreateAsset(gradientObject, objectRelativePath);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
SerializedObject data = new SerializedObject(gradientObject);
|
||||
data.Update();
|
||||
SerializedProperty gradientProperty = data.FindProperty("gradient");
|
||||
Texture2D texture = null;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(gradientProperty);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
data.ApplyModifiedProperties();
|
||||
texture = CreateRampTexture();
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
material.SetTexture("_RampTex", texture);
|
||||
isGradientSaved = false;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Save Gradient"))
|
||||
{
|
||||
if (texture == null)
|
||||
{
|
||||
texture = CreateRampTexture();
|
||||
}
|
||||
|
||||
byte[] png = texture.EncodeToPNG();
|
||||
string textureRelativePath = materialRelativePath + ".png";
|
||||
string textureAbsolutePath = Path.Combine(Directory.GetCurrentDirectory(), textureRelativePath);
|
||||
File.WriteAllBytes(textureAbsolutePath, png);
|
||||
|
||||
TextureImporter textureImporter = AssetImporter.GetAtPath(textureRelativePath) as TextureImporter;
|
||||
textureImporter.wrapMode = TextureWrapMode.Clamp;
|
||||
AssetDatabase.ImportAsset(textureRelativePath);
|
||||
|
||||
Texture2D savedTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(textureRelativePath);
|
||||
material.SetTexture("_RampTex", savedTexture);
|
||||
|
||||
isGradientSaved = true;
|
||||
}
|
||||
|
||||
if (!isGradientSaved)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Changes to gradient has not saved yet.", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Texture2D CreateRampTexture()
|
||||
{
|
||||
Gradient gradient = gradientObject.gradient;
|
||||
Texture2D texture = new Texture2D(128, 2);
|
||||
for (int h = 0; h < texture.height; h++)
|
||||
{
|
||||
for (int w = 0; w < texture.width; w++)
|
||||
{
|
||||
texture.SetPixel(w, h, gradient.Evaluate((float)w / texture.width));
|
||||
}
|
||||
}
|
||||
texture.Apply();
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7815b9f61f2140c438f009532ca4ce14
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace GradientSkybox
|
||||
{
|
||||
public class CircularTwoColorGradientSkyboxGUI : ShaderGUI
|
||||
{
|
||||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
|
||||
{
|
||||
base.OnGUI(materialEditor, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1f18e76b737a1e4c95b30a354171e2b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GradientSkybox
|
||||
{
|
||||
public class GradientObject : ScriptableObject
|
||||
{
|
||||
public Gradient gradient = new Gradient();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecc82c4a6883629448947ff714bb4a24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,89 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
namespace GradientSkybox
|
||||
{
|
||||
public class LinearMultipleColorGradientSkyboxGUI : ShaderGUI
|
||||
{
|
||||
private GradientObject gradientObject = null;
|
||||
private bool isGradientSaved = false;
|
||||
|
||||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
|
||||
{
|
||||
Material material = materialEditor.target as Material;
|
||||
string materialRelativePath = AssetDatabase.GetAssetPath(material);
|
||||
|
||||
if (gradientObject == null)
|
||||
{
|
||||
string objectRelativePath = materialRelativePath + ".asset";
|
||||
gradientObject = AssetDatabase.LoadAssetAtPath<GradientObject>(objectRelativePath);
|
||||
if (gradientObject == null)
|
||||
{
|
||||
gradientObject = ScriptableObject.CreateInstance<GradientObject>();
|
||||
AssetDatabase.CreateAsset(gradientObject, objectRelativePath);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
SerializedObject data = new SerializedObject(gradientObject);
|
||||
data.Update();
|
||||
SerializedProperty gradientProperty = data.FindProperty("gradient");
|
||||
Texture2D texture = null;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(gradientProperty);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
data.ApplyModifiedProperties();
|
||||
texture = CreateRampTexture();
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
material.SetTexture("_RampTex", texture);
|
||||
isGradientSaved = false;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Save Gradient"))
|
||||
{
|
||||
if (texture == null)
|
||||
{
|
||||
texture = CreateRampTexture();
|
||||
}
|
||||
|
||||
byte[] png = texture.EncodeToPNG();
|
||||
string textureRelativePath = materialRelativePath + ".png";
|
||||
string textureAbsolutePath = Path.Combine(System.IO.Directory.GetCurrentDirectory(), textureRelativePath);
|
||||
File.WriteAllBytes(textureAbsolutePath, png);
|
||||
|
||||
TextureImporter textureImporter = AssetImporter.GetAtPath(textureRelativePath) as TextureImporter;
|
||||
textureImporter.wrapMode = TextureWrapMode.Clamp;
|
||||
AssetDatabase.ImportAsset(textureRelativePath);
|
||||
|
||||
Texture2D savedTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(textureRelativePath);
|
||||
material.SetTexture("_RampTex", savedTexture);
|
||||
|
||||
isGradientSaved = true;
|
||||
}
|
||||
|
||||
if (!isGradientSaved)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Changes to gradient has not saved yet.", MessageType.Warning);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Texture2D CreateRampTexture()
|
||||
{
|
||||
Gradient gradient = gradientObject.gradient;
|
||||
Texture2D texture = new Texture2D(128, 2);
|
||||
for (int h = 0; h < texture.height; h++)
|
||||
{
|
||||
for (int w = 0; w < texture.width; w++)
|
||||
{
|
||||
texture.SetPixel(w, h, gradient.Evaluate((float)w / texture.width));
|
||||
}
|
||||
}
|
||||
texture.Apply();
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcaa818f680cd854b84e2caa4f1bc83b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace GradientSkybox
|
||||
{
|
||||
public class LinearThreeColorGradientSkyboxGUI : ShaderGUI
|
||||
{
|
||||
public override void OnGUI(MaterialEditor editor, MaterialProperty[] properties)
|
||||
{
|
||||
MaterialProperty topColor = FindProperty("_TopColor", properties);
|
||||
editor.ColorProperty(topColor, topColor.displayName);
|
||||
MaterialProperty middleColor = FindProperty("_MiddleColor", properties);
|
||||
editor.ColorProperty(middleColor, middleColor.displayName);
|
||||
MaterialProperty bottomColor = FindProperty("_BottomColor", properties);
|
||||
editor.ColorProperty(bottomColor, bottomColor.displayName);
|
||||
MaterialProperty up = FindProperty("_Up", properties);
|
||||
Vector3 upVector = up.vectorValue;
|
||||
upVector = EditorGUILayout.Vector3Field(up.displayName, upVector);
|
||||
up.vectorValue = upVector;
|
||||
MaterialProperty exp = FindProperty("_Exp", properties);
|
||||
editor.RangeProperty(exp, exp.displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 538fbb555bec3154cba1e49f1dc491ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GradientSkybox
|
||||
{
|
||||
public class LinearTwoColorGradientSkyboxGUI : ShaderGUI
|
||||
{
|
||||
public override void OnGUI(MaterialEditor editor, MaterialProperty[] properties)
|
||||
{
|
||||
MaterialProperty topColor = FindProperty("_TopColor", properties);
|
||||
editor.ColorProperty(topColor, topColor.displayName);
|
||||
MaterialProperty bottomColor = FindProperty("_BottomColor", properties);
|
||||
editor.ColorProperty(bottomColor, bottomColor.displayName);
|
||||
MaterialProperty up = FindProperty("_Up", properties);
|
||||
Vector3 upVector = up.vectorValue;
|
||||
upVector = EditorGUILayout.Vector3Field(up.displayName, upVector);
|
||||
up.vectorValue = upVector;
|
||||
MaterialProperty exp = FindProperty("_Exp", properties);
|
||||
editor.RangeProperty(exp, exp.displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6664fab09b203dd4090cb204bb5d0b55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user