ReplacementShaderSetup.

ReplacementShaderSetup.
SceneDebugViewerWindow.
This commit is contained in:
max 2021-03-30 21:04:06 +02:00
parent 644f5d5477
commit 6276c12668
3 changed files with 135 additions and 14 deletions

View File

@ -0,0 +1,84 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace TAO.SceneDebugViewer.Editor
{
[CreateAssetMenu(menuName = "SceneDebugViewer/ReplacementShaderSetup")]
public class ReplacementShaderSetupScriptableObject : ScriptableObject
{
[Header("GUI")]
public GUIContent content = new GUIContent();
[Header("Shader")]
public Shader shader = null;
public string replacementTag = "";
public List<GlobalShaderParameter> parameters = new List<GlobalShaderParameter>();
public void Replace()
{
SetupShaderParameters();
foreach (SceneView s in SceneView.sceneViews)
{
s.SetSceneViewShaderReplace(shader, replacementTag);
s.Repaint();
}
}
protected void SetupShaderParameters()
{
foreach (var p in parameters)
{
p.Set();
}
}
[System.Serializable]
public struct GlobalShaderParameter
{
public string m_name;
public ParameterType m_parameterType;
public Texture2D m_texture;
public Vector4 m_vector;
public Color m_color;
public float m_float;
public int m_int;
public void Set()
{
switch (m_parameterType)
{
case ParameterType.Texture:
Shader.SetGlobalTexture(m_name, m_texture);
break;
case ParameterType.Vector:
Shader.SetGlobalVector(m_name, m_vector);
break;
case ParameterType.Color:
Shader.SetGlobalColor(m_name, m_color);
break;
case ParameterType.Float:
Shader.SetGlobalFloat(m_name, m_float);
break;
case ParameterType.Int:
Shader.SetGlobalInt(m_name, m_int);
break;
default:
break;
}
}
}
public enum ParameterType
{
Texture,
Vector,
Color,
Float,
Int
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1aa272ccd1306c545b68254a527f8025
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,20 +1,46 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace TAO.SceneDebugViewer.Editor
{
public class SceneDebugViewerWindow : EditorWindow
{
static List<ReplacementShaderSetupScriptableObject> options = new List<ReplacementShaderSetupScriptableObject>();
[MenuItem("Window/SceneDebugViewer")]
static void Init()
{
options.Clear();
string[] guids = AssetDatabase.FindAssets("t:ReplacementShaderSetupScriptableObject", null);
foreach (string guid in guids)
{
options.Add((ReplacementShaderSetupScriptableObject)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(ReplacementShaderSetupScriptableObject)));
}
SceneDebugViewerWindow window = (SceneDebugViewerWindow)EditorWindow.GetWindow(typeof(SceneDebugViewerWindow));
window.Show();
}
private void OnGUI()
{
if (GUILayout.Button("Reset"))
{
foreach (SceneView s in SceneView.sceneViews)
{
s.SetSceneViewShaderReplace(null, null);
s.Repaint();
}
}
foreach (var o in options)
{
if (GUILayout.Button(o.content))
{
o.Replace();
}
}
}
}
}