mirror of
https://github.com/maxartz15/SceneDebugViewer.git
synced 2024-11-21 19:15:36 +01:00
ReplacementShaderSetup.
ReplacementShaderSetup. SceneDebugViewerWindow.
This commit is contained in:
parent
644f5d5477
commit
6276c12668
84
Editor/ReplacementShaderSetupScriptableObject.cs
Normal file
84
Editor/ReplacementShaderSetupScriptableObject.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Editor/ReplacementShaderSetupScriptableObject.cs.meta
Normal file
11
Editor/ReplacementShaderSetupScriptableObject.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1aa272ccd1306c545b68254a527f8025
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,20 +1,46 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace TAO.SceneDebugViewer.Editor
|
namespace TAO.SceneDebugViewer.Editor
|
||||||
{
|
{
|
||||||
public class SceneDebugViewerWindow : EditorWindow
|
public class SceneDebugViewerWindow : EditorWindow
|
||||||
{
|
{
|
||||||
[MenuItem("Window/SceneDebugViewer")]
|
static List<ReplacementShaderSetupScriptableObject> options = new List<ReplacementShaderSetupScriptableObject>();
|
||||||
static void Init()
|
|
||||||
{
|
|
||||||
SceneDebugViewerWindow window = (SceneDebugViewerWindow)EditorWindow.GetWindow(typeof(SceneDebugViewerWindow));
|
|
||||||
window.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGUI()
|
[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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user