111
This commit is contained in:
463
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPPSHelperTool.cs
vendored
Normal file
463
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPPSHelperTool.cs
vendored
Normal file
@@ -0,0 +1,463 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
//using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public enum ASEPostProcessEvent
|
||||
{
|
||||
BeforeTransparent = 0,
|
||||
BeforeStack = 1,
|
||||
AfterStack = 2
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ASEPPSHelperBuffer
|
||||
{
|
||||
public string Name;
|
||||
public string Tooltip;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ASEPPSHelperTool : EditorWindow
|
||||
{
|
||||
private const string PPSFullTemplate =
|
||||
"// Amplify Shader Editor - Visual Shader Editing Tool\n" +
|
||||
"// Copyright (c) Amplify Creations, Lda <info@amplify.pt>\n" +
|
||||
"#if UNITY_POST_PROCESSING_STACK_V2\n" +
|
||||
"using System;\n" +
|
||||
"using UnityEngine;\n" +
|
||||
"using UnityEngine.Rendering.PostProcessing;\n" +
|
||||
"\n" +
|
||||
"[Serializable]\n" +
|
||||
"[PostProcess( typeof( /*PPSRendererClass*/ ), PostProcessEvent./*PPSEventType*/, \"/*PPSMenuEntry*/\", /*AllowInSceneView*/ )]\n" +
|
||||
"public sealed class /*PPSSettingsClass*/ : PostProcessEffectSettings\n" +
|
||||
"{\n" +
|
||||
"/*PPSPropertiesDeclaration*/" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"public sealed class /*PPSRendererClass*/ : PostProcessEffectRenderer</*PPSSettingsClass*/>\n" +
|
||||
"{\n" +
|
||||
"\tpublic override void Render( PostProcessRenderContext context )\n" +
|
||||
"\t{\n" +
|
||||
"\t\tvar sheet = context.propertySheets.Get( Shader.Find( \"/*PPSShader*/\" ) );\n" +
|
||||
"/*PPSPropertySet*/" +
|
||||
"\t\tcontext.command.BlitFullscreenTriangle( context.source, context.destination, sheet, 0 );\n" +
|
||||
"\t}\n" +
|
||||
"}\n" +
|
||||
"#endif\n";
|
||||
|
||||
private const string PPSEventType = "/*PPSEventType*/";
|
||||
private const string PPSRendererClass = "/*PPSRendererClass*/";
|
||||
private const string PPSSettingsClass = "/*PPSSettingsClass*/";
|
||||
private const string PPSMenuEntry = "/*PPSMenuEntry*/";
|
||||
private const string PPSAllowInSceneView = "/*AllowInSceneView*/";
|
||||
private const string PPSShader = "/*PPSShader*/";
|
||||
private const string PPSPropertiesDecl = "/*PPSPropertiesDeclaration*/";
|
||||
private const string PPSPropertySet = "/*PPSPropertySet*/";
|
||||
|
||||
public static readonly string PPSPropertySetFormat = "\t\tsheet.properties.{0}( \"{1}\", settings.{1} );\n";
|
||||
public static readonly string PPSPropertySetNullPointerCheckFormat = "\t\tif(settings.{1}.value != null) sheet.properties.{0}( \"{1}\", settings.{1} );\n";
|
||||
public static readonly string PPSPropertyDecFormat =
|
||||
"\t[{0}Tooltip( \"{1}\" )]\n" +
|
||||
"\tpublic {2} {3} = new {2} {{ {4} }};\n";
|
||||
public static readonly Dictionary<WirePortDataType, string> WireToPPSType = new Dictionary<WirePortDataType, string>()
|
||||
{
|
||||
{ WirePortDataType.FLOAT,"FloatParameter"},
|
||||
{ WirePortDataType.FLOAT2,"Vector4Parameter"},
|
||||
{ WirePortDataType.FLOAT3,"Vector4Parameter"},
|
||||
{ WirePortDataType.FLOAT4,"Vector4Parameter"},
|
||||
{ WirePortDataType.COLOR,"ColorParameter"},
|
||||
{ WirePortDataType.SAMPLER1D,"TextureParameter"},
|
||||
{ WirePortDataType.SAMPLER2D,"TextureParameter"},
|
||||
{ WirePortDataType.SAMPLER3D,"TextureParameter"},
|
||||
{ WirePortDataType.SAMPLERCUBE,"TextureParameter"},
|
||||
{ WirePortDataType.SAMPLER2DARRAY,"TextureParameter"}
|
||||
};
|
||||
|
||||
public static readonly Dictionary<WirePortDataType, string> WireToPPSValueSet = new Dictionary<WirePortDataType, string>()
|
||||
{
|
||||
{ WirePortDataType.FLOAT,"SetFloat"},
|
||||
{ WirePortDataType.FLOAT2,"SetVector"},
|
||||
{ WirePortDataType.FLOAT3,"SetVector"},
|
||||
{ WirePortDataType.FLOAT4,"SetVector"},
|
||||
{ WirePortDataType.COLOR,"SetColor"},
|
||||
{ WirePortDataType.SAMPLER1D, "SetTexture"},
|
||||
{ WirePortDataType.SAMPLER2D, "SetTexture"},
|
||||
{ WirePortDataType.SAMPLER3D, "SetTexture"},
|
||||
{ WirePortDataType.SAMPLERCUBE,"SetTexture"},
|
||||
{ WirePortDataType.SAMPLER2DARRAY,"SetTexture"}
|
||||
};
|
||||
|
||||
public static readonly Dictionary<UnityEngine.Rendering.ShaderPropertyType, string> ShaderPropertyToPPSType = new Dictionary<UnityEngine.Rendering.ShaderPropertyType, string>()
|
||||
{
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Float,"FloatParameter"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Range,"FloatParameter"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Vector,"Vector4Parameter"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Color,"ColorParameter"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Texture,"TextureParameter"}
|
||||
};
|
||||
|
||||
|
||||
public static readonly Dictionary<UnityEngine.Rendering.ShaderPropertyType, string> ShaderPropertyToPPSSet = new Dictionary<UnityEngine.Rendering.ShaderPropertyType, string>()
|
||||
{
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Float,"SetFloat"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Range,"SetFloat"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Vector,"SetVector"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Color,"SetColor"},
|
||||
{ UnityEngine.Rendering.ShaderPropertyType.Texture,"SetTexture"}
|
||||
};
|
||||
|
||||
private Dictionary<string, bool> m_excludedProperties = new Dictionary<string, bool>
|
||||
{
|
||||
{ "_texcoord",true },
|
||||
{ "__dirty",true}
|
||||
};
|
||||
|
||||
private Material m_dummyMaterial = null;
|
||||
|
||||
private DragAndDropTool m_dragAndDropTool;
|
||||
private Rect m_draggableArea;
|
||||
|
||||
[SerializeField]
|
||||
private string m_rendererClassName = "PPSRenderer";
|
||||
|
||||
[SerializeField]
|
||||
private string m_settingsClassName = "PPSSettings";
|
||||
|
||||
[SerializeField]
|
||||
private string m_folderPath = "Assets/";
|
||||
|
||||
[SerializeField]
|
||||
private string m_menuEntry = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_allowInSceneView = true;
|
||||
|
||||
[SerializeField]
|
||||
private ASEPostProcessEvent m_eventType = ASEPostProcessEvent.AfterStack;
|
||||
|
||||
[SerializeField]
|
||||
private Shader m_currentShader = null;
|
||||
|
||||
[SerializeField]
|
||||
private List<ASEPPSHelperBuffer> m_tooltips = new List<ASEPPSHelperBuffer>();
|
||||
|
||||
[SerializeField]
|
||||
private bool m_tooltipsFoldout = true;
|
||||
|
||||
private GUIStyle m_contentStyle = null;
|
||||
private GUIStyle m_pathButtonStyle = null;
|
||||
private GUIContent m_pathButtonContent = new GUIContent();
|
||||
private Vector2 m_scrollPos = Vector2.zero;
|
||||
|
||||
[MenuItem( "Window/Amplify Shader Editor/Post-Processing Stack Tool", false, 1001 )]
|
||||
static void ShowWindow()
|
||||
{
|
||||
ASEPPSHelperTool window = EditorWindow.GetWindow<ASEPPSHelperTool>();
|
||||
window.titleContent.text = "Post-Processing Stack Tool";
|
||||
window.minSize = new Vector2( 302, 350 );
|
||||
window.Show();
|
||||
}
|
||||
|
||||
void FetchTooltips()
|
||||
{
|
||||
m_tooltips.Clear();
|
||||
int propertyCount = m_currentShader.GetPropertyCount();
|
||||
for( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
//UnityEngine.Rendering.ShaderPropertyType type = m_currentShader.GetPropertyType( i );
|
||||
string name = m_currentShader.GetPropertyName( i );
|
||||
string description = m_currentShader.GetPropertyDescription( i );
|
||||
|
||||
if( m_excludedProperties.ContainsKey( name ))
|
||||
continue;
|
||||
|
||||
m_tooltips.Add( new ASEPPSHelperBuffer { Name = name, Tooltip = description } );
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if( m_pathButtonStyle == null )
|
||||
m_pathButtonStyle = "minibutton";
|
||||
|
||||
m_scrollPos = EditorGUILayout.BeginScrollView( m_scrollPos, GUILayout.Height( position.height ) );
|
||||
|
||||
EditorGUILayout.BeginVertical( m_contentStyle );
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_currentShader = EditorGUILayout.ObjectField( "Shader", m_currentShader, typeof( Shader ), false ) as Shader;
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
GetInitialInfo( m_currentShader );
|
||||
}
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
EditorGUILayout.LabelField( "Path and Filename" );
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_pathButtonContent.text = m_folderPath;
|
||||
Vector2 buttonSize = m_pathButtonStyle.CalcSize( m_pathButtonContent );
|
||||
if( GUILayout.Button( m_pathButtonContent, m_pathButtonStyle, GUILayout.MaxWidth( Mathf.Min( position.width * 0.5f, buttonSize.x ) ) ) )
|
||||
{
|
||||
string folderpath = EditorUtility.OpenFolderPanel( "Save Texture Array to folder", "Assets/", "" );
|
||||
folderpath = FileUtil.GetProjectRelativePath( folderpath );
|
||||
if( string.IsNullOrEmpty( folderpath ) )
|
||||
m_folderPath = "Assets/";
|
||||
else
|
||||
m_folderPath = folderpath + "/";
|
||||
}
|
||||
|
||||
m_settingsClassName = EditorGUILayout.TextField( m_settingsClassName, GUILayout.ExpandWidth( true ) );
|
||||
|
||||
EditorGUILayout.LabelField( ".cs", GUILayout.MaxWidth( 40 ) );
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.HelpBox( "The path for the generated script should be outside of Amplify Shader Editor folder structure due to use of Assembly Definition files which will conflict and prevent to compile correctly.", MessageType.Warning );
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
m_menuEntry = EditorGUILayout.TextField( "Name", m_menuEntry );
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
m_allowInSceneView = EditorGUILayout.Toggle( "Allow In Scene View", m_allowInSceneView );
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
m_eventType = (ASEPostProcessEvent)EditorGUILayout.EnumPopup( "Event Type", m_eventType );
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
m_tooltipsFoldout = EditorGUILayout.Foldout( m_tooltipsFoldout, "Tooltips" );
|
||||
if( m_tooltipsFoldout )
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for( int i = 0; i < m_tooltips.Count; i++ )
|
||||
{
|
||||
m_tooltips[ i ].Tooltip = EditorGUILayout.TextField( m_tooltips[ i ].Name, m_tooltips[ i ].Tooltip );
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
if( GUILayout.Button( "Build" ) )
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
|
||||
string propertiesDecl = string.Empty;
|
||||
string propertiesSet = string.Empty;
|
||||
GetShaderInfoFromShaderAsset( ref propertiesDecl, ref propertiesSet );
|
||||
string template = PPSFullTemplate;
|
||||
template = template.Replace( PPSRendererClass, m_rendererClassName );
|
||||
template = template.Replace( PPSSettingsClass, m_settingsClassName );
|
||||
template = template.Replace( PPSEventType, m_eventType.ToString() );
|
||||
template = template.Replace( PPSPropertiesDecl, propertiesDecl );
|
||||
template = template.Replace( PPSPropertySet, propertiesSet );
|
||||
template = template.Replace( PPSMenuEntry, m_menuEntry );
|
||||
template = template.Replace( PPSAllowInSceneView, m_allowInSceneView?"true":"false" );
|
||||
template = template.Replace( PPSShader, m_currentShader.name );
|
||||
string path = m_folderPath + m_settingsClassName + ".cs";
|
||||
IOUtils.SaveTextfileToDisk( template, path, false );
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUILayout.EndScrollView();
|
||||
m_draggableArea.size = position.size;
|
||||
m_dragAndDropTool.TestDragAndDrop( m_draggableArea );
|
||||
}
|
||||
|
||||
public void GetShaderInfoFromASE( ref string propertiesDecl, ref string propertiesSet )
|
||||
{
|
||||
List<PropertyNode> properties = UIUtils.CurrentWindow.OutsideGraph.PropertyNodes.NodesList;
|
||||
int propertyCount = properties.Count;
|
||||
for( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
properties[ i ].GeneratePPSInfo( ref propertiesDecl, ref propertiesSet );
|
||||
}
|
||||
}
|
||||
|
||||
public void GetShaderInfoFromShaderAsset( ref string propertiesDecl, ref string propertiesSet )
|
||||
{
|
||||
bool fetchInitialInfo = false;
|
||||
if( m_currentShader == null )
|
||||
{
|
||||
Material mat = Selection.activeObject as Material;
|
||||
if( mat != null )
|
||||
{
|
||||
m_currentShader = mat.shader;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentShader = Selection.activeObject as Shader;
|
||||
}
|
||||
fetchInitialInfo = true;
|
||||
}
|
||||
|
||||
if( m_currentShader != null )
|
||||
{
|
||||
if( fetchInitialInfo )
|
||||
GetInitialInfo( m_currentShader );
|
||||
|
||||
if( m_dummyMaterial == null )
|
||||
{
|
||||
m_dummyMaterial = new Material( m_currentShader );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dummyMaterial.shader = m_currentShader;
|
||||
}
|
||||
|
||||
int propertyCount = m_currentShader.GetPropertyCount();
|
||||
//string allProperties = string.Empty;
|
||||
int validIds = 0;
|
||||
for( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
UnityEngine.Rendering.ShaderPropertyType type = m_currentShader.GetPropertyType( i );
|
||||
string name = m_currentShader.GetPropertyName( i );
|
||||
if( m_excludedProperties.ContainsKey( name ))
|
||||
continue;
|
||||
|
||||
string defaultValue = string.Empty;
|
||||
bool nullPointerCheck = false;
|
||||
switch( type )
|
||||
{
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Color:
|
||||
{
|
||||
Color value = m_dummyMaterial.GetColor( name );
|
||||
defaultValue = string.Format( "value = new Color({0}f,{1}f,{2}f,{3}f)", value.r, value.g, value.b, value.a );
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Vector:
|
||||
{
|
||||
Vector4 value = m_dummyMaterial.GetVector( name );
|
||||
defaultValue = string.Format( "value = new Vector4({0}f,{1}f,{2}f,{3}f)", value.x, value.y, value.z, value.w );
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Float:
|
||||
{
|
||||
float value = m_dummyMaterial.GetFloat( name );
|
||||
defaultValue = "value = " + value + "f";
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Range:
|
||||
{
|
||||
float value = m_dummyMaterial.GetFloat( name );
|
||||
defaultValue = "value = " + value + "f";
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Texture:
|
||||
{
|
||||
nullPointerCheck = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
propertiesDecl += string.Format( PPSPropertyDecFormat, string.Empty, m_tooltips[ validIds ].Tooltip, ShaderPropertyToPPSType[ type ], name, defaultValue );
|
||||
propertiesSet += string.Format( nullPointerCheck ? PPSPropertySetNullPointerCheckFormat : PPSPropertySetFormat, ShaderPropertyToPPSSet[ type ], name );
|
||||
validIds++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void GetInitialInfo()
|
||||
{
|
||||
MasterNode masterNode = UIUtils.CurrentWindow.OutsideGraph.CurrentMasterNode;
|
||||
m_menuEntry = masterNode.ShaderName.Replace( "Hidden/", string.Empty ).Replace( ".shader", string.Empty );
|
||||
string name = m_menuEntry;
|
||||
m_rendererClassName = name + "PPSRenderer";
|
||||
m_settingsClassName = name + "PPSSettings";
|
||||
m_folderPath = "Assets/";
|
||||
}
|
||||
|
||||
private void GetInitialInfo( Shader shader )
|
||||
{
|
||||
if( shader == null )
|
||||
{
|
||||
m_scrollPos = Vector2.zero;
|
||||
m_menuEntry = string.Empty;
|
||||
m_rendererClassName = "PPSRenderer";
|
||||
m_settingsClassName = "PPSSettings";
|
||||
m_folderPath = "Assets/";
|
||||
m_tooltips.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
m_menuEntry = shader.name.Replace( "Hidden/", string.Empty ).Replace( ".shader", string.Empty );
|
||||
m_menuEntry = UIUtils.RemoveInvalidCharacters( m_menuEntry );
|
||||
string name = m_menuEntry.Replace( "/", string.Empty );
|
||||
m_rendererClassName = name + "PPSRenderer";
|
||||
m_settingsClassName = name + "PPSSettings";
|
||||
m_folderPath = AssetDatabase.GetAssetPath( shader );
|
||||
m_folderPath = m_folderPath.Replace( System.IO.Path.GetFileName( m_folderPath ), string.Empty );
|
||||
|
||||
FetchTooltips();
|
||||
}
|
||||
|
||||
public void OnValidObjectsDropped( UnityEngine.Object[] droppedObjs )
|
||||
{
|
||||
for( int objIdx = 0; objIdx < droppedObjs.Length; objIdx++ )
|
||||
{
|
||||
Material mat = droppedObjs[ objIdx ] as Material;
|
||||
if( mat != null )
|
||||
{
|
||||
m_currentShader = mat.shader;
|
||||
GetInitialInfo( mat.shader );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Shader shader = droppedObjs[ objIdx ] as Shader;
|
||||
if( shader != null )
|
||||
{
|
||||
m_currentShader = shader;
|
||||
GetInitialInfo( shader );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_draggableArea = new Rect( 0, 0, 1, 1 );
|
||||
m_dragAndDropTool = new DragAndDropTool();
|
||||
m_dragAndDropTool.OnValidDropObjectEvt += OnValidObjectsDropped;
|
||||
|
||||
if( m_contentStyle == null )
|
||||
{
|
||||
m_contentStyle = new GUIStyle( GUIStyle.none );
|
||||
m_contentStyle.margin = new RectOffset( 6, 4, 5, 5 );
|
||||
}
|
||||
|
||||
m_pathButtonStyle = null;
|
||||
|
||||
//GetInitialInfo();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if( m_dummyMaterial != null )
|
||||
{
|
||||
GameObject.DestroyImmediate( m_dummyMaterial );
|
||||
m_dummyMaterial = null;
|
||||
}
|
||||
|
||||
m_dragAndDropTool.Destroy();
|
||||
m_dragAndDropTool = null;
|
||||
|
||||
m_tooltips.Clear();
|
||||
m_tooltips = null;
|
||||
|
||||
m_contentStyle = null;
|
||||
m_pathButtonStyle = null;
|
||||
m_currentShader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPPSHelperTool.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPPSHelperTool.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccaa3765dae023d4b8657544c1aeef4a
|
||||
timeCreated: 1550254201
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
518
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPackageManagerHelper.cs
vendored
Normal file
518
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPackageManagerHelper.cs
vendored
Normal file
@@ -0,0 +1,518 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public enum ASEImportFlags
|
||||
{
|
||||
None = 0,
|
||||
URP = 1 << 0,
|
||||
HDRP = 1 << 1,
|
||||
Both = URP | HDRP
|
||||
}
|
||||
|
||||
public static class AssetDatabaseEX
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEditor.AssetDatabase, UnityEditor" ) : type; } }
|
||||
|
||||
public static void ImportPackageImmediately( string packagePath )
|
||||
{
|
||||
AssetDatabaseEX.Type.InvokeMember( "ImportPackageImmediately", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { packagePath } );
|
||||
}
|
||||
}
|
||||
|
||||
public enum ASESRPBaseline
|
||||
{
|
||||
ASE_SRP_INVALID = 0,
|
||||
ASE_SRP_10_X = 100000,
|
||||
ASE_SRP_11_X = 110000,
|
||||
ASE_SRP_12_X = 120000,
|
||||
ASE_SRP_13_X = 130000,
|
||||
ASE_SRP_14_X = 140000,
|
||||
ASE_SRP_15_X = 150000,
|
||||
ASE_SRP_16_X = 160000,
|
||||
ASE_SRP_17_0 = 170000,
|
||||
ASE_SRP_17_1 = 170100,
|
||||
ASE_SRP_17_2 = 170200,
|
||||
ASE_SRP_17_3 = 170300
|
||||
}
|
||||
|
||||
public class ASESRPPackageDesc
|
||||
{
|
||||
public ASESRPBaseline baseline = ASESRPBaseline.ASE_SRP_INVALID;
|
||||
public string guidURP = string.Empty;
|
||||
public string guidHDRP = string.Empty;
|
||||
|
||||
public ASESRPPackageDesc( ASESRPBaseline baseline, string guidURP, string guidHDRP )
|
||||
{
|
||||
this.baseline = baseline;
|
||||
this.guidURP = guidURP;
|
||||
this.guidHDRP = guidHDRP;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[InitializeOnLoad]
|
||||
public static class ASEPackageManagerHelper
|
||||
{
|
||||
public static readonly string URPPackageId = "com.unity.render-pipelines.universal";
|
||||
public static readonly string HDRPPackageId = "com.unity.render-pipelines.high-definition";
|
||||
|
||||
private static readonly string NewVersionDetectedFormat = "A new {0} version {1} was detected and new templates are being imported.\nPlease hit the Update button on your ASE canvas to recompile your shader under the newest version.";
|
||||
private static readonly string PackageBaseFormat = "ASE_PkgBase_{0}_{1}";
|
||||
private static readonly string PackageCRCFormat = "ASE_PkgCRC_{0}_{1}";
|
||||
|
||||
private static readonly string SRPKeywordFormat = "ASE_SRP_VERSION {0}";
|
||||
private static readonly string ASEVersionKeywordFormat = "ASE_VERSION {0}";
|
||||
|
||||
public static readonly Dictionary<int, ASESRPPackageDesc> SRPPackageSupport = new Dictionary<int,ASESRPPackageDesc>()
|
||||
{
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_10_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_10_X, "b460b52e6c1feae45b70b7ddc2c45bd6", "2243c8b4e1ab6914995699133f67ab5a" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_11_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_11_X, "b460b52e6c1feae45b70b7ddc2c45bd6", "2243c8b4e1ab6914995699133f67ab5a" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_12_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_12_X, "57fcea0ed8b5eb347923c4c21fa31b57", "9a5e61a8b3421b944863d0946e32da0a" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_13_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_13_X, "57fcea0ed8b5eb347923c4c21fa31b57", "9a5e61a8b3421b944863d0946e32da0a" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_14_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_14_X, "2e9da72e7e3196146bf7d27450013734", "89f0b84148d149d4d96b838d7ef60e92" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_15_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_15_X, "0904cdf24ddcd5042b024326476220d5", "19939ee2cdb76e0489b1b8cd4bed7f3d" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_16_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_16_X, "929783250050f8a448821b6ca1f2c578", "70777e8ce9f3c8d4a8182ca2f965cdb2" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_0, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_0, "fcc4d2eb0af82e546ae75506872cf092", "ba281a1a00c8ac54c914e0763299f637" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_1, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_1, "cd0a0171c5157b748afe763b89f71211", "e6fc8948257acee42b666d0bfe1d782c" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_2, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_2, "f4990f6ace6142c4bbbf41cdd80b0bd3", "4b5cb8698f2d9c14fadf8e2383441d37" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_3, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_3, "b688bec486aafb24fa0e3dc57afaedb2", "5a07a5a188dd6fa42a63eb43dac1ad38" ) },
|
||||
};
|
||||
|
||||
private static Shader m_lateShader;
|
||||
private static Material m_lateMaterial;
|
||||
private static AmplifyShaderFunction m_lateShaderFunction;
|
||||
|
||||
private static ListRequest m_packageListRequest = null;
|
||||
private static UnityEditor.PackageManager.PackageInfo m_urpPackageInfo;
|
||||
private static UnityEditor.PackageManager.PackageInfo m_hdrpPackageInfo;
|
||||
|
||||
public static bool FoundURPVersion { get { return m_urpPackageInfo != null; } }
|
||||
public static bool FoundHDRPVersion { get { return m_hdrpPackageInfo != null; } }
|
||||
|
||||
private static bool m_lateImport = false;
|
||||
private static string m_latePackageToImport;
|
||||
private static bool m_requireUpdateList = false;
|
||||
private static ASEImportFlags m_importingPackage = ASEImportFlags.None;
|
||||
|
||||
public static bool CheckImporter { get { return m_importingPackage != ASEImportFlags.None; } }
|
||||
public static bool IsProcessing { get { return m_requireUpdateList && m_importingPackage == ASEImportFlags.None; } }
|
||||
|
||||
private static ASESRPBaseline m_currentURPBaseline = ASESRPBaseline.ASE_SRP_INVALID;
|
||||
private static ASESRPBaseline m_currentHDRPBaseline = ASESRPBaseline.ASE_SRP_INVALID;
|
||||
|
||||
public static ASESRPBaseline CurrentURPBaseline { get { return m_currentURPBaseline; } }
|
||||
public static ASESRPBaseline CurrentHDRPBaseline { get { return m_currentHDRPBaseline; } }
|
||||
|
||||
private static int m_packageURPVersion = -1; // @diogo: starts as missing
|
||||
private static int m_packageHDRPVersion = -1;
|
||||
|
||||
public static int PackageSRPVersion { get { return ( m_packageHDRPVersion >= m_packageURPVersion ) ? m_packageHDRPVersion : m_packageURPVersion; } }
|
||||
public static int CurrentSRPVersion { get { return UIUtils.CurrentWindow.MainGraphInstance.IsSRP ? PackageSRPVersion : -1; } }
|
||||
|
||||
private static string m_projectName = null;
|
||||
private static string ProjectName
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( string.IsNullOrEmpty( m_projectName ) )
|
||||
{
|
||||
string[] s = Application.dataPath.Split( '/' );
|
||||
m_projectName = s[ s.Length - 2 ];
|
||||
}
|
||||
return m_projectName;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if ( !RequestInfoNow() )
|
||||
{
|
||||
RequestInfo( true );
|
||||
}
|
||||
}
|
||||
|
||||
static void WaitForPackageListBeforeUpdating()
|
||||
{
|
||||
if ( m_packageListRequest.IsCompleted )
|
||||
{
|
||||
Update();
|
||||
EditorApplication.update -= WaitForPackageListBeforeUpdating;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RequestInfo( bool updateWhileWaiting = false )
|
||||
{
|
||||
if ( !m_requireUpdateList && m_importingPackage == ASEImportFlags.None )
|
||||
{
|
||||
m_requireUpdateList = true;
|
||||
m_packageListRequest = UnityEditor.PackageManager.Client.List( true );
|
||||
if ( updateWhileWaiting )
|
||||
{
|
||||
EditorApplication.update += WaitForPackageListBeforeUpdating;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool RequestInfoNow()
|
||||
{
|
||||
UnityEditor.PackageManager.PackageInfo[] packages = null;
|
||||
bool succeeded = true;
|
||||
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
packages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages();
|
||||
#else
|
||||
var request = UnityEditor.PackageManager.Client.List( true );
|
||||
while ( !request.IsCompleted && request.Status == StatusCode.InProgress )
|
||||
{
|
||||
}
|
||||
if ( request.Status == StatusCode.Success )
|
||||
{
|
||||
succeeded = ( request.Status == StatusCode.Success );
|
||||
packages = request.Result.ToArray();
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( succeeded )
|
||||
{
|
||||
UpdateNow( packages );
|
||||
}
|
||||
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
static void FailedPackageImport( string packageName, string errorMessage )
|
||||
{
|
||||
FinishImporter();
|
||||
}
|
||||
|
||||
static void CancelledPackageImport( string packageName )
|
||||
{
|
||||
FinishImporter();
|
||||
}
|
||||
|
||||
static void CompletedPackageImport( string packageName )
|
||||
{
|
||||
FinishImporter();
|
||||
}
|
||||
|
||||
public static void CheckLatePackageImport()
|
||||
{
|
||||
if ( !Application.isPlaying && m_lateImport && !string.IsNullOrEmpty( m_latePackageToImport ) )
|
||||
{
|
||||
m_lateImport = false;
|
||||
StartImporting( m_latePackageToImport );
|
||||
m_latePackageToImport = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool StartImporting( string packagePath )
|
||||
{
|
||||
if ( !Preferences.Project.AutoSRP )
|
||||
{
|
||||
m_importingPackage = ASEImportFlags.None;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Application.isPlaying )
|
||||
{
|
||||
if ( !m_lateImport )
|
||||
{
|
||||
m_lateImport = true;
|
||||
m_latePackageToImport = packagePath;
|
||||
Debug.LogWarning( "Amplify Shader Editor requires the \"" + packagePath + "\" package to be installed in order to continue. Please exit Play mode to proceed." );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AssetDatabase.importPackageCancelled += CancelledPackageImport;
|
||||
AssetDatabase.importPackageCompleted += CompletedPackageImport;
|
||||
AssetDatabase.importPackageFailed += FailedPackageImport;
|
||||
AssetDatabase.ImportPackage( packagePath, false );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void FinishImporter()
|
||||
{
|
||||
m_importingPackage = ASEImportFlags.None;
|
||||
AssetDatabase.importPackageCancelled -= CancelledPackageImport;
|
||||
AssetDatabase.importPackageCompleted -= CompletedPackageImport;
|
||||
AssetDatabase.importPackageFailed -= FailedPackageImport;
|
||||
}
|
||||
|
||||
public static void SetupLateShader( Shader shader )
|
||||
{
|
||||
if ( shader == null )
|
||||
return;
|
||||
|
||||
//If a previous delayed object is pending discard it and register the new one
|
||||
// So the last selection will be the choice of opening
|
||||
//This can happen when trying to open an ASE canvas while importing templates or in play mode
|
||||
if ( m_lateShader != null )
|
||||
{
|
||||
EditorApplication.delayCall -= LateShaderOpener;
|
||||
}
|
||||
|
||||
RequestInfo();
|
||||
m_lateShader = shader;
|
||||
EditorApplication.delayCall += LateShaderOpener;
|
||||
}
|
||||
|
||||
public static void LateShaderOpener()
|
||||
{
|
||||
Update();
|
||||
if ( IsProcessing )
|
||||
{
|
||||
EditorApplication.delayCall += LateShaderOpener;
|
||||
}
|
||||
else
|
||||
{
|
||||
AmplifyShaderEditorWindow.ConvertShaderToASE( m_lateShader );
|
||||
m_lateShader = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetupLateMaterial( Material material )
|
||||
{
|
||||
if ( material == null )
|
||||
return;
|
||||
|
||||
//If a previous delayed object is pending discard it and register the new one
|
||||
// So the last selection will be the choice of opening
|
||||
//This can happen when trying to open an ASE canvas while importing templates or in play mode
|
||||
if ( m_lateMaterial != null )
|
||||
{
|
||||
EditorApplication.delayCall -= LateMaterialOpener;
|
||||
}
|
||||
|
||||
RequestInfo();
|
||||
m_lateMaterial = material;
|
||||
EditorApplication.delayCall += LateMaterialOpener;
|
||||
}
|
||||
|
||||
public static void LateMaterialOpener()
|
||||
{
|
||||
Update();
|
||||
if ( IsProcessing )
|
||||
{
|
||||
EditorApplication.delayCall += LateMaterialOpener;
|
||||
}
|
||||
else
|
||||
{
|
||||
AmplifyShaderEditorWindow.LoadMaterialToASE( m_lateMaterial );
|
||||
m_lateMaterial = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetupLateShaderFunction( AmplifyShaderFunction shaderFunction )
|
||||
{
|
||||
if ( shaderFunction == null )
|
||||
return;
|
||||
|
||||
//If a previous delayed object is pending discard it and register the new one
|
||||
// So the last selection will be the choice of opening
|
||||
//This can happen when trying to open an ASE canvas while importing templates or in play mode
|
||||
if ( m_lateShaderFunction != null )
|
||||
{
|
||||
EditorApplication.delayCall -= LateShaderFunctionOpener;
|
||||
}
|
||||
|
||||
RequestInfo();
|
||||
m_lateShaderFunction = shaderFunction;
|
||||
EditorApplication.delayCall += LateShaderFunctionOpener;
|
||||
}
|
||||
|
||||
public static void LateShaderFunctionOpener()
|
||||
{
|
||||
Update();
|
||||
if ( IsProcessing )
|
||||
{
|
||||
EditorApplication.delayCall += LateShaderFunctionOpener;
|
||||
}
|
||||
else
|
||||
{
|
||||
AmplifyShaderEditorWindow.LoadShaderFunctionToASE( m_lateShaderFunction, false );
|
||||
m_lateShaderFunction = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string SemVerPattern = @"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$";
|
||||
|
||||
public static int PackageVersionStringToCode( string version, out int major, out int minor, out int patch )
|
||||
{
|
||||
MatchCollection matches = Regex.Matches( version, SemVerPattern, RegexOptions.Multiline );
|
||||
|
||||
bool validMatch = ( matches.Count > 0 && matches[ 0 ].Groups.Count >= 4 );
|
||||
major = validMatch ? int.Parse( matches[ 0 ].Groups[ 1 ].Value ) : 99;
|
||||
minor = validMatch ? int.Parse( matches[ 0 ].Groups[ 2 ].Value ) : 99;
|
||||
patch = validMatch ? int.Parse( matches[ 0 ].Groups[ 3 ].Value ) : 99;
|
||||
|
||||
int versionCode;
|
||||
versionCode = major * 10000;
|
||||
versionCode += minor * 100;
|
||||
versionCode += patch;
|
||||
return versionCode;
|
||||
}
|
||||
|
||||
public static void CodeToPackageVersionElements( int versionCode, out int major, out int minor, out int patch )
|
||||
{
|
||||
major = versionCode / 10000;
|
||||
minor = versionCode / 100 - major * 100;
|
||||
patch = versionCode - ( versionCode / 100 ) * 100;
|
||||
}
|
||||
|
||||
public static int PackageVersionElementsToCode( int major, int minor, int patch )
|
||||
{
|
||||
return major * 10000 + minor * 100 + patch;
|
||||
}
|
||||
|
||||
private static void CheckPackageImport( ASEImportFlags flag, ASESRPBaseline baseline, string guid, string version )
|
||||
{
|
||||
Debug.Assert( flag == ASEImportFlags.HDRP || flag == ASEImportFlags.URP );
|
||||
|
||||
string path = AssetDatabase.GUIDToAssetPath( guid );
|
||||
|
||||
if ( !string.IsNullOrEmpty( path ) && File.Exists( path ) )
|
||||
{
|
||||
uint currentCRC = IOUtils.CRC32( File.ReadAllBytes( path ) );
|
||||
|
||||
string srpName = flag.ToString();
|
||||
string packageBaseKey = string.Format( PackageBaseFormat, srpName, ProjectName );
|
||||
string packageCRCKey = string.Format( PackageCRCFormat, srpName, ProjectName );
|
||||
|
||||
ASESRPBaseline savedBaseline = ( ASESRPBaseline )EditorPrefs.GetInt( packageBaseKey );
|
||||
uint savedCRC = ( uint )EditorPrefs.GetInt( packageCRCKey, 0 );
|
||||
|
||||
bool foundNewVersion = ( savedBaseline != baseline ) || ( savedCRC != currentCRC );
|
||||
|
||||
EditorPrefs.SetInt( packageBaseKey, ( int )baseline );
|
||||
EditorPrefs.SetInt( packageCRCKey, ( int )currentCRC );
|
||||
|
||||
string testPath0 = string.Empty;
|
||||
string testPath1 = string.Empty;
|
||||
|
||||
switch ( flag )
|
||||
{
|
||||
case ASEImportFlags.URP:
|
||||
{
|
||||
testPath0 = AssetDatabase.GUIDToAssetPath( TemplatesManager.URPLitGUID );
|
||||
testPath1 = AssetDatabase.GUIDToAssetPath( TemplatesManager.URPUnlitGUID );
|
||||
break;
|
||||
}
|
||||
case ASEImportFlags.HDRP:
|
||||
{
|
||||
testPath0 = AssetDatabase.GUIDToAssetPath( TemplatesManager.HDRPLitGUID );
|
||||
testPath1 = AssetDatabase.GUIDToAssetPath( TemplatesManager.HDRPUnlitGUID );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !File.Exists( testPath0 ) || !File.Exists( testPath1 ) || foundNewVersion )
|
||||
{
|
||||
m_importingPackage |= flag;
|
||||
if ( StartImporting( path ) && foundNewVersion )
|
||||
{
|
||||
Debug.Log( "[AmplifyShaderEditor] " + string.Format( NewVersionDetectedFormat, srpName, version ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckPackage( UnityEditor.PackageManager.PackageInfo package )
|
||||
{
|
||||
int version = PackageVersionStringToCode( package.version, out int major, out int minor, out int patch );
|
||||
|
||||
int baselineMajor = major;
|
||||
int baselineMinor = ( major >= 17 ) ? minor: 0; // from 17+ baseline includes minor version
|
||||
int baseline = PackageVersionElementsToCode( baselineMajor, baselineMinor, 0 );
|
||||
|
||||
ASESRPPackageDesc match;
|
||||
|
||||
if ( package.name.Equals( URPPackageId ) && SRPPackageSupport.TryGetValue( baseline, out match ) )
|
||||
{
|
||||
// Universal Rendering Pipeline
|
||||
m_currentURPBaseline = match.baseline;
|
||||
m_packageURPVersion = version;
|
||||
m_urpPackageInfo = package;
|
||||
|
||||
CheckPackageImport( ASEImportFlags.URP, match.baseline, match.guidURP, package.version );
|
||||
}
|
||||
else if ( package.name.Equals( HDRPPackageId ) && SRPPackageSupport.TryGetValue( baseline, out match ) )
|
||||
{
|
||||
// High-Definition Rendering Pipeline
|
||||
m_currentHDRPBaseline = match.baseline;
|
||||
m_packageHDRPVersion = version;
|
||||
m_hdrpPackageInfo = package;
|
||||
|
||||
CheckPackageImport( ASEImportFlags.HDRP, match.baseline, match.guidHDRP, package.version );
|
||||
}
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
CheckLatePackageImport();
|
||||
|
||||
if ( m_requireUpdateList && m_importingPackage == ASEImportFlags.None )
|
||||
{
|
||||
if ( m_packageListRequest != null && m_packageListRequest.IsCompleted && m_packageListRequest.Result != null )
|
||||
{
|
||||
m_requireUpdateList = false;
|
||||
foreach ( UnityEditor.PackageManager.PackageInfo package in m_packageListRequest.Result )
|
||||
{
|
||||
CheckPackage( package );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateNow( UnityEditor.PackageManager.PackageInfo[] packages )
|
||||
{
|
||||
foreach ( UnityEditor.PackageManager.PackageInfo package in packages )
|
||||
{
|
||||
CheckPackage( package );
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetASEVersionInfoOnDataCollector( ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
if ( m_requireUpdateList )
|
||||
{
|
||||
Update();
|
||||
}
|
||||
|
||||
dataCollector.AddToDirectives( string.Format( ASEVersionKeywordFormat, VersionInfo.FullNumber ), -1, AdditionalLineType.Define );
|
||||
}
|
||||
|
||||
public static void SetSRPInfoOnDataCollector( ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
if ( m_requireUpdateList )
|
||||
{
|
||||
Update();
|
||||
}
|
||||
|
||||
if ( dataCollector.CurrentSRPType == TemplateSRPType.HDRP )
|
||||
{
|
||||
dataCollector.AddToDirectives( string.Format( SRPKeywordFormat, m_packageHDRPVersion ), -1, AdditionalLineType.Define );
|
||||
}
|
||||
else if ( dataCollector.CurrentSRPType == TemplateSRPType.URP )
|
||||
{
|
||||
dataCollector.AddToDirectives( string.Format( SRPKeywordFormat, m_packageURPVersion ), -1, AdditionalLineType.Define );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPackageManagerHelper.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEPackageManagerHelper.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f48de3e34ed250945ba8c16d98b8ca0e
|
||||
timeCreated: 1548881060
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleAsset.cs
vendored
Normal file
31
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleAsset.cs
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class ASESaveBundleAsset : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_packageContentsOrigin = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
private List<string> m_allExtras = new List<string>();
|
||||
|
||||
[SerializeField]
|
||||
private string m_packageTargetPath = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
private string m_packageTargetName = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
private List<Shader> m_allShaders = new List<Shader>();
|
||||
|
||||
public string PackageContentsOrigin { get { return m_packageContentsOrigin; } }
|
||||
public List<string> AllExtras{ get { return m_allExtras; } }
|
||||
public string PackageTargetPath{ get{ return m_packageTargetPath;}}
|
||||
public string PackageTargetName{ get { return m_packageTargetName; } }
|
||||
public List<Shader> AllShaders { get { return m_allShaders; } }
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleAsset.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleAsset.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0d8dab404a624247bc5d60b401b28d4
|
||||
timeCreated: 1634216888
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
520
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleTool.cs
vendored
Normal file
520
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleTool.cs
vendored
Normal file
@@ -0,0 +1,520 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
|
||||
public enum ASESaveBundleAssetAction
|
||||
{
|
||||
Update,
|
||||
Export,
|
||||
UpdateAndExport
|
||||
}
|
||||
|
||||
[CustomEditor( typeof( ASESaveBundleAsset ) )]
|
||||
public class ASESaveBundleAssetEditor : Editor
|
||||
{
|
||||
public ASESaveBundleAsset Instance;
|
||||
private DragAndDropTool m_dragAndDropTool;
|
||||
|
||||
private SerializedObject m_so;
|
||||
|
||||
private SerializedProperty m_packageContentsOrigin;
|
||||
private GUIContent m_packageContentsOriginLabel = new GUIContent("Search Path");
|
||||
|
||||
private SerializedProperty m_allExtras;
|
||||
|
||||
private SerializedProperty m_packageTargetPath;
|
||||
private GUIContent m_packageTargetPathLabel = new GUIContent( "Package Path" );
|
||||
|
||||
private SerializedProperty m_packageTargetName;
|
||||
private GUIContent m_packageTargetNameLabel = new GUIContent( "Package Name" );
|
||||
|
||||
private SerializedProperty m_allShaders;
|
||||
|
||||
[SerializeField]
|
||||
private ReorderableList m_listShaders = null;
|
||||
|
||||
[SerializeField]
|
||||
private ReorderableList m_listExtras = null;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
Instance = (ASESaveBundleAsset)target;
|
||||
|
||||
m_so = serializedObject;
|
||||
m_packageContentsOrigin = m_so.FindProperty( "m_packageContentsOrigin" );
|
||||
m_packageTargetPath = m_so.FindProperty( "m_packageTargetPath" );
|
||||
m_packageTargetName = m_so.FindProperty( "m_packageTargetName" );
|
||||
m_allShaders = m_so.FindProperty( "m_allShaders" );
|
||||
|
||||
if( m_listShaders == null )
|
||||
{
|
||||
m_listShaders = new ReorderableList( m_so , m_allShaders , true , true , true , true );
|
||||
m_listShaders.elementHeight = 16;
|
||||
|
||||
m_listShaders.drawElementCallback = ( Rect rect , int index , bool isActive , bool isFocused ) =>
|
||||
{
|
||||
m_allShaders.GetArrayElementAtIndex( index ).objectReferenceValue = (Shader)EditorGUI.ObjectField( rect , "Shader " + index , m_allShaders.GetArrayElementAtIndex( index ).objectReferenceValue , typeof( Shader ) , false );
|
||||
};
|
||||
|
||||
m_listShaders.drawHeaderCallback = ( Rect rect ) =>
|
||||
{
|
||||
EditorGUI.LabelField( rect , "Shader List" );
|
||||
};
|
||||
|
||||
m_listShaders.onAddCallback = ( list ) =>
|
||||
{
|
||||
m_allShaders.InsertArrayElementAtIndex( m_allShaders.arraySize );
|
||||
m_allShaders.GetArrayElementAtIndex( m_allShaders.arraySize - 1 ).objectReferenceValue = null;
|
||||
};
|
||||
|
||||
m_listShaders.onRemoveCallback = ( list ) =>
|
||||
{
|
||||
m_allShaders.GetArrayElementAtIndex( list.index ).objectReferenceValue = null;
|
||||
m_allShaders.DeleteArrayElementAtIndex( list.index );
|
||||
};
|
||||
}
|
||||
|
||||
m_allExtras = m_so.FindProperty( "m_allExtras" );
|
||||
if( m_listExtras == null )
|
||||
{
|
||||
m_listExtras = new ReorderableList( m_so , m_allExtras , true , true , true , true );
|
||||
m_listExtras.elementHeight = 18;
|
||||
|
||||
m_listExtras.drawElementCallback = ( Rect rect , int index , bool isActive , bool isFocused ) =>
|
||||
{
|
||||
rect.width -= 55;
|
||||
m_allExtras.GetArrayElementAtIndex( index ).stringValue = (string)EditorGUI.TextField( rect , "Path " + index , m_allExtras.GetArrayElementAtIndex( index ).stringValue );
|
||||
|
||||
rect.x += rect.width;
|
||||
rect.width = 55;
|
||||
if( GUI.Button( rect, "Browse" ) )
|
||||
m_allExtras.GetArrayElementAtIndex( index ).stringValue = ASESaveBundleTool.FetchPath( "Folder Path" , m_allExtras.GetArrayElementAtIndex( index ).stringValue );
|
||||
};
|
||||
|
||||
m_listExtras.drawHeaderCallback = ( Rect rect ) =>
|
||||
{
|
||||
EditorGUI.LabelField( rect , "Extra Paths" );
|
||||
};
|
||||
|
||||
m_listExtras.onAddCallback = ( list ) =>
|
||||
{
|
||||
m_allExtras.InsertArrayElementAtIndex( m_allExtras.arraySize );
|
||||
m_allExtras.GetArrayElementAtIndex( m_allExtras.arraySize - 1 ).stringValue = string.Empty;
|
||||
};
|
||||
|
||||
m_listExtras.onRemoveCallback = ( list ) =>
|
||||
{
|
||||
m_allExtras.GetArrayElementAtIndex( list.index ).stringValue = string.Empty;
|
||||
m_allExtras.DeleteArrayElementAtIndex( list.index );
|
||||
};
|
||||
}
|
||||
|
||||
m_dragAndDropTool = new DragAndDropTool();
|
||||
m_dragAndDropTool.OnValidDropObjectEvt += OnValidObjectsDropped;
|
||||
}
|
||||
|
||||
void FetchValidShadersFromPath( string path , bool updateProperty )
|
||||
{
|
||||
if( !path.StartsWith( "Assets" ) )
|
||||
{
|
||||
int idx = path.IndexOf( "Assets" );
|
||||
if( idx >= 0 )
|
||||
{
|
||||
path = path.Substring( idx );
|
||||
}
|
||||
}
|
||||
|
||||
if( AssetDatabase.IsValidFolder( path ) )
|
||||
{
|
||||
if( updateProperty )
|
||||
m_packageContentsOrigin.stringValue = path;
|
||||
|
||||
m_allShaders.ClearArray();
|
||||
|
||||
string[] pathArr = { path };
|
||||
string[] shaderInDir = AssetDatabase.FindAssets( "t:Shader" , pathArr );
|
||||
for( int shaderIdx = 0 ; shaderIdx < shaderInDir.Length ; shaderIdx++ )
|
||||
{
|
||||
Shader internalShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( shaderInDir[ shaderIdx ] ) );
|
||||
if( internalShader != null && IOUtils.IsASEShader( internalShader ) )
|
||||
{
|
||||
m_allShaders.InsertArrayElementAtIndex( m_allShaders.arraySize );
|
||||
m_allShaders.GetArrayElementAtIndex( m_allShaders.arraySize - 1 ).objectReferenceValue = internalShader;
|
||||
m_so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnValidObjectsDropped( UnityEngine.Object[] droppedObjs )
|
||||
{
|
||||
for( int objIdx = 0 ; objIdx < droppedObjs.Length ; objIdx++ )
|
||||
{
|
||||
Shader shader = droppedObjs[ objIdx ] as Shader;
|
||||
if( shader != null )
|
||||
{
|
||||
if( IOUtils.IsASEShader( shader ) )
|
||||
{
|
||||
m_allShaders.InsertArrayElementAtIndex( m_allShaders.arraySize );
|
||||
m_allShaders.GetArrayElementAtIndex( m_allShaders.arraySize - 1 ).objectReferenceValue = shader;
|
||||
m_so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DefaultAsset asset = droppedObjs[ objIdx ] as DefaultAsset;
|
||||
if( asset != null )
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath( asset );
|
||||
FetchValidShadersFromPath( path,true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Instance.AllShaders.Sort( ( x , y ) => string.Compare( x.name , y.name ) );
|
||||
m_so.Update();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
m_dragAndDropTool.Destroy();
|
||||
m_dragAndDropTool = null;
|
||||
}
|
||||
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
m_so.Update();
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
{
|
||||
EditorGUILayout.PropertyField( m_packageContentsOrigin, m_packageContentsOriginLabel );
|
||||
if( GUILayout.Button( "Browse", GUILayout.MaxWidth( 55 ) ) )
|
||||
{
|
||||
m_packageContentsOrigin.stringValue = ASESaveBundleTool.FetchPath( "Folder Path" , m_packageContentsOrigin.stringValue );
|
||||
}
|
||||
if( GUILayout.Button( "Fetch" , GUILayout.MaxWidth( 45 ) ) )
|
||||
{
|
||||
FetchValidShadersFromPath( m_packageContentsOrigin.stringValue, false );
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if( m_listExtras != null )
|
||||
m_listExtras.DoLayoutList();
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
{
|
||||
EditorGUILayout.PropertyField( m_packageTargetPath , m_packageTargetPathLabel );
|
||||
if( GUILayout.Button( "Browse",GUILayout.MaxWidth(55) ))
|
||||
m_packageTargetPath.stringValue = EditorUtility.OpenFolderPanel( "Folder Path" , m_packageTargetPath.stringValue , "" );
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.PropertyField( m_packageTargetName, m_packageTargetNameLabel );
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
if( GUILayout.Button( "Clear" ) )
|
||||
{
|
||||
m_allShaders.ClearArray();
|
||||
}
|
||||
|
||||
if( m_listShaders != null )
|
||||
m_listShaders.DoLayoutList();
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
m_dragAndDropTool.TestDragAndDrop( new Rect( 0 , 0 , Screen.width , Screen.height ) );
|
||||
|
||||
m_so.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
public void PackageFreeGUI()
|
||||
{
|
||||
m_so.Update();
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
{
|
||||
if ( string.IsNullOrEmpty( m_packageContentsOrigin.stringValue ) )
|
||||
{
|
||||
m_packageContentsOrigin.stringValue = "Assets";
|
||||
}
|
||||
EditorGUILayout.PropertyField( m_packageContentsOrigin, m_packageContentsOriginLabel );
|
||||
if ( GUILayout.Button( "Browse", GUILayout.MaxWidth( 55 ) ) )
|
||||
{
|
||||
m_packageContentsOrigin.stringValue = ASESaveBundleTool.FetchPath( "Folder Path", m_packageContentsOrigin.stringValue );
|
||||
}
|
||||
if ( GUILayout.Button( "Fetch", GUILayout.MaxWidth( 45 ) ) )
|
||||
{
|
||||
FetchValidShadersFromPath( m_packageContentsOrigin.stringValue, false );
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if ( m_listExtras != null )
|
||||
m_listExtras.DoLayoutList();
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
if ( GUILayout.Button( "Clear" ) )
|
||||
{
|
||||
m_allShaders.ClearArray();
|
||||
}
|
||||
|
||||
if ( m_listShaders != null )
|
||||
m_listShaders.DoLayoutList();
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
m_dragAndDropTool.TestDragAndDrop( new Rect( 0, 0, Screen.width, Screen.height ) );
|
||||
|
||||
m_so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public class ASESaveBundleTool : EditorWindow
|
||||
{
|
||||
private const string UpdateAllStr = "Update All";
|
||||
private const string UpdateAllStyle = "prebutton";
|
||||
|
||||
|
||||
[SerializeField]
|
||||
private ASESaveBundleAsset m_asset;
|
||||
|
||||
[SerializeField]
|
||||
private ASESaveBundleAsset m_dummyAsset;
|
||||
|
||||
private GUIStyle m_contentStyle = null;
|
||||
|
||||
private Vector2 m_scrollPos;
|
||||
private GUIContent m_ViewToolIcon;
|
||||
|
||||
ASESaveBundleAssetEditor m_editor;
|
||||
|
||||
private const string Title = "Batch Save and Pack";
|
||||
|
||||
[NonSerialized]
|
||||
private GUIStyle m_titleStyle;
|
||||
|
||||
[MenuItem( "Window/Amplify Shader Editor/" + Title, false, priority: 1100 )]
|
||||
static void ShowWindow()
|
||||
{
|
||||
ASESaveBundleTool window = EditorWindow.GetWindow<ASESaveBundleTool>();
|
||||
window.titleContent.text = "Batch Save...";
|
||||
window.titleContent.tooltip = Title;
|
||||
window.minSize = new Vector2( 302 , 350 );
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if( m_contentStyle == null )
|
||||
{
|
||||
m_contentStyle = new GUIStyle( GUIStyle.none );
|
||||
m_contentStyle.margin = new RectOffset( 6 , 4 , 5 , 5 );
|
||||
}
|
||||
|
||||
if( m_ViewToolIcon == null )
|
||||
{
|
||||
m_ViewToolIcon = EditorGUIUtility.IconContent( "icons/d_ViewToolZoom.png" );
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DestroyImmediate( m_editor );
|
||||
if( m_dummyAsset != null && m_dummyAsset != m_asset )
|
||||
DestroyImmediate( m_dummyAsset );
|
||||
}
|
||||
|
||||
|
||||
public static string FetchPath( string title, string folderpath )
|
||||
{
|
||||
folderpath = EditorUtility.OpenFolderPanel( title , folderpath , "" );
|
||||
folderpath = FileUtil.GetProjectRelativePath( folderpath );
|
||||
if( string.IsNullOrEmpty( folderpath ) )
|
||||
folderpath = "Assets";
|
||||
|
||||
return folderpath;
|
||||
}
|
||||
|
||||
private bool m_updatingShaders = false;
|
||||
|
||||
private void ExportCurrent( ASESaveBundleAsset currentAsset )
|
||||
{
|
||||
List<string> pathsList = new List<string>();
|
||||
pathsList.Add( currentAsset.PackageContentsOrigin );
|
||||
for( int i = 0 ; i < currentAsset.AllExtras.Count ; i++ )
|
||||
{
|
||||
if( currentAsset.AllExtras[ i ].StartsWith( "Assets" ) )
|
||||
{
|
||||
pathsList.Add( currentAsset.AllExtras[ i ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx = currentAsset.AllExtras[ i ].IndexOf( "Assets" );
|
||||
if( idx >= 0 )
|
||||
{
|
||||
pathsList.Add( currentAsset.AllExtras[ i ].Substring( idx ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
AssetDatabase.ExportPackage( pathsList.ToArray() , currentAsset.PackageTargetPath + "/" + currentAsset.PackageTargetName + ".unitypackage" , ExportPackageOptions.Recurse | ExportPackageOptions.Interactive );
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if( m_updatingShaders )
|
||||
{
|
||||
m_updatingShaders = EditorPrefs.HasKey( AmplifyShaderEditorWindow.ASEFileList );
|
||||
}
|
||||
|
||||
|
||||
if( m_titleStyle == null )
|
||||
{
|
||||
m_titleStyle = new GUIStyle( "BoldLabel" );
|
||||
m_titleStyle.fontSize = 13;
|
||||
m_titleStyle.alignment = TextAnchor.MiddleCenter;
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.LabelField( Title , m_titleStyle );
|
||||
EditorGUI.BeginDisabledGroup( m_updatingShaders );
|
||||
{
|
||||
ASESaveBundleAsset currentAsset = null;
|
||||
if( m_asset != null )
|
||||
{
|
||||
currentAsset = m_asset;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_dummyAsset == null )
|
||||
{
|
||||
m_dummyAsset = ScriptableObject.CreateInstance<ASESaveBundleAsset>();
|
||||
m_dummyAsset.name = "Dummy";
|
||||
}
|
||||
currentAsset = m_dummyAsset;
|
||||
}
|
||||
|
||||
m_scrollPos = EditorGUILayout.BeginScrollView( m_scrollPos , GUILayout.Height( position.height ) );
|
||||
{
|
||||
float cachedWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 100;
|
||||
EditorGUILayout.BeginVertical( m_contentStyle );
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup( currentAsset.AllShaders.Count <= 0 );
|
||||
{
|
||||
// Update all shaders
|
||||
if( GUILayout.Button( UpdateAllStr/* , UpdateAllStyle , GUILayout.Height( 20 )*/ ) )
|
||||
{
|
||||
m_updatingShaders = true;
|
||||
string[] assetPaths = new string[ currentAsset.AllShaders.Count ];
|
||||
for( int i = 0 ; i < assetPaths.Length ; i++ )
|
||||
{
|
||||
assetPaths[ i ] = AssetDatabase.GetAssetPath( currentAsset.AllShaders[ i ] );
|
||||
}
|
||||
AmplifyShaderEditorWindow.LoadAndSaveList( assetPaths );
|
||||
}
|
||||
|
||||
if( GUILayout.Button( "Remove Custom Inspector" ) )
|
||||
{
|
||||
int count = currentAsset.AllShaders.Count;
|
||||
for( int i = 0 ; i < count ; i++ )
|
||||
{
|
||||
EditorUtility.DisplayProgressBar( "Removing custom inspector", currentAsset.AllShaders[i].name , i / ( count - 1 ) );
|
||||
string path = AssetDatabase.GetAssetPath( currentAsset.AllShaders[ i ] );
|
||||
string shaderBody = IOUtils.LoadTextFileFromDisk( path );
|
||||
shaderBody = Regex.Replace( shaderBody , TemplateHelperFunctions.CustomInspectorPattern , string.Empty ,RegexOptions.Multiline );
|
||||
shaderBody = UIUtils.ForceLFLineEnding( shaderBody );
|
||||
IOUtils.SaveTextfileToDisk( shaderBody , path , false );
|
||||
}
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
|
||||
EditorGUI.BeginDisabledGroup( string.IsNullOrEmpty( currentAsset.PackageTargetName ) || string.IsNullOrEmpty( currentAsset.PackageTargetPath ) );
|
||||
{
|
||||
if( GUILayout.Button( "Export Unity Package" ) )
|
||||
{
|
||||
ExportCurrent( currentAsset );
|
||||
}
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
EditorGUILayout.Separator();
|
||||
// Asset creation/load
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_asset = EditorGUILayout.ObjectField( "Asset Preset" , m_asset , typeof( ASESaveBundleAsset ) , false ) as ASESaveBundleAsset;
|
||||
if( GUILayout.Button( m_asset != null ? "Save" : "Create" , "minibutton" , GUILayout.Width( 50 ) ) )
|
||||
{
|
||||
string defaultName = "ShaderBundlePreset";
|
||||
string assetPath = string.Empty;
|
||||
if( m_asset != null )
|
||||
{
|
||||
defaultName = m_asset.name;
|
||||
assetPath = Application.dataPath.Substring(0, Application.dataPath.Length - 6 )+ AssetDatabase.GetAssetPath( m_asset );
|
||||
}
|
||||
string path = EditorUtility.SaveFilePanelInProject( "Save as" , defaultName , "asset" , string.Empty , assetPath );
|
||||
if( !string.IsNullOrEmpty( path ) )
|
||||
{
|
||||
ASESaveBundleAsset outfile = AssetDatabase.LoadMainAssetAtPath( path ) as ASESaveBundleAsset;
|
||||
if( outfile != null )
|
||||
{
|
||||
EditorUtility.CopySerialized( currentAsset , outfile );
|
||||
AssetDatabase.SaveAssets();
|
||||
Selection.activeObject = outfile;
|
||||
EditorGUIUtility.PingObject( outfile );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_asset != null )
|
||||
{
|
||||
currentAsset = ScriptableObject.CreateInstance<ASESaveBundleAsset>();
|
||||
EditorUtility.CopySerialized( m_asset , currentAsset );
|
||||
}
|
||||
AssetDatabase.CreateAsset( currentAsset , path );
|
||||
Selection.activeObject = currentAsset;
|
||||
EditorGUIUtility.PingObject( currentAsset );
|
||||
m_asset = currentAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if( Event.current.type == EventType.Layout )
|
||||
{
|
||||
if( m_editor == null )
|
||||
{
|
||||
m_editor = Editor.CreateEditor( currentAsset , typeof( ASESaveBundleAssetEditor ) ) as ASESaveBundleAssetEditor;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_editor.Instance != currentAsset )
|
||||
{
|
||||
DestroyImmediate( m_editor );
|
||||
m_editor = Editor.CreateEditor( currentAsset , typeof( ASESaveBundleAssetEditor ) ) as ASESaveBundleAssetEditor;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( m_editor != null )
|
||||
m_editor.OnInspectorGUI();
|
||||
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleTool.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASESaveBundleTool.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10b84d00b09113748ac1353969d01918
|
||||
timeCreated: 1634216888
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
545
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEStartScreen.cs
vendored
Normal file
545
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEStartScreen.cs
vendored
Normal file
@@ -0,0 +1,545 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class ASEStartScreen : EditorWindow
|
||||
{
|
||||
[MenuItem( "Window/Amplify Shader Editor/Start Screen", false, 1999 )]
|
||||
public static void Init()
|
||||
{
|
||||
ASEStartScreen window = (ASEStartScreen)GetWindow( typeof( ASEStartScreen ), true, "Amplify Shader Editor Start Screen" );
|
||||
window.minSize = new Vector2( 650, 500 );
|
||||
window.maxSize = new Vector2( 650, 500 );
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private static readonly string ChangeLogGUID = "580cccd3e608b7f4cac35ea46d62d429";
|
||||
private static readonly string ResourcesGUID = "c0a0a980c9ba86345bc15411db88d34f";
|
||||
private static readonly string BuiltInGUID = "e00e6f90ab8233e46a41c5e33917c642";
|
||||
private static readonly string UniversalGUID = "a9d68dd8913f05d4d9ce75e7b40c6044";
|
||||
private static readonly string HighDefinitionGUID = "d1c0b77896049554fa4b635531caf741";
|
||||
|
||||
private static readonly string IconGUID = "2c6536772776dd84f872779990273bfc";
|
||||
|
||||
public static readonly string ChangelogURL = "https://amplify.pt/Banner/ASEchangelog.json";
|
||||
|
||||
private static readonly string ManualURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Manual";
|
||||
private static readonly string BasicURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Tutorials#Official_-_Basics";
|
||||
private static readonly string BeginnerURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Tutorials#Official_-_Beginner_Series";
|
||||
private static readonly string NodesURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Nodes";
|
||||
private static readonly string SRPURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Scriptable_Rendering_Pipeline";
|
||||
private static readonly string FunctionsURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Manual#Shader_Functions";
|
||||
private static readonly string TemplatesURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Templates";
|
||||
private static readonly string APIURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/API";
|
||||
private static readonly string SGtoASEURL = "https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Shader_Graph_to_ASE";
|
||||
|
||||
private static readonly string DiscordURL = "https://discordapp.com/invite/EdrVAP5";
|
||||
private static readonly string ForumURL = "https://forum.unity.com/threads/best-tool-asset-store-award-amplify-shader-editor-node-based-shader-creation-tool.430959/";
|
||||
|
||||
private static readonly string SiteURL = "http://amplify.pt/download/";
|
||||
private static readonly string StoreURL = "https://assetstore.unity.com/packages/tools/visual-scripting/amplify-shader-editor-68570";
|
||||
|
||||
private static readonly GUIContent SamplesTitle = new GUIContent( "Shader Samples", "Import samples according to you project rendering pipeline" );
|
||||
private static readonly GUIContent ResourcesTitle = new GUIContent( "Learning Resources", "Check the online wiki for various topics about how to use ASE with node examples and explanations" );
|
||||
private static readonly GUIContent CommunityTitle = new GUIContent( "Community", "Need help? Reach us through our discord server or the official support Unity forum" );
|
||||
private static readonly GUIContent UpdateTitle = new GUIContent( "Latest Update", "Check the lastest additions, improvements and bug fixes done to ASE" );
|
||||
private static readonly GUIContent ASETitle = new GUIContent( "Amplify Shader Editor", "Are you using the latest version? Now you know" );
|
||||
|
||||
private const string OnlineVersionWarning = "Please enable \"Allow downloads over HTTP*\" in Player Settings to access latest version information via Start Screen.";
|
||||
|
||||
Vector2 m_scrollPosition = Vector2.zero;
|
||||
Preferences.ShowOption m_startup = Preferences.ShowOption.Never;
|
||||
|
||||
[NonSerialized]
|
||||
Texture packageIcon = null;
|
||||
[NonSerialized]
|
||||
Texture textIcon = null;
|
||||
[NonSerialized]
|
||||
Texture webIcon = null;
|
||||
|
||||
GUIContent HDRPbutton = null;
|
||||
GUIContent URPbutton = null;
|
||||
GUIContent BuiltInbutton = null;
|
||||
|
||||
GUIContent Manualbutton = null;
|
||||
GUIContent Basicbutton = null;
|
||||
GUIContent Beginnerbutton = null;
|
||||
GUIContent Nodesbutton = null;
|
||||
GUIContent SRPusebutton = null;
|
||||
GUIContent Functionsbutton = null;
|
||||
GUIContent Templatesbutton = null;
|
||||
GUIContent APIbutton = null;
|
||||
GUIContent SGtoASEbutton = null;
|
||||
|
||||
GUIContent DiscordButton = null;
|
||||
GUIContent ForumButton = null;
|
||||
|
||||
GUIContent ASEIcon = null;
|
||||
RenderTexture rt;
|
||||
|
||||
[NonSerialized]
|
||||
GUIStyle m_buttonStyle = null;
|
||||
[NonSerialized]
|
||||
GUIStyle m_buttonLeftStyle = null;
|
||||
[NonSerialized]
|
||||
GUIStyle m_buttonRightStyle = null;
|
||||
[NonSerialized]
|
||||
GUIStyle m_minibuttonStyle = null;
|
||||
[NonSerialized]
|
||||
GUIStyle m_labelStyle = null;
|
||||
[NonSerialized]
|
||||
GUIStyle m_linkStyle = null;
|
||||
|
||||
private ChangeLogInfo m_changeLog;
|
||||
private bool m_infoDownloaded = false;
|
||||
private string m_newVersion = string.Empty;
|
||||
|
||||
private static Dictionary<int, ASESRPPackageDesc> m_srpSamplePackages = new Dictionary<int, ASESRPPackageDesc>()
|
||||
{
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_10_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_10_X, "2edbf4a9b9544774bbef617e92429664", "9da5530d5ebfab24c8ecad68795e720f" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_11_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_11_X, "2edbf4a9b9544774bbef617e92429664", "9da5530d5ebfab24c8ecad68795e720f" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_12_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_12_X, "13ab599a7bda4e54fba3e92a13c9580a", "aa102d640b98b5d4781710a3a3dd6983" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_13_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_13_X, "13ab599a7bda4e54fba3e92a13c9580a", "aa102d640b98b5d4781710a3a3dd6983" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_14_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_14_X, "f6f268949ccf3f34fa4d18e92501ed82", "7a0bb33169d95ec499136d59cb25918b" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_15_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_15_X, "69bc3229216b1504ea3e28b5820bbb0d", "641c955d37d2fac4f87e00ac5c9d9bd8" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_16_X, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_16_X, "4f665a06c5a2aa5499fa1c79ac058999", "2690f45490c175045bbdc63395bf6278" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_0, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_0, "8a87ed432fe2d97498c0de5fae312e35", "fbd1fd9b3a70fad429d1eaaa5799c2a5" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_1, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_1, "7c3bfbbeb9427b94099254e2e2768ad4", "3579d9cf4b75c564faa8fffc58a9f3f6" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_2, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_2, "c5303861611f41c438a30be552da5de4", "0023a0858ba124646a55dfcb7231ed46" ) },
|
||||
{ ( int )ASESRPBaseline.ASE_SRP_17_3, new ASESRPPackageDesc( ASESRPBaseline.ASE_SRP_17_3, "5634bb9710277c543987ff9d4ff9e4ff", "d7f739fdf66c738498523e76b3628caf" ) },
|
||||
};
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
rt = new RenderTexture( 16, 16, 0 );
|
||||
rt.Create();
|
||||
|
||||
m_startup = ( Preferences.ShowOption )EditorPrefs.GetInt( Preferences.User.Keys.StartUp, 0 );
|
||||
|
||||
if ( textIcon == null )
|
||||
{
|
||||
Texture icon = EditorGUIUtility.IconContent( "TextAsset Icon" ).image;
|
||||
var cache = RenderTexture.active;
|
||||
RenderTexture.active = rt;
|
||||
Graphics.Blit( icon, rt );
|
||||
RenderTexture.active = cache;
|
||||
textIcon = rt;
|
||||
|
||||
Manualbutton = new GUIContent( " Manual", textIcon );
|
||||
Basicbutton = new GUIContent( " Basic use tutorials", textIcon );
|
||||
Beginnerbutton = new GUIContent( " Beginner Series", textIcon );
|
||||
Nodesbutton = new GUIContent( " Node List", textIcon );
|
||||
SRPusebutton = new GUIContent( " SRP HDRP/URP use", textIcon );
|
||||
Functionsbutton = new GUIContent( " Shader Functions", textIcon );
|
||||
Templatesbutton = new GUIContent( " Shader Templates", textIcon );
|
||||
APIbutton = new GUIContent( " Node API", textIcon );
|
||||
SGtoASEbutton = new GUIContent( " Shader Graph to ASE", textIcon );
|
||||
}
|
||||
|
||||
if ( packageIcon == null )
|
||||
{
|
||||
packageIcon = EditorGUIUtility.IconContent( "BuildSettings.Editor.Small" ).image;
|
||||
HDRPbutton = new GUIContent( " HDRP Samples", packageIcon );
|
||||
URPbutton = new GUIContent( " URP Samples", packageIcon );
|
||||
BuiltInbutton = new GUIContent( " Built-In Samples", packageIcon );
|
||||
}
|
||||
|
||||
if ( webIcon == null )
|
||||
{
|
||||
webIcon = EditorGUIUtility.IconContent( "BuildSettings.Web.Small" ).image;
|
||||
DiscordButton = new GUIContent( " Discord", webIcon );
|
||||
ForumButton = new GUIContent( " Unity Forum", webIcon );
|
||||
}
|
||||
|
||||
if ( m_changeLog == null )
|
||||
{
|
||||
var changelog = AssetDatabase.LoadAssetAtPath<TextAsset>( AssetDatabase.GUIDToAssetPath( ChangeLogGUID ) );
|
||||
string lastUpdate = string.Empty;
|
||||
if ( changelog != null )
|
||||
{
|
||||
int oldestReleaseIndex = changelog.text.LastIndexOf( string.Format( "v{0}.{1}.{2}", VersionInfo.Major, VersionInfo.Minor, VersionInfo.Release ) );
|
||||
|
||||
lastUpdate = changelog.text.Substring( 0, changelog.text.IndexOf( "\nv", oldestReleaseIndex + 25 ) );// + "\n...";
|
||||
lastUpdate = lastUpdate.Replace( "* ", "\u2022 " );
|
||||
}
|
||||
m_changeLog = new ChangeLogInfo( VersionInfo.FullNumber, lastUpdate );
|
||||
}
|
||||
|
||||
if( ASEIcon == null )
|
||||
{
|
||||
ASEIcon = new GUIContent( AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( IconGUID ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if ( rt != null )
|
||||
{
|
||||
rt.Release();
|
||||
DestroyImmediate( rt );
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
if ( !m_infoDownloaded )
|
||||
{
|
||||
m_infoDownloaded = true;
|
||||
|
||||
StartBackgroundTask( StartRequest( ChangelogURL, () =>
|
||||
{
|
||||
if ( string.IsNullOrEmpty( www.error ) )
|
||||
{
|
||||
ChangeLogInfo temp;
|
||||
try
|
||||
{
|
||||
temp = ChangeLogInfo.CreateFromJSON( www.downloadHandler.text );
|
||||
}
|
||||
catch ( Exception )
|
||||
{
|
||||
temp = null;
|
||||
}
|
||||
if ( temp != null && temp.Version >= m_changeLog.Version )
|
||||
{
|
||||
m_changeLog = temp;
|
||||
}
|
||||
|
||||
int version = m_changeLog.Version;
|
||||
int major = version / 10000;
|
||||
int minor = version / 1000 - major * 10;
|
||||
int release = version / 100 - ( version / 1000 ) * 10;
|
||||
int revision = version - ( version / 100 ) * 100;
|
||||
|
||||
m_newVersion = major + "." + minor + "." + release + ( revision > 0 ? "." + revision : "" );
|
||||
|
||||
Repaint();
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
|
||||
if ( m_buttonStyle == null )
|
||||
{
|
||||
m_buttonStyle = new GUIStyle( GUI.skin.button );
|
||||
m_buttonStyle.alignment = TextAnchor.MiddleLeft;
|
||||
}
|
||||
|
||||
if ( m_buttonLeftStyle == null )
|
||||
{
|
||||
m_buttonLeftStyle = new GUIStyle( "ButtonLeft" );
|
||||
m_buttonLeftStyle.alignment = TextAnchor.MiddleLeft;
|
||||
m_buttonLeftStyle.margin = m_buttonStyle.margin;
|
||||
m_buttonLeftStyle.margin.right = 0;
|
||||
}
|
||||
|
||||
if ( m_buttonRightStyle == null )
|
||||
{
|
||||
m_buttonRightStyle = new GUIStyle( "ButtonRight" );
|
||||
m_buttonRightStyle.alignment = TextAnchor.MiddleLeft;
|
||||
m_buttonRightStyle.margin = m_buttonStyle.margin;
|
||||
m_buttonRightStyle.margin.left = 0;
|
||||
}
|
||||
|
||||
if ( m_minibuttonStyle == null )
|
||||
{
|
||||
m_minibuttonStyle = new GUIStyle( "MiniButton" );
|
||||
m_minibuttonStyle.alignment = TextAnchor.MiddleLeft;
|
||||
m_minibuttonStyle.margin = m_buttonStyle.margin;
|
||||
m_minibuttonStyle.margin.left = 20;
|
||||
m_minibuttonStyle.normal.textColor = m_buttonStyle.normal.textColor;
|
||||
m_minibuttonStyle.hover.textColor = m_buttonStyle.hover.textColor;
|
||||
}
|
||||
|
||||
if ( m_labelStyle == null )
|
||||
{
|
||||
m_labelStyle = new GUIStyle( "BoldLabel" );
|
||||
m_labelStyle.margin = new RectOffset( 4, 4, 4, 4 );
|
||||
m_labelStyle.padding = new RectOffset( 2, 2, 2, 2 );
|
||||
m_labelStyle.fontSize = 13;
|
||||
}
|
||||
|
||||
if ( m_linkStyle == null )
|
||||
{
|
||||
var inv = AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( "1004d06b4b28f5943abdf2313a22790a" ) ); // find a better solution for transparent buttons
|
||||
m_linkStyle = new GUIStyle();
|
||||
m_linkStyle.normal.textColor = new Color( 0.2980392f, 0.4901961f, 1f );
|
||||
m_linkStyle.hover.textColor = Color.white;
|
||||
m_linkStyle.active.textColor = Color.grey;
|
||||
m_linkStyle.margin.top = 3;
|
||||
m_linkStyle.margin.bottom = 2;
|
||||
m_linkStyle.hover.background = inv;
|
||||
m_linkStyle.active.background = inv;
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal( GUIStyle.none, GUILayout.ExpandWidth( true ) );
|
||||
{
|
||||
// left column
|
||||
EditorGUILayout.BeginVertical( GUILayout.Width( 175 ) );
|
||||
{
|
||||
GUILayout.Label( SamplesTitle, m_labelStyle );
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
if ( GUILayout.Button( HDRPbutton, m_buttonLeftStyle ) )
|
||||
{
|
||||
if ( ASEPackageManagerHelper.CurrentHDRPBaseline != ASESRPBaseline.ASE_SRP_INVALID )
|
||||
{
|
||||
ImportSample( HDRPbutton.text, TemplateSRPType.HDRP );
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog( "Import Sample", "Import failed because a valid HDRP package could not be found on this project.\n\nPlease install the \"High Definition RP\" package via \"Window/Package Manager\" before attempting to import HDRP samples again.", "OK" );
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if ( GUILayout.Button( URPbutton, m_buttonLeftStyle ) )
|
||||
{
|
||||
if ( ASEPackageManagerHelper.CurrentURPBaseline != ASESRPBaseline.ASE_SRP_INVALID )
|
||||
{
|
||||
ImportSample( URPbutton.text, TemplateSRPType.URP );
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog( "Import Sample", "Import failed because valid URP package could not be found on this project.\n\nPlease install the \"Universal RP\" package via \"Window/Package Manager\" before attempting to import URP samples again.", "OK" );
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if ( GUILayout.Button( BuiltInbutton, m_buttonStyle ) )
|
||||
ImportSample( BuiltInbutton.text, TemplateSRPType.BiRP );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
GUILayout.Label( ResourcesTitle, m_labelStyle );
|
||||
if ( GUILayout.Button( Manualbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( ManualURL );
|
||||
|
||||
if ( GUILayout.Button( Basicbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( BasicURL );
|
||||
|
||||
if ( GUILayout.Button( Beginnerbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( BeginnerURL );
|
||||
|
||||
if ( GUILayout.Button( Nodesbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( NodesURL );
|
||||
|
||||
if ( GUILayout.Button( SRPusebutton, m_buttonStyle ) )
|
||||
Application.OpenURL( SRPURL );
|
||||
|
||||
if ( GUILayout.Button( Functionsbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( FunctionsURL );
|
||||
|
||||
if ( GUILayout.Button( Templatesbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( TemplatesURL );
|
||||
|
||||
if ( GUILayout.Button( APIbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( APIURL );
|
||||
|
||||
if ( GUILayout.Button( SGtoASEbutton, m_buttonStyle ) )
|
||||
Application.OpenURL( SGtoASEURL );
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
// right column
|
||||
EditorGUILayout.BeginVertical( GUILayout.Width( 650 - 175 - 9 ), GUILayout.ExpandHeight( true ) );
|
||||
{
|
||||
GUILayout.Label( CommunityTitle, m_labelStyle );
|
||||
EditorGUILayout.BeginHorizontal( GUILayout.ExpandWidth( true ) );
|
||||
{
|
||||
if ( GUILayout.Button( DiscordButton, GUILayout.ExpandWidth( true ) ) )
|
||||
{
|
||||
Application.OpenURL( DiscordURL );
|
||||
}
|
||||
if ( GUILayout.Button( ForumButton, GUILayout.ExpandWidth( true ) ) )
|
||||
{
|
||||
Application.OpenURL( ForumURL );
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Label( UpdateTitle, m_labelStyle );
|
||||
m_scrollPosition = GUILayout.BeginScrollView( m_scrollPosition, "ProgressBarBack", GUILayout.ExpandHeight( true ), GUILayout.ExpandWidth( true ) );
|
||||
GUILayout.Label( m_changeLog.LastUpdate, "WordWrappedMiniLabel", GUILayout.ExpandHeight( true ) );
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
EditorGUILayout.BeginHorizontal( GUILayout.ExpandWidth( true ) );
|
||||
{
|
||||
EditorGUILayout.BeginVertical();
|
||||
GUILayout.Label( ASETitle, m_labelStyle );
|
||||
|
||||
GUILayout.Label( "Installed Version: " + VersionInfo.StaticToString() );
|
||||
|
||||
if ( m_changeLog.Version > VersionInfo.FullNumber )
|
||||
{
|
||||
var cache = GUI.color;
|
||||
GUI.color = Color.red;
|
||||
GUILayout.Label( "New version available: " + m_newVersion, "BoldLabel" );
|
||||
GUI.color = cache;
|
||||
}
|
||||
else
|
||||
{
|
||||
var cache = GUI.color;
|
||||
GUI.color = Color.green;
|
||||
GUILayout.Label( "You are using the latest version", "BoldLabel" );
|
||||
GUI.color = cache;
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Label( "Download links:" );
|
||||
if ( GUILayout.Button( "Amplify", m_linkStyle ) )
|
||||
Application.OpenURL( SiteURL );
|
||||
GUILayout.Label( "-" );
|
||||
if ( GUILayout.Button( "Asset Store", m_linkStyle ) )
|
||||
Application.OpenURL( StoreURL );
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space( 7 );
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.BeginVertical();
|
||||
GUILayout.Space( 7 );
|
||||
GUILayout.Label( ASEIcon );
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
|
||||
EditorGUILayout.BeginHorizontal( "ProjectBrowserBottomBarBg", GUILayout.ExpandWidth( true ), GUILayout.Height( 22 ) );
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var cache = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 100;
|
||||
m_startup = ( Preferences.ShowOption )EditorGUILayout.EnumPopup( "Show At Startup", m_startup, GUILayout.Width( 220 ) );
|
||||
EditorGUIUtility.labelWidth = cache;
|
||||
if ( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetInt( Preferences.User.Keys.StartUp, ( int )m_startup );
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
void ImportSample( string pipeline, TemplateSRPType srpType )
|
||||
{
|
||||
if ( EditorUtility.DisplayDialog( "Import Sample", "This will import the samples for" + pipeline.Replace( " Samples", "" ) + ", please make sure the pipeline is properly installed and/or selected before importing the samples.\n\nContinue?", "Yes", "No" ) )
|
||||
{
|
||||
AssetDatabase.ImportPackage( AssetDatabase.GUIDToAssetPath( ResourcesGUID ), false );
|
||||
|
||||
switch ( srpType )
|
||||
{
|
||||
case TemplateSRPType.BiRP:
|
||||
{
|
||||
AssetDatabase.ImportPackage( AssetDatabase.GUIDToAssetPath( BuiltInGUID ), false );
|
||||
break;
|
||||
}
|
||||
case TemplateSRPType.URP:
|
||||
{
|
||||
if ( m_srpSamplePackages.TryGetValue( ( int )ASEPackageManagerHelper.CurrentURPBaseline, out ASESRPPackageDesc desc ) )
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath( desc.guidURP );
|
||||
if ( !string.IsNullOrEmpty( path ) )
|
||||
{
|
||||
AssetDatabase.ImportPackage( AssetDatabase.GUIDToAssetPath( UniversalGUID ), false );
|
||||
AssetDatabase.ImportPackage( path, false );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TemplateSRPType.HDRP:
|
||||
{
|
||||
if ( m_srpSamplePackages.TryGetValue( ( int )ASEPackageManagerHelper.CurrentHDRPBaseline, out ASESRPPackageDesc desc ) )
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath( desc.guidHDRP );
|
||||
if ( !string.IsNullOrEmpty( path ) )
|
||||
{
|
||||
AssetDatabase.ImportPackage( AssetDatabase.GUIDToAssetPath( HighDefinitionGUID ), false );
|
||||
AssetDatabase.ImportPackage( path, false );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// no action
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UnityWebRequest www;
|
||||
|
||||
IEnumerator StartRequest( string url, Action success = null )
|
||||
{
|
||||
using ( www = UnityWebRequest.Get( url ) )
|
||||
{
|
||||
yield return www.SendWebRequest();
|
||||
|
||||
while ( www.isDone == false )
|
||||
yield return null;
|
||||
|
||||
if ( success != null )
|
||||
success();
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartBackgroundTask( IEnumerator update, Action end = null )
|
||||
{
|
||||
EditorApplication.CallbackFunction closureCallback = null;
|
||||
|
||||
closureCallback = () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( update.MoveNext() == false )
|
||||
{
|
||||
if ( end != null )
|
||||
end();
|
||||
EditorApplication.update -= closureCallback;
|
||||
}
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
if ( end != null )
|
||||
end();
|
||||
Debug.LogException( ex );
|
||||
EditorApplication.update -= closureCallback;
|
||||
}
|
||||
};
|
||||
|
||||
EditorApplication.update += closureCallback;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class ChangeLogInfo
|
||||
{
|
||||
public int Version;
|
||||
public string LastUpdate;
|
||||
|
||||
public static ChangeLogInfo CreateFromJSON( string jsonString )
|
||||
{
|
||||
return JsonUtility.FromJson<ChangeLogInfo>( jsonString );
|
||||
}
|
||||
|
||||
public ChangeLogInfo( int version, string lastUpdate )
|
||||
{
|
||||
Version = version;
|
||||
LastUpdate = lastUpdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEStartScreen.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASEStartScreen.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e7433fb42db4d9428571bfcd0da64f3
|
||||
timeCreated: 1585827066
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
808
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASETextureArrayCreator.cs
vendored
Normal file
808
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASETextureArrayCreator.cs
vendored
Normal file
@@ -0,0 +1,808 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
//#define NEW_TEXTURE_3D_METHOD
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditorInternal;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[CustomEditor( typeof( TextureArrayCreatorAsset ) )]
|
||||
public class TextureArrayCreatorAssetEditor : Editor
|
||||
{
|
||||
private string[] m_sizesStr = { "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192" };
|
||||
private int[] m_sizes = { 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
|
||||
|
||||
private const string ArrayFilename = "NewTextureArray";
|
||||
private const string Texture3DFilename = "NewTexture3D";
|
||||
|
||||
private GUIContent m_pathButtonContent = new GUIContent();
|
||||
private GUIStyle m_pathButtonStyle = null;
|
||||
|
||||
public TextureArrayCreatorAsset Instance;
|
||||
|
||||
private DragAndDropTool m_dragAndDropTool;
|
||||
|
||||
SerializedObject m_so;
|
||||
SerializedProperty m_selectedSize;
|
||||
SerializedProperty m_lockRatio;
|
||||
SerializedProperty m_sizeX;
|
||||
SerializedProperty m_sizeY;
|
||||
SerializedProperty m_tex3DMode;
|
||||
SerializedProperty m_linearMode;
|
||||
SerializedProperty m_mipMaps;
|
||||
SerializedProperty m_wrapMode;
|
||||
SerializedProperty m_filterMode;
|
||||
SerializedProperty m_anisoLevel;
|
||||
SerializedProperty m_selectedFormatEnum;
|
||||
SerializedProperty m_quality;
|
||||
SerializedProperty m_folderPath;
|
||||
SerializedProperty m_fileName;
|
||||
SerializedProperty m_filenameChanged;
|
||||
SerializedProperty m_allTextures;
|
||||
|
||||
[SerializeField]
|
||||
private ReorderableList m_listTextures = null;
|
||||
|
||||
[SerializeField]
|
||||
private int m_previewSize;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
Instance = (TextureArrayCreatorAsset)target;
|
||||
|
||||
m_so = serializedObject;
|
||||
m_selectedSize = m_so.FindProperty( "m_selectedSize" );
|
||||
m_lockRatio = m_so.FindProperty( "m_lockRatio" );
|
||||
m_sizeX = m_so.FindProperty( "m_sizeX" );
|
||||
m_sizeY = m_so.FindProperty( "m_sizeY" );
|
||||
m_tex3DMode = m_so.FindProperty( "m_tex3DMode" );
|
||||
m_linearMode = m_so.FindProperty( "m_linearMode" );
|
||||
m_mipMaps = m_so.FindProperty( "m_mipMaps" );
|
||||
m_wrapMode = m_so.FindProperty( "m_wrapMode" );
|
||||
m_filterMode = m_so.FindProperty( "m_filterMode" );
|
||||
m_anisoLevel = m_so.FindProperty( "m_anisoLevel" );
|
||||
m_selectedFormatEnum = m_so.FindProperty( "m_selectedFormatEnum" );
|
||||
m_quality = m_so.FindProperty( "m_quality" );
|
||||
m_folderPath = m_so.FindProperty( "m_folderPath" );
|
||||
m_fileName = m_so.FindProperty( "m_fileName" );
|
||||
m_filenameChanged = m_so.FindProperty( "m_filenameChanged" );
|
||||
m_allTextures = m_so.FindProperty( "m_allTextures" );
|
||||
|
||||
if( m_listTextures == null )
|
||||
{
|
||||
m_listTextures = new ReorderableList( m_so, m_allTextures, true, true, true, true );
|
||||
m_listTextures.elementHeight = 16;
|
||||
|
||||
m_listTextures.drawElementCallback = ( Rect rect, int index, bool isActive, bool isFocused ) =>
|
||||
{
|
||||
m_allTextures.GetArrayElementAtIndex( index ).objectReferenceValue = (Texture2D)EditorGUI.ObjectField( rect, "Texture " + index, m_allTextures.GetArrayElementAtIndex( index ).objectReferenceValue, typeof( Texture2D ), false );
|
||||
};
|
||||
|
||||
m_listTextures.drawHeaderCallback = ( Rect rect ) =>
|
||||
{
|
||||
m_previewSize = EditorGUI.IntSlider( rect, "Texture List", m_previewSize, 16, 64 );
|
||||
if( (float)m_previewSize != m_listTextures.elementHeight )
|
||||
m_listTextures.elementHeight = m_previewSize;
|
||||
};
|
||||
|
||||
m_listTextures.onAddCallback = ( list ) =>
|
||||
{
|
||||
m_allTextures.InsertArrayElementAtIndex( m_allTextures.arraySize );
|
||||
m_allTextures.GetArrayElementAtIndex( m_allTextures.arraySize - 1 ).objectReferenceValue = null;
|
||||
};
|
||||
|
||||
m_listTextures.onRemoveCallback = ( list ) =>
|
||||
{
|
||||
m_allTextures.GetArrayElementAtIndex( list.index ).objectReferenceValue = null;
|
||||
m_allTextures.DeleteArrayElementAtIndex( list.index );
|
||||
};
|
||||
}
|
||||
|
||||
m_dragAndDropTool = new DragAndDropTool();
|
||||
m_dragAndDropTool.OnValidDropObjectEvt += OnValidObjectsDropped;
|
||||
}
|
||||
|
||||
public void OnValidObjectsDropped( UnityEngine.Object[] droppedObjs )
|
||||
{
|
||||
for( int objIdx = 0; objIdx < droppedObjs.Length; objIdx++ )
|
||||
{
|
||||
Texture2D tex = droppedObjs[ objIdx ] as Texture2D;
|
||||
if( tex != null )
|
||||
{
|
||||
m_allTextures.InsertArrayElementAtIndex( m_allTextures.arraySize );
|
||||
m_allTextures.GetArrayElementAtIndex( m_allTextures.arraySize - 1 ).objectReferenceValue = tex;
|
||||
m_so.ApplyModifiedProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
DefaultAsset asset = droppedObjs[ objIdx ] as DefaultAsset;
|
||||
if( asset != null )
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath( asset );
|
||||
if( AssetDatabase.IsValidFolder( path ) )
|
||||
{
|
||||
string[] pathArr = { path };
|
||||
string[] texInDir = AssetDatabase.FindAssets( "t:Texture2D", pathArr );
|
||||
for( int texIdx = 0; texIdx < texInDir.Length; texIdx++ )
|
||||
{
|
||||
Texture2D internalTex = AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( texInDir[ texIdx ] ) );
|
||||
if( internalTex != null )
|
||||
{
|
||||
m_allTextures.InsertArrayElementAtIndex( m_allTextures.arraySize );
|
||||
m_allTextures.GetArrayElementAtIndex( m_allTextures.arraySize - 1 ).objectReferenceValue = internalTex;
|
||||
m_so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Instance.AllTextures.Sort( ( x, y ) => string.Compare( x.name, y.name ) );
|
||||
m_so.Update();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
m_dragAndDropTool.Destroy();
|
||||
m_dragAndDropTool = null;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
m_so.Update();
|
||||
|
||||
if( m_pathButtonStyle == null )
|
||||
m_pathButtonStyle = "minibutton";
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var cache = EditorGUIUtility.labelWidth;
|
||||
EditorGUILayout.PrefixLabel( "Size" );
|
||||
EditorGUIUtility.labelWidth = 16;
|
||||
if( m_lockRatio.boolValue )
|
||||
{
|
||||
m_selectedSize.intValue = EditorGUILayout.Popup( "X", m_selectedSize.intValue, m_sizesStr );
|
||||
EditorGUI.BeginDisabledGroup( m_lockRatio.boolValue );
|
||||
EditorGUILayout.Popup( "Y", m_selectedSize.intValue, m_sizesStr );
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField( m_sizeX, new GUIContent( "X" ) );
|
||||
EditorGUILayout.PropertyField( m_sizeY, new GUIContent( "Y" ) );
|
||||
}
|
||||
EditorGUIUtility.labelWidth = 100;
|
||||
m_lockRatio.boolValue = GUILayout.Toggle( m_lockRatio.boolValue, "L", "minibutton", GUILayout.Width( 18 ) );
|
||||
if( m_lockRatio.boolValue )
|
||||
{
|
||||
m_sizeX.intValue = m_sizes[ m_selectedSize.intValue ];
|
||||
m_sizeY.intValue = m_sizes[ m_selectedSize.intValue ];
|
||||
}
|
||||
EditorGUIUtility.labelWidth = cache;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField( m_tex3DMode, new GUIContent( "Texture 3D" ) );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
if( !m_filenameChanged.boolValue )
|
||||
{
|
||||
m_fileName.stringValue = m_tex3DMode.boolValue ? Texture3DFilename : ArrayFilename;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.PropertyField( m_linearMode, new GUIContent( "Linear" ) );
|
||||
EditorGUILayout.PropertyField( m_mipMaps );
|
||||
EditorGUILayout.PropertyField( m_wrapMode );
|
||||
EditorGUILayout.PropertyField( m_filterMode );
|
||||
m_anisoLevel.intValue = EditorGUILayout.IntSlider( "Aniso Level", m_anisoLevel.intValue, 0, 16 );
|
||||
EditorGUILayout.PropertyField( m_selectedFormatEnum, new GUIContent( "Format" ) );
|
||||
|
||||
if( m_selectedFormatEnum.intValue == (int)TextureFormat.DXT1Crunched )
|
||||
{
|
||||
m_selectedFormatEnum.intValue = (int)TextureFormat.DXT1;
|
||||
Debug.Log( "Texture Array does not support crunched DXT1 format. Changing to DXT1..." );
|
||||
}
|
||||
else if( m_selectedFormatEnum.intValue == (int)TextureFormat.DXT5Crunched )
|
||||
{
|
||||
m_selectedFormatEnum.intValue = (int)TextureFormat.DXT5;
|
||||
Debug.Log( "Texture Array does not support crunched DXT5 format. Changing to DXT5..." );
|
||||
}
|
||||
|
||||
m_quality.intValue = EditorGUILayout.IntSlider( "Format Quality", m_quality.intValue, 0, 100 );
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
EditorGUILayout.LabelField( "Path and Name" );
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_pathButtonContent.text = m_folderPath.stringValue;
|
||||
Vector2 buttonSize = m_pathButtonStyle.CalcSize( m_pathButtonContent );
|
||||
if( GUILayout.Button( m_pathButtonContent, m_pathButtonStyle, GUILayout.MaxWidth( Mathf.Min( Screen.width * 0.5f, buttonSize.x ) ) ) )
|
||||
{
|
||||
string folderpath = EditorUtility.OpenFolderPanel( "Save Texture Array to folder", "Assets/", "" );
|
||||
folderpath = FileUtil.GetProjectRelativePath( folderpath );
|
||||
if( string.IsNullOrEmpty( folderpath ) )
|
||||
m_folderPath.stringValue = "Assets/";
|
||||
else
|
||||
m_folderPath.stringValue = folderpath + "/";
|
||||
}
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_fileName.stringValue = EditorGUILayout.TextField( m_fileName.stringValue, GUILayout.ExpandWidth( true ) );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
m_filenameChanged.boolValue = m_fileName.stringValue == ArrayFilename ? false : true;
|
||||
}
|
||||
EditorGUILayout.LabelField( ".asset", GUILayout.MaxWidth( 40 ) );
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
if( GUILayout.Button( "Clear" ) )
|
||||
{
|
||||
m_allTextures.ClearArray();
|
||||
}
|
||||
|
||||
if( m_listTextures != null )
|
||||
m_listTextures.DoLayoutList();
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
m_dragAndDropTool.TestDragAndDrop( new Rect( 0, 0, Screen.width, Screen.height ) );
|
||||
|
||||
m_so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public class ASETextureArrayCreator : EditorWindow
|
||||
{
|
||||
[MenuItem( "Window/Amplify Shader Editor/Texture Array Creator", false, 1001 )]
|
||||
static void ShowWindow()
|
||||
{
|
||||
ASETextureArrayCreator window = EditorWindow.GetWindow<ASETextureArrayCreator>();
|
||||
window.titleContent.text = "Texture Array";
|
||||
window.minSize = new Vector2( 302, 350 );
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private const string ClearButtonStr = "Clear";
|
||||
private const string TextureFilter = "t:Texture2D";
|
||||
private const string BuildArrayMessage = "Build Array";
|
||||
private const string BuildTexture3DMessage = "Build Texture 3D";
|
||||
private const string ArrayFilename = "NewTextureArray";
|
||||
private const string Texture3DFilename = "NewTexture3D";
|
||||
|
||||
TextureArrayCreatorAssetEditor m_editor;
|
||||
|
||||
[SerializeField]
|
||||
private TextureArrayCreatorAsset m_asset;
|
||||
|
||||
[SerializeField]
|
||||
private TextureArrayCreatorAsset m_dummyAsset;
|
||||
|
||||
private static List<TextureFormat> UncompressedFormats = new List<TextureFormat>()
|
||||
{
|
||||
TextureFormat.RGBAFloat,
|
||||
TextureFormat.RGBAHalf,
|
||||
TextureFormat.ARGB32,
|
||||
TextureFormat.RGBA32,
|
||||
TextureFormat.RGB24,
|
||||
TextureFormat.Alpha8
|
||||
};
|
||||
|
||||
private GUIStyle m_contentStyle = null;
|
||||
|
||||
private Vector2 m_scrollPos;
|
||||
private Texture m_lastSaved;
|
||||
private string m_message = string.Empty;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if( m_contentStyle == null )
|
||||
{
|
||||
m_contentStyle = new GUIStyle( GUIStyle.none );
|
||||
m_contentStyle.margin = new RectOffset( 6, 4, 5, 5 );
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DestroyImmediate( m_editor );
|
||||
if( m_dummyAsset != null && m_dummyAsset != m_asset )
|
||||
DestroyImmediate( m_dummyAsset );
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
TextureArrayCreatorAsset currentAsset = null;
|
||||
if( m_asset != null )
|
||||
{
|
||||
currentAsset = m_asset;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_dummyAsset == null )
|
||||
{
|
||||
m_dummyAsset = ScriptableObject.CreateInstance<TextureArrayCreatorAsset>();
|
||||
m_dummyAsset.name = "Dummy";
|
||||
}
|
||||
currentAsset = m_dummyAsset;
|
||||
}
|
||||
|
||||
m_scrollPos = EditorGUILayout.BeginScrollView( m_scrollPos, GUILayout.Height( position.height ) );
|
||||
float cachedWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 100;
|
||||
EditorGUILayout.BeginVertical( m_contentStyle );
|
||||
|
||||
string buildButtonStr = currentAsset.Tex3DMode ? BuildTexture3DMessage : BuildArrayMessage;
|
||||
// build button
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUI.BeginDisabledGroup( currentAsset.AllTextures.Count <= 0 );
|
||||
if( GUILayout.Button( buildButtonStr, "prebutton", GUILayout.Height( 20 ) ) )
|
||||
{
|
||||
bool showWarning = false;
|
||||
for( int i = 0; i < currentAsset.AllTextures.Count; i++ )
|
||||
{
|
||||
if( currentAsset.AllTextures[ i ].width != currentAsset.SizeX || currentAsset.AllTextures[ i ].height != currentAsset.SizeY )
|
||||
{
|
||||
showWarning = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !showWarning )
|
||||
{
|
||||
m_message = string.Empty;
|
||||
if( currentAsset.Tex3DMode )
|
||||
BuildTexture3D( currentAsset );
|
||||
else
|
||||
BuildArray( currentAsset );
|
||||
}
|
||||
else if( EditorUtility.DisplayDialog( "Warning!", "Some textures need to be resized to fit the selected size. Do you want to continue?", "Yes", "No" ) )
|
||||
{
|
||||
m_message = string.Empty;
|
||||
if( currentAsset.Tex3DMode )
|
||||
BuildTexture3D( currentAsset );
|
||||
else
|
||||
BuildArray( currentAsset );
|
||||
}
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
EditorGUI.BeginDisabledGroup( m_lastSaved == null );
|
||||
GUIContent icon = EditorGUIUtility.IconContent( "icons/d_ViewToolZoom.png" );
|
||||
if( GUILayout.Button( icon, "prebutton", GUILayout.Width( 28 ), GUILayout.Height( 20 ) ) )
|
||||
{
|
||||
EditorGUIUtility.PingObject( m_lastSaved );
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
// message
|
||||
if( !string.IsNullOrEmpty( m_message ) )
|
||||
if( GUILayout.Button( "BUILD REPORT (click to hide):\n\n" + m_message, "helpbox" ) )
|
||||
m_message = string.Empty;
|
||||
|
||||
// asset
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_asset = EditorGUILayout.ObjectField( "Asset Preset", m_asset, typeof( TextureArrayCreatorAsset ), false ) as TextureArrayCreatorAsset;
|
||||
if( GUILayout.Button( m_asset != null ? "Save" : "Create", "minibutton", GUILayout.Width( 50 ) ) )
|
||||
{
|
||||
string defaultName = "ArrayPreset";
|
||||
if( m_asset != null )
|
||||
defaultName = m_asset.name;
|
||||
|
||||
string path = EditorUtility.SaveFilePanelInProject( "Save as", defaultName, "asset", string.Empty );
|
||||
if( !string.IsNullOrEmpty( path ) )
|
||||
{
|
||||
TextureArrayCreatorAsset outfile = AssetDatabase.LoadMainAssetAtPath( path ) as TextureArrayCreatorAsset;
|
||||
if( outfile != null )
|
||||
{
|
||||
EditorUtility.CopySerialized( currentAsset, outfile );
|
||||
AssetDatabase.SaveAssets();
|
||||
Selection.activeObject = outfile;
|
||||
EditorGUIUtility.PingObject( outfile );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_asset != null )
|
||||
{
|
||||
currentAsset = ScriptableObject.CreateInstance<TextureArrayCreatorAsset>();
|
||||
EditorUtility.CopySerialized( m_asset, currentAsset );
|
||||
}
|
||||
AssetDatabase.CreateAsset( currentAsset, path );
|
||||
Selection.activeObject = currentAsset;
|
||||
EditorGUIUtility.PingObject( currentAsset );
|
||||
m_asset = currentAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
if( Event.current.type == EventType.Layout )
|
||||
{
|
||||
if( m_editor == null )
|
||||
{
|
||||
m_editor = Editor.CreateEditor( currentAsset, typeof( TextureArrayCreatorAssetEditor ) ) as TextureArrayCreatorAssetEditor;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_editor.Instance != currentAsset )
|
||||
{
|
||||
DestroyImmediate( m_editor );
|
||||
m_editor = Editor.CreateEditor( currentAsset, typeof( TextureArrayCreatorAssetEditor ) ) as TextureArrayCreatorAssetEditor;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( m_editor != null )
|
||||
m_editor.OnInspectorGUI();
|
||||
|
||||
GUILayout.Space( 20 );
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUIUtility.labelWidth = cachedWidth;
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void CopyToArray( ref Texture2D from, ref Texture2DArray to, int arrayIndex, int mipLevel, bool compressed = true )
|
||||
{
|
||||
if( compressed )
|
||||
{
|
||||
Graphics.CopyTexture( from, 0, mipLevel, to, arrayIndex, mipLevel );
|
||||
}
|
||||
else
|
||||
{
|
||||
to.SetPixels( from.GetPixels(), arrayIndex, mipLevel );
|
||||
to.Apply();
|
||||
}
|
||||
}
|
||||
|
||||
#if NEW_TEXTURE_3D_METHOD
|
||||
private void BuildTexture3D( TextureArrayCreatorAsset asset )
|
||||
{
|
||||
int sizeX = asset.SizeX;
|
||||
int sizeY = asset.SizeY;
|
||||
|
||||
Texture3D texture3D = new Texture3D( sizeX, sizeY, asset.AllTextures.Count, asset.SelectedFormatEnum, asset.MipMaps );
|
||||
texture3D.wrapMode = asset.WrapMode;
|
||||
texture3D.filterMode = asset.FilterMode;
|
||||
texture3D.anisoLevel = asset.AnisoLevel;
|
||||
//texture3D.Apply( false );
|
||||
RenderTexture cache = RenderTexture.active;
|
||||
RenderTexture rt = new RenderTexture( sizeX, sizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default );
|
||||
rt.Create();
|
||||
List<Texture2D> textures = new List<Texture2D>( asset.AllTextures.Count );
|
||||
|
||||
for( int i = 0; i < asset.AllTextures.Count; i++ )
|
||||
{
|
||||
// build report
|
||||
int widthChanges = asset.AllTextures[ i ].width < sizeX ? -1 : asset.AllTextures[ i ].width > sizeX ? 1 : 0;
|
||||
int heightChanges = asset.AllTextures[ i ].height < sizeY ? -1 : asset.AllTextures[ i ].height > sizeY ? 1 : 0;
|
||||
if( ( widthChanges < 0 && heightChanges <= 0 ) || ( widthChanges <= 0 && heightChanges < 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was upscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges >= 0 ) || ( widthChanges >= 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was downscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges < 0 ) || ( widthChanges < 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " changed dimensions\n";
|
||||
|
||||
// blit image to upscale or downscale the image to any size
|
||||
RenderTexture.active = rt;
|
||||
|
||||
bool cachedsrgb = GL.sRGBWrite;
|
||||
GL.sRGBWrite = !asset.LinearMode;
|
||||
Graphics.Blit( asset.AllTextures[ i ], rt );
|
||||
GL.sRGBWrite = cachedsrgb;
|
||||
|
||||
textures.Add( new Texture2D( sizeX, sizeY, TextureFormat.ARGB32, asset.MipMaps, asset.LinearMode ) );
|
||||
textures[ i ].ReadPixels( new Rect( 0, 0, sizeX, sizeY ), 0, 0, asset.MipMaps );
|
||||
RenderTexture.active = null;
|
||||
|
||||
bool isCompressed = UncompressedFormats.FindIndex( x => x.Equals( asset.SelectedFormatEnum ) ) < 0;
|
||||
if( isCompressed )
|
||||
{
|
||||
EditorUtility.CompressTexture( textures[ i ], asset.SelectedFormatEnum, asset.Quality );
|
||||
// t2d.Apply( false );
|
||||
}
|
||||
textures[ i ].Apply( false );
|
||||
}
|
||||
|
||||
rt.Release();
|
||||
RenderTexture.active = cache;
|
||||
|
||||
if( m_message.Length > 0 )
|
||||
m_message = m_message.Substring( 0, m_message.Length - 1 );
|
||||
|
||||
int sizeZ = textures.Count;
|
||||
Color[] colors = new Color[ sizeX * sizeY * sizeZ ];
|
||||
int idx = 0;
|
||||
for( int z = 0; z < sizeZ; z++ )
|
||||
{
|
||||
for( int y = 0; y < sizeY; y++ )
|
||||
{
|
||||
for( int x = 0; x < sizeX; x++, idx++ )
|
||||
{
|
||||
colors[ idx ] = textures[ z ].GetPixel(x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
texture3D.SetPixels( colors );
|
||||
texture3D.Apply();
|
||||
|
||||
string path = asset.FolderPath + asset.FileName + ".asset";
|
||||
Texture3D outfile = AssetDatabase.LoadMainAssetAtPath( path ) as Texture3D;
|
||||
if( outfile != null )
|
||||
{
|
||||
EditorUtility.CopySerialized( texture3D, outfile );
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorGUIUtility.PingObject( outfile );
|
||||
m_lastSaved = outfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetDatabase.CreateAsset( texture3D, path );
|
||||
EditorGUIUtility.PingObject( texture3D );
|
||||
m_lastSaved = texture3D;
|
||||
}
|
||||
}
|
||||
#else
|
||||
private void BuildTexture3D( TextureArrayCreatorAsset asset )
|
||||
{
|
||||
int sizeX = asset.SizeX;
|
||||
int sizeY = asset.SizeY;
|
||||
int numLevels = 1 + (int)Mathf.Floor( Mathf.Log( Mathf.Max( sizeX, sizeY ), 2 ) );
|
||||
int mipCount = asset.MipMaps ? numLevels : 1;
|
||||
|
||||
Texture3D texture3D = new Texture3D( sizeX, sizeY, asset.AllTextures.Count, asset.SelectedFormatEnum, asset.MipMaps );
|
||||
texture3D.wrapMode = asset.WrapMode;
|
||||
texture3D.filterMode = asset.FilterMode;
|
||||
texture3D.anisoLevel = asset.AnisoLevel;
|
||||
texture3D.Apply( false );
|
||||
RenderTexture cache = RenderTexture.active;
|
||||
RenderTexture rt = new RenderTexture( sizeX, sizeY, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default );
|
||||
rt.Create();
|
||||
List<List<Color>> mipColor = new List<List<Color>>();
|
||||
if( asset.MipMaps )
|
||||
{
|
||||
for( int i = 0; i < mipCount; i++ )
|
||||
{
|
||||
mipColor.Add( new List<Color>() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mipColor.Add( new List<Color>() );
|
||||
}
|
||||
|
||||
for( int i = 0; i < asset.AllTextures.Count; i++ )
|
||||
{
|
||||
// build report
|
||||
int widthChanges = asset.AllTextures[ i ].width < sizeX ? -1 : asset.AllTextures[ i ].width > sizeX ? 1 : 0;
|
||||
int heightChanges = asset.AllTextures[ i ].height < sizeY ? -1 : asset.AllTextures[ i ].height > sizeY ? 1 : 0;
|
||||
if( ( widthChanges < 0 && heightChanges <= 0 ) || ( widthChanges <= 0 && heightChanges < 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was upscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges >= 0 ) || ( widthChanges >= 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was downscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges < 0 ) || ( widthChanges < 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " changed dimensions\n";
|
||||
|
||||
// blit image to upscale or downscale the image to any size
|
||||
RenderTexture.active = rt;
|
||||
|
||||
bool cachedsrgb = GL.sRGBWrite;
|
||||
GL.sRGBWrite = !asset.LinearMode;
|
||||
Graphics.Blit( asset.AllTextures[ i ], rt );
|
||||
GL.sRGBWrite = cachedsrgb;
|
||||
|
||||
bool isCompressed = UncompressedFormats.FindIndex( x => x.Equals( asset.SelectedFormatEnum ) ) < 0;
|
||||
TextureFormat validReadPixelsFormat = isCompressed ? TextureFormat.RGBAFloat : asset.SelectedFormatEnum;
|
||||
Texture2D t2d = new Texture2D( sizeX, sizeY, validReadPixelsFormat, asset.MipMaps, asset.LinearMode );
|
||||
t2d.ReadPixels( new Rect( 0, 0, sizeX, sizeY ), 0, 0, asset.MipMaps );
|
||||
RenderTexture.active = null;
|
||||
|
||||
if( isCompressed )
|
||||
{
|
||||
EditorUtility.CompressTexture( t2d, asset.SelectedFormatEnum, asset.Quality );
|
||||
// t2d.Apply( false );
|
||||
}
|
||||
t2d.Apply( false );
|
||||
|
||||
if( asset.MipMaps )
|
||||
{
|
||||
for( int mip = 0; mip < mipCount; mip++ )
|
||||
{
|
||||
mipColor[ mip ].AddRange( t2d.GetPixels( mip ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mipColor[ 0 ].AddRange( t2d.GetPixels( 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
rt.Release();
|
||||
RenderTexture.active = cache;
|
||||
|
||||
if( m_message.Length > 0 )
|
||||
m_message = m_message.Substring( 0, m_message.Length - 1 );
|
||||
|
||||
for( int i = 0; i < mipCount; i++ )
|
||||
{
|
||||
texture3D.SetPixels( mipColor[ i ].ToArray(), i );
|
||||
}
|
||||
|
||||
texture3D.Apply( false );
|
||||
|
||||
string path = asset.FolderPath + asset.FileName + ".asset";
|
||||
Texture3D outfile = AssetDatabase.LoadMainAssetAtPath( path ) as Texture3D;
|
||||
if( outfile != null )
|
||||
{
|
||||
EditorUtility.CopySerialized( texture3D, outfile );
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorGUIUtility.PingObject( outfile );
|
||||
m_lastSaved = outfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetDatabase.CreateAsset( texture3D, path );
|
||||
EditorGUIUtility.PingObject( texture3D );
|
||||
m_lastSaved = texture3D;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
private void BuildTexture3DAutoMips( TextureArrayCreatorAsset asset )
|
||||
{
|
||||
int sizeX = asset.SizeX;
|
||||
int sizeY = asset.SizeY;
|
||||
|
||||
Texture3D texture3D = new Texture3D( sizeX, sizeY, asset.AllTextures.Count, asset.SelectedFormatEnum, asset.MipMaps );
|
||||
texture3D.wrapMode = asset.WrapMode;
|
||||
texture3D.filterMode = asset.FilterMode;
|
||||
texture3D.anisoLevel = asset.AnisoLevel;
|
||||
texture3D.Apply( false );
|
||||
RenderTexture cache = RenderTexture.active;
|
||||
RenderTexture rt = new RenderTexture( sizeX, sizeY, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default );
|
||||
rt.Create();
|
||||
List<Color> texColors = new List<Color>();
|
||||
|
||||
for( int i = 0; i < asset.AllTextures.Count; i++ )
|
||||
{
|
||||
// build report
|
||||
int widthChanges = asset.AllTextures[ i ].width < sizeX ? -1 : asset.AllTextures[ i ].width > sizeX ? 1 : 0;
|
||||
int heightChanges = asset.AllTextures[ i ].height < sizeY ? -1 : asset.AllTextures[ i ].height > sizeY ? 1 : 0;
|
||||
if( ( widthChanges < 0 && heightChanges <= 0 ) || ( widthChanges <= 0 && heightChanges < 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was upscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges >= 0 ) || ( widthChanges >= 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was downscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges < 0 ) || ( widthChanges < 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " changed dimensions\n";
|
||||
|
||||
// blit image to upscale or downscale the image to any size
|
||||
RenderTexture.active = rt;
|
||||
|
||||
bool cachedsrgb = GL.sRGBWrite;
|
||||
GL.sRGBWrite = !asset.LinearMode;
|
||||
Graphics.Blit( asset.AllTextures[ i ], rt );
|
||||
GL.sRGBWrite = cachedsrgb;
|
||||
|
||||
bool isCompressed = UncompressedFormats.FindIndex( x => x.Equals( asset.SelectedFormatEnum ) ) < 0;
|
||||
TextureFormat validReadPixelsFormat = isCompressed ? TextureFormat.RGBAFloat : asset.SelectedFormatEnum;
|
||||
Texture2D t2d = new Texture2D( sizeX, sizeY, validReadPixelsFormat, asset.MipMaps, asset.LinearMode );
|
||||
t2d.ReadPixels( new Rect( 0, 0, sizeX, sizeY ), 0, 0, asset.MipMaps );
|
||||
RenderTexture.active = null;
|
||||
|
||||
if( isCompressed )
|
||||
{
|
||||
EditorUtility.CompressTexture( t2d, asset.SelectedFormatEnum, asset.Quality );
|
||||
t2d.Apply( false );
|
||||
}
|
||||
texColors.AddRange( t2d.GetPixels() );
|
||||
}
|
||||
|
||||
rt.Release();
|
||||
RenderTexture.active = cache;
|
||||
|
||||
if( m_message.Length > 0 )
|
||||
m_message = m_message.Substring( 0, m_message.Length - 1 );
|
||||
|
||||
texture3D.SetPixels( texColors.ToArray() );
|
||||
texture3D.Apply();
|
||||
|
||||
string path = asset.FolderPath + asset.FileName + ".asset";
|
||||
Texture3D outfile = AssetDatabase.LoadMainAssetAtPath( path ) as Texture3D;
|
||||
if( outfile != null )
|
||||
{
|
||||
EditorUtility.CopySerialized( texture3D, outfile );
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorGUIUtility.PingObject( outfile );
|
||||
m_lastSaved = outfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetDatabase.CreateAsset( texture3D, path );
|
||||
EditorGUIUtility.PingObject( texture3D );
|
||||
m_lastSaved = texture3D;
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildArray( TextureArrayCreatorAsset asset )
|
||||
{
|
||||
int sizeX = asset.SizeX;
|
||||
int sizeY = asset.SizeY;
|
||||
|
||||
Texture2DArray textureArray = new Texture2DArray( sizeX, sizeY, asset.AllTextures.Count, asset.SelectedFormatEnum, asset.MipMaps, asset.LinearMode );
|
||||
textureArray.wrapMode = asset.WrapMode;
|
||||
textureArray.filterMode = asset.FilterMode;
|
||||
textureArray.anisoLevel = asset.AnisoLevel;
|
||||
textureArray.Apply( false );
|
||||
RenderTexture cache = RenderTexture.active;
|
||||
RenderTexture rt = new RenderTexture( sizeX, sizeY, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default );
|
||||
rt.Create();
|
||||
for( int i = 0; i < asset.AllTextures.Count; i++ )
|
||||
{
|
||||
// build report
|
||||
int widthChanges = asset.AllTextures[ i ].width < sizeX ? -1 : asset.AllTextures[ i ].width > sizeX ? 1 : 0;
|
||||
int heightChanges = asset.AllTextures[ i ].height < sizeY ? -1 : asset.AllTextures[ i ].height > sizeY ? 1 : 0;
|
||||
if( ( widthChanges < 0 && heightChanges <= 0 ) || ( widthChanges <= 0 && heightChanges < 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was upscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges >= 0 ) || ( widthChanges >= 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " was downscaled\n";
|
||||
else if( ( widthChanges > 0 && heightChanges < 0 ) || ( widthChanges < 0 && heightChanges > 0 ) )
|
||||
m_message += asset.AllTextures[ i ].name + " changed dimensions\n";
|
||||
|
||||
// blit image to upscale or downscale the image to any size
|
||||
RenderTexture.active = rt;
|
||||
|
||||
bool cachedsrgb = GL.sRGBWrite;
|
||||
GL.sRGBWrite = !asset.LinearMode;
|
||||
Graphics.Blit( asset.AllTextures[ i ], rt );
|
||||
GL.sRGBWrite = cachedsrgb;
|
||||
|
||||
bool isCompressed = UncompressedFormats.FindIndex( x => x.Equals( asset.SelectedFormatEnum ) ) < 0;
|
||||
TextureFormat validReadPixelsFormat = isCompressed ? TextureFormat.RGBAFloat : asset.SelectedFormatEnum;
|
||||
Texture2D t2d = new Texture2D( sizeX, sizeY, validReadPixelsFormat, asset.MipMaps, asset.LinearMode );
|
||||
t2d.ReadPixels( new Rect( 0, 0, sizeX, sizeY ), 0, 0, asset.MipMaps );
|
||||
RenderTexture.active = null;
|
||||
|
||||
if( isCompressed )
|
||||
{
|
||||
EditorUtility.CompressTexture( t2d, asset.SelectedFormatEnum, asset.Quality );
|
||||
t2d.Apply( false );
|
||||
}
|
||||
|
||||
if( asset.MipMaps )
|
||||
{
|
||||
int maxSize = Mathf.Max( sizeX, sizeY );
|
||||
int numLevels = 1 + (int)Mathf.Floor( Mathf.Log( maxSize, 2 ) );
|
||||
for( int mip = 0; mip < numLevels; mip++ )
|
||||
{
|
||||
CopyToArray( ref t2d, ref textureArray, i, mip, isCompressed );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyToArray( ref t2d, ref textureArray, i, 0, isCompressed );
|
||||
}
|
||||
}
|
||||
|
||||
rt.Release();
|
||||
RenderTexture.active = cache;
|
||||
if( m_message.Length > 0 )
|
||||
m_message = m_message.Substring( 0, m_message.Length - 1 );
|
||||
|
||||
string path = asset.FolderPath + asset.FileName + ".asset";
|
||||
Texture2DArray outfile = AssetDatabase.LoadMainAssetAtPath( path ) as Texture2DArray;
|
||||
if( outfile != null )
|
||||
{
|
||||
EditorUtility.CopySerialized( textureArray, outfile );
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorGUIUtility.PingObject( outfile );
|
||||
m_lastSaved = outfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetDatabase.CreateAsset( textureArray, path );
|
||||
EditorGUIUtility.PingObject( textureArray );
|
||||
m_lastSaved = textureArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASETextureArrayCreator.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ASETextureArrayCreator.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 436dc8bc09773454db57b9fbf799ec9d
|
||||
timeCreated: 1504633068
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
155
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/BatchUpdateShaders.cs
vendored
Normal file
155
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/BatchUpdateShaders.cs
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class BatchUpdateShaders : EditorWindow
|
||||
{
|
||||
private const string UpdateAllStr = "Update All";
|
||||
private const string UpdateAllStyle = "prebutton";
|
||||
|
||||
|
||||
[SerializeField]
|
||||
private ASESaveBundleAsset m_asset;
|
||||
|
||||
[SerializeField]
|
||||
private ASESaveBundleAsset m_dummyAsset;
|
||||
|
||||
private GUIStyle m_contentStyle = null;
|
||||
|
||||
private Vector2 m_scrollPos;
|
||||
private GUIContent m_ViewToolIcon;
|
||||
|
||||
ASESaveBundleAssetEditor m_editor;
|
||||
|
||||
private const string Title = "Batch Update Shaders";
|
||||
|
||||
[NonSerialized]
|
||||
private GUIStyle m_titleStyle;
|
||||
|
||||
[MenuItem( "Window/Amplify Shader Editor/" + Title, false, priority: 1100 )]
|
||||
static void ShowWindow()
|
||||
{
|
||||
var window = EditorWindow.GetWindow<BatchUpdateShaders>();
|
||||
window.titleContent.text = "Batch Update...";
|
||||
window.titleContent.tooltip = Title;
|
||||
window.minSize = new Vector2( 302 , 350 );
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if( m_contentStyle == null )
|
||||
{
|
||||
m_contentStyle = new GUIStyle( GUIStyle.none );
|
||||
m_contentStyle.margin = new RectOffset( 6 , 4 , 5 , 5 );
|
||||
}
|
||||
|
||||
if( m_ViewToolIcon == null )
|
||||
{
|
||||
m_ViewToolIcon = EditorGUIUtility.IconContent( "icons/d_ViewToolZoom.png" );
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DestroyImmediate( m_editor );
|
||||
if( m_dummyAsset != null && m_dummyAsset != m_asset )
|
||||
DestroyImmediate( m_dummyAsset );
|
||||
}
|
||||
|
||||
|
||||
public static string FetchPath( string title, string folderpath )
|
||||
{
|
||||
folderpath = EditorUtility.OpenFolderPanel( title , folderpath , "" );
|
||||
folderpath = FileUtil.GetProjectRelativePath( folderpath );
|
||||
if( string.IsNullOrEmpty( folderpath ) )
|
||||
folderpath = "Assets";
|
||||
|
||||
return folderpath;
|
||||
}
|
||||
|
||||
private bool m_updatingShaders = false;
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if( m_updatingShaders )
|
||||
{
|
||||
m_updatingShaders = EditorPrefs.HasKey( AmplifyShaderEditorWindow.ASEFileList );
|
||||
}
|
||||
|
||||
|
||||
if( m_titleStyle == null )
|
||||
{
|
||||
m_titleStyle = new GUIStyle( "BoldLabel" );
|
||||
m_titleStyle.fontSize = 13;
|
||||
m_titleStyle.alignment = TextAnchor.MiddleCenter;
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.LabelField( Title , m_titleStyle );
|
||||
EditorGUI.BeginDisabledGroup( m_updatingShaders );
|
||||
{
|
||||
ASESaveBundleAsset currentAsset = null;
|
||||
if( m_dummyAsset == null )
|
||||
{
|
||||
m_dummyAsset = ScriptableObject.CreateInstance<ASESaveBundleAsset>();
|
||||
m_dummyAsset.name = "Dummy";
|
||||
}
|
||||
currentAsset = m_dummyAsset;
|
||||
|
||||
m_scrollPos = EditorGUILayout.BeginScrollView( m_scrollPos , GUILayout.Height( position.height ) );
|
||||
{
|
||||
float cachedWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 100;
|
||||
EditorGUILayout.BeginVertical( m_contentStyle );
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup( currentAsset.AllShaders.Count <= 0 );
|
||||
{
|
||||
// Update all shaders
|
||||
if( GUILayout.Button( UpdateAllStr ) )
|
||||
{
|
||||
m_updatingShaders = true;
|
||||
string[] assetPaths = new string[ currentAsset.AllShaders.Count ];
|
||||
for( int i = 0 ; i < assetPaths.Length ; i++ )
|
||||
{
|
||||
assetPaths[ i ] = AssetDatabase.GetAssetPath( currentAsset.AllShaders[ i ] );
|
||||
}
|
||||
AmplifyShaderEditorWindow.LoadAndSaveList( assetPaths );
|
||||
}
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
if( Event.current.type == EventType.Layout )
|
||||
{
|
||||
if( m_editor == null )
|
||||
{
|
||||
m_editor = Editor.CreateEditor( currentAsset , typeof( ASESaveBundleAssetEditor ) ) as ASESaveBundleAssetEditor;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_editor.Instance != currentAsset )
|
||||
{
|
||||
DestroyImmediate( m_editor );
|
||||
m_editor = Editor.CreateEditor( currentAsset , typeof( ASESaveBundleAssetEditor ) ) as ASESaveBundleAssetEditor;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( m_editor != null )
|
||||
m_editor.PackageFreeGUI();
|
||||
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/BatchUpdateShaders.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/BatchUpdateShaders.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ee118a25f852d340ae5078747d62094
|
||||
timeCreated: 1634216888
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
622
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomMaterialInspector.cs
vendored
Normal file
622
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomMaterialInspector.cs
vendored
Normal file
@@ -0,0 +1,622 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public static class MaterialPropertyHandlerEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEditor.MaterialPropertyHandler, UnityEditor" ) : type; } }
|
||||
public static object GetHandler( Shader shader, string name )
|
||||
{
|
||||
return MaterialPropertyHandlerEx.Type.InvokeMember( "GetHandler", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { shader, name } );
|
||||
}
|
||||
|
||||
public static void OnGUI( object obj, ref Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor )
|
||||
{
|
||||
Type.InvokeMember( "OnGUI", BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod, null, obj, new object[] { position, prop, label, editor } );
|
||||
}
|
||||
|
||||
public static float GetPropertyHeight( object obj, MaterialProperty prop, string label, MaterialEditor editor )
|
||||
{
|
||||
return (float)Type.InvokeMember( "GetPropertyHeight", BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod, null, obj, new object[] { prop, label, editor } );
|
||||
}
|
||||
|
||||
public static object PropertyDrawer( object obj )
|
||||
{
|
||||
return Type.InvokeMember( "propertyDrawer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty, null, obj, new object[] {} );
|
||||
}
|
||||
}
|
||||
|
||||
internal class MaterialInspector : ShaderGUI
|
||||
{
|
||||
private const string CopyButtonStr = "Copy Values";
|
||||
private const string PasteButtonStr = "Paste Values";
|
||||
private const string PreviewModelPref = "ASEMI_PREVIEWMODEL";
|
||||
|
||||
private static MaterialEditor m_instance = null;
|
||||
private static bool m_refreshOnUndo = false;
|
||||
|
||||
private bool m_initialized = false;
|
||||
private double m_lastRenderedTime;
|
||||
private PreviewRenderUtility m_previewRenderUtility;
|
||||
private Mesh m_targetMesh;
|
||||
private Vector2 m_previewDir = new Vector2( 120f, -20f );
|
||||
private int m_selectedMesh = 0;
|
||||
private int m_prevSelectedMesh = 0;
|
||||
|
||||
|
||||
// Reflection Fields
|
||||
|
||||
private FieldInfo m_previewDirDefault = null;
|
||||
|
||||
private Type m_modelInspectorType = null;
|
||||
private MethodInfo m_renderMeshMethod = null;
|
||||
private Type m_previewGUIType = null;
|
||||
private MethodInfo m_dragMethod = null;
|
||||
private FieldInfo m_selectedField = null;
|
||||
private FieldInfo m_infoField = null;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
private Type m_previewSettingsType = null;
|
||||
object m_previewSettingsInstance;
|
||||
FieldInfo previewDirInfo;
|
||||
FieldInfo shadedMaterialInfo;
|
||||
FieldInfo activeMaterialInfo;
|
||||
#endif
|
||||
|
||||
public override void OnClosed( Material material )
|
||||
{
|
||||
base.OnClosed( material );
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
void CleanUp()
|
||||
{
|
||||
if( m_previewRenderUtility != null )
|
||||
{
|
||||
m_previewRenderUtility.Cleanup();
|
||||
m_previewRenderUtility = null;
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoPerformed()
|
||||
{
|
||||
m_refreshOnUndo = true;
|
||||
}
|
||||
|
||||
~MaterialInspector()
|
||||
{
|
||||
UndoUtils.UnregisterUndoRedoCallback( UndoRedoPerformed );
|
||||
CleanUp();
|
||||
}
|
||||
public override void OnGUI( MaterialEditor materialEditor, MaterialProperty[] properties )
|
||||
{
|
||||
IOUtils.Init();
|
||||
Material mat = materialEditor.target as Material;
|
||||
|
||||
if( mat == null )
|
||||
return;
|
||||
|
||||
m_instance = materialEditor;
|
||||
|
||||
if( !m_initialized )
|
||||
{
|
||||
Init();
|
||||
m_initialized = true;
|
||||
UndoUtils.RegisterUndoRedoCallback( UndoRedoPerformed );
|
||||
}
|
||||
|
||||
if( Event.current.type == EventType.Repaint &&
|
||||
mat.HasProperty( IOUtils.DefaultASEDirtyCheckId ) &&
|
||||
mat.GetInt( IOUtils.DefaultASEDirtyCheckId ) == 1 )
|
||||
{
|
||||
mat.SetInt( IOUtils.DefaultASEDirtyCheckId, 0 );
|
||||
UIUtils.ForceUpdateFromMaterial();
|
||||
//Event.current.Use();
|
||||
}
|
||||
|
||||
if( materialEditor.isVisible )
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUILayout.Space( 3 );
|
||||
if( GUILayout.Button( "Open in Shader Editor" ) )
|
||||
{
|
||||
ASEPackageManagerHelper.SetupLateMaterial( mat );
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
if( GUILayout.Button( CopyButtonStr ) )
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
|
||||
|
||||
Shader shader = mat.shader;
|
||||
int propertyCount = shader.GetPropertyCount();
|
||||
string allProperties = string.Empty;
|
||||
for( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
UnityEngine.Rendering.ShaderPropertyType type = shader.GetPropertyType( i );
|
||||
string name = shader.GetPropertyName( i );
|
||||
string valueStr = string.Empty;
|
||||
switch( type )
|
||||
{
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Color:
|
||||
{
|
||||
Color value = mat.GetColor( name );
|
||||
valueStr = value.r.ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
value.g.ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
value.b.ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
value.a.ToString();
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Vector:
|
||||
{
|
||||
Vector4 value = mat.GetVector( name );
|
||||
valueStr = value.x.ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
value.y.ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
value.z.ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
value.w.ToString();
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Float:
|
||||
{
|
||||
float value = mat.GetFloat( name );
|
||||
valueStr = value.ToString();
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Range:
|
||||
{
|
||||
float value = mat.GetFloat( name );
|
||||
valueStr = value.ToString();
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Texture:
|
||||
{
|
||||
Texture value = mat.GetTexture( name );
|
||||
valueStr = AssetDatabase.GetAssetPath( value );
|
||||
Vector2 offset = mat.GetTextureOffset( name );
|
||||
Vector2 scale = mat.GetTextureScale( name );
|
||||
valueStr += IOUtils.VECTOR_SEPARATOR + scale.x.ToString() +
|
||||
IOUtils.VECTOR_SEPARATOR + scale.y.ToString() +
|
||||
IOUtils.VECTOR_SEPARATOR + offset.x.ToString() +
|
||||
IOUtils.VECTOR_SEPARATOR + offset.y.ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
allProperties += name + IOUtils.FIELD_SEPARATOR + type + IOUtils.FIELD_SEPARATOR + valueStr;
|
||||
|
||||
if( i < ( propertyCount - 1 ) )
|
||||
{
|
||||
allProperties += IOUtils.LINE_TERMINATOR;
|
||||
}
|
||||
}
|
||||
EditorPrefs.SetString( IOUtils.MAT_CLIPBOARD_ID, allProperties );
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
|
||||
}
|
||||
|
||||
if( GUILayout.Button( PasteButtonStr ) )
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
|
||||
string propertiesStr = EditorPrefs.GetString( IOUtils.MAT_CLIPBOARD_ID, string.Empty );
|
||||
if( !string.IsNullOrEmpty( propertiesStr ) )
|
||||
{
|
||||
string[] propertyArr = propertiesStr.Split( IOUtils.LINE_TERMINATOR );
|
||||
bool validData = true;
|
||||
try
|
||||
{
|
||||
for( int i = 0; i < propertyArr.Length; i++ )
|
||||
{
|
||||
string[] valuesArr = propertyArr[ i ].Split( IOUtils.FIELD_SEPARATOR );
|
||||
if( valuesArr.Length != 3 )
|
||||
{
|
||||
Debug.LogWarning( "Material clipboard data is corrupted" );
|
||||
validData = false;
|
||||
break;
|
||||
}
|
||||
else if( mat.HasProperty( valuesArr[ 0 ] ) )
|
||||
{
|
||||
UnityEngine.Rendering.ShaderPropertyType type = (UnityEngine.Rendering.ShaderPropertyType)Enum.Parse( typeof( UnityEngine.Rendering.ShaderPropertyType ), valuesArr[ 1 ] );
|
||||
switch( type )
|
||||
{
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Color:
|
||||
{
|
||||
string[] colorVals = valuesArr[ 2 ].Split( IOUtils.VECTOR_SEPARATOR );
|
||||
if( colorVals.Length != 4 )
|
||||
{
|
||||
Debug.LogWarning( "Material clipboard data is corrupted" );
|
||||
validData = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.SetColor( valuesArr[ 0 ], new Color( Convert.ToSingle( colorVals[ 0 ] ),
|
||||
Convert.ToSingle( colorVals[ 1 ] ),
|
||||
Convert.ToSingle( colorVals[ 2 ] ),
|
||||
Convert.ToSingle( colorVals[ 3 ] ) ) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Vector:
|
||||
{
|
||||
string[] vectorVals = valuesArr[ 2 ].Split( IOUtils.VECTOR_SEPARATOR );
|
||||
if( vectorVals.Length != 4 )
|
||||
{
|
||||
Debug.LogWarning( "Material clipboard data is corrupted" );
|
||||
validData = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.SetVector( valuesArr[ 0 ], new Vector4( Convert.ToSingle( vectorVals[ 0 ] ),
|
||||
Convert.ToSingle( vectorVals[ 1 ] ),
|
||||
Convert.ToSingle( vectorVals[ 2 ] ),
|
||||
Convert.ToSingle( vectorVals[ 3 ] ) ) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Float:
|
||||
{
|
||||
mat.SetFloat( valuesArr[ 0 ], Convert.ToSingle( valuesArr[ 2 ] ) );
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Range:
|
||||
{
|
||||
mat.SetFloat( valuesArr[ 0 ], Convert.ToSingle( valuesArr[ 2 ] ) );
|
||||
}
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Texture:
|
||||
{
|
||||
string[] texVals = valuesArr[ 2 ].Split( IOUtils.VECTOR_SEPARATOR );
|
||||
if( texVals.Length != 5 )
|
||||
{
|
||||
Debug.LogWarning( "Material clipboard data is corrupted" );
|
||||
validData = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.SetTexture( valuesArr[ 0 ], AssetDatabase.LoadAssetAtPath<Texture>( texVals[ 0 ] ) );
|
||||
mat.SetTextureScale( valuesArr[ 0 ], new Vector2( Convert.ToSingle( texVals[ 1 ] ), Convert.ToSingle( texVals[ 2 ] ) ) );
|
||||
mat.SetTextureOffset( valuesArr[ 0 ], new Vector2( Convert.ToSingle( texVals[ 3 ] ), Convert.ToSingle( texVals[ 4 ] ) ) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
validData = false;
|
||||
}
|
||||
|
||||
|
||||
if( validData )
|
||||
{
|
||||
materialEditor.PropertiesChanged();
|
||||
UIUtils.CopyValuesFromMaterial( mat );
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorPrefs.SetString( IOUtils.MAT_CLIPBOARD_ID, string.Empty );
|
||||
}
|
||||
}
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space( 5 );
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
EditorGUI.BeginChangeCheck();
|
||||
//base.OnGUI( materialEditor, properties );
|
||||
|
||||
// Draw custom properties instead of calling BASE to use single line texture properties
|
||||
materialEditor.SetDefaultGUIWidths();
|
||||
|
||||
if( m_infoField == null )
|
||||
{
|
||||
m_infoField = typeof( MaterialEditor ).GetField( "m_InfoMessage", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
}
|
||||
|
||||
string info = m_infoField.GetValue( materialEditor ) as string;
|
||||
if( !string.IsNullOrEmpty( info ) )
|
||||
{
|
||||
EditorGUILayout.HelpBox( info, MessageType.Info );
|
||||
}
|
||||
else
|
||||
{
|
||||
GUIUtility.GetControlID( "EditorTextField".GetHashCode(), FocusType.Passive, new Rect( 0f, 0f, 0f, 0f ) );
|
||||
}
|
||||
|
||||
for( int i = 0; i < properties.Length; i++ )
|
||||
{
|
||||
#if UNITY_6000_2_OR_NEWER
|
||||
int propertyFlags = ( int )properties[ i ].propertyFlags;
|
||||
#else
|
||||
int propertyFlags = ( int )properties[ i ].flags;
|
||||
#endif
|
||||
|
||||
if ( ( propertyFlags & ( ( int )UnityEngine.Rendering.ShaderPropertyFlags.HideInInspector | ( int )UnityEngine.Rendering.ShaderPropertyFlags.PerRendererData ) ) == ( int )UnityEngine.Rendering.ShaderPropertyFlags.None )
|
||||
{
|
||||
// Removed no scale offset one line texture property for consistency :( sad face
|
||||
//if( ( properties[ i ].flags & MaterialProperty.PropFlags.NoScaleOffset ) == MaterialProperty.PropFlags.NoScaleOffset )
|
||||
//{
|
||||
// object obj = MaterialPropertyHandlerEx.GetHandler( mat.shader, properties[ i ].name );
|
||||
// if( obj != null )
|
||||
// {
|
||||
// float height = MaterialPropertyHandlerEx.GetPropertyHeight( obj, properties[ i ], properties[ i ].displayName, materialEditor );
|
||||
// //Rect rect = (Rect)materialEditor.GetType().InvokeMember( "GetPropertyRect", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, materialEditor, new object[] { properties[ i ], properties[ i ].displayName, true } );
|
||||
// Rect rect = EditorGUILayout.GetControlRect( true, height, EditorStyles.layerMaskField );
|
||||
// MaterialPropertyHandlerEx.OnGUI( obj, ref rect, properties[ i ], new GUIContent( properties[ i ].displayName ), materialEditor );
|
||||
|
||||
// if( MaterialPropertyHandlerEx.PropertyDrawer( obj ) != null )
|
||||
// continue;
|
||||
|
||||
// rect = EditorGUILayout.GetControlRect( true, height, EditorStyles.layerMaskField );
|
||||
// materialEditor.TexturePropertyMiniThumbnail( rect, properties[ i ], properties[ i ].displayName, string.Empty );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// materialEditor.TexturePropertySingleLine( new GUIContent( properties[ i ].displayName ), properties[ i ] );
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
float propertyHeight = materialEditor.GetPropertyHeight( properties[ i ], properties[ i ].displayName );
|
||||
Rect controlRect = EditorGUILayout.GetControlRect( true, propertyHeight, EditorStyles.layerMaskField, new GUILayoutOption[ 0 ] );
|
||||
materialEditor.ShaderProperty( controlRect, properties[ i ], properties[ i ].displayName );
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
materialEditor.RenderQueueField();
|
||||
materialEditor.EnableInstancingField();
|
||||
materialEditor.DoubleSidedGIField();
|
||||
materialEditor.LightmapEmissionProperty();
|
||||
if( m_refreshOnUndo || EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
m_refreshOnUndo = false;
|
||||
|
||||
string isEmissive = mat.GetTag( "IsEmissive", false, "false" );
|
||||
if( isEmissive.Equals( "true" ) )
|
||||
{
|
||||
mat.globalIlluminationFlags &= (MaterialGlobalIlluminationFlags)3;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
|
||||
}
|
||||
|
||||
UIUtils.CopyValuesFromMaterial( mat );
|
||||
}
|
||||
|
||||
// @diogo: set useful texture keywords in case someone wants to use them
|
||||
SetTextureKeywords( mat );
|
||||
|
||||
if( materialEditor.RequiresConstantRepaint() && m_lastRenderedTime + ( 1.0f / 30.0f ) < EditorApplication.timeSinceStartup )
|
||||
{
|
||||
this.m_lastRenderedTime = EditorApplication.timeSinceStartup;
|
||||
materialEditor.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
static void EnsureKeywordState( Material mat, string keyword, bool state )
|
||||
{
|
||||
if ( state && !mat.IsKeywordEnabled( keyword ) )
|
||||
{
|
||||
mat.EnableKeyword( keyword );
|
||||
}
|
||||
else if ( !state && mat.IsKeywordEnabled( keyword ) )
|
||||
{
|
||||
mat.DisableKeyword( keyword );
|
||||
}
|
||||
}
|
||||
|
||||
private bool FindGenKeyForTextureProperty( Material mat, string propertyName )
|
||||
{
|
||||
int propertyCount = mat.shader.GetPropertyCount();
|
||||
for ( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
if ( mat.shader.GetPropertyType( i ) == UnityEngine.Rendering.ShaderPropertyType.Float &&
|
||||
mat.shader.GetPropertyName( i ).StartsWith( "GenKey_" + propertyName ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SetTextureKeywords( Material mat )
|
||||
{
|
||||
int propertyCount = mat.shader.GetPropertyCount();
|
||||
for ( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
if ( mat.shader.GetPropertyType( i ) == UnityEngine.Rendering.ShaderPropertyType.Texture )
|
||||
{
|
||||
string name = mat.shader.GetPropertyName( i );
|
||||
if ( !name.StartsWith( "GenKey_" ) && FindGenKeyForTextureProperty( mat, name ) )
|
||||
{
|
||||
EnsureKeywordState( mat, name.ToUpper(), mat.HasProperty( name ) && ( mat.GetTexture( name ) != null ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
string guid = EditorPrefs.GetString( PreviewModelPref, "" );
|
||||
if( !string.IsNullOrEmpty( guid ) )
|
||||
{
|
||||
m_targetMesh = AssetDatabase.LoadAssetAtPath<Mesh>( AssetDatabase.GUIDToAssetPath( guid ) );
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnMaterialPreviewSettingsGUI( MaterialEditor materialEditor )
|
||||
{
|
||||
|
||||
base.OnMaterialPreviewSettingsGUI( materialEditor );
|
||||
|
||||
if( UnityEditor.ShaderUtil.hardwareSupportsRectRenderTexture )
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_targetMesh = (Mesh)EditorGUILayout.ObjectField( m_targetMesh, typeof( Mesh ), false, GUILayout.MaxWidth( 120 ) );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
if( m_targetMesh != null )
|
||||
{
|
||||
EditorPrefs.SetString( PreviewModelPref, AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( m_targetMesh ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorPrefs.SetString( PreviewModelPref, "" );
|
||||
}
|
||||
}
|
||||
|
||||
if( m_selectedField == null )
|
||||
{
|
||||
m_selectedField = typeof( MaterialEditor ).GetField( "m_SelectedMesh", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
}
|
||||
|
||||
if( m_previewDirDefault == null )
|
||||
{
|
||||
m_previewDirDefault = typeof( MaterialEditor ).GetField( "m_PreviewDir" , BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
}
|
||||
|
||||
|
||||
m_selectedMesh = (int)m_selectedField.GetValue( materialEditor );
|
||||
if ( m_selectedMesh != m_prevSelectedMesh )
|
||||
{
|
||||
m_prevSelectedMesh = m_selectedMesh;
|
||||
if( m_targetMesh != null )
|
||||
{
|
||||
m_targetMesh = null;
|
||||
EditorPrefs.SetString( PreviewModelPref, "" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( GUILayout.Button( "R" ,GUILayout.MaxWidth(17), GUILayout.MaxHeight( 13 ) ) )
|
||||
{
|
||||
m_previewDir = new Vector2( 0 , 0 );
|
||||
if( m_previewDirDefault != null )
|
||||
m_previewDirDefault.SetValue( materialEditor , m_previewDir );
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnMaterialInteractivePreviewGUI( MaterialEditor materialEditor, Rect r, GUIStyle background )
|
||||
{
|
||||
if( Event.current.type == EventType.DragExited )
|
||||
{
|
||||
if( DragAndDrop.objectReferences.Length > 0 )
|
||||
{
|
||||
GameObject dropped = DragAndDrop.objectReferences[ 0 ] as GameObject;
|
||||
if( dropped != null )
|
||||
{
|
||||
m_targetMesh = AssetDatabase.LoadAssetAtPath<Mesh>( AssetDatabase.GetAssetPath( dropped ) );
|
||||
EditorPrefs.SetString( PreviewModelPref, AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( m_targetMesh ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( m_targetMesh == null )
|
||||
{
|
||||
base.OnMaterialInteractivePreviewGUI( materialEditor, r, background );
|
||||
return;
|
||||
}
|
||||
|
||||
Material mat = materialEditor.target as Material;
|
||||
|
||||
if( m_previewRenderUtility == null )
|
||||
{
|
||||
m_previewRenderUtility = new PreviewRenderUtility();
|
||||
m_previewRenderUtility.cameraFieldOfView = 30f;
|
||||
}
|
||||
|
||||
if( m_previewGUIType == null )
|
||||
{
|
||||
m_previewGUIType = Type.GetType( "PreviewGUI, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" );
|
||||
m_dragMethod = m_previewGUIType.GetMethod( "Drag2D", BindingFlags.Static | BindingFlags.Public );
|
||||
}
|
||||
|
||||
m_previewDir = ( Vector2 )m_dragMethod.Invoke( m_previewGUIType, new object[] { m_previewDir, r } );
|
||||
|
||||
if ( m_modelInspectorType == null )
|
||||
{
|
||||
m_modelInspectorType = Type.GetType( "UnityEditor.MeshPreview, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" );
|
||||
if ( m_modelInspectorType == null )
|
||||
{
|
||||
m_modelInspectorType = Type.GetType( "UnityEditor.ModelInspector, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" );
|
||||
}
|
||||
m_renderMeshMethod = m_modelInspectorType.GetMethod( "RenderMeshPreview", BindingFlags.Static | BindingFlags.NonPublic );
|
||||
}
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
|
||||
m_previewDir = ( Vector2 )m_dragMethod.Invoke( m_previewGUIType, new object[] { m_previewDir, r } );
|
||||
|
||||
if ( m_previewSettingsType == null )
|
||||
{
|
||||
m_previewSettingsType = m_modelInspectorType.GetNestedType( "PreviewSettings", BindingFlags.NonPublic );
|
||||
if ( m_previewSettingsType == null )
|
||||
{
|
||||
m_previewSettingsType = m_modelInspectorType.GetNestedType( "Settings", BindingFlags.NonPublic );
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_previewSettingsInstance == null )
|
||||
{
|
||||
m_previewSettingsInstance = Activator.CreateInstance( m_previewSettingsType );
|
||||
}
|
||||
|
||||
if ( shadedMaterialInfo == null || activeMaterialInfo == null || previewDirInfo == null )
|
||||
{
|
||||
shadedMaterialInfo = m_previewSettingsType.GetField( "shadedPreviewMaterial", BindingFlags.Instance | BindingFlags.Public );
|
||||
activeMaterialInfo = m_previewSettingsType.GetField( "activeMaterial", BindingFlags.Instance | BindingFlags.Public );
|
||||
previewDirInfo = m_previewSettingsType.GetField( "previewDir", BindingFlags.Instance | BindingFlags.Public );
|
||||
}
|
||||
|
||||
if ( shadedMaterialInfo == null || activeMaterialInfo == null || previewDirInfo == null )
|
||||
{
|
||||
shadedMaterialInfo = m_previewSettingsType.GetField( "m_ShadedPreviewMaterial", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
activeMaterialInfo = m_previewSettingsType.GetField( "m_ActiveMaterial", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
previewDirInfo = m_previewSettingsType.GetField( "m_PreviewDir", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
}
|
||||
|
||||
shadedMaterialInfo.SetValue( m_previewSettingsInstance, mat );
|
||||
activeMaterialInfo.SetValue( m_previewSettingsInstance, mat );
|
||||
previewDirInfo.SetValue( m_previewSettingsInstance, m_previewDir );
|
||||
|
||||
if ( Event.current.type == EventType.Repaint )
|
||||
{
|
||||
m_previewRenderUtility.BeginPreview( r, background );
|
||||
m_renderMeshMethod.Invoke( m_modelInspectorType, new object[] { m_targetMesh, m_previewRenderUtility, m_previewSettingsInstance, -1 } );
|
||||
m_previewRenderUtility.EndAndDrawPreview( r );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if( Event.current.type == EventType.Repaint )
|
||||
{
|
||||
m_previewRenderUtility.BeginPreview( r, background );
|
||||
m_renderMeshMethod.Invoke( m_modelInspectorType, new object[] { m_targetMesh, m_previewRenderUtility, mat, null, m_previewDir, -1 } );
|
||||
m_previewRenderUtility.EndAndDrawPreview( r );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public static MaterialEditor Instance { get { return m_instance; } set { m_instance = value; } }
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomMaterialInspector.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomMaterialInspector.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1c012872b428594f95e585bd19e5347
|
||||
timeCreated: 1481126958
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
958
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomShaderInspector.cs
vendored
Normal file
958
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomShaderInspector.cs
vendored
Normal file
@@ -0,0 +1,958 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using AmplifyShaderEditor;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[CustomEditor( typeof( Shader ) )]
|
||||
internal class CustomShaderInspector : Editor
|
||||
{
|
||||
internal class Styles
|
||||
{
|
||||
public static Texture2D errorIcon = EditorGUIUtilityEx.LoadIcon( "console.erroricon.sml" );
|
||||
|
||||
public static Texture2D warningIcon = EditorGUIUtilityEx.LoadIcon( "console.warnicon.sml" );
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
public static GUIContent togglePreprocess = EditorGUIUtilityEx.TextContent( "Preprocess only|Show preprocessor output instead of compiled shader code" );
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
public static GUIContent toggleStripLineDirective = EditorGUIUtility.TrTextContent( "Strip #line directives", "Strip #line directives from preprocessor output" );
|
||||
#endif
|
||||
#endif
|
||||
public static GUIContent showSurface = EditorGUIUtilityEx.TextContent( "Show generated code|Show generated code of a surface shader" );
|
||||
|
||||
public static GUIContent showFF = EditorGUIUtilityEx.TextContent( "Show generated code|Show generated code of a fixed function shader" );
|
||||
|
||||
public static GUIContent showCurrent = new GUIContent( "Compile and show code | ▾" );
|
||||
|
||||
public static GUIStyle messageStyle = "CN StatusInfo";
|
||||
|
||||
public static GUIStyle evenBackground = "CN EntryBackEven";
|
||||
|
||||
public static GUIContent no = EditorGUIUtilityEx.TextContent( "no" );
|
||||
|
||||
public static GUIContent builtinShader = EditorGUIUtilityEx.TextContent( "Built-in shader" );
|
||||
|
||||
public static GUIContent arrayValuePopupButton = EditorGUIUtilityEx.TextContent( "..." );
|
||||
}
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
private static bool s_PreprocessOnly = false;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
private static bool s_StripLineDirectives = true;
|
||||
#endif
|
||||
#endif
|
||||
private const float kSpace = 5f;
|
||||
|
||||
const float kValueFieldWidth = 200.0f;
|
||||
const float kArrayValuePopupBtnWidth = 25.0f;
|
||||
|
||||
private static readonly string[] kPropertyTypes = new string[]
|
||||
{
|
||||
"Color: ",
|
||||
"Vector: ",
|
||||
"Float: ",
|
||||
"Range: ",
|
||||
"Texture: ",
|
||||
"Int: "
|
||||
};
|
||||
|
||||
private static readonly string[] kTextureTypes = new string[]
|
||||
{
|
||||
"No Texture?: ",
|
||||
"1D?: ",
|
||||
"2D: ",
|
||||
"3D: ",
|
||||
"Cube: ",
|
||||
"2DArray: ",
|
||||
"Any texture: "
|
||||
};
|
||||
|
||||
private static readonly int kErrorViewHash = "ShaderErrorView".GetHashCode();
|
||||
|
||||
private Vector2 m_ScrollPosition = Vector2.zero;
|
||||
|
||||
private PreviewRenderUtility m_previewRenderUtility;
|
||||
private Material m_material;
|
||||
private Mesh m_previewMesh;
|
||||
private Vector2 m_mouseDelta;
|
||||
private Transform m_cameraTransform;
|
||||
private bool m_allowOpenInCanvas = true;
|
||||
|
||||
private static int m_sliderHashCode = -1;
|
||||
private const float MaxDeltaY = 90;
|
||||
private const int DefaultMouseSpeed = 1;
|
||||
private const int ShiftMouseSpeed = 3;
|
||||
private const float DeltaMultiplier = 135f;
|
||||
private void ValidateData()
|
||||
{
|
||||
if ( m_previewRenderUtility == null )
|
||||
{
|
||||
m_previewRenderUtility = new PreviewRenderUtility();
|
||||
m_cameraTransform = m_previewRenderUtility.camera.transform;
|
||||
m_cameraTransform.position = new Vector3( 0, 0, -4 );
|
||||
m_cameraTransform.rotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
if ( m_material == null )
|
||||
{
|
||||
m_material = new Material( target as Shader );
|
||||
m_material.hideFlags = HideFlags.DontSave;
|
||||
}
|
||||
|
||||
if ( m_previewMesh == null )
|
||||
{
|
||||
m_previewMesh = Resources.GetBuiltinResource<Mesh>( "Sphere.fbx" );
|
||||
}
|
||||
|
||||
if ( m_sliderHashCode < 0 )
|
||||
{
|
||||
"Slider".GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI()
|
||||
{
|
||||
ValidateData();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Vector2 CheckMouseMovement( Vector2 scrollPosition, Rect position )
|
||||
{
|
||||
int controlID = GUIUtility.GetControlID( m_sliderHashCode, FocusType.Passive );
|
||||
Event current = Event.current;
|
||||
switch ( current.GetTypeForControl( controlID ) )
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
{
|
||||
if ( position.Contains( current.mousePosition ) && position.width > 50f )
|
||||
{
|
||||
GUIUtility.hotControl = controlID;
|
||||
current.Use();
|
||||
EditorGUIUtility.SetWantsMouseJumping( 1 );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EventType.MouseUp:
|
||||
{
|
||||
if ( GUIUtility.hotControl == controlID )
|
||||
{
|
||||
GUIUtility.hotControl = 0;
|
||||
}
|
||||
EditorGUIUtility.SetWantsMouseJumping( 0 );
|
||||
}
|
||||
break;
|
||||
case EventType.MouseDrag:
|
||||
{
|
||||
if ( GUIUtility.hotControl == controlID )
|
||||
{
|
||||
scrollPosition -= DeltaMultiplier * current.delta * ( float ) ( ( current.shift ) ? ShiftMouseSpeed : DefaultMouseSpeed ) / Mathf.Min( position.width, position.height );
|
||||
scrollPosition.y = Mathf.Clamp( scrollPosition.y, -MaxDeltaY, MaxDeltaY );
|
||||
current.Use();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return scrollPosition;
|
||||
}
|
||||
|
||||
public override void OnPreviewGUI( Rect r, GUIStyle background )
|
||||
{
|
||||
m_mouseDelta = CheckMouseMovement( m_mouseDelta, r );
|
||||
|
||||
if ( Event.current.type == EventType.Repaint )
|
||||
{
|
||||
m_previewRenderUtility.BeginPreview( r, background );
|
||||
|
||||
Texture resultRender = m_previewRenderUtility.EndPreview();
|
||||
m_previewRenderUtility.DrawMesh( m_previewMesh, Matrix4x4.identity, m_material, 0 );
|
||||
m_cameraTransform.rotation = Quaternion.Euler( new Vector3( -m_mouseDelta.y, -m_mouseDelta.x, 0 ) );
|
||||
m_cameraTransform.position = m_cameraTransform.forward * -8f;
|
||||
m_previewRenderUtility.camera.Render();
|
||||
GUI.DrawTexture( r, resultRender, ScaleMode.StretchToFill, false );
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
CleanUp();
|
||||
if( m_SrpCompatibilityCheckMaterial != null )
|
||||
{
|
||||
GameObject.DestroyImmediate( m_SrpCompatibilityCheckMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
void CleanUp()
|
||||
{
|
||||
if( m_previewRenderUtility != null )
|
||||
{
|
||||
m_previewRenderUtility.Cleanup();
|
||||
m_previewRenderUtility = null;
|
||||
}
|
||||
|
||||
if( m_previewMesh != null )
|
||||
{
|
||||
Resources.UnloadAsset( m_previewMesh );
|
||||
m_previewMesh = null;
|
||||
}
|
||||
|
||||
if( m_previewRenderUtility != null )
|
||||
{
|
||||
m_previewRenderUtility.Cleanup();
|
||||
m_previewRenderUtility = null;
|
||||
}
|
||||
m_material = null;
|
||||
}
|
||||
|
||||
private Material m_SrpCompatibilityCheckMaterial = null;
|
||||
public Material srpCompatibilityCheckMaterial
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_SrpCompatibilityCheckMaterial == null )
|
||||
{
|
||||
m_SrpCompatibilityCheckMaterial = new Material( target as Shader );
|
||||
}
|
||||
return m_SrpCompatibilityCheckMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnEnable()
|
||||
{
|
||||
Shader s = this.target as Shader;
|
||||
if( s!= null )
|
||||
ShaderUtilEx.FetchCachedErrors( s );
|
||||
|
||||
m_allowOpenInCanvas = IOUtils.IsASEShader( s );
|
||||
}
|
||||
|
||||
private static string GetPropertyType( Shader s, int index )
|
||||
{
|
||||
UnityEngine.Rendering.ShaderPropertyType propertyType = s.GetPropertyType( index );
|
||||
if ( propertyType == UnityEngine.Rendering.ShaderPropertyType.Texture )
|
||||
{
|
||||
return CustomShaderInspector.kTextureTypes[ ( int ) s.GetPropertyTextureDimension( index ) ];
|
||||
}
|
||||
return CustomShaderInspector.kPropertyTypes[ ( int ) propertyType ];
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
Shader shader = this.target as Shader;
|
||||
if ( shader == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
|
||||
GUILayout.Space( 3 );
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUI.enabled = m_allowOpenInCanvas;
|
||||
if ( GUILayout.Button( "Open in Shader Editor" ) )
|
||||
{
|
||||
ASEPackageManagerHelper.SetupLateShader( shader );
|
||||
}
|
||||
GUI.enabled = true;
|
||||
|
||||
if ( GUILayout.Button( "Open in Text Editor" ) )
|
||||
{
|
||||
if( UIUtils.IsUnityNativeShader( shader ) )
|
||||
{
|
||||
Debug.LogWarningFormat( "Action not allowed. Attempting to load the native {0} shader into Text Editor", shader.name );
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetDatabase.OpenAsset( shader, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space( 5 );
|
||||
EditorGUI.indentLevel = 0;
|
||||
this.ShowShaderCodeArea( shader );
|
||||
if ( shader.isSupported )
|
||||
{
|
||||
EditorGUILayout.LabelField( "Cast shadows", ( !ShaderUtilEx.HasShadowCasterPass( shader ) ) ? "no" : "yes", new GUILayoutOption[ 0 ] );
|
||||
EditorGUILayout.LabelField( "Render queue", ShaderUtilEx.GetRenderQueue( shader ).ToString( System.Globalization.CultureInfo.InvariantCulture ), new GUILayoutOption[ 0 ] );
|
||||
EditorGUILayout.LabelField( "LOD", ShaderUtilEx.GetLOD( shader ).ToString( System.Globalization.CultureInfo.InvariantCulture ), new GUILayoutOption[ 0 ] );
|
||||
EditorGUILayout.LabelField( "Ignore projector", ( !ShaderUtilEx.DoesIgnoreProjector( shader ) ) ? "no" : "yes", new GUILayoutOption[ 0 ] );
|
||||
string label;
|
||||
switch ( ShaderEx.GetDisableBatching( shader ) )
|
||||
{
|
||||
case DisableBatchingType.False:
|
||||
label = "no";
|
||||
break;
|
||||
case DisableBatchingType.True:
|
||||
label = "yes";
|
||||
break;
|
||||
case DisableBatchingType.WhenLODFading:
|
||||
label = "when LOD fading is on";
|
||||
break;
|
||||
default:
|
||||
label = "unknown";
|
||||
break;
|
||||
}
|
||||
EditorGUILayout.LabelField( "Disable batching", label, new GUILayoutOption[ 0 ] );
|
||||
ShowKeywords( shader );
|
||||
|
||||
if ( !AmplifyShaderEditorWindow.IsSavingToDisk )
|
||||
{
|
||||
srpCompatibilityCheckMaterial.SetPass( 0 );
|
||||
}
|
||||
|
||||
int shaderActiveSubshaderIndex = ShaderUtilEx.GetShaderActiveSubshaderIndex( shader );
|
||||
int sRPBatcherCompatibilityCode = ShaderUtilEx.GetSRPBatcherCompatibilityCode( shader, shaderActiveSubshaderIndex );
|
||||
string label2 = ( sRPBatcherCompatibilityCode != 0 ) ? "not compatible" : "compatible";
|
||||
EditorGUILayout.LabelField( "SRP Batcher", label2 );
|
||||
if( sRPBatcherCompatibilityCode != 0 )
|
||||
{
|
||||
EditorGUILayout.HelpBox( ShaderUtilEx.GetSRPBatcherCompatibilityIssueReason( shader, shaderActiveSubshaderIndex, sRPBatcherCompatibilityCode ), MessageType.Info );
|
||||
}
|
||||
|
||||
CustomShaderInspector.ShowShaderProperties( shader );
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowKeywords( Shader s )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel( "Keywords", EditorStyles.miniButton );
|
||||
|
||||
Rect buttonRect = GUILayoutUtility.GetRect( Styles.arrayValuePopupButton, GUI.skin.button, GUILayout.MinWidth( kValueFieldWidth ) );
|
||||
buttonRect.width = kArrayValuePopupBtnWidth;
|
||||
if( GUI.Button( buttonRect, Styles.arrayValuePopupButton, EditorStyles.miniButton ) )
|
||||
{
|
||||
var globalKeywords = ShaderUtilEx.GetShaderGlobalKeywords( s );
|
||||
var localKeywords = ShaderUtilEx.GetShaderLocalKeywords( s );
|
||||
PopupWindow.Show( buttonRect, new KeywordsPopup( globalKeywords, localKeywords, 150.0f ) );
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void ShowShaderCodeArea( Shader s )
|
||||
{
|
||||
CustomShaderInspector.ShowSurfaceShaderButton( s );
|
||||
CustomShaderInspector.ShowFixedFunctionShaderButton( s );
|
||||
this.ShowCompiledCodeButton( s );
|
||||
this.ShowShaderErrors( s );
|
||||
}
|
||||
|
||||
private static void ShowShaderProperties( Shader s )
|
||||
{
|
||||
GUILayout.Space( 5f );
|
||||
GUILayout.Label( "Properties:", EditorStyles.boldLabel, new GUILayoutOption[ 0 ] );
|
||||
int propertyCount = s.GetPropertyCount();
|
||||
for ( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
string propertyName = s.GetPropertyName( i );
|
||||
string label = CustomShaderInspector.GetPropertyType( s, i ) + s.GetPropertyDescription( i );
|
||||
EditorGUILayout.LabelField( propertyName, label, new GUILayoutOption[ 0 ] );
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ShaderErrorListUI( UnityEngine.Object shader, ShaderError[] errors, ref Vector2 scrollPosition )
|
||||
{
|
||||
int num = errors.Length;
|
||||
GUILayout.Space( 5f );
|
||||
GUILayout.Label( string.Format( "Errors ({0}):", num ), EditorStyles.boldLabel, new GUILayoutOption[ 0 ] );
|
||||
int controlID = GUIUtility.GetControlID( CustomShaderInspector.kErrorViewHash, FocusType.Passive );
|
||||
float minHeight = Mathf.Min( ( float ) num * 20f + 40f, 150f );
|
||||
scrollPosition = GUILayout.BeginScrollView( scrollPosition, GUISkinEx.GetCurrentSkin().box, new GUILayoutOption[]
|
||||
{
|
||||
GUILayout.MinHeight(minHeight)
|
||||
} );
|
||||
EditorGUIUtility.SetIconSize( new Vector2( 16f, 16f ) );
|
||||
float height = CustomShaderInspector.Styles.messageStyle.CalcHeight( EditorGUIUtilityEx.TempContent( CustomShaderInspector.Styles.errorIcon ), 100f );
|
||||
Event current = Event.current;
|
||||
for ( int i = 0; i < num; i++ )
|
||||
{
|
||||
Rect controlRect = EditorGUILayout.GetControlRect( false, height, new GUILayoutOption[ 0 ] );
|
||||
string message = errors[ i ].message;
|
||||
string platform = errors[ i ].platform;
|
||||
bool flag = errors[ i ].warning != 0;
|
||||
string lastPathNameComponent = FileUtilEx.GetLastPathNameComponent( errors[ i ].file );
|
||||
int line = errors[ i ].line;
|
||||
if ( current.type == EventType.MouseDown && current.button == 0 && controlRect.Contains( current.mousePosition ) )
|
||||
{
|
||||
GUIUtility.keyboardControl = controlID;
|
||||
if ( current.clickCount == 2 )
|
||||
{
|
||||
string file = errors[ i ].file;
|
||||
UnityEngine.Object @object = ( !string.IsNullOrEmpty( file ) ) ? AssetDatabase.LoadMainAssetAtPath( file ) : null;
|
||||
AssetDatabase.OpenAsset( @object ?? shader, line );
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
current.Use();
|
||||
}
|
||||
if ( current.type == EventType.ContextClick && controlRect.Contains( current.mousePosition ) )
|
||||
{
|
||||
current.Use();
|
||||
GenericMenu genericMenu = new GenericMenu();
|
||||
int errorIndex = i;
|
||||
genericMenu.AddItem( new GUIContent( "Copy error text" ), false, delegate
|
||||
{
|
||||
string text = errors[ errorIndex ].message;
|
||||
if ( !string.IsNullOrEmpty( errors[ errorIndex ].messageDetails ) )
|
||||
{
|
||||
text += '\n';
|
||||
text += errors[ errorIndex ].messageDetails;
|
||||
}
|
||||
EditorGUIUtility.systemCopyBuffer = text;
|
||||
} );
|
||||
genericMenu.ShowAsContext();
|
||||
}
|
||||
if ( current.type == EventType.Repaint && ( i & 1 ) == 0 )
|
||||
{
|
||||
GUIStyle evenBackground = CustomShaderInspector.Styles.evenBackground;
|
||||
evenBackground.Draw( controlRect, false, false, false, false );
|
||||
}
|
||||
Rect rect = controlRect;
|
||||
rect.xMin = rect.xMax;
|
||||
if ( line > 0 )
|
||||
{
|
||||
GUIContent content;
|
||||
if ( string.IsNullOrEmpty( lastPathNameComponent ) )
|
||||
{
|
||||
content = EditorGUIUtilityEx.TempContent( line.ToString( System.Globalization.CultureInfo.InvariantCulture ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
content = EditorGUIUtilityEx.TempContent( lastPathNameComponent + ":" + line.ToString( System.Globalization.CultureInfo.InvariantCulture ) );
|
||||
}
|
||||
Vector2 vector = EditorStyles.miniLabel.CalcSize( content );
|
||||
rect.xMin -= vector.x;
|
||||
GUI.Label( rect, content, EditorStyles.miniLabel );
|
||||
rect.xMin -= 2f;
|
||||
if ( rect.width < 30f )
|
||||
{
|
||||
rect.xMin = rect.xMax - 30f;
|
||||
}
|
||||
}
|
||||
Rect position = rect;
|
||||
position.width = 0f;
|
||||
if ( platform.Length > 0 )
|
||||
{
|
||||
GUIContent content2 = EditorGUIUtilityEx.TempContent( platform );
|
||||
Vector2 vector2 = EditorStyles.miniLabel.CalcSize( content2 );
|
||||
position.xMin -= vector2.x;
|
||||
Color contentColor = GUI.contentColor;
|
||||
GUI.contentColor = new Color( 1f, 1f, 1f, 0.5f );
|
||||
GUI.Label( position, content2, EditorStyles.miniLabel );
|
||||
GUI.contentColor = contentColor;
|
||||
position.xMin -= 2f;
|
||||
}
|
||||
Rect position2 = controlRect;
|
||||
position2.xMax = position.xMin;
|
||||
GUI.Label( position2, EditorGUIUtilityEx.TempContent( message, ( !flag ) ? CustomShaderInspector.Styles.errorIcon : CustomShaderInspector.Styles.warningIcon ), CustomShaderInspector.Styles.messageStyle );
|
||||
}
|
||||
EditorGUIUtility.SetIconSize( Vector2.zero );
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
ShaderMessage[] m_ShaderMessages;
|
||||
|
||||
private void ShowShaderErrors( Shader s )
|
||||
{
|
||||
if( Event.current.type == EventType.Layout )
|
||||
{
|
||||
int n = ShaderUtil.GetShaderMessageCount( s );
|
||||
m_ShaderMessages = null;
|
||||
if( n >= 1 )
|
||||
{
|
||||
m_ShaderMessages = ShaderUtil.GetShaderMessages( s );
|
||||
}
|
||||
}
|
||||
|
||||
if( m_ShaderMessages == null )
|
||||
return;
|
||||
|
||||
ShaderInspectorEx.ShaderErrorListUI( s, m_ShaderMessages, ref this.m_ScrollPosition );
|
||||
}
|
||||
|
||||
private void ShowCompiledCodeButton( Shader s )
|
||||
{
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
using( new EditorGUI.DisabledScope( !EditorSettings.cachingShaderPreprocessor ) )
|
||||
{
|
||||
s_PreprocessOnly = EditorGUILayout.Toggle( Styles.togglePreprocess, s_PreprocessOnly );
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
if( s_PreprocessOnly )
|
||||
{
|
||||
s_StripLineDirectives = EditorGUILayout.Toggle( Styles.toggleStripLineDirective, s_StripLineDirectives );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
EditorGUILayout.BeginHorizontal( new GUILayoutOption[ 0 ] );
|
||||
EditorGUILayout.PrefixLabel( "Compiled code", EditorStyles.miniButton );
|
||||
|
||||
bool hasCode = ShaderUtilEx.HasShaderSnippets( s ) || ShaderUtilEx.HasSurfaceShaders( s ) || ShaderUtilEx.HasFixedFunctionShaders( s );
|
||||
if( hasCode )
|
||||
{
|
||||
GUIContent showCurrent = Styles.showCurrent;
|
||||
Rect rect = GUILayoutUtility.GetRect( showCurrent, EditorStyles.miniButton, new GUILayoutOption[]
|
||||
{
|
||||
GUILayout.ExpandWidth(false)
|
||||
} );
|
||||
Rect position = new Rect( rect.xMax - 16f, rect.y, 16f, rect.height );
|
||||
if( EditorGUIEx.ButtonMouseDown( position, GUIContent.none, FocusType.Passive, GUIStyle.none ) )
|
||||
{
|
||||
Rect last = GUILayoutUtilityEx.TopLevel_GetLast();
|
||||
PopupWindow.Show( last, (PopupWindowContent)Activator.CreateInstance( System.Type.GetType( "UnityEditor.ShaderInspectorPlatformsPopup, UnityEditor" ), new object[] { s } ) );
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
if( GUI.Button( rect, showCurrent, EditorStyles.miniButton ) )
|
||||
{
|
||||
#if UNITY_2020_1
|
||||
ShaderUtilEx.OpenCompiledShader( s, ShaderInspectorPlatformsPopupEx.GetCurrentMode(), ShaderInspectorPlatformsPopupEx.GetCurrentPlatformMask(), ShaderInspectorPlatformsPopupEx.GetCurrentVariantStripping() == 0, s_PreprocessOnly );
|
||||
#elif UNITY_2020_2_OR_NEWER
|
||||
ShaderUtilEx.OpenCompiledShader( s, ShaderInspectorPlatformsPopupEx.GetCurrentMode(), ShaderInspectorPlatformsPopupEx.GetCurrentPlatformMask(), ShaderInspectorPlatformsPopupEx.GetCurrentVariantStripping() == 0, s_PreprocessOnly, s_StripLineDirectives );
|
||||
#else
|
||||
ShaderUtilEx.OpenCompiledShader( s, ShaderInspectorPlatformsPopupEx.GetCurrentMode(), ShaderInspectorPlatformsPopupEx.GetCurrentPlatformMask(), ShaderInspectorPlatformsPopupEx.GetCurrentVariantStripping() == 0 );
|
||||
#endif
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Button( "none (precompiled shader)", GUI.skin.label, new GUILayoutOption[ 0 ] );
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private static void ShowSurfaceShaderButton( Shader s )
|
||||
{
|
||||
bool flag = ShaderUtilEx.HasSurfaceShaders( s );
|
||||
EditorGUILayout.BeginHorizontal( new GUILayoutOption[ 0 ] );
|
||||
EditorGUILayout.PrefixLabel( "Surface shader", EditorStyles.miniButton );
|
||||
if ( flag )
|
||||
{
|
||||
if ( !( AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( s ) ) == null ) )
|
||||
{
|
||||
if ( GUILayout.Button( CustomShaderInspector.Styles.showSurface, EditorStyles.miniButton, new GUILayoutOption[]
|
||||
{
|
||||
GUILayout.ExpandWidth(false)
|
||||
} ) )
|
||||
{
|
||||
ShaderUtilEx.OpenParsedSurfaceShader( s );
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Button( CustomShaderInspector.Styles.builtinShader, GUI.skin.label, new GUILayoutOption[ 0 ] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Button( CustomShaderInspector.Styles.no, GUI.skin.label, new GUILayoutOption[ 0 ] );
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private static void ShowFixedFunctionShaderButton( Shader s )
|
||||
{
|
||||
bool flag = ShaderUtilEx.HasFixedFunctionShaders( s );
|
||||
EditorGUILayout.BeginHorizontal( new GUILayoutOption[ 0 ] );
|
||||
EditorGUILayout.PrefixLabel( "Fixed function", EditorStyles.miniButton );
|
||||
if ( flag )
|
||||
{
|
||||
if ( !( AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( s ) ) == null ) )
|
||||
{
|
||||
if ( GUILayout.Button( CustomShaderInspector.Styles.showFF, EditorStyles.miniButton, new GUILayoutOption[]
|
||||
{
|
||||
GUILayout.ExpandWidth(false)
|
||||
} ) )
|
||||
{
|
||||
ShaderUtilEx.OpenGeneratedFixedFunctionShader( s );
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Button( CustomShaderInspector.Styles.builtinShader, GUI.skin.label, new GUILayoutOption[ 0 ] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Button( CustomShaderInspector.Styles.no, GUI.skin.label, new GUILayoutOption[ 0 ] );
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
internal class KeywordsPopup : PopupWindowContent
|
||||
{
|
||||
private Vector2 m_ScrollPos = Vector2.zero;
|
||||
private string[] m_GlobalKeywords;
|
||||
private string[] m_LocalKeywords;
|
||||
private bool m_GlobalKeywordsExpended;
|
||||
private bool m_LocalKeywordsExpended;
|
||||
private float m_WindowWidth;
|
||||
|
||||
private static readonly GUIStyle m_Style = EditorStyles.miniLabel;
|
||||
|
||||
public KeywordsPopup( string[] globalKeywords, string[] localKeywords, float windowWidth )
|
||||
{
|
||||
m_GlobalKeywords = globalKeywords;
|
||||
m_LocalKeywords = localKeywords;
|
||||
m_GlobalKeywordsExpended = true;
|
||||
m_LocalKeywordsExpended = true;
|
||||
m_WindowWidth = windowWidth;
|
||||
}
|
||||
|
||||
public override Vector2 GetWindowSize()
|
||||
{
|
||||
var numValues = m_GlobalKeywords.Length + m_LocalKeywords.Length + 2;
|
||||
var lineHeight = m_Style.lineHeight + m_Style.padding.vertical + m_Style.margin.top;
|
||||
return new Vector2( m_WindowWidth, Math.Min( lineHeight * numValues, 250.0f ) );
|
||||
}
|
||||
|
||||
public override void OnGUI( Rect rect )
|
||||
{
|
||||
m_ScrollPos = EditorGUILayout.BeginScrollView( m_ScrollPos );
|
||||
|
||||
m_GlobalKeywordsExpended = KeywordsFoldout( m_GlobalKeywordsExpended, "Global Keywords", m_GlobalKeywords );
|
||||
m_LocalKeywordsExpended = KeywordsFoldout( m_LocalKeywordsExpended, "Local Keywords", m_LocalKeywords );
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private bool KeywordsFoldout( bool expended, string name, string[] values )
|
||||
{
|
||||
expended = EditorGUILayout.Foldout( expended, name, true, m_Style );
|
||||
|
||||
if( expended )
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for( int i = 0; i < values.Length; ++i )
|
||||
{
|
||||
EditorGUILayout.LabelField( values[ i ], m_Style );
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
return expended;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// UNITY EDITOR EXTENSIONS
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public enum DisableBatchingType
|
||||
{
|
||||
False,
|
||||
True,
|
||||
WhenLODFading
|
||||
}
|
||||
|
||||
public struct ShaderError
|
||||
{
|
||||
public string message;
|
||||
public string messageDetails;
|
||||
public string platform;
|
||||
public string file;
|
||||
public int line;
|
||||
public int warning;
|
||||
}
|
||||
|
||||
public static class EditorGUIUtilityEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEditor.EditorGUIUtility, UnityEditor" ) : type; } }
|
||||
|
||||
public static Texture2D LoadIcon( string icon )
|
||||
{
|
||||
return ( Texture2D ) EditorGUIUtilityEx.Type.InvokeMember( "LoadIcon", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { icon } );
|
||||
}
|
||||
|
||||
public static GUIContent TextContent( string t )
|
||||
{
|
||||
return ( GUIContent ) EditorGUIUtilityEx.Type.InvokeMember( "TextContent", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { t } );
|
||||
}
|
||||
|
||||
internal static GUIContent TempContent( string t )
|
||||
{
|
||||
return ( GUIContent ) EditorGUIUtilityEx.Type.InvokeMember( "TempContent", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { t } );
|
||||
}
|
||||
|
||||
internal static GUIContent TempContent( Texture i )
|
||||
{
|
||||
return ( GUIContent ) EditorGUIUtilityEx.Type.InvokeMember( "TempContent", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { i } );
|
||||
}
|
||||
|
||||
internal static GUIContent TempContent( string t, Texture i )
|
||||
{
|
||||
return ( GUIContent ) EditorGUIUtilityEx.Type.InvokeMember( "TempContent", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { t, i } );
|
||||
}
|
||||
}
|
||||
|
||||
public static class GUILayoutUtilityEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEngine.GUILayoutUtility, UnityEngine" ) : type; } }
|
||||
|
||||
public static Rect TopLevel_GetLast()
|
||||
{
|
||||
System.Type guiLayoutGroup = System.Type.GetType( "UnityEngine.GUILayoutGroup, UnityEngine" );
|
||||
var topLevel = GUILayoutUtilityEx.Type.GetProperty( "topLevel", BindingFlags.NonPublic | BindingFlags.Static ).GetValue( null, null );
|
||||
return ( Rect ) guiLayoutGroup.InvokeMember( "GetLast", BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, topLevel, new object[] { } );
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShaderEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEngine.Shader, UnityEngine" ) : type; } }
|
||||
|
||||
public static DisableBatchingType GetDisableBatching( Shader s )
|
||||
{
|
||||
return ( DisableBatchingType ) ShaderEx.Type.GetProperty( "disableBatching", BindingFlags.NonPublic | BindingFlags.Instance ).GetValue( s, new object[ 0 ] );
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShaderUtilEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEditor.ShaderUtil, UnityEditor" ) : type; } }
|
||||
|
||||
public static void OpenParsedSurfaceShader( Shader s )
|
||||
{
|
||||
ShaderUtilEx.Type.InvokeMember( "OpenParsedSurfaceShader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static void OpenGeneratedFixedFunctionShader( Shader s )
|
||||
{
|
||||
ShaderUtilEx.Type.InvokeMember( "OpenGeneratedFixedFunctionShader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
#if UNITY_2020_1
|
||||
public static void OpenCompiledShader( Shader shader, int mode, int customPlatformsMask, bool includeAllVariants, bool preprocessOnly )
|
||||
{
|
||||
ShaderUtilEx.Type.InvokeMember( "OpenCompiledShader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { shader, mode, customPlatformsMask, includeAllVariants, preprocessOnly } );
|
||||
}
|
||||
#elif UNITY_2020_2_OR_NEWER
|
||||
public static void OpenCompiledShader( Shader shader, int mode, int customPlatformsMask, bool includeAllVariants, bool preprocessOnly, bool stripLineDirectives )
|
||||
{
|
||||
ShaderUtilEx.Type.InvokeMember( "OpenCompiledShader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { shader, mode, customPlatformsMask, includeAllVariants, preprocessOnly, stripLineDirectives } );
|
||||
}
|
||||
#else
|
||||
public static void OpenCompiledShader( Shader shader, int mode, int customPlatformsMask, bool includeAllVariants )
|
||||
{
|
||||
ShaderUtilEx.Type.InvokeMember( "OpenCompiledShader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { shader, mode, customPlatformsMask, includeAllVariants } );
|
||||
}
|
||||
#endif
|
||||
public static void FetchCachedErrors( Shader s )
|
||||
{
|
||||
ShaderUtilEx.Type.InvokeMember( "FetchCachedMessages", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static string[] GetShaderGlobalKeywords( Shader s )
|
||||
{
|
||||
return ShaderUtilEx.Type.InvokeMember( "GetShaderGlobalKeywords", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } ) as string[];
|
||||
}
|
||||
|
||||
public static string[] GetShaderLocalKeywords( Shader s )
|
||||
{
|
||||
return ShaderUtilEx.Type.InvokeMember( "GetShaderLocalKeywords", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } ) as string[];
|
||||
}
|
||||
|
||||
public static int GetShaderErrorCount( Shader s )
|
||||
{
|
||||
return ShaderUtil.GetShaderMessageCount( s );
|
||||
}
|
||||
|
||||
public static int GetAvailableShaderCompilerPlatforms()
|
||||
{
|
||||
return (int)ShaderUtilEx.Type.InvokeMember( "GetAvailableShaderCompilerPlatforms", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { } );
|
||||
}
|
||||
|
||||
public static ShaderError[] GetShaderErrors( Shader s )
|
||||
{
|
||||
System.Type shaderErrorType = System.Type.GetType( "UnityEditor.ShaderError, UnityEditor" );
|
||||
var errorList = ( System.Collections.IList ) ShaderUtilEx.Type.InvokeMember( "GetShaderErrors", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
|
||||
FieldInfo messageField = shaderErrorType.GetField( "message", BindingFlags.Public | BindingFlags.Instance );
|
||||
FieldInfo messageDetailsField = shaderErrorType.GetField( "messageDetails", BindingFlags.Public | BindingFlags.Instance );
|
||||
FieldInfo platformField = shaderErrorType.GetField( "platform", BindingFlags.Public | BindingFlags.Instance );
|
||||
FieldInfo fileField = shaderErrorType.GetField( "file", BindingFlags.Public | BindingFlags.Instance );
|
||||
FieldInfo lineField = shaderErrorType.GetField( "line", BindingFlags.Public | BindingFlags.Instance );
|
||||
FieldInfo warningField = shaderErrorType.GetField( "warning", BindingFlags.Public | BindingFlags.Instance );
|
||||
|
||||
ShaderError[] errors = new ShaderError[ errorList.Count ];
|
||||
for ( int i = 0; i < errorList.Count; i++ )
|
||||
{
|
||||
errors[ i ].message = ( string ) messageField.GetValue( errorList[ i ] );
|
||||
errors[ i ].messageDetails = ( string ) messageDetailsField.GetValue( errorList[ i ] );
|
||||
errors[ i ].platform = ( string ) platformField.GetValue( errorList[ i ] );
|
||||
errors[ i ].file = ( string ) fileField.GetValue( errorList[ i ] );
|
||||
errors[ i ].line = ( int ) lineField.GetValue( errorList[ i ] );
|
||||
errors[ i ].warning = ( int ) warningField.GetValue( errorList[ i ] );
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
public static bool HasShaderSnippets( Shader s )
|
||||
{
|
||||
return ( bool ) ShaderUtilEx.Type.InvokeMember( "HasShaderSnippets", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static bool HasSurfaceShaders( Shader s )
|
||||
{
|
||||
return ( bool ) ShaderUtilEx.Type.InvokeMember( "HasSurfaceShaders", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static bool HasFixedFunctionShaders( Shader s )
|
||||
{
|
||||
return ( bool ) ShaderUtilEx.Type.InvokeMember( "HasFixedFunctionShaders", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static bool HasShadowCasterPass( Shader s )
|
||||
{
|
||||
return ( bool ) ShaderUtilEx.Type.InvokeMember( "HasShadowCasterPass", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static int GetRenderQueue( Shader s )
|
||||
{
|
||||
return ( int ) ShaderUtilEx.Type.InvokeMember( "GetRenderQueue", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static int GetLOD( Shader s )
|
||||
{
|
||||
return ( int ) ShaderUtilEx.Type.InvokeMember( "GetLOD", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static bool DoesIgnoreProjector( Shader s )
|
||||
{
|
||||
return ( bool ) ShaderUtilEx.Type.InvokeMember( "DoesIgnoreProjector", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static int GetShaderActiveSubshaderIndex( Shader s )
|
||||
{
|
||||
return (int)ShaderUtilEx.Type.InvokeMember( "GetShaderActiveSubshaderIndex", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
}
|
||||
|
||||
public static int GetSRPBatcherCompatibilityCode( Shader s, int subShaderIdx )
|
||||
{
|
||||
return (int)ShaderUtilEx.Type.InvokeMember( "GetSRPBatcherCompatibilityCode", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s, subShaderIdx } );
|
||||
}
|
||||
|
||||
public static string GetSRPBatcherCompatibilityIssueReason( Shader s, int subShaderIdx, int err )
|
||||
{
|
||||
return (string)ShaderUtilEx.Type.InvokeMember( "GetSRPBatcherCompatibilityIssueReason", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s, subShaderIdx, err } );
|
||||
}
|
||||
}
|
||||
|
||||
public static class FileUtilEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEditor.FileUtil, UnityEditor" ) : type; } }
|
||||
|
||||
public static string GetLastPathNameComponent( string path )
|
||||
{
|
||||
return ( string ) FileUtilEx.Type.InvokeMember( "GetLastPathNameComponent", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { path } );
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShaderInspectorEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEditor.ShaderInspector, UnityEditor" ) : type; } }
|
||||
|
||||
public static void ShaderErrorListUI( UnityEngine.Object shader, ShaderMessage[] messages, ref Vector2 scrollPosition )
|
||||
{
|
||||
Type.InvokeMember( "ShaderErrorListUI", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { shader, messages, scrollPosition } );
|
||||
}
|
||||
}
|
||||
|
||||
public static class GUISkinEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEngine.GUISkin, UnityEngine" ) : type; } }
|
||||
|
||||
public static GUISkin GetCurrentSkin()
|
||||
{
|
||||
return ( GUISkin ) GUISkinEx.Type.GetField( "current", BindingFlags.NonPublic | BindingFlags.Static ).GetValue( null );
|
||||
}
|
||||
}
|
||||
|
||||
public static class EditorGUIEx
|
||||
{
|
||||
public static System.Type Type = typeof( EditorGUI );
|
||||
|
||||
public static bool ButtonMouseDown( Rect position, GUIContent content, FocusType focusType, GUIStyle style )
|
||||
{
|
||||
return EditorGUI.DropdownButton( position, content, focusType, style );
|
||||
}
|
||||
|
||||
public static float kObjectFieldMiniThumbnailHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return (float)EditorGUIEx.Type.InvokeMember( "kObjectFieldMiniThumbnailHeight", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField, null, null, new object[] {} );
|
||||
}
|
||||
}
|
||||
|
||||
public static float kSingleLineHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return (float)EditorGUIEx.Type.InvokeMember( "kSingleLineHeight", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField, null, null, new object[] { } );
|
||||
}
|
||||
}
|
||||
|
||||
public static Gradient GradientField( Rect position, Gradient gradient )
|
||||
{
|
||||
return EditorGUI.GradientField( position, gradient );
|
||||
}
|
||||
}
|
||||
|
||||
internal static class EditorGUILayoutEx
|
||||
{
|
||||
public static System.Type Type = typeof( EditorGUILayout );
|
||||
public static Gradient GradientField( Gradient value, params GUILayoutOption[] options )
|
||||
{
|
||||
return EditorGUILayout.GradientField( value, options );
|
||||
}
|
||||
|
||||
public static Gradient GradientField( string label, Gradient value, params GUILayoutOption[] options )
|
||||
{
|
||||
return EditorGUILayout.GradientField( label, value, options );
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShaderInspectorPlatformsPopupEx
|
||||
{
|
||||
private static System.Type type = null;
|
||||
public static System.Type Type { get { return ( type == null ) ? type = System.Type.GetType( "UnityEditor.ShaderInspectorPlatformsPopup, UnityEditor" ) : type; } }
|
||||
|
||||
public static int GetCurrentMode()
|
||||
{
|
||||
return ( int ) ShaderInspectorPlatformsPopupEx.Type.GetProperty( "currentMode", BindingFlags.Public | BindingFlags.Static ).GetValue( null, null );
|
||||
}
|
||||
|
||||
public static int GetCurrentPlatformMask()
|
||||
{
|
||||
return ( int ) ShaderInspectorPlatformsPopupEx.Type.GetProperty( "currentPlatformMask", BindingFlags.Public | BindingFlags.Static ).GetValue( null, null );
|
||||
}
|
||||
|
||||
public static int GetCurrentVariantStripping()
|
||||
{
|
||||
return ( int ) ShaderInspectorPlatformsPopupEx.Type.GetProperty( "currentVariantStripping", BindingFlags.Public | BindingFlags.Static ).GetValue( null, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomShaderInspector.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomShaderInspector.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 641dff721f3c24c4188f01fea49484cb
|
||||
timeCreated: 1481126956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
132
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomTexture2DArrayInspector.cs
vendored
Normal file
132
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/CustomTexture2DArrayInspector.cs
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
#if !UNITY_2019_1_OR_NEWER
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[CustomEditor( typeof( Texture2DArray ) )]
|
||||
public class CustomTexture2DArrayInspector : Editor
|
||||
{
|
||||
Texture2DArray m_target;
|
||||
[SerializeField]
|
||||
float m_index;
|
||||
Shader m_textureArrayPreview;
|
||||
Material m_previewMaterial;
|
||||
GUIStyle slider = null;
|
||||
GUIStyle thumb = null;
|
||||
GUIContent m_allButton = null;
|
||||
[SerializeField]
|
||||
bool m_seeAll;
|
||||
void OnEnable()
|
||||
{
|
||||
m_target = ( target as Texture2DArray );
|
||||
m_textureArrayPreview = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "610c24aad350fba4583068c6c22fa428" ) );
|
||||
m_previewMaterial = new Material( m_textureArrayPreview );
|
||||
slider = null;
|
||||
thumb = null;
|
||||
}
|
||||
|
||||
public override void OnPreviewGUI( Rect r, GUIStyle background )
|
||||
{
|
||||
base.OnPreviewGUI( r, background );
|
||||
m_previewMaterial.SetTexture( "_MainTex", m_target );
|
||||
m_previewMaterial.SetFloat( "_Index", m_index );
|
||||
EditorGUI.DrawPreviewTexture( r, m_target, m_previewMaterial, ScaleMode.ScaleToFit, 1f );
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
DestroyImmediate( m_previewMaterial );
|
||||
m_previewMaterial = null;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if( slider == null )
|
||||
slider = "preSlider";
|
||||
|
||||
if( thumb == null )
|
||||
thumb = "preSliderThumb";
|
||||
|
||||
if( m_allButton == null )
|
||||
m_allButton = EditorGUIUtility.IconContent( "PreTextureMipMapLow" );
|
||||
|
||||
base.OnInspectorGUI();
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnPreviewSettings()
|
||||
{
|
||||
base.OnPreviewSettings();
|
||||
m_seeAll = GUILayout.Toggle( m_seeAll, m_allButton, "preButton" );
|
||||
EditorGUI.BeginDisabledGroup( m_seeAll );
|
||||
m_index = Mathf.Round( GUILayout.HorizontalSlider( m_index, 0, m_target.depth - 1, slider, thumb ) );
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
public override void OnInteractivePreviewGUI( Rect r, GUIStyle background )
|
||||
{
|
||||
//base.OnInteractivePreviewGUI( r, background );
|
||||
if( m_seeAll )
|
||||
{
|
||||
int columns = Mathf.CeilToInt( Mathf.Sqrt( m_target.depth ) );
|
||||
float sizeX = r.width / columns - 20;
|
||||
float centerY = ( columns * columns ) - m_target.depth;
|
||||
int rows = columns;
|
||||
if( centerY >= columns )
|
||||
rows--;
|
||||
float sizeY = ( r.height - 16 ) / rows - 15;
|
||||
|
||||
if( centerY >= columns )
|
||||
centerY = sizeY * 0.5f;
|
||||
else
|
||||
centerY = 0;
|
||||
|
||||
Rect smallRect = r;
|
||||
if( rows > 1 )
|
||||
smallRect.y += ( 15 / ( rows - 1 ) );
|
||||
else
|
||||
smallRect.y += 15;
|
||||
smallRect.x = r.x + 10;
|
||||
smallRect.width = sizeX;
|
||||
smallRect.height = sizeY;
|
||||
|
||||
for( int i = 0; i < m_target.depth; i++ )
|
||||
{
|
||||
m_previewMaterial.SetTexture( "_MainTex", m_target );
|
||||
m_previewMaterial.SetFloat( "_Index", i );
|
||||
EditorGUI.DrawPreviewTexture( smallRect, m_target, m_previewMaterial, ScaleMode.ScaleToFit, 1 );
|
||||
Rect dropRect = smallRect;
|
||||
|
||||
float diff = smallRect.height - smallRect.width;
|
||||
if( diff > 0 )
|
||||
dropRect.y -= diff * 0.5f;
|
||||
dropRect.y += 16;
|
||||
EditorGUI.DropShadowLabel( dropRect, "[" + i + "]" );
|
||||
|
||||
smallRect.x += sizeX + 20;
|
||||
if( ( ( i + 1 ) % ( columns ) ) == 0 )
|
||||
{
|
||||
smallRect.x = r.x + 10;
|
||||
smallRect.height = sizeY;
|
||||
smallRect.y += sizeY + 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_previewMaterial.SetTexture( "_MainTex", m_target );
|
||||
m_previewMaterial.SetFloat( "_Index", m_index );
|
||||
EditorGUI.DrawPreviewTexture( r, m_target, m_previewMaterial, ScaleMode.ScaleToFit, 1f );
|
||||
EditorGUI.DropShadowLabel( r, "[" + m_index + "]" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 871ecf36e52b267449b9047596793d6f
|
||||
timeCreated: 1517913060
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
254
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/EditorVariablesManager.cs
vendored
Normal file
254
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/EditorVariablesManager.cs
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class EditorVariable<T>
|
||||
{
|
||||
protected string m_labelName;
|
||||
protected string m_name;
|
||||
protected T m_value;
|
||||
protected T m_defaultValue;
|
||||
|
||||
public EditorVariable( string name, string labelName, T defaultValue ) { m_name = name; m_labelName = labelName; m_defaultValue = defaultValue; m_value = defaultValue; }
|
||||
public string Name { get { return m_name; } }
|
||||
|
||||
public virtual T Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
}
|
||||
public string LabelName { get { return m_labelName; } }
|
||||
}
|
||||
|
||||
public sealed class EditorVariableFloat : EditorVariable<float>
|
||||
{
|
||||
public EditorVariableFloat( string name, string labelName, float defaultValue ) : base( name, labelName, defaultValue )
|
||||
{
|
||||
m_value = EditorPrefs.GetFloat( name, m_defaultValue );
|
||||
}
|
||||
|
||||
public override float Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
if( m_value != value )
|
||||
{
|
||||
m_value = value;
|
||||
EditorPrefs.SetFloat( m_name, m_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EditorVariableBool : EditorVariable<bool>
|
||||
{
|
||||
public EditorVariableBool( string name, string labelName, bool defaultValue ) : base( name, labelName, defaultValue )
|
||||
{
|
||||
m_value = EditorPrefs.GetBool( name, m_defaultValue );
|
||||
}
|
||||
|
||||
public override bool Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
if( m_value != value )
|
||||
{
|
||||
m_value = value;
|
||||
EditorPrefs.SetBool( m_name, m_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EditorVariableInt : EditorVariable<int>
|
||||
{
|
||||
public EditorVariableInt( string name, string labelName, int defaultValue ) : base( name, labelName, defaultValue )
|
||||
{
|
||||
m_value = EditorPrefs.GetInt( name, m_defaultValue );
|
||||
}
|
||||
|
||||
public override int Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
if( m_value != value )
|
||||
{
|
||||
m_value = value;
|
||||
EditorPrefs.SetInt( m_name, m_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EditorVariableString : EditorVariable<string>
|
||||
{
|
||||
public EditorVariableString( string name, string labelName, string defaultValue ) : base( name, labelName, defaultValue )
|
||||
{
|
||||
m_value = EditorPrefs.GetString( name, m_defaultValue );
|
||||
}
|
||||
|
||||
public override string Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
if( !m_value.Equals( value ) )
|
||||
{
|
||||
m_value = value;
|
||||
EditorPrefs.SetString( m_name, m_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class EditorVariablesManager
|
||||
{
|
||||
public static EditorVariableBool LiveMode = new EditorVariableBool( "ASELiveMode", "LiveMode", false );
|
||||
public static EditorVariableBool OutlineActiveMode = new EditorVariableBool( "ASEOutlineActiveMode", " Outline", false );
|
||||
public static EditorVariableBool NodeParametersMaximized = new EditorVariableBool( "ASENodeParametersVisible", " NodeParameters", true );
|
||||
public static EditorVariableBool NodePaletteMaximized = new EditorVariableBool( "ASENodePaletteVisible", " NodePalette", true );
|
||||
public static EditorVariableBool ExpandedRenderingPlatforms = new EditorVariableBool( "ASEExpandedRenderingPlatforms", " ExpandedRenderingPlatforms", false );
|
||||
public static EditorVariableBool ExpandedRenderingOptions = new EditorVariableBool( "ASEExpandedRenderingOptions", " ExpandedRenderingPlatforms", false );
|
||||
public static EditorVariableBool ExpandedGeneralShaderOptions = new EditorVariableBool( "ASEExpandedGeneralShaderOptions", " ExpandedGeneralShaderOptions", false );
|
||||
public static EditorVariableBool ExpandedBlendOptions = new EditorVariableBool( "ASEExpandedBlendOptions", " ExpandedBlendOptions", false );
|
||||
public static EditorVariableBool ExpandedStencilOptions = new EditorVariableBool( "ASEExpandedStencilOptions", " ExpandedStencilOptions", false );
|
||||
public static EditorVariableBool ExpandedVertexOptions = new EditorVariableBool( "ASEExpandedVertexOptions", " ExpandedVertexOptions", false );
|
||||
public static EditorVariableBool ExpandedFunctionInputs = new EditorVariableBool( "ASEExpandedFunctionInputs", " ExpandedFunctionInputs", false );
|
||||
public static EditorVariableBool ExpandedFunctionSwitches = new EditorVariableBool( "ASEExpandedFunctionSwitches", " ExpandedFunctionSwitches", false );
|
||||
public static EditorVariableBool ExpandedFunctionOutputs = new EditorVariableBool( "ASEExpandedFunctionOutputs", " ExpandedFunctionOutputs", false );
|
||||
public static EditorVariableBool ExpandedAdditionalIncludes = new EditorVariableBool( "ASEExpandedAdditionalIncludes", " ExpandedAdditionalIncludes", false );
|
||||
public static EditorVariableBool ExpandedAdditionalDefines = new EditorVariableBool( "ASEExpandedAdditionalDefines", " ExpandedAdditionalDefines", false );
|
||||
public static EditorVariableBool ExpandedAdditionalDirectives = new EditorVariableBool( "ASEExpandedAdditionalDirectives", " ExpandedAdditionalDirectives", false );
|
||||
public static EditorVariableBool ExpandedCustomTags = new EditorVariableBool( "ASEExpandedCustomTags", " ExpandedCustomTags", false );
|
||||
public static EditorVariableBool ExpandedAdditionalSurfaceOptions = new EditorVariableBool( "ASEExpandedAdditionalSurfaceOptions", " ExpandedAdditionalSurfaceOptions", false );
|
||||
public static EditorVariableBool ExpandedAdditionalPragmas = new EditorVariableBool( "ASEExpandedAdditionalPragmas", " ExpandedAdditionalPragmas", false );
|
||||
public static EditorVariableBool ExpandedDependencies = new EditorVariableBool( "ASEExpandedDependencies", " ExpandedDependencies", false );
|
||||
public static EditorVariableBool ExpandedDepth = new EditorVariableBool( "ASEExpandedDepth", " ExpandedDepth", false );
|
||||
public static EditorVariableBool ExpandedTesselation = new EditorVariableBool( "ASEExpandedTesselation", " ExpandedTesselation", false );
|
||||
public static EditorVariableBool ExpandedProperties = new EditorVariableBool( "ASEExpandedProperties", " ExpandedProperties", false );
|
||||
public static EditorVariableBool ExpandedUsePass = new EditorVariableBool( "ASEUsePass", " UsePass", false );
|
||||
//Templates
|
||||
public static EditorVariableBool ExpandedBlendModeModule = new EditorVariableBool( "ASEExpandedBlendModeModule", " ExpandedBlendModeModule", false );
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class InnerWindowEditorVariables
|
||||
{
|
||||
[SerializeField]
|
||||
private bool m_liveMode = false;
|
||||
[SerializeField]
|
||||
private bool m_outlineActiveMode = false;
|
||||
[SerializeField]
|
||||
private bool m_nodeParametersMaximized = false;
|
||||
[SerializeField]
|
||||
private bool m_nodePaletteMaximized = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedRenderingPlatforms = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedRenderingOptions = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedGeneralShaderOptions = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedBlendOptions = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedStencilOptions = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedVertexOptions = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedFunctionInputs = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedFunctionSwitches = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedFunctionOutputs = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedAdditionalIncludes = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedAdditionalDefines = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedAdditionalDirectives = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedCustomTags = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedAdditionalSurfaceOptions = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedAdditionalPragmas = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedDependencies = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedBlendModeModule = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedDepth = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedTesselation = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedProperties = false;
|
||||
[SerializeField]
|
||||
private bool m_expandedUsePass = false;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
m_liveMode = EditorVariablesManager.LiveMode.Value;
|
||||
m_outlineActiveMode = EditorVariablesManager.OutlineActiveMode.Value;
|
||||
m_nodeParametersMaximized = EditorVariablesManager.NodeParametersMaximized.Value;
|
||||
m_nodePaletteMaximized = EditorVariablesManager.NodePaletteMaximized.Value;
|
||||
m_expandedRenderingPlatforms = EditorVariablesManager.ExpandedRenderingPlatforms.Value;
|
||||
m_expandedRenderingOptions = EditorVariablesManager.ExpandedRenderingOptions.Value;
|
||||
m_expandedGeneralShaderOptions = EditorVariablesManager.ExpandedGeneralShaderOptions.Value;
|
||||
m_expandedBlendOptions = EditorVariablesManager.ExpandedBlendOptions.Value;
|
||||
m_expandedStencilOptions = EditorVariablesManager.ExpandedStencilOptions.Value;
|
||||
m_expandedVertexOptions = EditorVariablesManager.ExpandedVertexOptions.Value;
|
||||
m_expandedFunctionInputs = EditorVariablesManager.ExpandedFunctionInputs.Value;
|
||||
m_expandedFunctionSwitches = EditorVariablesManager.ExpandedFunctionSwitches.Value;
|
||||
m_expandedFunctionOutputs = EditorVariablesManager.ExpandedFunctionOutputs.Value;
|
||||
m_expandedAdditionalIncludes = EditorVariablesManager.ExpandedAdditionalIncludes.Value;
|
||||
m_expandedAdditionalDefines = EditorVariablesManager.ExpandedAdditionalDefines.Value;
|
||||
m_expandedAdditionalDirectives = EditorVariablesManager.ExpandedAdditionalDirectives.Value;
|
||||
m_expandedCustomTags = EditorVariablesManager.ExpandedCustomTags.Value;
|
||||
m_expandedAdditionalSurfaceOptions = EditorVariablesManager.ExpandedAdditionalSurfaceOptions.Value;
|
||||
m_expandedAdditionalPragmas = EditorVariablesManager.ExpandedAdditionalPragmas.Value;
|
||||
m_expandedDependencies = EditorVariablesManager.ExpandedDependencies.Value;
|
||||
m_expandedBlendModeModule = EditorVariablesManager.ExpandedBlendModeModule.Value;
|
||||
m_expandedDepth = EditorVariablesManager.ExpandedDepth.Value;
|
||||
m_expandedTesselation = EditorVariablesManager.ExpandedTesselation.Value;
|
||||
m_expandedProperties = EditorVariablesManager.ExpandedProperties.Value;
|
||||
m_expandedUsePass = EditorVariablesManager.ExpandedUsePass.Value;
|
||||
}
|
||||
|
||||
public bool LiveMode{ get { return m_liveMode; } set { m_liveMode = value; EditorVariablesManager.LiveMode.Value = value; } }
|
||||
public bool OutlineActiveMode { get { return m_outlineActiveMode; } set { m_outlineActiveMode = value; EditorVariablesManager.OutlineActiveMode.Value = value; } }
|
||||
public bool NodeParametersMaximized { get { return m_nodeParametersMaximized; } set { m_nodeParametersMaximized = value; EditorVariablesManager.NodeParametersMaximized.Value = value; } }
|
||||
public bool NodePaletteMaximized { get { return m_nodePaletteMaximized; } set { m_nodePaletteMaximized = value; EditorVariablesManager.NodePaletteMaximized.Value = value; } }
|
||||
public bool ExpandedRenderingPlatforms { get { return m_expandedRenderingPlatforms; } set { m_expandedRenderingPlatforms = value; EditorVariablesManager.ExpandedRenderingPlatforms.Value = value; } }
|
||||
public bool ExpandedRenderingOptions { get { return m_expandedRenderingOptions; } set { m_expandedRenderingOptions = value; EditorVariablesManager.ExpandedRenderingOptions.Value = value; } }
|
||||
public bool ExpandedGeneralShaderOptions { get { return m_expandedGeneralShaderOptions; } set { m_expandedGeneralShaderOptions = value; EditorVariablesManager.ExpandedGeneralShaderOptions.Value = value; } }
|
||||
public bool ExpandedBlendOptions { get { return m_expandedBlendOptions; } set { m_expandedBlendOptions = value; EditorVariablesManager.ExpandedBlendOptions.Value = value; } }
|
||||
public bool ExpandedStencilOptions { get { return m_expandedStencilOptions; } set { m_expandedStencilOptions = value; EditorVariablesManager.ExpandedStencilOptions.Value = value; } }
|
||||
public bool ExpandedVertexOptions { get { return m_expandedVertexOptions; } set { m_expandedVertexOptions = value; EditorVariablesManager.ExpandedVertexOptions.Value = value; } }
|
||||
public bool ExpandedFunctionInputs { get { return m_expandedFunctionInputs; } set { m_expandedFunctionInputs = value; EditorVariablesManager.ExpandedFunctionInputs.Value = value; } }
|
||||
public bool ExpandedFunctionSwitches { get { return m_expandedFunctionSwitches; } set { m_expandedFunctionSwitches = value; EditorVariablesManager.ExpandedFunctionSwitches.Value = value; } }
|
||||
public bool ExpandedFunctionOutputs { get { return m_expandedFunctionOutputs; } set { m_expandedFunctionOutputs = value; EditorVariablesManager.ExpandedFunctionOutputs.Value = value; } }
|
||||
public bool ExpandedAdditionalIncludes { get { return m_expandedAdditionalIncludes; } set { m_expandedAdditionalIncludes = value; EditorVariablesManager.ExpandedAdditionalIncludes.Value = value; } }
|
||||
public bool ExpandedAdditionalDefines { get { return m_expandedAdditionalDefines; } set { m_expandedAdditionalDefines = value; EditorVariablesManager.ExpandedAdditionalDefines.Value = value; } }
|
||||
public bool ExpandedAdditionalDirectives { get { return m_expandedAdditionalDirectives; } set { m_expandedAdditionalDirectives = value; EditorVariablesManager.ExpandedAdditionalDirectives.Value = value; } }
|
||||
public bool ExpandedCustomTags { get { return m_expandedCustomTags; } set { m_expandedCustomTags = value; EditorVariablesManager.ExpandedCustomTags.Value = value; } }
|
||||
public bool ExpandedAdditionalSurfaceOptions { get { return m_expandedAdditionalSurfaceOptions; } set { m_expandedAdditionalSurfaceOptions = value; EditorVariablesManager.ExpandedAdditionalSurfaceOptions.Value = value; } }
|
||||
public bool ExpandedAdditionalPragmas { get { return m_expandedAdditionalPragmas; } set { m_expandedAdditionalPragmas = value; EditorVariablesManager.ExpandedAdditionalPragmas.Value = value; } }
|
||||
public bool ExpandedDependencies { get { return m_expandedDependencies; } set { m_expandedDependencies = value; EditorVariablesManager.ExpandedDependencies.Value = value; } }
|
||||
public bool ExpandedBlendModeModule { get { return m_expandedBlendModeModule; } set { m_expandedBlendModeModule = value; EditorVariablesManager.ExpandedBlendModeModule.Value = value; } }
|
||||
public bool ExpandedDepth { get { return m_expandedDepth; } set { m_expandedDepth = value; EditorVariablesManager.ExpandedDepth.Value = value; } }
|
||||
public bool ExpandedTesselation { get { return m_expandedTesselation; } set { m_expandedTesselation = value; EditorVariablesManager.ExpandedTesselation.Value = value; } }
|
||||
public bool ExpandedProperties { get { return m_expandedProperties; } set { m_expandedProperties = value; EditorVariablesManager.ExpandedProperties.Value = value; } }
|
||||
public bool ExpandedUsePass { get { return m_expandedUsePass; } set { m_expandedUsePass = value; EditorVariablesManager.ExpandedUsePass.Value = value; } }
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/EditorVariablesManager.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/EditorVariablesManager.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d402e3c7d578ee046a5d0826b9a41c27
|
||||
timeCreated: 1487245046
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
2020
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GeneratorUtils.cs
vendored
Normal file
2020
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GeneratorUtils.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GeneratorUtils.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GeneratorUtils.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ab31d77d200c7a4ca43f4bf159de6b3
|
||||
timeCreated: 1490798546
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
117
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GenericMessage.cs
vendored
Normal file
117
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GenericMessage.cs
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public enum MessageSeverity
|
||||
{
|
||||
Normal,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
public class GenericMessageData
|
||||
{
|
||||
public string message;
|
||||
public MessageSeverity severity;
|
||||
public bool console;
|
||||
public GenericMessageData( string msg, MessageSeverity svrty, bool csle )
|
||||
{
|
||||
message = msg;
|
||||
severity = svrty;
|
||||
console = csle;
|
||||
}
|
||||
}
|
||||
|
||||
class GenericMessageUI
|
||||
{
|
||||
public delegate void OnMessageDisplay( string message, MessageSeverity severity, bool console );
|
||||
public event OnMessageDisplay OnMessageDisplayEvent;
|
||||
|
||||
private const double MESSAGE_TIME = 2;
|
||||
private double m_currentMessageStartTime;
|
||||
private Queue<GenericMessageData> m_messageQueue;
|
||||
private bool m_displayingMessage;
|
||||
|
||||
public GenericMessageUI()
|
||||
{
|
||||
m_messageQueue = new Queue<GenericMessageData>();
|
||||
m_displayingMessage = false;
|
||||
m_currentMessageStartTime = EditorApplication.timeSinceStartup;
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
m_messageQueue.Clear();
|
||||
OnMessageDisplayEvent = null;
|
||||
}
|
||||
|
||||
public void AddToQueue( string message, MessageSeverity severity, bool console )
|
||||
{
|
||||
m_messageQueue.Enqueue( new GenericMessageData( message, severity, console ) );
|
||||
}
|
||||
|
||||
public void Log( string message )
|
||||
{
|
||||
m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Normal, true ) );
|
||||
Debug.Log( message );
|
||||
}
|
||||
|
||||
public void LogError( string message )
|
||||
{
|
||||
m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Error, true ) );
|
||||
Debug.LogError( message );
|
||||
}
|
||||
|
||||
public void LogWarning( string message )
|
||||
{
|
||||
m_messageQueue.Enqueue( new GenericMessageData( message, MessageSeverity.Warning, true ) );
|
||||
Debug.LogWarning( message );
|
||||
}
|
||||
|
||||
public void CheckForMessages()
|
||||
{
|
||||
if ( m_displayingMessage )
|
||||
{
|
||||
double timeLeft = EditorApplication.timeSinceStartup - m_currentMessageStartTime;
|
||||
if ( timeLeft > MESSAGE_TIME )
|
||||
{
|
||||
m_displayingMessage = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_displayingMessage )
|
||||
{
|
||||
if ( m_messageQueue.Count > 0 )
|
||||
{
|
||||
m_displayingMessage = true;
|
||||
GenericMessageData data = m_messageQueue.Dequeue();
|
||||
m_currentMessageStartTime = EditorApplication.timeSinceStartup;
|
||||
|
||||
if ( OnMessageDisplayEvent != null )
|
||||
OnMessageDisplayEvent( data.message, data.severity, data.console );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanUpMessageStack()
|
||||
{
|
||||
m_displayingMessage = false;
|
||||
m_messageQueue.Clear();
|
||||
}
|
||||
|
||||
public void StartMessageCounter()
|
||||
{
|
||||
m_displayingMessage = true;
|
||||
m_currentMessageStartTime = EditorApplication.timeSinceStartup;
|
||||
}
|
||||
|
||||
public bool DisplayingMessage
|
||||
{
|
||||
get { return ( m_displayingMessage || m_messageQueue.Count > 0 ); }
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GenericMessage.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/GenericMessage.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87cfef50a69ad24479fb8b472dac6d6e
|
||||
timeCreated: 1481126957
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1030
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/IOUtils.cs
vendored
Normal file
1030
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/IOUtils.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/IOUtils.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/IOUtils.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d39b4c96fb4d7f847b3a21c377d4188d
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
381
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlineProperty.cs
vendored
Normal file
381
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlineProperty.cs
vendored
Normal file
@@ -0,0 +1,381 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[System.Serializable]
|
||||
public class InlineProperty
|
||||
{
|
||||
[SerializeField]
|
||||
private float m_value = 0;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_active = false;
|
||||
|
||||
[SerializeField]
|
||||
private int m_nodeId = -1;
|
||||
|
||||
[SerializeField]
|
||||
private string m_nodePropertyName = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_inlineButtonVisible = true;
|
||||
|
||||
public InlineProperty()
|
||||
{
|
||||
InlinePropertyTable.Register( this );
|
||||
}
|
||||
|
||||
public InlineProperty( float val ) : base()
|
||||
{
|
||||
m_value = val;
|
||||
}
|
||||
|
||||
public InlineProperty( int val ) : base()
|
||||
{
|
||||
m_value = val;
|
||||
}
|
||||
|
||||
public void ResetProperty()
|
||||
{
|
||||
m_nodeId = -1;
|
||||
m_active = false;
|
||||
}
|
||||
|
||||
public void CopyFrom( InlineProperty other )
|
||||
{
|
||||
m_value = other.m_value;
|
||||
m_active = other.m_active;
|
||||
m_nodeId = other.m_nodeId;
|
||||
}
|
||||
|
||||
public void SetInlineByName( string propertyName )
|
||||
{
|
||||
m_nodeId = UIUtils.GetFloatIntNodeIdByName( propertyName );
|
||||
m_nodePropertyName = propertyName;
|
||||
m_active = !string.IsNullOrEmpty( propertyName );
|
||||
}
|
||||
|
||||
public void CheckInlineButton()
|
||||
{
|
||||
if( m_inlineButtonVisible )
|
||||
{
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON , UIUtils.FloatIntPickerONOFF , GUILayout.Width( 15 ) , GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
}
|
||||
}
|
||||
|
||||
public void IntField( ref UndoParentNode owner , string content )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutIntField( content , (int)m_value );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
public void IntSlider( ref UndoParentNode owner , GUIContent content , int min , int max )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutIntSlider( content , (int)m_value , min , max );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
public void IntSlider( ref UndoParentNode owner , string content , int min , int max )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutIntSlider( content , (int)m_value , min , max );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
public void EnumTypePopup( ref UndoParentNode owner , string content , string[] displayOptions )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutPopup( content , (int)m_value , displayOptions );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
public void FloatField( ref UndoParentNode owner , string content )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutFloatField( content , m_value );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
public void SliderField( ref UndoParentNode owner , string content , float min , float max )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutSlider( content , m_value , min , max );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
public void RangedFloatField( ref UndoParentNode owner , string content , float min , float max )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutRangedFloatField( content , m_value , min , max );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CustomDrawer( ref UndoParentNode owner , DrawPropertySection Drawer , string content )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
Drawer( owner );
|
||||
CheckInlineButton();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner , content );
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void DrawPropertySection( UndoParentNode owner );
|
||||
|
||||
private void DrawPicker( ref UndoParentNode owner , GUIContent content )
|
||||
{
|
||||
DrawPicker( ref owner , content.text );
|
||||
}
|
||||
|
||||
private void DrawPicker( ref UndoParentNode owner , string content )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
string[] intArraysNames = owner.ContainerGraph.ParentWindow.CurrentGraph.FloatIntNodes.NodesArr;
|
||||
int[] intIds = owner.ContainerGraph.ParentWindow.CurrentGraph.FloatIntNodes.NodeIds;
|
||||
int prevNodeId = m_nodeId;
|
||||
m_nodeId = owner.EditorGUILayoutIntPopup( content , m_nodeId , intArraysNames , intIds );
|
||||
if ( m_nodeId != prevNodeId )
|
||||
{
|
||||
m_nodePropertyName = UIUtils.GetFloatIntNameByNodeId( m_nodeId, m_nodePropertyName );
|
||||
}
|
||||
if ( GUILayout.Button( UIUtils.FloatIntIconOFF , UIUtils.FloatIntPickerONOFF , GUILayout.Width( 15 ) , GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public string GetValueOrProperty( bool parentesis = true )
|
||||
{
|
||||
if( m_active )
|
||||
{
|
||||
PropertyNode node = GetPropertyNode();
|
||||
if( node != null )
|
||||
{
|
||||
return parentesis ? "[" + node.PropertyName + "]" : node.PropertyName;
|
||||
}
|
||||
else if ( !string.IsNullOrEmpty( m_nodePropertyName ) )
|
||||
{
|
||||
return parentesis ? "[" + m_nodePropertyName + "]" : m_nodePropertyName;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_active = false;
|
||||
m_nodeId = -1;
|
||||
return m_value.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetValueOrProperty( string defaultValue , bool parentesis = true )
|
||||
{
|
||||
if( m_active )
|
||||
{
|
||||
PropertyNode node = GetPropertyNode();
|
||||
if( node != null )
|
||||
{
|
||||
return parentesis ? "[" + node.PropertyName + "]" : node.PropertyName;
|
||||
}
|
||||
else if ( !string.IsNullOrEmpty( m_nodePropertyName ) )
|
||||
{
|
||||
return parentesis ? "[" + m_nodePropertyName + "]" : m_nodePropertyName;
|
||||
}
|
||||
else if( !string.IsNullOrEmpty( defaultValue ) )
|
||||
{
|
||||
m_active = false;
|
||||
m_nodeId = -1;
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_active = false;
|
||||
m_nodeId = -1;
|
||||
return m_value.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void TryResolveDependency()
|
||||
{
|
||||
if ( m_active && !string.IsNullOrEmpty( m_nodePropertyName ) )
|
||||
{
|
||||
m_nodeId = UIUtils.GetFloatIntNodeIdByName( m_nodePropertyName );
|
||||
}
|
||||
}
|
||||
|
||||
private void TryReadUniqueId( string param )
|
||||
{
|
||||
if ( Preferences.User.ForceTemplateInlineProperties && !string.IsNullOrEmpty( m_nodePropertyName ) )
|
||||
{
|
||||
// @diogo: exception path => ignore param and revert to template default
|
||||
m_nodeId = UIUtils.GetFloatIntNodeIdByName( m_nodePropertyName );
|
||||
|
||||
// @diogo: by defaulting to template we are signaling the inline property is active
|
||||
m_active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// @diogo: normal path
|
||||
if ( int.TryParse( param, out int nodeId ) )
|
||||
{
|
||||
m_nodeId = Convert.ToInt32( param );
|
||||
m_nodePropertyName = UIUtils.GetFloatIntNameByNodeId( m_nodeId, m_nodePropertyName );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nodePropertyName = param;
|
||||
m_nodeId = UIUtils.GetFloatIntNodeIdByName( m_nodePropertyName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadFromString( ref uint index , ref string[] nodeParams , bool isInt = true )
|
||||
{
|
||||
m_value = isInt ? Convert.ToInt32( nodeParams[ index++ ] ) : Convert.ToSingle( nodeParams[ index++ ] );
|
||||
m_active = Convert.ToBoolean( nodeParams[ index++ ] );
|
||||
TryReadUniqueId( nodeParams[ index++ ] );
|
||||
}
|
||||
|
||||
public void ReadFromSingle( string singleLine )
|
||||
{
|
||||
string[] data = singleLine.Split( IOUtils.VECTOR_SEPARATOR );
|
||||
m_value = Convert.ToSingle( data[ 0 ] , System.Globalization.CultureInfo.InvariantCulture );
|
||||
m_active = Convert.ToBoolean( data[ 1 ] );
|
||||
TryReadUniqueId( data[ 2 ] );
|
||||
}
|
||||
|
||||
public void WriteToString( ref string nodeInfo )
|
||||
{
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo , m_value );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo , m_active );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_nodePropertyName );
|
||||
}
|
||||
|
||||
public string WriteToSingle()
|
||||
{
|
||||
return m_value.ToString( System.Globalization.CultureInfo.InvariantCulture ) + IOUtils.VECTOR_SEPARATOR + m_active + IOUtils.VECTOR_SEPARATOR + m_nodePropertyName;
|
||||
}
|
||||
|
||||
public void SetInlineNodeValue()
|
||||
{
|
||||
if( IsValid )
|
||||
{
|
||||
RangedFloatNode fnode = UIUtils.GetNode( m_nodeId ) as RangedFloatNode;
|
||||
if( fnode != null )
|
||||
{
|
||||
fnode.Value = m_value;
|
||||
fnode.SetMaterialValueFromInline( m_value );
|
||||
}
|
||||
else
|
||||
{
|
||||
IntNode inode = UIUtils.GetNode( m_nodeId ) as IntNode;
|
||||
inode.Value = (int)m_value;
|
||||
inode.SetMaterialValueFromInline( (int)m_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValid { get { return m_active; } }
|
||||
|
||||
public PropertyNode GetPropertyNode()
|
||||
{
|
||||
if( m_nodeId >= 0 )
|
||||
return UIUtils.GetNode( m_nodeId ) as PropertyNode;
|
||||
|
||||
if( m_nodeId < -1 )
|
||||
{
|
||||
if( !string.IsNullOrEmpty( m_nodePropertyName ) )
|
||||
return UIUtils.GetInternalTemplateNode( m_nodePropertyName );
|
||||
|
||||
|
||||
return UIUtils.GetInternalTemplateNode( m_nodeId );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void HideInlineButton()
|
||||
{
|
||||
m_inlineButtonVisible = false;
|
||||
}
|
||||
|
||||
public int IntValue { get { return (int)m_value; } set { m_value = value; } }
|
||||
public float FloatValue { get { return m_value; } set { m_value = value; } }
|
||||
public bool Active { get { return m_active; } set { m_active = value; } }
|
||||
public int NodeId { get { return m_nodeId; } set { m_nodeId = value; } }
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlineProperty.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlineProperty.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4f4421f529503243bfef5076ae82512
|
||||
timeCreated: 1519298230
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlinePropertyTable.cs
vendored
Normal file
43
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlinePropertyTable.cs
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class InlinePropertyTable
|
||||
{
|
||||
// @diogo: Used to keep track of inline properties during Graph loading process, in order to resolve
|
||||
// dependencies AFTER the meta data is parsed, not during the process, making it order agnostic.
|
||||
|
||||
static List<InlineProperty> m_pool = new List<InlineProperty>( 32 );
|
||||
static List<InlineProperty> m_trackingTable = null;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
m_trackingTable = m_pool; // keep memory allocated, despite empty list
|
||||
}
|
||||
|
||||
public static void Register( InlineProperty prop )
|
||||
{
|
||||
if ( m_trackingTable != null )
|
||||
{
|
||||
m_trackingTable.Add( prop );
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResolveDependencies()
|
||||
{
|
||||
if ( m_trackingTable != null )
|
||||
{
|
||||
foreach ( var prop in m_trackingTable )
|
||||
{
|
||||
prop.TryResolveDependency();
|
||||
}
|
||||
|
||||
m_trackingTable.Clear();
|
||||
m_trackingTable = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlinePropertyTable.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InlinePropertyTable.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e4654284143e4149873b379a6ea5adc
|
||||
timeCreated: 1519298230
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
168
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InvalidDataChecker.cs
vendored
Normal file
168
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InvalidDataChecker.cs
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class InvalidDataChecker
|
||||
{
|
||||
private static string[] m_invalidData = { "674ea7bed6b1cd94b8057074298096db", //"/Samples",
|
||||
"2738539936eacef409be91f148b2a4a0", //"/Resources",
|
||||
"c880e50f07f2be9499d414ac6f9f3a7a", //"/Templates",
|
||||
"563f992b9989cf547ac59bf748442c17"};//"/Textures"};
|
||||
//private static string m_ASEFolderPath;
|
||||
private static string m_invalidDataCollected = string.Empty;
|
||||
static InvalidDataChecker()
|
||||
{
|
||||
bool foundInvalidData = false;
|
||||
//m_ASEFolderPath = AssetDatabase.GUIDToAssetPath( IOUtils.ASEFolderGUID );
|
||||
int count = 0;
|
||||
for ( int i = 0; i < m_invalidData.Length; i++ )
|
||||
{
|
||||
//m_invalidData[ i ] = m_ASEFolderPath + m_invalidData[ i ];
|
||||
m_invalidData[ i ] = AssetDatabase.GUIDToAssetPath( m_invalidData[ i ] );
|
||||
if ( AssetDatabase.IsValidFolder( m_invalidData[ i ] ) )
|
||||
{
|
||||
foundInvalidData = true;
|
||||
m_invalidDataCollected += m_invalidData[ i ]+"\n";
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
if ( count < 5 )
|
||||
{
|
||||
for ( ; count < 5; count++ )
|
||||
{
|
||||
m_invalidDataCollected += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ( foundInvalidData )
|
||||
{
|
||||
InvalidDataPopUp window = ( InvalidDataPopUp ) EditorWindow.GetWindow( typeof( InvalidDataPopUp ), true, "Found Invalid Data" );
|
||||
window.minSize = new Vector2( 502, 265 );
|
||||
window.maxSize = new Vector2( 502, 265 );
|
||||
window.Show();
|
||||
}
|
||||
|
||||
EditorApplication.update += Update;
|
||||
}
|
||||
|
||||
static void Update()
|
||||
{
|
||||
EditorApplication.update -= Update;
|
||||
|
||||
if( !EditorApplication.isPlayingOrWillChangePlaymode && !Application.isBatchMode )
|
||||
{
|
||||
Preferences.ShowOption show = Preferences.ShowOption.Never;
|
||||
if( !EditorPrefs.HasKey( Preferences.User.Keys.StartUp ) )
|
||||
{
|
||||
show = Preferences.ShowOption.Always;
|
||||
EditorPrefs.SetInt( Preferences.User.Keys.StartUp, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( Time.realtimeSinceStartup < 10 )
|
||||
{
|
||||
show = (Preferences.ShowOption) EditorPrefs.GetInt( Preferences.User.Keys.StartUp, 0 );
|
||||
// check version here
|
||||
if( show == Preferences.ShowOption.OnNewVersion )
|
||||
{
|
||||
ASEStartScreen.StartBackgroundTask( StartRequest( ASEStartScreen.ChangelogURL, () =>
|
||||
{
|
||||
var changeLog = ChangeLogInfo.CreateFromJSON( www.downloadHandler.text );
|
||||
if( changeLog != null )
|
||||
{
|
||||
if( changeLog.Version > VersionInfo.FullNumber )
|
||||
ASEStartScreen.Init();
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( show == Preferences.ShowOption.Always )
|
||||
ASEStartScreen.Init();
|
||||
}
|
||||
}
|
||||
|
||||
static UnityWebRequest www;
|
||||
|
||||
static IEnumerator StartRequest( string url, Action success = null )
|
||||
{
|
||||
using( www = UnityWebRequest.Get( url ) )
|
||||
{
|
||||
yield return www.SendWebRequest();
|
||||
|
||||
while( www.isDone == false )
|
||||
yield return null;
|
||||
|
||||
if( success != null )
|
||||
success();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CleanInvalidData()
|
||||
{
|
||||
for ( int i = 0; i < m_invalidData.Length; i++ )
|
||||
{
|
||||
if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] ) )
|
||||
{
|
||||
Debug.Log( "Removed invalid " + m_invalidData[ i ] );
|
||||
if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] + ".meta" ) )
|
||||
{
|
||||
Debug.Log( "Removed invalid " + m_invalidData[ i ] + ".meta" );
|
||||
}
|
||||
}
|
||||
}
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public static string InvalidDataCollected { get { return m_invalidDataCollected; } }
|
||||
}
|
||||
|
||||
public class InvalidDataPopUp : EditorWindow
|
||||
{
|
||||
private readonly GUIContent m_buttonContent = new GUIContent( "Remove Invalid Data" );
|
||||
private Vector2 m_scrollPosition = Vector2.zero;
|
||||
public void OnGUI()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUIStyle labelStyle = new GUIStyle( EditorStyles.label );
|
||||
labelStyle.alignment = TextAnchor.MiddleCenter;
|
||||
labelStyle.wordWrap = true;
|
||||
GUILayout.Label( "\nAmplify Shader Editor " + VersionInfo.StaticToString(), labelStyle, GUILayout.ExpandWidth( true ) );
|
||||
GUILayout.Space( 5 );
|
||||
GUILayout.Label( "Invalid/Legacy Data was found on your previous ASE folder which needs to be removed in order for it to work correctly." , labelStyle, GUILayout.ExpandWidth( true ) );
|
||||
GUILayout.Space( 5 );
|
||||
GUILayout.Label( "Below are the detected files/folders which require to be removed.", labelStyle, GUILayout.ExpandWidth( true ) );
|
||||
GUILayout.Space( 5 );
|
||||
|
||||
m_scrollPosition = GUILayout.BeginScrollView( m_scrollPosition ,GUILayout.Height(85));
|
||||
|
||||
GUILayout.TextArea( InvalidDataChecker.InvalidDataCollected );
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
|
||||
GUILayout.Label( "VERY IMPORTANT: If you have assets of yours inside these folders you need to move them to another location before hitting the button below or they will be PERMANENTLY DELETED", labelStyle, GUILayout.ExpandWidth( true ) );
|
||||
GUILayout.Space( 5 );
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.Space( 151 );
|
||||
if ( GUILayout.Button( m_buttonContent, GUILayout.Width( 200 ) ) )
|
||||
{
|
||||
InvalidDataChecker.CleanInvalidData();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InvalidDataChecker.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/InvalidDataChecker.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c71b815458d61e24184a60dbce19573d
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
334
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeExporterUtils.cs
vendored
Normal file
334
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeExporterUtils.cs
vendored
Normal file
@@ -0,0 +1,334 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public enum DebugScreenShotNodeState
|
||||
{
|
||||
CreateNode,
|
||||
FocusOnNode,
|
||||
TakeScreenshot,
|
||||
WaitFrame,
|
||||
DeleteNode
|
||||
};
|
||||
|
||||
public enum DebugUndoNodeState
|
||||
{
|
||||
CreateNode,
|
||||
FocusOnNode,
|
||||
WaitFrameCreate,
|
||||
DeleteNode,
|
||||
WaitFrameDelete,
|
||||
UndoNode,
|
||||
WaitFrameUndo,
|
||||
PrepareForNext
|
||||
};
|
||||
|
||||
|
||||
public class NodeExporterUtils
|
||||
{
|
||||
//Auto-Screenshot nodes
|
||||
private RenderTexture m_screenshotRT;
|
||||
private Texture2D m_screenshotTex2D;
|
||||
private List<ContextMenuItem> m_screenshotList = new List<ContextMenuItem>();
|
||||
private DebugScreenShotNodeState m_screenShotState;
|
||||
private bool m_takingShots = false;
|
||||
|
||||
private DebugUndoNodeState m_undoState;
|
||||
private bool m_testingUndo = false;
|
||||
|
||||
|
||||
private AmplifyShaderEditorWindow m_window;
|
||||
private ParentNode m_node;
|
||||
|
||||
|
||||
private string m_pathname;
|
||||
|
||||
public NodeExporterUtils( AmplifyShaderEditorWindow window )
|
||||
{
|
||||
m_window = window;
|
||||
UndoUtils.RegisterUndoRedoCallback( OnUndoRedoPerformed );
|
||||
}
|
||||
|
||||
public void OnUndoRedoPerformed()
|
||||
{
|
||||
if( m_testingUndo && m_undoState == DebugUndoNodeState.WaitFrameUndo )
|
||||
{
|
||||
m_undoState = DebugUndoNodeState.PrepareForNext;
|
||||
}
|
||||
}
|
||||
|
||||
public void CalculateShaderInstructions( Shader shader )
|
||||
{
|
||||
//Type shaderutilType = Type.GetType( "UnityEditor.ShaderUtil, UnityEditor" );
|
||||
//shaderutilType.InvokeMember( "OpenCompiledShader", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { shader, mode, customPlatformsMask, includeAllVariants } );
|
||||
}
|
||||
|
||||
public void ActivateAutoScreenShot( string pathname, int from, int to )
|
||||
{
|
||||
|
||||
m_pathname = pathname;
|
||||
if( !System.IO.Directory.Exists( m_pathname ) )
|
||||
{
|
||||
System.IO.Directory.CreateDirectory( m_pathname );
|
||||
}
|
||||
|
||||
m_screenshotRT = new RenderTexture( (int)m_window.position.width, (int)m_window.position.height, 0 );
|
||||
m_screenshotTex2D = new Texture2D( (int)m_window.position.width, (int)m_window.position.height, TextureFormat.RGB24, false );
|
||||
|
||||
RenderTexture.active = m_screenshotRT;
|
||||
m_window.CurrentPaletteWindow.FillList( ref m_screenshotList, true );
|
||||
m_window.CurrentGraph.ClearGraph();
|
||||
if( m_window.IsShaderFunctionWindow )
|
||||
{
|
||||
m_window.CurrentGraph.CurrentOutputNode.Vec2Position = new Vector2( 1500, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_window.CurrentGraph.CurrentMasterNode.Vec2Position = new Vector2( 1500, 0 );
|
||||
}
|
||||
m_window.ResetCameraSettings();
|
||||
|
||||
m_takingShots = true;
|
||||
m_screenShotState = DebugScreenShotNodeState.CreateNode;
|
||||
|
||||
}
|
||||
|
||||
public void ActivateNodesURL( int from , int to )
|
||||
{
|
||||
m_window.CurrentPaletteWindow.FillList( ref m_screenshotList, true );
|
||||
|
||||
if( to < 0 || to > m_screenshotList.Count )
|
||||
to = m_screenshotList.Count;
|
||||
|
||||
if( from >= to )
|
||||
return;
|
||||
|
||||
for( int i = from; i < to; i++ )
|
||||
{
|
||||
if( m_screenshotList[ i ].NodeType != typeof( FunctionNode ) )
|
||||
{
|
||||
Application.OpenURL( m_screenshotList[ i ].NodeAttributes.NodeUrl );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ActivateAutoUndo()
|
||||
{
|
||||
m_window.CurrentPaletteWindow.FillList( ref m_screenshotList, true );
|
||||
m_window.CurrentGraph.ClearGraph();
|
||||
m_window.CurrentGraph.CurrentMasterNode.Vec2Position = new Vector2( 1500, 0 );
|
||||
m_window.ResetCameraSettings();
|
||||
|
||||
m_testingUndo = true;
|
||||
m_undoState = DebugUndoNodeState.CreateNode;
|
||||
}
|
||||
|
||||
private Type[] GetTypesInNamespace( Assembly assembly , string nameSpace )
|
||||
{
|
||||
return assembly.GetTypes().Where( t => String.Equals( t.Namespace , nameSpace , StringComparison.Ordinal ) ).ToArray();
|
||||
}
|
||||
|
||||
public void GenerateNodesCSV( string path )
|
||||
{
|
||||
path += "AvailableNodesCSV.txt";
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.AppendLine( "Nodes" );
|
||||
result.AppendLine( "Name,Updated" );
|
||||
try
|
||||
{
|
||||
//IEnumerable<System.Type> availableTypes = AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany( type => type.GetTypes() );
|
||||
var mainAssembly = Assembly.GetExecutingAssembly();
|
||||
Type[] availableTypes = GetTypesInNamespace( mainAssembly , "AmplifyShaderEditor" );
|
||||
foreach( System.Type type in availableTypes )
|
||||
{
|
||||
foreach( NodeAttributes attribute in Attribute.GetCustomAttributes( type ).OfType<NodeAttributes>() )
|
||||
{
|
||||
if( attribute.Available && !attribute.Deprecated )
|
||||
{
|
||||
result.AppendLine( attribute.Name + ", false" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( ReflectionTypeLoadException exception )
|
||||
{
|
||||
Debug.LogException( exception );
|
||||
}
|
||||
|
||||
result.AppendLine();
|
||||
result.AppendLine( "Shader Functions" );
|
||||
result.AppendLine( "Name,Updated" );
|
||||
string[] guids = AssetDatabase.FindAssets( "t:AmplifyShaderFunction" );
|
||||
for( int i = 0 ; i < guids.Length ; i++ )
|
||||
{
|
||||
AmplifyShaderFunction sf = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( AssetDatabase.GUIDToAssetPath( guids[ i ] ) );
|
||||
result.AppendLine( sf.FunctionName + ",false" );
|
||||
}
|
||||
|
||||
IOUtils.SaveTextfileToDisk( result.ToString() , path , false );
|
||||
Debug.Log( "Available nodes CSV saved to: " + path );
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if( m_testingUndo )
|
||||
{
|
||||
if( Event.current.type == EventType.Repaint )
|
||||
{
|
||||
m_window.Focus();
|
||||
switch( m_undoState )
|
||||
{
|
||||
case DebugUndoNodeState.CreateNode:
|
||||
{
|
||||
m_window.CurrentGraph.DeSelectAll();
|
||||
m_node = m_window.CreateNode( m_screenshotList[ 0 ].NodeType, Vector2.zero, null, true );
|
||||
m_node.RefreshExternalReferences();
|
||||
m_undoState = DebugUndoNodeState.FocusOnNode;
|
||||
Debug.Log( "Created " + m_node.Attributes.Name );
|
||||
}
|
||||
break;
|
||||
case DebugUndoNodeState.FocusOnNode:
|
||||
{
|
||||
m_window.FocusOnPoint( m_node.TruePosition.center, 1, false );
|
||||
m_undoState = DebugUndoNodeState.WaitFrameCreate;
|
||||
Debug.Log( "Focused " + m_node.Attributes.Name );
|
||||
}
|
||||
break;
|
||||
case DebugUndoNodeState.WaitFrameCreate:
|
||||
{
|
||||
m_undoState = DebugUndoNodeState.DeleteNode;
|
||||
Debug.Log( "Waiting on Create" );
|
||||
}
|
||||
break;
|
||||
case DebugUndoNodeState.DeleteNode:
|
||||
{
|
||||
Debug.Log( "Deleting " + m_node.Attributes.Name );
|
||||
m_window.DeleteSelectedNodeWithRepaint();
|
||||
m_undoState = DebugUndoNodeState.WaitFrameDelete;
|
||||
}
|
||||
break;
|
||||
case DebugUndoNodeState.WaitFrameDelete:
|
||||
{
|
||||
m_undoState = DebugUndoNodeState.UndoNode;
|
||||
Debug.Log( "Waiting on Delete" );
|
||||
}
|
||||
break;
|
||||
case DebugUndoNodeState.UndoNode:
|
||||
{
|
||||
Debug.Log( "Performing Undo" );
|
||||
m_undoState = DebugUndoNodeState.WaitFrameUndo;
|
||||
UndoUtils.PerformUndo();
|
||||
}
|
||||
break;
|
||||
case DebugUndoNodeState.WaitFrameUndo: { } break;
|
||||
case DebugUndoNodeState.PrepareForNext:
|
||||
{
|
||||
m_screenshotList.RemoveAt( 0 );
|
||||
Debug.Log( "Undo Performed. Nodes Left " + m_screenshotList.Count );
|
||||
m_testingUndo = m_screenshotList.Count > 0;
|
||||
if( m_testingUndo )
|
||||
{
|
||||
m_undoState = DebugUndoNodeState.CreateNode;
|
||||
Debug.Log( "Going to next node" );
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log( "Finished Undo Test" );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( m_takingShots )
|
||||
{
|
||||
m_window.Focus();
|
||||
switch( m_screenShotState )
|
||||
{
|
||||
case DebugScreenShotNodeState.CreateNode:
|
||||
{
|
||||
m_node = m_window.CreateNode( m_screenshotList[ 0 ].NodeType, Vector2.zero, null, false );
|
||||
m_node.RefreshExternalReferences();
|
||||
m_screenShotState = DebugScreenShotNodeState.FocusOnNode;
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case DebugScreenShotNodeState.FocusOnNode:
|
||||
{
|
||||
//m_window.FocusOnNode( m_node, 1, false );
|
||||
m_window.FocusOnPoint( m_node.TruePosition.center, 1, false );
|
||||
m_screenShotState = DebugScreenShotNodeState.TakeScreenshot;
|
||||
}
|
||||
break;
|
||||
case DebugScreenShotNodeState.TakeScreenshot:
|
||||
{
|
||||
if( m_screenshotRT != null && Event.current.type == EventType.Repaint )
|
||||
{
|
||||
m_screenshotTex2D.ReadPixels( new Rect( 0, 0, m_screenshotRT.width, m_screenshotRT.height ), 0, 0 );
|
||||
m_screenshotTex2D.Apply();
|
||||
|
||||
byte[] bytes = m_screenshotTex2D.EncodeToPNG();
|
||||
string pictureFilename = UIUtils.ReplaceInvalidStrings( m_screenshotList[ 0 ].Name );
|
||||
pictureFilename = UIUtils.RemoveInvalidCharacters( pictureFilename );
|
||||
|
||||
System.IO.File.WriteAllBytes( m_pathname + pictureFilename + ".png", bytes );
|
||||
m_screenShotState = DebugScreenShotNodeState.WaitFrame;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DebugScreenShotNodeState.WaitFrame: { Debug.Log( "Wait Frame" ); m_screenShotState = DebugScreenShotNodeState.DeleteNode; } break;
|
||||
case DebugScreenShotNodeState.DeleteNode:
|
||||
{
|
||||
m_window.DestroyNode( m_node );
|
||||
m_screenshotList.RemoveAt( 0 );
|
||||
m_takingShots = m_screenshotList.Count > 0;
|
||||
Debug.Log( "Destroy Node " + m_screenshotList.Count );
|
||||
|
||||
if( m_takingShots )
|
||||
{
|
||||
m_screenShotState = DebugScreenShotNodeState.CreateNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderTexture.active = null;
|
||||
m_screenshotRT.Release();
|
||||
UnityEngine.Object.DestroyImmediate( m_screenshotRT );
|
||||
m_screenshotRT = null;
|
||||
UnityEngine.Object.DestroyImmediate( m_screenshotTex2D );
|
||||
m_screenshotTex2D = null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
m_window = null;
|
||||
if( m_screenshotRT != null )
|
||||
{
|
||||
m_screenshotRT.Release();
|
||||
UnityEngine.Object.DestroyImmediate( m_screenshotRT );
|
||||
m_screenshotRT = null;
|
||||
}
|
||||
|
||||
if( m_screenshotTex2D != null )
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate( m_screenshotTex2D );
|
||||
m_screenshotTex2D = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeExporterUtils.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeExporterUtils.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9b3f6c515f0e16469de89d9e22263c5
|
||||
timeCreated: 1486374353
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeUpdateCache.cs
vendored
Normal file
25
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeUpdateCache.cs
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class NodeUpdateCache : HashSet<ParentNode>
|
||||
{
|
||||
public bool Touch( ParentNode node )
|
||||
{
|
||||
if ( Contains( node ) )
|
||||
{
|
||||
// @diogo: already touched; cache hit
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// @diogo: not touched yet; cache miss
|
||||
Add( node );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeUpdateCache.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/NodeUpdateCache.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c46fc0ec7fe47c4482962f3756cfc88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
101
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.Project.cs
vendored
Normal file
101
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.Project.cs
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public partial class Preferences
|
||||
{
|
||||
public class Project
|
||||
{
|
||||
public static bool AutoSRP => Values.AutoSRP;
|
||||
public static bool DefineSymbol => Values.DefineSymbol;
|
||||
public static string TemplateExtensions => Values.TemplateExtensions;
|
||||
|
||||
private class Styles
|
||||
{
|
||||
public static readonly GUIContent AutoSRP = new GUIContent( "Auto import SRP shader templates", "By default Amplify Shader Editor checks for your SRP version and automatically imports the correct corresponding shader templates.\nTurn this OFF if you prefer to import them manually." );
|
||||
public static readonly GUIContent DefineSymbol = new GUIContent( "Add Amplify Shader Editor define symbol", "Turning it OFF will disable the automatic insertion of the define symbol and remove it from the list while turning it ON will do the opposite.\nThis is used for compatibility with other plugins, if you are not sure if you need this leave it ON." );
|
||||
public static readonly GUIContent TemplateExtensions = new GUIContent( "Template Extensions", "Supported file extensions for parsing shader templates." );
|
||||
}
|
||||
|
||||
private class Defaults
|
||||
{
|
||||
public const bool AutoSRP = true;
|
||||
public const bool DefineSymbol = true;
|
||||
public const string TemplateExtensions = ".shader;.shader.template";
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private struct Layout
|
||||
{
|
||||
public bool AutoSRP;
|
||||
public bool DefineSymbol;
|
||||
public string TemplateExtensions;
|
||||
}
|
||||
|
||||
private const string RelativePath = "ProjectSettings/AmplifyShaderEditor.asset";
|
||||
private static string FullPath = Path.GetFullPath( RelativePath );
|
||||
private static Layout Values = new Layout();
|
||||
|
||||
public static void ResetSettings()
|
||||
{
|
||||
Values.AutoSRP = Defaults.AutoSRP;
|
||||
Values.DefineSymbol = Defaults.DefineSymbol;
|
||||
Values.TemplateExtensions = Defaults.TemplateExtensions;
|
||||
}
|
||||
|
||||
public static void LoadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
Values = JsonUtility.FromJson<Layout>( File.ReadAllText( FullPath ) );
|
||||
}
|
||||
catch ( System.Exception e )
|
||||
{
|
||||
if ( e.GetType() == typeof( FileNotFoundException ) )
|
||||
{
|
||||
ResetSettings();
|
||||
SaveSettings();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning( "[AmplifyTexture] Failed importing \"" + RelativePath + "\". Reverting to default settings." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveSettings()
|
||||
{
|
||||
if ( DefineSymbol )
|
||||
{
|
||||
IOUtils.SetAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
|
||||
}
|
||||
else
|
||||
{
|
||||
IOUtils.RemoveAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllText( FullPath, JsonUtility.ToJson( Values ) );
|
||||
}
|
||||
catch ( System.Exception )
|
||||
{
|
||||
// TODO: Not critical?
|
||||
}
|
||||
}
|
||||
|
||||
public static void InspectorLayout()
|
||||
{
|
||||
Values.AutoSRP = EditorGUILayout.Toggle( Styles.AutoSRP, Values.AutoSRP );
|
||||
Values.DefineSymbol = EditorGUILayout.Toggle( Styles.DefineSymbol, Values.DefineSymbol );
|
||||
Values.TemplateExtensions = EditorGUILayout.TextField( Styles.TemplateExtensions, Values.TemplateExtensions );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.Project.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.Project.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6ca58aab98bca44384d9845269ada5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
192
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.User.cs
vendored
Normal file
192
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.User.cs
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public partial class Preferences
|
||||
{
|
||||
public enum ShowOption
|
||||
{
|
||||
Always = 0,
|
||||
OnNewVersion = 1,
|
||||
Never = 2
|
||||
}
|
||||
|
||||
public class User
|
||||
{
|
||||
private class Styles
|
||||
{
|
||||
public static readonly GUIContent StartUp = new GUIContent( "Show start screen on Unity launch", "You can set if you want to see the start screen everytime Unity launchs, only just when there's a new version available or never." );
|
||||
public static readonly GUIContent AlwaysSnapToGrid = new GUIContent( "Always Snap to Grid", "Always snap to grid when dragging nodes around, instead of using control." );
|
||||
public static readonly GUIContent EnableUndo = new GUIContent( "Enable Undo (unstable)", "Enables undo for actions within the shader graph canvas. Currently unstable, use with caution." );
|
||||
public static readonly GUIContent ClearLog = new GUIContent( "Clear Log on Update", "Clears the previously generated log each time the Update button is pressed." );
|
||||
public static readonly GUIContent LogShaderCompile = new GUIContent( "Log Shader Compile", "Log message to console when a shader compilation is finished." );
|
||||
public static readonly GUIContent LogBatchCompile = new GUIContent( "Log Batch Compile", "Log message to console when a batch compilation is finished." );
|
||||
public static readonly GUIContent UpdateOnSceneSave = new GUIContent( "Update on Scene save (Ctrl+S)", "ASE is aware of Ctrl+S and will use it to save shader." );
|
||||
public static readonly GUIContent PreviewUpdateFrequency = new GUIContent( "Preview Update Frequency", "Frequency limit, in Hz/FPS, at which we allow previews to refresh." );
|
||||
public static readonly GUIContent PreviewQuality = new GUIContent( "Preview Quality", "Adjusts size and precision of preview textures to save VRAM: Low, Medium, High (default)" );
|
||||
public static readonly GUIContent DisablePreviews = new GUIContent( "Disable Node Previews", "Disable preview on nodes from being updated to boost up performance on large graphs." );
|
||||
public static readonly GUIContent DisableMaterialMode = new GUIContent( "Disable Material Mode", "Disable enter Material Mode graph when double-clicking on material asset." );
|
||||
public static readonly GUIContent ForceTemplateMinShaderModel = new GUIContent( "Force Template Min. Shader Model", "If active, when loading a shader its shader model will be replaced by the one specified in template if what is loaded is below the one set over the template." );
|
||||
public static readonly GUIContent ForceTemplateInlineProperties = new GUIContent( "Force Template Inline Properties", "If active, defaults all inline properties to template values." );
|
||||
}
|
||||
|
||||
private class Defaults
|
||||
{
|
||||
public const ShowOption StartUp = ShowOption.Always;
|
||||
public const bool AlwaysSnapToGrid = true;
|
||||
public const bool EnableUndo = false;
|
||||
public const bool ClearLog = true;
|
||||
public const bool LogShaderCompile = false;
|
||||
public const bool LogBatchCompile = false;
|
||||
public const bool UpdateOnSceneSave = true;
|
||||
public const int PreviewUpdateFrequency = 60;
|
||||
public const int PreviewQuality = 1;
|
||||
public const bool DisablePreviews = false;
|
||||
public const bool DisableMaterialMode = false;
|
||||
public const bool ForceTemplateMinShaderModel = false;
|
||||
public const bool ForceTemplateInlineProperties = false;
|
||||
}
|
||||
|
||||
// @diogo: make this private
|
||||
public class Keys
|
||||
{
|
||||
public static string StartUp = "ASELastSession";
|
||||
public static string AlwaysSnapToGrid = "ASEAlwaysSnapToGrid";
|
||||
public static string EnableUndo = "ASEEnableUndo";
|
||||
public static string ClearLog = "ASEClearLog";
|
||||
public static string LogShaderCompile = "ASELogShaderCompile";
|
||||
public static string LogBatchCompile = "ASELogBatchCompile";
|
||||
public static string UpdateOnSceneSave = "ASEUpdateOnSceneSave";
|
||||
public static string PreviewUpdateFrequency = "ASEPreviewUpdateFrequency";
|
||||
public static string PreviewQuality = "ASEPreviewQuality";
|
||||
public static string DisablePreviews = "ASEActivatePreviews";
|
||||
public static string DisableMaterialMode = "ASEDisableMaterialMode";
|
||||
public static string ForceTemplateMinShaderModel = "ASEForceTemplateMinShaderModel";
|
||||
public static string ForceTemplateInlineProperties = "ASEForceTemplateInlineProperties";
|
||||
}
|
||||
|
||||
public static ShowOption StartUp = Defaults.StartUp;
|
||||
public static bool AlwaysSnapToGrid = Defaults.AlwaysSnapToGrid;
|
||||
public static bool EnableUndo = Defaults.EnableUndo;
|
||||
public static bool ClearLog = Defaults.ClearLog;
|
||||
public static bool LogShaderCompile = Defaults.LogShaderCompile;
|
||||
public static bool LogBatchCompile = Defaults.LogBatchCompile;
|
||||
public static bool UpdateOnSceneSave = Defaults.UpdateOnSceneSave;
|
||||
public static int PreviewUpdateFrequency = Defaults.PreviewUpdateFrequency;
|
||||
public static int PreviewQuality = Defaults.PreviewQuality;
|
||||
public static bool DisablePreviews = Defaults.DisablePreviews;
|
||||
public static bool DisableMaterialMode = Defaults.DisableMaterialMode;
|
||||
public static bool ForceTemplateMinShaderModel = Defaults.ForceTemplateMinShaderModel;
|
||||
public static bool ForceTemplateInlineProperties = Defaults.ForceTemplateInlineProperties;
|
||||
|
||||
public static void ResetSettings()
|
||||
{
|
||||
EditorPrefs.DeleteKey( Keys.StartUp );
|
||||
EditorPrefs.DeleteKey( Keys.AlwaysSnapToGrid );
|
||||
EditorPrefs.DeleteKey( Keys.EnableUndo );
|
||||
EditorPrefs.DeleteKey( Keys.ClearLog );
|
||||
EditorPrefs.DeleteKey( Keys.LogShaderCompile );
|
||||
EditorPrefs.DeleteKey( Keys.LogBatchCompile );
|
||||
EditorPrefs.DeleteKey( Keys.UpdateOnSceneSave );
|
||||
EditorPrefs.DeleteKey( Keys.PreviewUpdateFrequency );
|
||||
EditorPrefs.DeleteKey( Keys.PreviewQuality );
|
||||
EditorPrefs.DeleteKey( Keys.DisablePreviews );
|
||||
EditorPrefs.DeleteKey( Keys.DisableMaterialMode );
|
||||
EditorPrefs.DeleteKey( Keys.ForceTemplateMinShaderModel );
|
||||
EditorPrefs.DeleteKey( Keys.ForceTemplateInlineProperties );
|
||||
|
||||
StartUp = Defaults.StartUp;
|
||||
AlwaysSnapToGrid = Defaults.AlwaysSnapToGrid;
|
||||
EnableUndo = Defaults.EnableUndo;
|
||||
ClearLog = Defaults.ClearLog;
|
||||
LogShaderCompile = Defaults.LogShaderCompile;
|
||||
LogBatchCompile = Defaults.LogBatchCompile;
|
||||
UpdateOnSceneSave = Defaults.UpdateOnSceneSave;
|
||||
PreviewUpdateFrequency = Defaults.PreviewUpdateFrequency;
|
||||
PreviewQuality = Defaults.PreviewQuality;
|
||||
DisablePreviews = Defaults.DisablePreviews;
|
||||
DisableMaterialMode = Defaults.DisableMaterialMode;
|
||||
ForceTemplateMinShaderModel = Defaults.ForceTemplateMinShaderModel;
|
||||
ForceTemplateInlineProperties = Defaults.ForceTemplateInlineProperties;
|
||||
}
|
||||
|
||||
public static void LoadSettings()
|
||||
{
|
||||
StartUp = ( ShowOption )EditorPrefs.GetInt( Keys.StartUp, ( int )Defaults.StartUp );
|
||||
AlwaysSnapToGrid = EditorPrefs.GetBool( Keys.AlwaysSnapToGrid, Defaults.AlwaysSnapToGrid );
|
||||
EnableUndo = EditorPrefs.GetBool( Keys.EnableUndo, Defaults.EnableUndo );
|
||||
ClearLog = EditorPrefs.GetBool( Keys.ClearLog, Defaults.ClearLog );
|
||||
LogShaderCompile = EditorPrefs.GetBool( Keys.LogShaderCompile, Defaults.LogShaderCompile );
|
||||
LogBatchCompile = EditorPrefs.GetBool( Keys.LogBatchCompile, Defaults.LogBatchCompile );
|
||||
UpdateOnSceneSave = EditorPrefs.GetBool( Keys.UpdateOnSceneSave, Defaults.UpdateOnSceneSave );
|
||||
PreviewUpdateFrequency = EditorPrefs.GetInt( Keys.PreviewUpdateFrequency, Defaults.PreviewUpdateFrequency );
|
||||
PreviewQuality = EditorPrefs.GetInt( Keys.PreviewQuality, Defaults.PreviewQuality );
|
||||
DisablePreviews = EditorPrefs.GetBool( Keys.DisablePreviews, Defaults.DisablePreviews );
|
||||
DisableMaterialMode = EditorPrefs.GetBool( Keys.DisableMaterialMode, Defaults.DisableMaterialMode );
|
||||
ForceTemplateMinShaderModel = EditorPrefs.GetBool( Keys.ForceTemplateMinShaderModel, Defaults.ForceTemplateMinShaderModel );
|
||||
ForceTemplateInlineProperties = EditorPrefs.GetBool( Keys.ForceTemplateInlineProperties, Defaults.ForceTemplateInlineProperties );
|
||||
}
|
||||
|
||||
public static void SaveSettings()
|
||||
{
|
||||
bool prevDisablePreviews = EditorPrefs.GetBool( Keys.DisablePreviews, false );
|
||||
if ( DisablePreviews != prevDisablePreviews )
|
||||
{
|
||||
UIUtils.ActivatePreviews( !DisablePreviews );
|
||||
}
|
||||
|
||||
EditorPrefs.SetInt( Keys.StartUp, ( int )StartUp );
|
||||
EditorPrefs.SetBool( Keys.AlwaysSnapToGrid, AlwaysSnapToGrid );
|
||||
EditorPrefs.SetBool( Keys.EnableUndo, EnableUndo );
|
||||
EditorPrefs.SetBool( Keys.ClearLog, ClearLog );
|
||||
EditorPrefs.SetBool( Keys.LogShaderCompile, LogShaderCompile );
|
||||
EditorPrefs.SetBool( Keys.LogBatchCompile, LogBatchCompile );
|
||||
EditorPrefs.SetBool( Keys.UpdateOnSceneSave, UpdateOnSceneSave );
|
||||
EditorPrefs.SetInt( Keys.PreviewUpdateFrequency, PreviewUpdateFrequency );
|
||||
EditorPrefs.SetInt( Keys.PreviewQuality, PreviewQuality );
|
||||
EditorPrefs.SetBool( Keys.DisablePreviews, DisablePreviews );
|
||||
EditorPrefs.SetBool( Keys.DisableMaterialMode, DisableMaterialMode );
|
||||
EditorPrefs.SetBool( Keys.ForceTemplateMinShaderModel, ForceTemplateMinShaderModel );
|
||||
EditorPrefs.SetBool( Keys.ForceTemplateInlineProperties, ForceTemplateInlineProperties );
|
||||
}
|
||||
|
||||
static readonly string[] FrequencyOptions = { "30 hz", "60 hz", "120 hz", "240 hz", "Unlimited" };
|
||||
static readonly int[] FrequencyOptionsIndexToValue = { 30, 60, 120, 240, 10000 };
|
||||
static readonly Dictionary<int, int> FrequencyOptionsValueToIndex = new Dictionary<int, int>()
|
||||
{
|
||||
{ FrequencyOptionsIndexToValue[ 0 ], 0 },
|
||||
{ FrequencyOptionsIndexToValue[ 1 ], 1 },
|
||||
{ FrequencyOptionsIndexToValue[ 2 ], 2 },
|
||||
{ FrequencyOptionsIndexToValue[ 3 ], 3 },
|
||||
{ FrequencyOptionsIndexToValue[ 4 ], 4 }
|
||||
};
|
||||
|
||||
static readonly string[] PreviewQualityOptions = { "Low", "Medium", "High" };
|
||||
|
||||
public static int PreviewSize { get { return ( PreviewQuality < 2 ) ? 64 : 128; } }
|
||||
public static RenderTextureFormat PreviewFormat { get { return ( PreviewQuality < 1 ) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGBFloat; } }
|
||||
|
||||
public static void InspectorLayout()
|
||||
{
|
||||
StartUp = ( ShowOption )EditorGUILayout.EnumPopup( Styles.StartUp, StartUp );
|
||||
AlwaysSnapToGrid = EditorGUILayout.Toggle( Styles.AlwaysSnapToGrid, AlwaysSnapToGrid );
|
||||
EnableUndo = EditorGUILayout.Toggle( Styles.EnableUndo, EnableUndo );
|
||||
ClearLog = EditorGUILayout.Toggle( Styles.ClearLog, ClearLog );
|
||||
LogShaderCompile = EditorGUILayout.Toggle( Styles.LogShaderCompile, LogShaderCompile );
|
||||
LogBatchCompile = EditorGUILayout.Toggle( Styles.LogBatchCompile, LogBatchCompile );
|
||||
UpdateOnSceneSave = EditorGUILayout.Toggle( Styles.UpdateOnSceneSave, UpdateOnSceneSave );
|
||||
PreviewUpdateFrequency = FrequencyOptionsIndexToValue[ EditorGUILayout.Popup( Styles.PreviewUpdateFrequency, FrequencyOptionsValueToIndex[ PreviewUpdateFrequency ], FrequencyOptions ) ];
|
||||
PreviewQuality = ( int )EditorGUILayout.Popup( Styles.PreviewQuality, PreviewQuality, PreviewQualityOptions );
|
||||
DisablePreviews = EditorGUILayout.Toggle( Styles.DisablePreviews, DisablePreviews );
|
||||
DisableMaterialMode = EditorGUILayout.Toggle( Styles.DisableMaterialMode, DisableMaterialMode );
|
||||
ForceTemplateMinShaderModel = EditorGUILayout.Toggle( Styles.ForceTemplateMinShaderModel, ForceTemplateMinShaderModel );
|
||||
ForceTemplateInlineProperties = EditorGUILayout.Toggle( Styles.ForceTemplateInlineProperties, ForceTemplateInlineProperties );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.User.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.User.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab4d917144f5cdc498a08f865e37754c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.cs
vendored
Normal file
83
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.cs
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public partial class Preferences
|
||||
{
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider AmplifyShaderEditorSettings()
|
||||
{
|
||||
var provider = new SettingsProvider( "Preferences/Amplify Shader Editor", SettingsScope.User )
|
||||
{
|
||||
guiHandler = ( string searchContext ) =>
|
||||
{
|
||||
PreferencesGUI();
|
||||
},
|
||||
|
||||
keywords = new HashSet<string>( new[] { "start", "screen", "import", "shader", "templates", "macros", "macros", "define", "symbol" } ),
|
||||
|
||||
};
|
||||
return provider;
|
||||
}
|
||||
|
||||
private static void ResetSettings()
|
||||
{
|
||||
User.ResetSettings();
|
||||
Project.ResetSettings();
|
||||
|
||||
User.SaveSettings();
|
||||
Project.SaveSettings();
|
||||
}
|
||||
|
||||
private static void LoadSettings()
|
||||
{
|
||||
User.LoadSettings();
|
||||
Project.LoadSettings();
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
public static void PreferencesGUI()
|
||||
{
|
||||
var cache = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 250;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
{
|
||||
EditorGUILayout.LabelField( "User", EditorStyles.boldLabel );
|
||||
User.InspectorLayout();
|
||||
}
|
||||
if ( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
User.SaveSettings();
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
{
|
||||
EditorGUILayout.LabelField( "Project", EditorStyles.boldLabel );
|
||||
Project.InspectorLayout();
|
||||
}
|
||||
if ( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
Project.SaveSettings();
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
if( GUILayout.Button( "Reset and Forget All" ) )
|
||||
{
|
||||
ResetSettings();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUIUtility.labelWidth = cache;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.cs.meta
vendored
Normal file
11
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d036571a581792b44951e3723aef2c01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/RectExtension.cs
vendored
Normal file
40
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/RectExtension.cs
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public static class RectExtension
|
||||
{
|
||||
private static Rect ValidateBoundaries( this Rect thisRect )
|
||||
{
|
||||
if ( thisRect.yMin > thisRect.yMax )
|
||||
{
|
||||
float yMin = thisRect.yMin;
|
||||
thisRect.yMin = thisRect.yMax;
|
||||
thisRect.yMax = yMin;
|
||||
}
|
||||
|
||||
if ( thisRect.xMin > thisRect.xMax )
|
||||
{
|
||||
float xMin = thisRect.xMin;
|
||||
thisRect.xMin = thisRect.xMax;
|
||||
thisRect.xMax = xMin;
|
||||
}
|
||||
return thisRect;
|
||||
}
|
||||
|
||||
public static bool Includes( this Rect thisRect , Rect other )
|
||||
{
|
||||
thisRect = thisRect.ValidateBoundaries();
|
||||
other = other.ValidateBoundaries();
|
||||
|
||||
if ( other.xMin >= thisRect.xMin && other.xMax <= thisRect.xMax )
|
||||
{
|
||||
if ( other.yMin >= thisRect.yMin && other.yMax <= thisRect.yMax )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/RectExtension.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/RectExtension.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5a7e5c0308e038448cd1a235bf840ca
|
||||
timeCreated: 1501521591
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
185
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/SamplerStateAutoGenerator.cs
vendored
Normal file
185
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/SamplerStateAutoGenerator.cs
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public enum InlineSamplerFilteringMode
|
||||
{
|
||||
Point,
|
||||
Linear,
|
||||
Trilinear
|
||||
};
|
||||
|
||||
public enum InlineSamplerWrapMode
|
||||
{
|
||||
Clamp,
|
||||
Repeat,
|
||||
Mirror,
|
||||
MirrorOnce
|
||||
};
|
||||
|
||||
public enum InlineSamplerWrapCoordinates
|
||||
{
|
||||
All,
|
||||
U,
|
||||
V,
|
||||
W
|
||||
};
|
||||
|
||||
[Serializable]
|
||||
public class InlineSamplerWrapOptions
|
||||
{
|
||||
public InlineSamplerWrapMode WrapMode = InlineSamplerWrapMode.Clamp;
|
||||
public InlineSamplerWrapCoordinates Coordinates = InlineSamplerWrapCoordinates.All;
|
||||
public string InlineValue
|
||||
{
|
||||
get
|
||||
{
|
||||
string name = "_"+WrapMode.ToString();
|
||||
if( Coordinates != InlineSamplerWrapCoordinates.All )
|
||||
name += Coordinates.ToString();
|
||||
name += "_";
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SamplerStateAutoGenerator
|
||||
{
|
||||
private const int MaxCount = 3;
|
||||
private const float ButtonLayoutWidth = 15;
|
||||
private const string AdditionalWrapsStr = "Additional Wraps";
|
||||
private const string InlineSamplerStateStr = "Inline Sampler State";
|
||||
|
||||
[SerializeField]
|
||||
private InlineSamplerFilteringMode m_filterMode = InlineSamplerFilteringMode.Point;
|
||||
|
||||
[SerializeField]
|
||||
private InlineSamplerWrapOptions m_mainWrapMode = new InlineSamplerWrapOptions();
|
||||
|
||||
[SerializeField]
|
||||
private List<InlineSamplerWrapOptions> m_additionalWrapOptions = new List<InlineSamplerWrapOptions>();
|
||||
|
||||
[SerializeField]
|
||||
private bool m_visibleWrapsFoldout = false;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_visibleMainFoldout = false;
|
||||
|
||||
[NonSerialized]
|
||||
private UndoParentNode m_owner;
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
m_mainWrapMode = null;
|
||||
m_additionalWrapOptions.Clear();
|
||||
m_additionalWrapOptions = null;
|
||||
}
|
||||
|
||||
public string AddToDataCollector( ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
string inlineSampler = "sampler_";
|
||||
|
||||
inlineSampler += m_filterMode.ToString();
|
||||
inlineSampler += m_mainWrapMode.InlineValue;
|
||||
|
||||
int count = m_additionalWrapOptions.Count;
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
inlineSampler += m_additionalWrapOptions[ i ].InlineValue;
|
||||
}
|
||||
return inlineSampler;
|
||||
}
|
||||
|
||||
void DrawAddRemoveButtons()
|
||||
{
|
||||
int count = m_additionalWrapOptions.Count;
|
||||
if( count < MaxCount && m_owner.GUILayoutButton( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
|
||||
{
|
||||
m_additionalWrapOptions.Add( new InlineSamplerWrapOptions() );
|
||||
EditorGUI.FocusTextInControl( null );
|
||||
}
|
||||
|
||||
if( count > 0 && m_owner.GUILayoutButton( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
|
||||
{
|
||||
m_additionalWrapOptions.RemoveAt( count - 1 );
|
||||
EditorGUI.FocusTextInControl( null );
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw( UndoParentNode owner )
|
||||
{
|
||||
m_owner = owner;
|
||||
NodeUtils.DrawNestedPropertyGroup( ref m_visibleMainFoldout, InlineSamplerStateStr, DrawMain );
|
||||
}
|
||||
|
||||
void DrawMain()
|
||||
{
|
||||
m_filterMode = (InlineSamplerFilteringMode)m_owner.EditorGUILayoutEnumPopup( m_filterMode );
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_mainWrapMode.WrapMode = (InlineSamplerWrapMode)m_owner.EditorGUILayoutEnumPopup( m_mainWrapMode.WrapMode );
|
||||
m_mainWrapMode.Coordinates = (InlineSamplerWrapCoordinates)m_owner.EditorGUILayoutEnumPopup( m_mainWrapMode.Coordinates );
|
||||
EditorGUILayout.EndHorizontal();
|
||||
NodeUtils.DrawNestedPropertyGroup( ref m_visibleWrapsFoldout, AdditionalWrapsStr, DrawAdditionalWrapModes, DrawAddRemoveButtons );
|
||||
}
|
||||
|
||||
void DrawAdditionalWrapModes()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
int count = m_additionalWrapOptions.Count;
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
float maxWidth = 90;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_additionalWrapOptions[ i ].WrapMode = (InlineSamplerWrapMode)m_owner.EditorGUILayoutEnumPopup( m_additionalWrapOptions[ i ].WrapMode ,GUILayout.MaxWidth( maxWidth ) );
|
||||
m_additionalWrapOptions[ i ].Coordinates = (InlineSamplerWrapCoordinates)m_owner.EditorGUILayoutEnumPopup( m_additionalWrapOptions[ i ].Coordinates, GUILayout.MaxWidth( maxWidth ) );
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadFromString( ref uint index, ref string[] nodeParams )
|
||||
{
|
||||
Enum.TryParse<InlineSamplerFilteringMode>( nodeParams[ index++ ], out m_filterMode );
|
||||
Enum.TryParse<InlineSamplerWrapCoordinates>( nodeParams[ index++ ], out m_mainWrapMode.Coordinates );
|
||||
|
||||
int count = 0;
|
||||
int.TryParse( nodeParams[ index++ ], out count );
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
InlineSamplerWrapOptions option = new InlineSamplerWrapOptions();
|
||||
|
||||
Enum.TryParse<InlineSamplerWrapMode>( nodeParams[ index++ ], out option.WrapMode );
|
||||
Enum.TryParse<InlineSamplerWrapCoordinates>( nodeParams[ index++ ], out option.Coordinates );
|
||||
|
||||
m_additionalWrapOptions.Add( option );
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteToString( ref string nodeInfo )
|
||||
{
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_filterMode );
|
||||
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_mainWrapMode.WrapMode );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_mainWrapMode.Coordinates );
|
||||
|
||||
int count = m_additionalWrapOptions.Count;
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, count );
|
||||
if( count > 0 )
|
||||
{
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_additionalWrapOptions[i].WrapMode );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_additionalWrapOptions[i].Coordinates );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe831fe9de481bc4b9df1c1142bb9aa5
|
||||
timeCreated: 1580322794
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
155
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShaderBodyTokenizer.cs
vendored
Normal file
155
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShaderBodyTokenizer.cs
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public struct TokenDesc
|
||||
{
|
||||
public string name;
|
||||
public int position;
|
||||
public int line;
|
||||
|
||||
public TokenDesc( string name, int position, int line )
|
||||
{
|
||||
this.name = name;
|
||||
this.position = position;
|
||||
this.line = line;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShaderBodyTokenTable
|
||||
{
|
||||
private int count = 0;
|
||||
public int Count { get { return count; } }
|
||||
|
||||
private LinkedList<TokenDesc> tokens = new LinkedList<TokenDesc>();
|
||||
private Dictionary<string, List<LinkedListNode<TokenDesc>>> tokensByName = new Dictionary<string, List<LinkedListNode<TokenDesc>>>();
|
||||
private Dictionary<int, List<LinkedListNode<TokenDesc>>> tokensByLine = new Dictionary<int, List<LinkedListNode<TokenDesc>>>();
|
||||
|
||||
private static List<LinkedListNode<TokenDesc>> EmptyTokenList = new List<LinkedListNode<TokenDesc>>();
|
||||
|
||||
public bool Contains( string token )
|
||||
{
|
||||
return tokensByName.ContainsKey( token );
|
||||
}
|
||||
|
||||
public List<LinkedListNode<TokenDesc>> ListTokensByName( string name )
|
||||
{
|
||||
if ( tokensByName.TryGetValue( name, out List<LinkedListNode<TokenDesc>> list ) )
|
||||
{
|
||||
return list;
|
||||
}
|
||||
return EmptyTokenList;
|
||||
}
|
||||
|
||||
public List<LinkedListNode<TokenDesc>> ListTokensByLine( int line )
|
||||
{
|
||||
if ( tokensByLine.TryGetValue( line, out List<LinkedListNode<TokenDesc>> list ) )
|
||||
{
|
||||
return list;
|
||||
}
|
||||
return EmptyTokenList;
|
||||
}
|
||||
|
||||
public void Add( string name, int position, int line )
|
||||
{
|
||||
var node = tokens.AddLast( new TokenDesc( name, position, line ) );
|
||||
|
||||
if ( !tokensByName.TryGetValue( name, out List<LinkedListNode<TokenDesc>> listPerName ) )
|
||||
{
|
||||
listPerName = new List<LinkedListNode<TokenDesc>>();
|
||||
tokensByName.Add( name, listPerName );
|
||||
}
|
||||
|
||||
if ( !tokensByLine.TryGetValue( line, out List<LinkedListNode<TokenDesc>> listPerLine ) )
|
||||
{
|
||||
listPerLine = new List<LinkedListNode<TokenDesc>>();
|
||||
tokensByLine.Add( line, listPerLine );
|
||||
}
|
||||
|
||||
listPerName.Add( node );
|
||||
listPerLine.Add( node );
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShaderBodyTokenizer
|
||||
{
|
||||
private static double TimeSinceStartup
|
||||
{
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
get { return Time.realtimeSinceStartupAsDouble; }
|
||||
#else
|
||||
get { return Time.realtimeSinceStartup; }
|
||||
#endif
|
||||
}
|
||||
|
||||
public static ShaderBodyTokenTable Process( string body )
|
||||
{
|
||||
var tokens = new ShaderBodyTokenTable();
|
||||
int charIndex = 0;
|
||||
int charCount = body.Length;
|
||||
int line = 0;
|
||||
var tokenBuilder = new StringBuilder( 1024 );
|
||||
do
|
||||
{
|
||||
char c = body[ charIndex++ ];
|
||||
bool isBreak = ( c == '\n' );
|
||||
bool isEmpty = ( isBreak || c == ' ' || c == '\t' || c == '\r' || c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || c == ';' || c == ',' || c == '\"' );
|
||||
if ( !isEmpty )
|
||||
{
|
||||
tokenBuilder.Clear();
|
||||
int position = charIndex;
|
||||
|
||||
while ( !isEmpty && charIndex < charCount )
|
||||
{
|
||||
tokenBuilder.Append( c );
|
||||
c = body[ charIndex++ ];
|
||||
isBreak = ( c == '\n' );
|
||||
isEmpty = ( isBreak || c == ' ' || c == '\t' || c == '\r' || c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || c == ';' || c == ',' || c == '\"' );
|
||||
line += isBreak ? 1 : 0;
|
||||
}
|
||||
|
||||
string token = tokenBuilder.ToString();
|
||||
if ( !token.StartsWith( "//" ) )
|
||||
{
|
||||
tokens.Add( token, position, line );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
line += isBreak ? 1 : 0;
|
||||
}
|
||||
} while ( charIndex < charCount );
|
||||
return tokens;
|
||||
}
|
||||
|
||||
public static void TestProcess( string body )
|
||||
{
|
||||
UnityEngine.Profiling.Profiler.BeginSample( "Tokenize" );
|
||||
double start = TimeSinceStartup;
|
||||
ShaderBodyTokenTable tokens = ShaderBodyTokenizer.Process( body );
|
||||
UnityEngine.Profiling.Profiler.EndSample();
|
||||
Debug.Log( "Found " + tokens.Count + " tokens, taking " + ( ( TimeSinceStartup - start ) * 1000 ) + " ms" );
|
||||
Debug.Log( "Has Fallback " + tokens.Contains( "Fallback" ) );
|
||||
Debug.Log( "Has CustomEditor " + tokens.Contains( "CustomEditor" ) );
|
||||
var list = tokens.ListTokensByName( "CustomEditor" );
|
||||
foreach ( var node in list )
|
||||
{
|
||||
Debug.Log( "Name: " + node.Value.name + ", Position: " + node.Value.position + ", Line: " + node.Value.line );
|
||||
}
|
||||
|
||||
//foreach ( var node in list )
|
||||
//
|
||||
//File.WriteAllLines( "C:/Users/Diogo/Desktop/dump.txt", tokens.Keys );
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShaderBodyTokenizer.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShaderBodyTokenizer.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6852cf9e70d26d54eb91f7b259b65dfb
|
||||
timeCreated: 1481126954
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
215
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShortcutsManager.cs
vendored
Normal file
215
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShortcutsManager.cs
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class ShortcutItem
|
||||
{
|
||||
public delegate void ShortcutFunction();
|
||||
public ShortcutFunction MyKeyDownFunctionPtr;
|
||||
public ShortcutFunction MyKeyUpFunctionPtr;
|
||||
public string Name;
|
||||
public string Description;
|
||||
|
||||
public ShortcutItem( string name, string description )
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public ShortcutItem( string name, string description, ShortcutFunction myKeyDownFunctionPtr, ShortcutFunction myKeyUpFunctionPtr = null )
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
MyKeyDownFunctionPtr = myKeyDownFunctionPtr;
|
||||
MyKeyUpFunctionPtr = myKeyUpFunctionPtr;
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
MyKeyDownFunctionPtr = null;
|
||||
MyKeyUpFunctionPtr = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShortcutsManager
|
||||
{
|
||||
public static readonly KeyCode ScrollUpKey = KeyCode.PageUp;
|
||||
public static readonly KeyCode ScrollDownKey = KeyCode.PageDown;
|
||||
|
||||
|
||||
private const string ItemWikiFormat = "*<b>[{0}]:</b> {1}\n";
|
||||
private Dictionary<KeyCode, Dictionary<EventModifiers, ShortcutItem>> m_editorShortcutsDict = new Dictionary<KeyCode, Dictionary<EventModifiers, ShortcutItem>>();
|
||||
private Dictionary<KeyCode, ShortcutItem> m_editorNoModifiersShortcutsDict = new Dictionary<KeyCode, ShortcutItem>();
|
||||
private List<ShortcutItem> m_editorShortcutsList = new List<ShortcutItem>();
|
||||
|
||||
private Dictionary<KeyCode, ShortcutItem> m_nodesShortcutsDict = new Dictionary<KeyCode, ShortcutItem>();
|
||||
private List<ShortcutItem> m_nodesShortcutsList = new List<ShortcutItem>();
|
||||
|
||||
public void DumpShortcutsToDisk( string pathname )
|
||||
{
|
||||
if ( !System.IO.Directory.Exists( pathname ) )
|
||||
{
|
||||
System.IO.Directory.CreateDirectory( pathname );
|
||||
}
|
||||
|
||||
string list = "=== Full Shortcut List ===\n";
|
||||
list += "==== Editor ====\n";
|
||||
for ( int i = 0; i < m_editorShortcutsList.Count; i++ )
|
||||
{
|
||||
list += string.Format( ItemWikiFormat, m_editorShortcutsList[ i ].Name, m_editorShortcutsList[ i ].Description );
|
||||
}
|
||||
list += "\n";
|
||||
list += "==== Nodes ====\n";
|
||||
for ( int i = 0; i < m_nodesShortcutsList.Count; i++ )
|
||||
{
|
||||
list += string.Format( ItemWikiFormat, m_nodesShortcutsList[ i ].Name, m_nodesShortcutsList[ i ].Description );
|
||||
}
|
||||
|
||||
string shortcutsPathnames = pathname + "KeyboardShortcuts.txt";
|
||||
Debug.Log( " Creating shortcuts file at " + shortcutsPathnames );
|
||||
IOUtils.SaveTextfileToDisk( list, shortcutsPathnames, false );
|
||||
}
|
||||
|
||||
public void RegisterNodesShortcuts( KeyCode key, string nodeName )
|
||||
{
|
||||
if ( m_nodesShortcutsDict.ContainsKey( key ) )
|
||||
{
|
||||
if ( DebugConsoleWindow.DeveloperMode )
|
||||
{
|
||||
Debug.Log( "Attempting to register an already used node shortcut key " + key );
|
||||
}
|
||||
return;
|
||||
}
|
||||
m_nodesShortcutsDict.Add( key, new ShortcutItem( key.ToString(), nodeName ) );
|
||||
m_nodesShortcutsList.Add( m_nodesShortcutsDict[ key ] );
|
||||
}
|
||||
|
||||
public void RegisterEditorShortcut( bool showOnList, EventModifiers modifiers, KeyCode key, string description, ShortcutItem.ShortcutFunction myKeyDownFunctionPtr, ShortcutItem.ShortcutFunction myKeyUpFunctionPtr = null )
|
||||
{
|
||||
if ( m_editorShortcutsDict.ContainsKey( key ) )
|
||||
{
|
||||
if ( m_editorShortcutsDict[ key ].ContainsKey( modifiers ) )
|
||||
{
|
||||
if ( DebugConsoleWindow.DeveloperMode )
|
||||
{
|
||||
Debug.Log( "Attempting to register an already used editor shortcut key " + key );
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_editorShortcutsDict.Add( key, new Dictionary<EventModifiers, ShortcutItem>() );
|
||||
}
|
||||
ShortcutItem item = new ShortcutItem( ( ( modifiers == EventModifiers.None || modifiers == EventModifiers.FunctionKey ) ? key.ToString() : modifiers + " + " + key ), description, myKeyDownFunctionPtr, myKeyUpFunctionPtr );
|
||||
m_editorShortcutsDict[ key ].Add( modifiers, item );
|
||||
if ( showOnList )
|
||||
m_editorShortcutsList.Add( item );
|
||||
}
|
||||
|
||||
public void RegisterEditorShortcut( bool showOnList, KeyCode key, string description, ShortcutItem.ShortcutFunction myKeyDownFunctionPtr, ShortcutItem.ShortcutFunction myKeyUpFunctionPtr = null )
|
||||
{
|
||||
if ( m_editorNoModifiersShortcutsDict.ContainsKey( key ) )
|
||||
{
|
||||
if ( DebugConsoleWindow.DeveloperMode )
|
||||
{
|
||||
Debug.Log( "Attempting to register an already used editor shortcut key " + key );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ShortcutItem item = new ShortcutItem( key.ToString(), description, myKeyDownFunctionPtr, myKeyUpFunctionPtr );
|
||||
m_editorNoModifiersShortcutsDict.Add( key, item );
|
||||
if ( showOnList )
|
||||
m_editorShortcutsList.Add( item );
|
||||
}
|
||||
|
||||
public bool ActivateShortcut( EventModifiers modifiers, KeyCode key, bool isKeyDown )
|
||||
{
|
||||
if ( m_editorShortcutsDict.ContainsKey( key ) )
|
||||
{
|
||||
if ( isKeyDown )
|
||||
{
|
||||
if ( m_editorShortcutsDict[ key ].ContainsKey( modifiers ) )
|
||||
{
|
||||
if ( m_editorShortcutsDict[ key ][ modifiers ].MyKeyDownFunctionPtr != null )
|
||||
{
|
||||
m_editorShortcutsDict[ key ][ modifiers ].MyKeyDownFunctionPtr();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_editorShortcutsDict[ key ].ContainsKey( modifiers ) )
|
||||
{
|
||||
if ( m_editorShortcutsDict[ key ][ modifiers ].MyKeyUpFunctionPtr != null )
|
||||
{
|
||||
m_editorShortcutsDict[ key ][ modifiers ].MyKeyUpFunctionPtr();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( modifiers == EventModifiers.None && m_editorNoModifiersShortcutsDict.ContainsKey( key ) )
|
||||
{
|
||||
if ( isKeyDown )
|
||||
{
|
||||
if ( m_editorNoModifiersShortcutsDict[ key ].MyKeyDownFunctionPtr != null )
|
||||
{
|
||||
m_editorNoModifiersShortcutsDict[ key ].MyKeyDownFunctionPtr();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_editorNoModifiersShortcutsDict[ key ].MyKeyUpFunctionPtr != null )
|
||||
{
|
||||
m_editorNoModifiersShortcutsDict[ key ].MyKeyUpFunctionPtr();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
foreach ( KeyValuePair<KeyCode, ShortcutItem> kvp in m_editorNoModifiersShortcutsDict )
|
||||
{
|
||||
kvp.Value.Destroy();
|
||||
}
|
||||
m_editorNoModifiersShortcutsDict.Clear();
|
||||
m_editorNoModifiersShortcutsDict = null;
|
||||
|
||||
foreach ( KeyValuePair<KeyCode, Dictionary<EventModifiers, ShortcutItem>> kvpKey in m_editorShortcutsDict )
|
||||
{
|
||||
foreach ( KeyValuePair<EventModifiers, ShortcutItem> kvpMod in kvpKey.Value )
|
||||
{
|
||||
kvpMod.Value.Destroy();
|
||||
}
|
||||
kvpKey.Value.Clear();
|
||||
}
|
||||
m_editorShortcutsDict.Clear();
|
||||
m_editorShortcutsDict = null;
|
||||
|
||||
m_editorShortcutsList.Clear();
|
||||
m_editorShortcutsList = null;
|
||||
|
||||
m_nodesShortcutsDict.Clear();
|
||||
m_nodesShortcutsDict = null;
|
||||
|
||||
m_nodesShortcutsList.Clear();
|
||||
m_nodesShortcutsList = null;
|
||||
}
|
||||
|
||||
public List<ShortcutItem> AvailableEditorShortcutsList { get { return m_editorShortcutsList; } }
|
||||
public List<ShortcutItem> AvailableNodesShortcutsList { get { return m_nodesShortcutsList; } }
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShortcutsManager.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/ShortcutsManager.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15917e71489c3ca4dbc5fdef9bb37433
|
||||
timeCreated: 1487952057
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/TextureArrayCreatorAsset.cs
vendored
Normal file
78
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/TextureArrayCreatorAsset.cs
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
public class TextureArrayCreatorAsset : ScriptableObject
|
||||
{
|
||||
#pragma warning disable
|
||||
[SerializeField]
|
||||
private int m_selectedSize = 4;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_lockRatio = true;
|
||||
|
||||
[SerializeField]
|
||||
private int m_sizeX = 512;
|
||||
|
||||
[SerializeField]
|
||||
private int m_sizeY = 512;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_tex3DMode = false;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_linearMode = false;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_mipMaps = true;
|
||||
|
||||
[SerializeField]
|
||||
private TextureWrapMode m_wrapMode = TextureWrapMode.Repeat;
|
||||
|
||||
[SerializeField]
|
||||
private FilterMode m_filterMode = FilterMode.Bilinear;
|
||||
|
||||
[SerializeField]
|
||||
private int m_anisoLevel = 1;
|
||||
|
||||
[SerializeField]
|
||||
private TextureFormat m_selectedFormatEnum = TextureFormat.ARGB32;
|
||||
|
||||
[SerializeField]
|
||||
private int m_quality = 100;
|
||||
|
||||
[SerializeField]
|
||||
private string m_folderPath = "Assets/";
|
||||
|
||||
[SerializeField]
|
||||
private string m_fileName = "NewTextureArray";
|
||||
|
||||
[SerializeField]
|
||||
private bool m_filenameChanged = false;
|
||||
|
||||
[SerializeField]
|
||||
private List<Texture2D> m_allTextures = new List<Texture2D>();
|
||||
|
||||
public int SelectedSize { get { return m_selectedSize; } }
|
||||
public int SizeX { get { return m_sizeX; } }
|
||||
public int SizeY { get { return m_sizeY; } }
|
||||
public bool Tex3DMode { get { return m_tex3DMode; } }
|
||||
public bool LinearMode { get { return m_linearMode; } }
|
||||
public bool MipMaps { get { return m_mipMaps; } }
|
||||
public TextureWrapMode WrapMode { get { return m_wrapMode; } }
|
||||
public FilterMode FilterMode { get { return m_filterMode; } }
|
||||
public int AnisoLevel { get { return m_anisoLevel; } }
|
||||
public TextureFormat SelectedFormatEnum { get { return m_selectedFormatEnum; } }
|
||||
public int Quality { get { return m_quality; } }
|
||||
public string FolderPath { get { return m_folderPath; } }
|
||||
public string FileName { get { return m_fileName; } }
|
||||
public List<Texture2D> AllTextures { get { return m_allTextures; } }
|
||||
#pragma warning restore
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47f91343d4ad12542b3eb9511e2b310c
|
||||
timeCreated: 1596799060
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
148
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/TipsWindow.cs
vendored
Normal file
148
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/TipsWindow.cs
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
public class TipsWindow : MenuParent
|
||||
{
|
||||
private static bool m_showWindow = false;
|
||||
private bool m_dontShowAtStart = false;
|
||||
|
||||
private static List<string> AllTips = new List<string>() {
|
||||
"You can press W to toggle between a flat and color coded Wires and ports.",
|
||||
"You can press CTRL+W to toggle between multiline or singleline Wire connections.",
|
||||
"You can press P to globally open all node Previews.",
|
||||
"You can press F to Focus your selection, single tap centers the selection while double tap it to also zooms on in.",
|
||||
"You can press CTRL+F to open a search bar and Find a node by it's title",
|
||||
"You can press SPACE to open a context menu to add a new node and press TAB or SHIFT+TAB tocycle between the found nodes",
|
||||
"You can remove a node without breaking the graph connections by pressing ALT and then dragging the node out",
|
||||
"You can switch two input connections holding CTRL while dragging one input connection into the other",
|
||||
};
|
||||
|
||||
int m_currentTip = 0;
|
||||
|
||||
public TipsWindow( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 0, 64, "Tips", MenuAnchor.TOP_LEFT, MenuAutoSize.NONE )
|
||||
{
|
||||
//m_dontShowAtStart = EditorPrefs.GetBool( "DontShowTipAtStart", false );
|
||||
}
|
||||
|
||||
public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
|
||||
{
|
||||
base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus );
|
||||
|
||||
DrawWindow( mousePosition );
|
||||
}
|
||||
|
||||
public void DrawWindow( Vector2 mousePosition )
|
||||
{
|
||||
if( !m_showWindow )
|
||||
return;
|
||||
|
||||
Rect windowRect = new Rect( 0, 0, Screen.width, Screen.height );
|
||||
Vector2 center = windowRect.center;
|
||||
windowRect.size = new Vector2( 300, 200 );
|
||||
windowRect.center = center;
|
||||
Color temp = GUI.color;
|
||||
GUI.color = Color.white;
|
||||
GUI.Label( windowRect, string.Empty, GUI.skin.FindStyle( "flow node 0" ) );
|
||||
|
||||
if( Event.current.type == EventType.MouseDown && !windowRect.Contains( mousePosition ) )
|
||||
m_showWindow = false;
|
||||
|
||||
Rect titleRect = windowRect;
|
||||
titleRect.height = 35;
|
||||
GUI.Label( titleRect, "Quick Tip!", GUI.skin.FindStyle( "TL Selection H2" ) );
|
||||
Rect button = titleRect;
|
||||
button.size = new Vector2( 14, 14 );
|
||||
button.y += 2;
|
||||
button.x = titleRect.xMax - 16;
|
||||
if( GUI.Button( button, string.Empty, GUI.skin.FindStyle( "WinBtnClose" ) ) )
|
||||
CloseWindow();
|
||||
|
||||
button.y += 100;
|
||||
if( GUI.Button( button, ">" ) )
|
||||
{
|
||||
m_currentTip++;
|
||||
if( m_currentTip >= AllTips.Count )
|
||||
m_currentTip = 0;
|
||||
}
|
||||
|
||||
Rect textRect = windowRect;
|
||||
textRect.yMin = titleRect.yMax;
|
||||
GUI.Label( textRect, AllTips[ m_currentTip ], GUI.skin.FindStyle( "WordWrappedLabel" ) );
|
||||
|
||||
Rect footerRect = windowRect;
|
||||
footerRect.yMin = footerRect.yMax - 18;
|
||||
footerRect.x += 3;
|
||||
GUI.Label( footerRect, (m_currentTip + 1) + " of " + AllTips.Count + " tips" );
|
||||
footerRect.x += 170;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_dontShowAtStart = GUI.Toggle( footerRect, m_dontShowAtStart, "Don't show at start" );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetBool( "DontShowTipAtStart", m_dontShowAtStart );
|
||||
}
|
||||
GUI.color = temp;
|
||||
|
||||
if( Event.current.type == EventType.MouseDown && windowRect.Contains( mousePosition ) )
|
||||
{
|
||||
Event.current.Use();
|
||||
ParentWindow.MouseInteracted = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
}
|
||||
|
||||
public static void ShowWindow( bool toggle = true )
|
||||
{
|
||||
if( toggle )
|
||||
m_showWindow = !m_showWindow;
|
||||
else
|
||||
m_showWindow = true;
|
||||
|
||||
//Test();
|
||||
//ExportCompiledShaders();
|
||||
}
|
||||
|
||||
//public static void Test()
|
||||
//{
|
||||
// Shader shader = UIUtils.CurrentWindow.CurrentGraph.CurrentShader;
|
||||
// int mode = EditorPrefs.GetInt( "ShaderInspectorPlatformMode", 1 );
|
||||
// int mask = EditorPrefs.GetInt( "ShaderInspectorPlatformMask", 524287 );
|
||||
// bool strip = EditorPrefs.GetInt( "ShaderInspectorVariantStripping", 1 ) == 0;
|
||||
// ShaderUtilEx.OpenCompiledShader( shader, mode, mask, strip );
|
||||
//}
|
||||
|
||||
//public static void ExportCompiledShaders()
|
||||
//{
|
||||
// Shader shader = UIUtils.CurrentWindow.CurrentGraph.CurrentShader;
|
||||
// string shaderPath = AssetDatabase.GetAssetPath( shader );
|
||||
// SerializedObject so = new SerializedObject( shader );
|
||||
// SerializedProperty prop = so.FindProperty( "m_Script" );
|
||||
// var compiledShaderString = prop.stringValue;
|
||||
// Directory.CreateDirectory( Application.dataPath + "/../ShaderSource/" );
|
||||
// if( compiledShaderString == null )
|
||||
// return;
|
||||
// var outputPath = Application.dataPath + "/../ShaderSource/" + Path.GetFileNameWithoutExtension( shaderPath ) + "_compiled.shader";
|
||||
// var sw = File.CreateText( outputPath );
|
||||
// sw.Write( compiledShaderString );
|
||||
// sw.Close();
|
||||
//}
|
||||
|
||||
public static void CloseWindow()
|
||||
{
|
||||
m_showWindow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/TipsWindow.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/TipsWindow.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 565dc3c9725b0db49b7d5ea17d151682
|
||||
timeCreated: 1504704078
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3335
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UIUtils.cs
vendored
Normal file
3335
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UIUtils.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UIUtils.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UIUtils.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23e0210afe076544ca92d761094a9119
|
||||
timeCreated: 1481126954
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
118
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UndoUtils.cs
vendored
Normal file
118
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UndoUtils.cs
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEngine.Internal;
|
||||
using System;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class UndoUtils
|
||||
{
|
||||
public static void RegisterUndoRedoCallback( Undo.UndoRedoCallback onUndoRedo )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Undo.undoRedoPerformed -= onUndoRedo;
|
||||
Undo.undoRedoPerformed += onUndoRedo;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnregisterUndoRedoCallback( Undo.UndoRedoCallback onUndoRedo )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Undo.undoRedoPerformed -= onUndoRedo;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterCompleteObjectUndo( UnityEngine.Object objectToUndo, string name )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_RegisterCompleteObjectUndo" );
|
||||
Undo.RegisterCompleteObjectUndo( objectToUndo, name );
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterCreatedObjectUndo( UnityEngine.Object objectToUndo, string name )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_RegisterCreatedObjectUndo" );
|
||||
Undo.RegisterCreatedObjectUndo( objectToUndo, name );
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearUndo( UnityEngine.Object obj )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_ClearUndo" );
|
||||
Undo.ClearUndo( obj );
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void RecordObject( UnityEngine.Object objectToUndo, string name )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_RecordObject" );
|
||||
Undo.RecordObject( objectToUndo, name );
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void RecordObjects( UnityEngine.Object[] objectsToUndo, string name )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_RecordObjects" );
|
||||
Undo.RecordObjects( objectsToUndo, name );
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestroyObjectImmediate( UnityEngine.Object objectToUndo )
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_DestroyObjectImmediate" );
|
||||
Undo.DestroyObjectImmediate( objectToUndo );
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void PerformUndo()
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_PerformUndo" );
|
||||
Undo.PerformUndo();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void PerformRedo()
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_PerformRedo" );
|
||||
Undo.PerformRedo();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
public static void IncrementCurrentGroup()
|
||||
{
|
||||
if ( Preferences.User.EnableUndo )
|
||||
{
|
||||
Profiler.BeginSample( "Undo_IncrementCurrentGroup" );
|
||||
Undo.IncrementCurrentGroup();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UndoUtils.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UndoUtils.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89dee7566d97f1847b9fe114e1c9a1a2
|
||||
timeCreated: 1489603190
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
91
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs
vendored
Normal file
91
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class UpperLeftWidgetHelper
|
||||
{
|
||||
public int DrawWidget( ParentNode owner, int selectedIndex, GUIContent[] displayedOptions )
|
||||
{
|
||||
if( owner.DropdownEditing )
|
||||
{
|
||||
int newValue = owner.EditorGUIPopup( owner.DropdownRect, selectedIndex, displayedOptions, UIUtils.PropertyPopUp );
|
||||
if( newValue != selectedIndex )
|
||||
{
|
||||
owner.DropdownEditing = false;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
return selectedIndex;
|
||||
}
|
||||
|
||||
public int DrawWidget( ParentNode owner, int selectedIndex, string[] displayedOptions )
|
||||
{
|
||||
if( owner.DropdownEditing )
|
||||
{
|
||||
int newValue = owner.EditorGUIPopup( owner.DropdownRect, selectedIndex, displayedOptions, UIUtils.PropertyPopUp );
|
||||
if( newValue != selectedIndex )
|
||||
{
|
||||
owner.DropdownEditing = false;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
return selectedIndex;
|
||||
}
|
||||
|
||||
public int DrawWidget( ParentNode owner, int selectedIndex, string[] displayedOptions, int[] optionValues )
|
||||
{
|
||||
if( owner.DropdownEditing )
|
||||
{
|
||||
int newValue = owner.EditorGUIIntPopup( owner.DropdownRect, selectedIndex, displayedOptions, optionValues, UIUtils.PropertyPopUp );
|
||||
if( newValue != selectedIndex )
|
||||
{
|
||||
owner.DropdownEditing = false;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
return selectedIndex;
|
||||
}
|
||||
|
||||
// GC free version
|
||||
public void DrawWidget<TEnum>( ref TEnum selectedIndex, ParentNode owner, Action<ParentNode> callback ) where TEnum : struct
|
||||
{
|
||||
if( owner.DropdownEditing )
|
||||
{
|
||||
Enum asEnumType = selectedIndex as Enum;
|
||||
if( asEnumType != null )
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
selectedIndex = ( owner.EditorGUIEnumPopup( owner.DropdownRect, asEnumType, UIUtils.PropertyPopUp ) as TEnum? ).Value;
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
owner.DropdownEditing = false;
|
||||
if( callback != null )
|
||||
callback( owner );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* USE THIS OVERRIDE IN CASE THE NODE DOESN'T HAVE PREVIEW
|
||||
*/
|
||||
//public override void AfterCommonInit()
|
||||
//{
|
||||
// base.AfterCommonInit();
|
||||
// if( PaddingTitleLeft == 0 )
|
||||
// {
|
||||
// PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
|
||||
// if( PaddingTitleRight == 0 )
|
||||
// PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
/*
|
||||
* USE THE SOURCE CODE BELOW INTO THE NODE YOU WANT THE WIDGET TO SHOW
|
||||
*/
|
||||
//private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32dbececad3a67a4fbde694ae50ce82c
|
||||
timeCreated: 1504080603
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
257
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowHelper.cs
vendored
Normal file
257
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowHelper.cs
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public static class WindowHelper
|
||||
{
|
||||
private class R_EditorWindow
|
||||
{
|
||||
private EditorWindow m_instance;
|
||||
private System.Type m_type;
|
||||
|
||||
public R_EditorWindow( EditorWindow instance )
|
||||
{
|
||||
m_instance = instance;
|
||||
m_type = instance.GetType();
|
||||
}
|
||||
|
||||
public object Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
var field = m_type.GetField( "m_Parent", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
return field.GetValue( m_instance );
|
||||
}
|
||||
}
|
||||
|
||||
public object Docked
|
||||
{
|
||||
get
|
||||
{
|
||||
var property = m_type.GetProperty( "docked", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
return property.GetValue( m_instance, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class R_DockArea
|
||||
{
|
||||
private object m_instance;
|
||||
private System.Type m_type;
|
||||
|
||||
public R_DockArea( object instance )
|
||||
{
|
||||
m_instance = instance;
|
||||
m_type = instance.GetType();
|
||||
}
|
||||
|
||||
public object Window
|
||||
{
|
||||
get
|
||||
{
|
||||
var property = m_type.GetProperty( "window", BindingFlags.Instance | BindingFlags.Public );
|
||||
return property.GetValue( m_instance, null );
|
||||
}
|
||||
}
|
||||
|
||||
public object ActualView
|
||||
{
|
||||
get
|
||||
{
|
||||
var field = m_type.GetField( "m_ActualView", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
return field.GetValue( m_instance );
|
||||
}
|
||||
}
|
||||
|
||||
public object OriginalDragSource
|
||||
{
|
||||
set
|
||||
{
|
||||
var field = m_type.GetField( "s_OriginalDragSource", BindingFlags.Static | BindingFlags.NonPublic );
|
||||
field.SetValue( null, value );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AddTab( EditorWindow pane )
|
||||
{
|
||||
var method = m_type.GetMethod( "AddTab", BindingFlags.Instance | BindingFlags.Public, null, new System.Type[] { typeof( EditorWindow ), typeof( bool ) }, null );
|
||||
if( method != null )
|
||||
method.Invoke( m_instance, new object[] { pane, true } );
|
||||
}
|
||||
|
||||
public void RemoveTab( EditorWindow pane )
|
||||
{
|
||||
if( !pane.maximized )
|
||||
{
|
||||
var method = m_type.GetMethod( "RemoveTab", BindingFlags.Instance | BindingFlags.Public, null, new System.Type[] { typeof( EditorWindow ) }, null );
|
||||
if( method != null )
|
||||
method.Invoke( m_instance, new object[] { pane } );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class R_ContainerWindow
|
||||
{
|
||||
private object m_instance;
|
||||
private System.Type m_type;
|
||||
|
||||
public R_ContainerWindow( object instance )
|
||||
{
|
||||
m_instance = instance;
|
||||
m_type = instance.GetType();
|
||||
}
|
||||
|
||||
public object RootSplitView
|
||||
{
|
||||
get
|
||||
{
|
||||
var property = m_type.GetProperty( "rootSplitView", BindingFlags.Instance | BindingFlags.Public );
|
||||
return property.GetValue( m_instance, null );
|
||||
}
|
||||
}
|
||||
|
||||
public object RootView
|
||||
{
|
||||
get
|
||||
{
|
||||
var property = m_type.GetProperty( "rootView", BindingFlags.Instance | BindingFlags.Public );
|
||||
return property.GetValue( m_instance, null );
|
||||
}
|
||||
}
|
||||
|
||||
public object WindowPtr
|
||||
{
|
||||
get
|
||||
{
|
||||
var all = m_type.GetNestedTypes();
|
||||
foreach( var item in all )
|
||||
{
|
||||
Debug.Log( item.Name );
|
||||
}
|
||||
var property = m_type.GetField( "m_WindowPtr", BindingFlags.Instance | BindingFlags.NonPublic );
|
||||
return property.GetValue( m_instance );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class R_SplitView
|
||||
{
|
||||
private object m_instance;
|
||||
private System.Type m_type;
|
||||
|
||||
public R_SplitView( object instance )
|
||||
{
|
||||
m_instance = instance;
|
||||
m_type = instance.GetType();
|
||||
}
|
||||
|
||||
public object DragOver( EditorWindow child, Vector2 screenPoint )
|
||||
{
|
||||
var method = m_type.GetMethod( "DragOver", BindingFlags.Instance | BindingFlags.Public );
|
||||
return method.Invoke( m_instance, new object[] { child, screenPoint } );
|
||||
}
|
||||
|
||||
public void PerformDrop( EditorWindow child, object dropInfo, Vector2 screenPoint )
|
||||
{
|
||||
var method = m_type.GetMethod( "PerformDrop", BindingFlags.Instance | BindingFlags.Public );
|
||||
method.Invoke( m_instance, new object[] { child, dropInfo, screenPoint } );
|
||||
}
|
||||
}
|
||||
|
||||
public enum DockPosition
|
||||
{
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom
|
||||
}
|
||||
|
||||
public static bool IsDocked( this EditorWindow wnd )
|
||||
{
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
return wnd.docked;
|
||||
#else
|
||||
var parent = new R_EditorWindow( wnd );
|
||||
return (bool)parent.Docked;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Undock( this EditorWindow wnd )
|
||||
{
|
||||
var parent = new R_EditorWindow( wnd );
|
||||
var dockArea = new R_DockArea( parent.Parent );
|
||||
dockArea.RemoveTab( wnd );
|
||||
wnd.Show( true );
|
||||
}
|
||||
|
||||
public static void RemoveTab( this EditorWindow wnd )
|
||||
{
|
||||
var parent = new R_EditorWindow( wnd );
|
||||
var dockArea = new R_DockArea( parent.Parent );
|
||||
dockArea.RemoveTab( wnd );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Docks the second window to the first window at the given position
|
||||
/// </summary>
|
||||
public static void Dock( this EditorWindow wnd, EditorWindow other, DockPosition position )
|
||||
{
|
||||
var mousePosition = GetFakeMousePosition( wnd, position );
|
||||
|
||||
var parent = new R_EditorWindow( wnd );
|
||||
var child = new R_EditorWindow( other );
|
||||
var dockArea = new R_DockArea( parent.Parent );
|
||||
var containerWindow = new R_ContainerWindow( dockArea.Window );
|
||||
var splitView = new R_SplitView( containerWindow.RootSplitView );
|
||||
var dropInfo = splitView.DragOver( other, mousePosition );
|
||||
dockArea.OriginalDragSource = child.Parent;
|
||||
splitView.PerformDrop( other, dropInfo, mousePosition );
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds the the second window as a tab at the end of the first window tab list
|
||||
/// </summary>
|
||||
/// <param name="existingWindow"></param>
|
||||
/// <param name="newWindow"></param>
|
||||
public static void AddTab( this EditorWindow existingWindow, EditorWindow newWindow )
|
||||
{
|
||||
var parent = new R_EditorWindow( existingWindow );
|
||||
var child = new R_EditorWindow( newWindow );
|
||||
var dockArea = new R_DockArea( parent.Parent );
|
||||
dockArea.OriginalDragSource = child.Parent;
|
||||
dockArea.AddTab( newWindow );
|
||||
}
|
||||
|
||||
private static Vector2 GetFakeMousePosition( EditorWindow wnd, DockPosition position )
|
||||
{
|
||||
Vector2 mousePosition = Vector2.zero;
|
||||
|
||||
// The 20 is required to make the docking work.
|
||||
// Smaller values might not work when faking the mouse position.
|
||||
switch ( position )
|
||||
{
|
||||
case DockPosition.Left:
|
||||
mousePosition = new Vector2( 20, wnd.position.size.y / 2 );
|
||||
break;
|
||||
case DockPosition.Top:
|
||||
mousePosition = new Vector2( wnd.position.size.x / 2, 20 );
|
||||
break;
|
||||
case DockPosition.Right:
|
||||
mousePosition = new Vector2( wnd.position.size.x - 20, wnd.position.size.y / 2 );
|
||||
break;
|
||||
case DockPosition.Bottom:
|
||||
mousePosition = new Vector2( wnd.position.size.x / 2, wnd.position.size.y - 20 );
|
||||
break;
|
||||
}
|
||||
|
||||
return GUIUtility.GUIToScreenPoint( mousePosition );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowHelper.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowHelper.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad6ef05d39dc39e42b8bfe0bdb826b7a
|
||||
timeCreated: 1494336778
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
150
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowsUtil.cs
vendored
Normal file
150
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowsUtil.cs
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
#if UNITY_EDITOR_WIN
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class WindowsUtil
|
||||
{
|
||||
public const int GWL_STYLE = -16; //hex constant for style changing
|
||||
public const int WS_BORDER = 0x00800000; //window with border
|
||||
public const int WS_CAPTION = 0x00C00000; //window with a title bar with border
|
||||
public const int WS_SYSMENU = 0x00080000; //window with no borders etc.
|
||||
public const int WS_MAXIMIZE = 0x01000000;
|
||||
public const int WS_MAXIMIZEBOX = 0x00010000;
|
||||
public const int WS_MINIMIZE = 0x20000000;
|
||||
public const int WS_MINIMIZEBOX = 0x00020000;
|
||||
public const int WS_SIZEBOX = 0x00040000;
|
||||
public const int WS_VISIBLE = 0x10000000;
|
||||
public const int WS_TABSTOP = 0x00010000;
|
||||
public const int WS_CLIPCHILDREN = 0x02000000;
|
||||
public const int WS_CLIPSIBLINGS = 0x04000000;
|
||||
|
||||
[DllImport( "user32.dll", EntryPoint = "SetWindowPos" )]
|
||||
public static extern bool SetWindowPos( System.IntPtr hwnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags );
|
||||
|
||||
public delegate bool EnumWindowsProc( System.IntPtr hWnd, System.IntPtr lParam );
|
||||
|
||||
[DllImport( "user32.dll", CharSet = CharSet.Auto, ExactSpelling = true )]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern int SetWindowLong( IntPtr hWnd, int nIndex, int dwNewLong );
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern int GetWindowLong( IntPtr hWnd, int nIndex );
|
||||
|
||||
[DllImport( "user32.dll", ExactSpelling = true, SetLastError = true )]
|
||||
internal static extern int MapWindowPoints( IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref Rect rect, [MarshalAs( UnmanagedType.U4 )] int cPoints );
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern bool EnumWindows( EnumWindowsProc enumProc, System.IntPtr lParam );
|
||||
|
||||
[DllImport( "user32" )]
|
||||
[return: MarshalAs( UnmanagedType.Bool )]
|
||||
public static extern bool EnumChildWindows( IntPtr window, EnumWindowProc callback, IntPtr lParam );
|
||||
|
||||
public delegate bool EnumWindowProc( IntPtr hwnd, IntPtr lParam );
|
||||
|
||||
[DllImport( "user32.dll", SetLastError = true )]
|
||||
public static extern bool MoveWindow( IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint );
|
||||
|
||||
[DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
|
||||
public static extern int GetWindowThreadProcessId( System.IntPtr handle, out int processId );
|
||||
|
||||
[DllImport( "user32.dll", SetLastError = true )]
|
||||
public static extern IntPtr FindWindowEx( string lpClassName, string lpWindowName );
|
||||
|
||||
// Find window by Caption only. Note you must pass IntPtr.Zero as the first parameter.
|
||||
[DllImport( "user32.dll", EntryPoint = "FindWindow", SetLastError = true )]
|
||||
public static extern IntPtr FindWindowByCaptionEx( IntPtr ZeroOnly, string lpWindowName );
|
||||
|
||||
[DllImport( "user32.dll", SetLastError = true, CharSet = CharSet.Auto )]
|
||||
public static extern int GetClassName( IntPtr hWnd, StringBuilder lpClassName, int nMaxCount );
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern int GetWindowText( System.IntPtr hWnd, StringBuilder text, int nMaxCount );
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern int GetWindowTextLength( System.IntPtr hWnd );
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern IntPtr FindWindowEx( IntPtr parentWindow, IntPtr previousChildWindow, string windowClass, string windowTitle );
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern IntPtr GetActiveWindow();
|
||||
|
||||
[DllImport( "user32.dll" )]
|
||||
public static extern bool GetWindowRect( System.IntPtr hwnd, ref Rect rectangle );
|
||||
|
||||
static public IntPtr[] GetProcessWindows( int processId )
|
||||
{
|
||||
List<IntPtr> output = new List<IntPtr>();
|
||||
IntPtr winPtr = IntPtr.Zero;
|
||||
do
|
||||
{
|
||||
winPtr = FindWindowEx( IntPtr.Zero, winPtr, null, null );
|
||||
int id;
|
||||
GetWindowThreadProcessId( winPtr, out id );
|
||||
if ( id == processId )
|
||||
output.Add( winPtr );
|
||||
} while ( winPtr != IntPtr.Zero );
|
||||
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
public struct Rect
|
||||
{
|
||||
public int Left { get; set; }
|
||||
public int Top { get; set; }
|
||||
public int Right { get; set; }
|
||||
public int Bottom { get; set; }
|
||||
public int Width { get { return Right - Left; } }
|
||||
public int Height { get { return Bottom - Top; } }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "(l: " + Left + ", r: " + Right + ", t: " + Top + ", b: " + Bottom + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetProcessRect( System.Diagnostics.Process process, ref Rect rect )
|
||||
{
|
||||
IntPtr[] winPtrs = WindowsUtil.GetProcessWindows( process.Id );
|
||||
|
||||
for ( int i = 0; i < winPtrs.Length; i++ )
|
||||
{
|
||||
bool gotRect = WindowsUtil.GetWindowRect( winPtrs[ i ], ref rect );
|
||||
if ( gotRect && ( rect.Left != 0 && rect.Top != 0 ) )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SetWindowPosition( int x, int y, int sizeX = 0, int sizeY = 0 )
|
||||
{
|
||||
System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
|
||||
process.Refresh();
|
||||
|
||||
EnumWindows( delegate ( System.IntPtr wnd, System.IntPtr param )
|
||||
{
|
||||
int id;
|
||||
GetWindowThreadProcessId( wnd, out id );
|
||||
if ( id == process.Id )
|
||||
{
|
||||
SetWindowPos( wnd, 0, x, y, sizeX, sizeY, sizeX * sizeY == 0 ? 1 : 0 );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, System.IntPtr.Zero );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowsUtil.cs.meta
vendored
Normal file
12
Assets/ThirdParty/Tools/AmplifyShaderEditor/Plugins/Editor/Utils/WindowsUtil.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84d9a18b60b810c4c894886264a89da0
|
||||
timeCreated: 1559138384
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user