summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/VRM/VRMShaders/UniUnlit/Editor/UniUnlitEditor.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-11 20:00:58 +0800
committerchai <chaifix@163.com>2020-10-11 20:00:58 +0800
commit8b384dffa0d9c63c7a657c6e567c2ddefbf046cd (patch)
tree3f4d669b73b6622aa49627c4ccb3c78d51a82bde /Assets/ThirdParty/VRM/VRMShaders/UniUnlit/Editor/UniUnlitEditor.cs
parentcd3aee8d640f6abcc82802ca7abbcdfa031c20d3 (diff)
+Saionji show off scene
Diffstat (limited to 'Assets/ThirdParty/VRM/VRMShaders/UniUnlit/Editor/UniUnlitEditor.cs')
-rw-r--r--Assets/ThirdParty/VRM/VRMShaders/UniUnlit/Editor/UniUnlitEditor.cs159
1 files changed, 159 insertions, 0 deletions
diff --git a/Assets/ThirdParty/VRM/VRMShaders/UniUnlit/Editor/UniUnlitEditor.cs b/Assets/ThirdParty/VRM/VRMShaders/UniUnlit/Editor/UniUnlitEditor.cs
new file mode 100644
index 00000000..326f129a
--- /dev/null
+++ b/Assets/ThirdParty/VRM/VRMShaders/UniUnlit/Editor/UniUnlitEditor.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEditor;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+
+namespace UniGLTF.UniUnlit
+{
+ public class UniUnlitEditor : ShaderGUI
+ {
+ private MaterialProperty _mainTex;
+ private MaterialProperty _color;
+ private MaterialProperty _cutoff;
+ private MaterialProperty _blendMode;
+ private MaterialProperty _cullMode;
+ private MaterialProperty _vColBlendMode;
+// private MaterialProperty _srcBlend;
+// private MaterialProperty _dstBlend;
+// private MaterialProperty _zWrite;
+
+ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
+ {
+ _mainTex = FindProperty(Utils.PropNameMainTex, properties);
+ _color = FindProperty(Utils.PropNameColor, properties);
+ _cutoff = FindProperty(Utils.PropNameCutoff, properties);
+ _blendMode = FindProperty(Utils.PropNameBlendMode, properties);
+ _cullMode = FindProperty(Utils.PropNameCullMode, properties);
+ _vColBlendMode = FindProperty(Utils.PropNameVColBlendMode, properties);
+// _srcBlend = FindProperty(PropNameSrcBlend, properties);
+// _dstBlend = FindProperty(PropNameDstBlend, properties);
+// _zWrite = FindProperty(PropNameZWrite, properties);
+
+ var materials = materialEditor.targets.Select(x => x as Material).ToArray();
+
+ EditorGUI.BeginChangeCheck();
+ {
+ DrawRenderingBox(materialEditor, materials);
+ DrawColorBox(materialEditor, materials);
+ DrawOptionsBox(materialEditor, materials);
+ }
+ EditorGUI.EndChangeCheck();
+ }
+
+ public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
+ {
+ var blendMode = UniUnlitRenderMode.Opaque;
+ if (material.HasProperty(Utils.PropNameStandardShadersRenderMode)) // from Standard shader
+ {
+ blendMode = (UniUnlitRenderMode) Math.Min(2f, material.GetFloat(Utils.PropNameStandardShadersRenderMode));
+ }
+
+ // assigns UniUnlit's properties...
+ base.AssignNewShaderToMaterial(material, oldShader, newShader);
+
+ // take over old value
+ material.SetFloat(Utils.PropNameBlendMode, (float) blendMode);
+
+ Utils.ValidateProperties(material, isRenderModeChangedByUser: true);
+ }
+
+ private void DrawRenderingBox(MaterialEditor materialEditor, Material[] materials)
+ {
+ EditorGUILayout.LabelField("Rendering", EditorStyles.boldLabel);
+ EditorGUILayout.BeginVertical(GUI.skin.box);
+ {
+ if (PopupEnum<UniUnlitRenderMode>("Rendering Type", _blendMode, materialEditor))
+ {
+ ModeChanged(materials, isRenderModeChangedByUser: true);
+ }
+ if (PopupEnum<UniUnlitCullMode>("Cull Mode", _cullMode, materialEditor))
+ {
+ ModeChanged(materials, isRenderModeChangedByUser: true);
+ }
+ EditorGUILayout.Space();
+
+ switch ((UniUnlitRenderMode) _blendMode.floatValue)
+ {
+ case UniUnlitRenderMode.Cutout:
+ materialEditor.ShaderProperty(_cutoff, "Cutoff");
+ break;
+ case UniUnlitRenderMode.Opaque:
+ case UniUnlitRenderMode.Transparent:
+ break;
+ }
+ }
+ EditorGUILayout.EndVertical();
+ EditorGUILayout.Space();
+ }
+
+ private void DrawColorBox(MaterialEditor materialEditor, Material[] materials)
+ {
+ EditorGUILayout.LabelField("Color", EditorStyles.boldLabel);
+ EditorGUILayout.BeginVertical(GUI.skin.box);
+ {
+ materialEditor.TexturePropertySingleLine(new GUIContent("Main Tex", "(RGBA)"), _mainTex, _color);
+ materialEditor.TextureScaleOffsetProperty(_mainTex);
+ EditorGUILayout.Space();
+
+ if (PopupEnum<UniUnlitVertexColorBlendOp>("Vertex Color Blend Mode", _vColBlendMode, materialEditor))
+ {
+ ModeChanged(materials, isRenderModeChangedByUser: true);
+ }
+ }
+ EditorGUILayout.EndVertical();
+ EditorGUILayout.Space();
+ }
+
+ private void DrawOptionsBox(MaterialEditor materialEditor, Material[] materials)
+ {
+ EditorGUILayout.LabelField("Options", EditorStyles.boldLabel);
+ EditorGUILayout.BeginVertical(GUI.skin.box);
+ {
+ #if UNITY_5_6_OR_NEWER
+// materialEditor.EnableInstancingField();
+ materialEditor.DoubleSidedGIField();
+ #endif
+ materialEditor.RenderQueueField();
+ }
+ EditorGUILayout.EndVertical();
+ EditorGUILayout.Space();
+ }
+
+ private static bool PopupEnum<T>(string name, MaterialProperty property, MaterialEditor editor) where T : struct
+ {
+ if (!typeof(T).IsEnum) return false;
+
+ EditorGUI.showMixedValue = property.hasMixedValue;
+ EditorGUI.BeginChangeCheck();
+ var values = (T[]) Enum.GetValues(typeof(T));
+ var names = Enum.GetNames(typeof(T));
+
+ var currInt = (int) property.floatValue;
+ var currValue = (T) Enum.ToObject(typeof(T), currInt);
+ var currIndex = Array.IndexOf(values, currValue);
+ var nextIndex = EditorGUILayout.Popup(name, currIndex, names);
+ var changed = EditorGUI.EndChangeCheck();
+ if (changed)
+ {
+ editor.RegisterPropertyChangeUndo("EnumPopUp");
+ var nextValue = values[nextIndex];
+ var nextInt = (int) (object) nextValue;
+ property.floatValue = nextInt;
+ }
+ EditorGUI.showMixedValue = false;
+ return changed;
+ }
+
+
+ private static void ModeChanged(Material[] materials, bool isRenderModeChangedByUser = false)
+ {
+ foreach (var material in materials)
+ {
+ Utils.ValidateProperties(material, isRenderModeChangedByUser);
+ }
+ }
+ }
+}