You've already forked FateViewer
Add project files.
This commit is contained in:
@@ -0,0 +1,464 @@
|
||||
// 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<UnityEditor.ShaderUtil.ShaderPropertyType, string> ShaderPropertyToPPSType = new Dictionary<UnityEditor.ShaderUtil.ShaderPropertyType, string>()
|
||||
{
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Float,"FloatParameter"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Range,"FloatParameter"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Vector,"Vector4Parameter"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Color,"ColorParameter"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv,"TextureParameter"}
|
||||
};
|
||||
|
||||
|
||||
public static readonly Dictionary<UnityEditor.ShaderUtil.ShaderPropertyType, string> ShaderPropertyToPPSSet = new Dictionary<UnityEditor.ShaderUtil.ShaderPropertyType, string>()
|
||||
{
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Float,"SetFloat"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Range,"SetFloat"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Vector,"SetVector"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.Color,"SetColor"},
|
||||
{ UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv,"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 = UnityEditor.ShaderUtil.GetPropertyCount( m_currentShader );
|
||||
for( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
//UnityEditor.ShaderUtil.ShaderPropertyType type = UnityEditor.ShaderUtil.GetPropertyType( m_currentShader, i );
|
||||
string name = UnityEditor.ShaderUtil.GetPropertyName( m_currentShader, i );
|
||||
string description = UnityEditor.ShaderUtil.GetPropertyDescription( m_currentShader, 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 = UnityEditor.ShaderUtil.GetPropertyCount( m_currentShader );
|
||||
//string allProperties = string.Empty;
|
||||
int validIds = 0;
|
||||
for( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
UnityEditor.ShaderUtil.ShaderPropertyType type = UnityEditor.ShaderUtil.GetPropertyType( m_currentShader, i );
|
||||
string name = UnityEditor.ShaderUtil.GetPropertyName( m_currentShader, i );
|
||||
//string description = UnityEditor.ShaderUtil.GetPropertyDescription( m_currentShader, i );
|
||||
if( m_excludedProperties.ContainsKey( name ))
|
||||
continue;
|
||||
|
||||
string defaultValue = string.Empty;
|
||||
bool nullPointerCheck = false;
|
||||
switch( type )
|
||||
{
|
||||
case UnityEditor.ShaderUtil.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 UnityEditor.ShaderUtil.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 UnityEditor.ShaderUtil.ShaderPropertyType.Float:
|
||||
{
|
||||
float value = m_dummyMaterial.GetFloat( name );
|
||||
defaultValue = "value = " + value + "f";
|
||||
}
|
||||
break;
|
||||
case UnityEditor.ShaderUtil.ShaderPropertyType.Range:
|
||||
{
|
||||
float value = m_dummyMaterial.GetFloat( name );
|
||||
defaultValue = "value = " + value + "f";
|
||||
}
|
||||
break;
|
||||
case UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv:
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccaa3765dae023d4b8657544c1aeef4a
|
||||
timeCreated: 1550254201
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,679 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public enum ASESRPVersions
|
||||
{
|
||||
ASE_SRP_3_0_0 = 030000,
|
||||
ASE_SRP_3_1_0 = 030100,
|
||||
ASE_SRP_3_3_0 = 030300,
|
||||
ASE_SRP_4_1_0 = 040100,
|
||||
ASE_SRP_4_2_0 = 040200,
|
||||
ASE_SRP_4_3_0 = 040300,
|
||||
ASE_SRP_4_6_0 = 040600,
|
||||
ASE_SRP_4_8_0 = 040800,
|
||||
ASE_SRP_4_9_0 = 040900,
|
||||
ASE_SRP_4_10_0 = 041000,
|
||||
ASE_SRP_5_7_2 = 050702,
|
||||
ASE_SRP_5_8_2 = 050802,
|
||||
ASE_SRP_5_9_0 = 050900,
|
||||
ASE_SRP_5_10_0 = 051000,
|
||||
ASE_SRP_5_13_0 = 051300,
|
||||
ASE_SRP_5_16_1 = 051601,
|
||||
ASE_SRP_6_9_0 = 060900,
|
||||
ASE_SRP_6_9_1 = 060901,
|
||||
ASE_SRP_6_9_2 = 060902,
|
||||
ASE_SRP_7_0_1 = 070001,
|
||||
ASE_SRP_7_1_1 = 070101,
|
||||
ASE_SRP_7_1_2 = 070102,
|
||||
ASE_SRP_7_1_5 = 070105,
|
||||
ASE_SRP_7_1_6 = 070106,
|
||||
ASE_SRP_7_1_7 = 070107,
|
||||
ASE_SRP_7_1_8 = 070108,
|
||||
ASE_SRP_7_2_0 = 070200,
|
||||
ASE_SRP_7_2_1 = 070201,
|
||||
ASE_SRP_7_3_1 = 070301,
|
||||
ASE_SRP_7_4_1 = 070401,
|
||||
ASE_SRP_7_4_2 = 070402,
|
||||
ASE_SRP_7_4_3 = 070403,
|
||||
ASE_SRP_7_5_1 = 070501,
|
||||
ASE_SRP_7_5_2 = 070502,
|
||||
ASE_SRP_7_5_3 = 070503,
|
||||
ASE_SRP_8_2_0 = 080200,
|
||||
ASE_SRP_8_3_1 = 080301,
|
||||
ASE_SRP_9_0_0 = 090000,
|
||||
ASE_SRP_10_0_0 = 100000,
|
||||
ASE_SRP_10_1_0 = 100100,
|
||||
ASE_SRP_10_2_2 = 100202,
|
||||
ASE_SRP_10_3_1 = 100301,
|
||||
ASE_SRP_10_3_2 = 100302,
|
||||
ASE_SRP_RECENT = 999999
|
||||
}
|
||||
|
||||
public enum ASEImportState
|
||||
{
|
||||
None,
|
||||
Lightweight,
|
||||
HD,
|
||||
Both
|
||||
}
|
||||
|
||||
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 } );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public static class ASEPackageManagerHelper
|
||||
{
|
||||
private static string LightweightNewVersionDetected = "A new Lighweight RP version was detected and new templates are being imported.\n" +
|
||||
"Please hit the Update button on your ASE canvas to recompile your shader under the newest version.";
|
||||
|
||||
private static string HDNewVersionDetected = "A new HD RP version was detected and new templates are being imported.\n" +
|
||||
"Please hit the Update button on your ASE canvas to recompile your shader under the newest version.";
|
||||
|
||||
private static string HDPackageId = "com.unity.render-pipelines.high-definition";
|
||||
private static string LWPackageId = "com.unity.render-pipelines.lightweight";
|
||||
private static string UniversalPackageId = "com.unity.render-pipelines.universal";
|
||||
private static string HDEditorPrefsId = "ASEHDEditorPrefsId";
|
||||
private static string LWEditorPrefsId = "ASELightweigthEditorPrefsId ";
|
||||
|
||||
private static string URPTemplateVersion = "ASEURPtemplate" + Application.productName;
|
||||
private static string HDRPTemplateVersion = "ASEHDRPtemplate" + Application.productName;
|
||||
|
||||
private static string SPKeywordFormat = "ASE_SRP_VERSION {0}";
|
||||
private static ListRequest m_packageListRequest = null;
|
||||
private static UnityEditor.PackageManager.PackageInfo m_lwPackageInfo;
|
||||
private static UnityEditor.PackageManager.PackageInfo m_hdPackageInfo;
|
||||
|
||||
// V4.8.0 and bellow
|
||||
// HD
|
||||
private static readonly string[] GetNormalWSFunc =
|
||||
{
|
||||
"inline void GetNormalWS( FragInputs input, float3 normalTS, out float3 normalWS, float3 doubleSidedConstants )\n",
|
||||
"{\n",
|
||||
"\tGetNormalWS( input, normalTS, normalWS );\n",
|
||||
"}\n"
|
||||
};
|
||||
|
||||
// v4.6.0 and below
|
||||
private static readonly string[] BuildWordTangentFunc =
|
||||
{
|
||||
"float3x3 BuildWorldToTangent(float4 tangentWS, float3 normalWS)\n",
|
||||
"{\n",
|
||||
"\tfloat3 unnormalizedNormalWS = normalWS;\n",
|
||||
"\tfloat renormFactor = 1.0 / length(unnormalizedNormalWS);\n",
|
||||
"\tfloat3x3 worldToTangent = CreateWorldToTangent(unnormalizedNormalWS, tangentWS.xyz, tangentWS.w > 0.0 ? 1.0 : -1.0);\n",
|
||||
"\tworldToTangent[0] = worldToTangent[0] * renormFactor;\n",
|
||||
"\tworldToTangent[1] = worldToTangent[1] * renormFactor;\n",
|
||||
"\tworldToTangent[2] = worldToTangent[2] * renormFactor;\n",
|
||||
"\treturn worldToTangent;\n",
|
||||
"}\n"
|
||||
};
|
||||
|
||||
private static bool m_lateImport = false;
|
||||
private static string m_latePackageToImport;
|
||||
|
||||
private static bool m_requireUpdateList = false;
|
||||
private static ASEImportState m_importingPackage = ASEImportState.None;
|
||||
|
||||
|
||||
private static ASESRPVersions m_currentHDVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
private static ASESRPVersions m_currentLWVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
|
||||
private static int m_urpTemplateVersion = 18;
|
||||
private static int m_hdrpTemplateVersion = 14;
|
||||
|
||||
private static Dictionary<string, ASESRPVersions> m_srpVersionConverter = new Dictionary<string, ASESRPVersions>()
|
||||
{
|
||||
{"3.0.0-preview", ASESRPVersions.ASE_SRP_3_0_0},
|
||||
{"3.1.0-preview", ASESRPVersions.ASE_SRP_3_1_0},
|
||||
{"3.3.0-preview", ASESRPVersions.ASE_SRP_3_3_0},
|
||||
{"4.1.0-preview", ASESRPVersions.ASE_SRP_4_1_0},
|
||||
{"4.2.0-preview", ASESRPVersions.ASE_SRP_4_2_0},
|
||||
{"4.3.0-preview", ASESRPVersions.ASE_SRP_4_3_0},
|
||||
{"4.6.0-preview", ASESRPVersions.ASE_SRP_4_6_0},
|
||||
{"4.8.0-preview", ASESRPVersions.ASE_SRP_4_8_0},
|
||||
{"4.9.0-preview", ASESRPVersions.ASE_SRP_4_9_0},
|
||||
{"4.10.0-preview", ASESRPVersions.ASE_SRP_4_10_0},
|
||||
{"5.7.2-preview", ASESRPVersions.ASE_SRP_5_7_2},
|
||||
{"5.7.2", ASESRPVersions.ASE_SRP_5_7_2},
|
||||
{"5.8.2-preview", ASESRPVersions.ASE_SRP_5_8_2},
|
||||
{"5.8.2", ASESRPVersions.ASE_SRP_5_8_2},
|
||||
{"5.9.0-preview", ASESRPVersions.ASE_SRP_5_9_0},
|
||||
{"5.9.0", ASESRPVersions.ASE_SRP_5_9_0},
|
||||
{"5.10.0-preview", ASESRPVersions.ASE_SRP_5_10_0},
|
||||
{"5.10.0", ASESRPVersions.ASE_SRP_5_10_0},
|
||||
{"5.13.0-preview", ASESRPVersions.ASE_SRP_5_13_0},
|
||||
{"5.13.0", ASESRPVersions.ASE_SRP_5_13_0},
|
||||
{"5.16.1-preview", ASESRPVersions.ASE_SRP_5_16_1},
|
||||
{"5.16.1", ASESRPVersions.ASE_SRP_5_16_1},
|
||||
{"6.9.0", ASESRPVersions.ASE_SRP_6_9_0},
|
||||
{"6.9.0-preview", ASESRPVersions.ASE_SRP_6_9_0},
|
||||
{"6.9.1", ASESRPVersions.ASE_SRP_6_9_1},
|
||||
{"6.9.1-preview", ASESRPVersions.ASE_SRP_6_9_1},
|
||||
{"6.9.2", ASESRPVersions.ASE_SRP_6_9_2},
|
||||
{"6.9.2-preview", ASESRPVersions.ASE_SRP_6_9_2},
|
||||
{"7.0.1", ASESRPVersions.ASE_SRP_7_0_1},
|
||||
{"7.0.1-preview", ASESRPVersions.ASE_SRP_7_0_1},
|
||||
{"7.1.1", ASESRPVersions.ASE_SRP_7_1_1},
|
||||
{"7.1.1-preview", ASESRPVersions.ASE_SRP_7_1_1},
|
||||
{"7.1.2", ASESRPVersions.ASE_SRP_7_1_2},
|
||||
{"7.1.2-preview", ASESRPVersions.ASE_SRP_7_1_2},
|
||||
{"7.1.5", ASESRPVersions.ASE_SRP_7_1_5},
|
||||
{"7.1.5-preview", ASESRPVersions.ASE_SRP_7_1_5},
|
||||
{"7.1.6", ASESRPVersions.ASE_SRP_7_1_6},
|
||||
{"7.1.6-preview", ASESRPVersions.ASE_SRP_7_1_6},
|
||||
{"7.1.7", ASESRPVersions.ASE_SRP_7_1_7},
|
||||
{"7.1.7-preview", ASESRPVersions.ASE_SRP_7_1_7},
|
||||
{"7.1.8", ASESRPVersions.ASE_SRP_7_1_8},
|
||||
{"7.1.8-preview", ASESRPVersions.ASE_SRP_7_1_8},
|
||||
{"7.2.0", ASESRPVersions.ASE_SRP_7_2_0},
|
||||
{"7.2.0-preview", ASESRPVersions.ASE_SRP_7_2_0},
|
||||
{"7.2.1", ASESRPVersions.ASE_SRP_7_2_1},
|
||||
{"7.2.1-preview", ASESRPVersions.ASE_SRP_7_2_1},
|
||||
{"7.3.1", ASESRPVersions.ASE_SRP_7_3_1},
|
||||
{"7.3.1-preview", ASESRPVersions.ASE_SRP_7_3_1},
|
||||
{"7.4.1", ASESRPVersions.ASE_SRP_7_4_1},
|
||||
{"7.4.1-preview", ASESRPVersions.ASE_SRP_7_4_1},
|
||||
{"7.4.2", ASESRPVersions.ASE_SRP_7_4_2},
|
||||
{"7.4.2-preview", ASESRPVersions.ASE_SRP_7_4_2},
|
||||
{"7.4.3", ASESRPVersions.ASE_SRP_7_4_3},
|
||||
{"7.4.3-preview", ASESRPVersions.ASE_SRP_7_4_3},
|
||||
{"7.5.1", ASESRPVersions.ASE_SRP_7_5_1},
|
||||
{"7.5.1-preview", ASESRPVersions.ASE_SRP_7_5_1},
|
||||
{"7.5.2", ASESRPVersions.ASE_SRP_7_5_2},
|
||||
{"7.5.2-preview", ASESRPVersions.ASE_SRP_7_5_2},
|
||||
{"7.5.3", ASESRPVersions.ASE_SRP_7_5_3},
|
||||
{"7.5.3-preview", ASESRPVersions.ASE_SRP_7_5_3},
|
||||
{"8.2.0", ASESRPVersions.ASE_SRP_8_2_0},
|
||||
{"8.2.0-preview", ASESRPVersions.ASE_SRP_8_2_0},
|
||||
{"8.3.1", ASESRPVersions.ASE_SRP_8_3_1},
|
||||
{"8.3.1-preview", ASESRPVersions.ASE_SRP_8_3_1},
|
||||
{"9.0.0", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"9.0.0-preview.13", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"9.0.0-preview.14", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"9.0.0-preview.33", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"9.0.0-preview.35", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"9.0.0-preview.54", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"9.0.0-preview.55", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"9.0.0-preview.71", ASESRPVersions.ASE_SRP_9_0_0},
|
||||
{"10.0.0-preview.26", ASESRPVersions.ASE_SRP_10_0_0},
|
||||
{"10.0.0-preview.27", ASESRPVersions.ASE_SRP_10_0_0},
|
||||
{"10.1.0", ASESRPVersions.ASE_SRP_10_1_0},
|
||||
{"10.2.2", ASESRPVersions.ASE_SRP_10_2_2},
|
||||
{"10.3.1", ASESRPVersions.ASE_SRP_10_3_1},
|
||||
{"10.3.2", ASESRPVersions.ASE_SRP_10_3_2},
|
||||
};
|
||||
|
||||
|
||||
|
||||
private static Dictionary<ASESRPVersions, string> m_srpToASEPackageLW = new Dictionary<ASESRPVersions, string>()
|
||||
{
|
||||
{ASESRPVersions.ASE_SRP_3_0_0, "b53d2f3b156ff104f90d4d7693d769c8"},
|
||||
{ASESRPVersions.ASE_SRP_3_1_0, "b53d2f3b156ff104f90d4d7693d769c8"},
|
||||
{ASESRPVersions.ASE_SRP_3_3_0, "b53d2f3b156ff104f90d4d7693d769c8"},
|
||||
{ASESRPVersions.ASE_SRP_4_1_0, "3e8eabcfae1e5aa4397de89fedeb48db"},
|
||||
{ASESRPVersions.ASE_SRP_4_2_0, "3e8eabcfae1e5aa4397de89fedeb48db"},
|
||||
{ASESRPVersions.ASE_SRP_4_3_0, "3e8eabcfae1e5aa4397de89fedeb48db"},
|
||||
{ASESRPVersions.ASE_SRP_4_6_0, "3e8eabcfae1e5aa4397de89fedeb48db"},
|
||||
{ASESRPVersions.ASE_SRP_4_8_0, "3e8eabcfae1e5aa4397de89fedeb48db"},
|
||||
{ASESRPVersions.ASE_SRP_4_9_0, "3e8eabcfae1e5aa4397de89fedeb48db"},
|
||||
{ASESRPVersions.ASE_SRP_4_10_0, "3e8eabcfae1e5aa4397de89fedeb48db"},
|
||||
{ASESRPVersions.ASE_SRP_5_7_2, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_5_8_2, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_5_9_0, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_5_10_0, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_5_13_0, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_5_16_1, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_6_9_0, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_6_9_1, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_6_9_2, "4c816894a3147d343891060451241bfe"},
|
||||
{ASESRPVersions.ASE_SRP_7_0_1, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_1, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_2, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_5, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_6, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_7, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_8, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_2_0, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_2_1, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_3_1, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_4_1, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_4_2, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_4_3, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_5_1, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_5_2, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_7_5_3, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_8_2_0, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_8_3_1, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_9_0_0, "f54faaaf4faf8784183ede7f87dfeb23"},
|
||||
{ASESRPVersions.ASE_SRP_10_0_0, "57fcea0ed8b5eb347923c4c21fa31b57"},
|
||||
{ASESRPVersions.ASE_SRP_10_1_0, "57fcea0ed8b5eb347923c4c21fa31b57"},
|
||||
{ASESRPVersions.ASE_SRP_10_2_2, "57fcea0ed8b5eb347923c4c21fa31b57"},
|
||||
{ASESRPVersions.ASE_SRP_10_3_1, "57fcea0ed8b5eb347923c4c21fa31b57"},
|
||||
{ASESRPVersions.ASE_SRP_10_3_2, "57fcea0ed8b5eb347923c4c21fa31b57"},
|
||||
{ASESRPVersions.ASE_SRP_RECENT, "57fcea0ed8b5eb347923c4c21fa31b57"}
|
||||
};
|
||||
|
||||
private static Dictionary<ASESRPVersions, string> m_srpToASEPackageHD = new Dictionary<ASESRPVersions, string>()
|
||||
{
|
||||
{ASESRPVersions.ASE_SRP_3_0_0, "4dc1afbcc68875c4780502f5e6b80158"},
|
||||
{ASESRPVersions.ASE_SRP_3_1_0, "4dc1afbcc68875c4780502f5e6b80158"},
|
||||
{ASESRPVersions.ASE_SRP_3_3_0, "4dc1afbcc68875c4780502f5e6b80158"},
|
||||
{ASESRPVersions.ASE_SRP_4_1_0, "5d615bf612f33364e96fb9fd2959ae9c"},
|
||||
{ASESRPVersions.ASE_SRP_4_2_0, "5d615bf612f33364e96fb9fd2959ae9c"},
|
||||
{ASESRPVersions.ASE_SRP_4_3_0, "5d615bf612f33364e96fb9fd2959ae9c"},
|
||||
{ASESRPVersions.ASE_SRP_4_6_0, "5d615bf612f33364e96fb9fd2959ae9c"},
|
||||
{ASESRPVersions.ASE_SRP_4_8_0, "5d615bf612f33364e96fb9fd2959ae9c"},
|
||||
{ASESRPVersions.ASE_SRP_4_9_0, "5d615bf612f33364e96fb9fd2959ae9c"},
|
||||
{ASESRPVersions.ASE_SRP_4_10_0, "5d615bf612f33364e96fb9fd2959ae9c"},
|
||||
{ASESRPVersions.ASE_SRP_5_7_2, "f51b7b861facbc3429fcc5f1f6f91183"},
|
||||
{ASESRPVersions.ASE_SRP_5_8_2, "2d7fe4f7c19e90f41b893bc01fc17230"},
|
||||
{ASESRPVersions.ASE_SRP_5_9_0, "2d7fe4f7c19e90f41b893bc01fc17230"},
|
||||
{ASESRPVersions.ASE_SRP_5_10_0, "2d7fe4f7c19e90f41b893bc01fc17230"},
|
||||
{ASESRPVersions.ASE_SRP_5_13_0, "2d7fe4f7c19e90f41b893bc01fc17230"},
|
||||
{ASESRPVersions.ASE_SRP_5_16_1, "2d7fe4f7c19e90f41b893bc01fc17230"},
|
||||
{ASESRPVersions.ASE_SRP_6_9_0, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_6_9_1, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_6_9_2, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_7_0_1, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_1, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_2, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_5, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_6, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_7, "e137dba02f4d0f542ab09dcedea27314"},
|
||||
{ASESRPVersions.ASE_SRP_7_1_8, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_2_0, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_2_1, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_3_1, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_4_1, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_4_2, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_4_3, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_5_1, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_5_2, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_7_5_3, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_8_2_0, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_8_3_1, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_9_0_0, "3aeabe705b70b154ea99893f91351100"},
|
||||
{ASESRPVersions.ASE_SRP_10_0_0, "9a5e61a8b3421b944863d0946e32da0a"},
|
||||
{ASESRPVersions.ASE_SRP_10_1_0, "9a5e61a8b3421b944863d0946e32da0a"},
|
||||
{ASESRPVersions.ASE_SRP_10_2_2, "9a5e61a8b3421b944863d0946e32da0a"},
|
||||
{ASESRPVersions.ASE_SRP_10_3_1, "9a5e61a8b3421b944863d0946e32da0a"},
|
||||
{ASESRPVersions.ASE_SRP_10_3_2, "9a5e61a8b3421b944863d0946e32da0a"},
|
||||
{ASESRPVersions.ASE_SRP_RECENT, "9a5e61a8b3421b944863d0946e32da0a"}
|
||||
|
||||
};
|
||||
|
||||
private static Shader m_lateShader;
|
||||
private static Material m_lateMaterial;
|
||||
private static AmplifyShaderFunction m_lateShaderFunction;
|
||||
|
||||
|
||||
public static void RequestInfo()
|
||||
{
|
||||
if( !m_requireUpdateList && m_importingPackage == ASEImportState.None )
|
||||
{
|
||||
m_requireUpdateList = true;
|
||||
m_packageListRequest = UnityEditor.PackageManager.Client.List( true );
|
||||
}
|
||||
}
|
||||
|
||||
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 void StartImporting( string packagePath )
|
||||
{
|
||||
if( !Preferences.GlobalAutoSRP )
|
||||
{
|
||||
m_importingPackage = ASEImportState.None;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
AssetDatabase.importPackageCancelled += CancelledPackageImport;
|
||||
AssetDatabase.importPackageCompleted += CompletedPackageImport;
|
||||
AssetDatabase.importPackageFailed += FailedPackageImport;
|
||||
AssetDatabase.ImportPackage( packagePath, false );
|
||||
//AssetDatabaseEX.ImportPackageImmediately( packagePath );
|
||||
}
|
||||
|
||||
public static void FinishImporter()
|
||||
{
|
||||
m_importingPackage = ASEImportState.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()
|
||||
{
|
||||
Preferences.LoadDefaults();
|
||||
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()
|
||||
{
|
||||
Preferences.LoadDefaults();
|
||||
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()
|
||||
{
|
||||
Preferences.LoadDefaults();
|
||||
Update();
|
||||
if( IsProcessing )
|
||||
{
|
||||
EditorApplication.delayCall += LateShaderFunctionOpener;
|
||||
}
|
||||
else
|
||||
{
|
||||
AmplifyShaderEditorWindow.LoadShaderFunctionToASE( m_lateShaderFunction, false );
|
||||
m_lateShaderFunction = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
//if( Application.isPlaying )
|
||||
// return;
|
||||
|
||||
CheckLatePackageImport();
|
||||
//if( m_lwPackageInfo != null )
|
||||
//{
|
||||
// if( m_srpVersionConverter[ m_lwPackageInfo.version ] != m_currentLWVersion )
|
||||
// {
|
||||
// m_currentLWVersion = m_srpVersionConverter[ m_lwPackageInfo.version ];
|
||||
// EditorPrefs.SetInt( LWEditorPrefsId, (int)m_currentLWVersion );
|
||||
// m_importingPackage = ASEImportState.Lightweight;
|
||||
// string packagePath = AssetDatabase.GUIDToAssetPath( m_srpToASEPackageLW[ m_currentLWVersion ] );
|
||||
// StartImporting( packagePath );
|
||||
// }
|
||||
//}
|
||||
|
||||
//if( m_hdPackageInfo != null )
|
||||
//{
|
||||
// if( m_srpVersionConverter[ m_hdPackageInfo.version ] != m_currentHDVersion )
|
||||
// {
|
||||
// m_currentHDVersion = m_srpVersionConverter[ m_hdPackageInfo.version ];
|
||||
// EditorPrefs.SetInt( HDEditorPrefsId, (int)m_currentHDVersion );
|
||||
// m_importingPackage = ASEImportState.HD;
|
||||
// string packagePath = AssetDatabase.GUIDToAssetPath( m_srpToASEPackageHD[ m_currentHDVersion ] );
|
||||
// StartImporting( packagePath );
|
||||
// }
|
||||
//}
|
||||
|
||||
if( m_requireUpdateList && m_importingPackage == ASEImportState.None )
|
||||
{
|
||||
if( m_packageListRequest != null && m_packageListRequest.IsCompleted )
|
||||
{
|
||||
m_requireUpdateList = false;
|
||||
foreach( UnityEditor.PackageManager.PackageInfo pi in m_packageListRequest.Result )
|
||||
{
|
||||
if( pi.name.Equals( LWPackageId ) )
|
||||
{
|
||||
m_currentLWVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
m_lwPackageInfo = pi;
|
||||
ASESRPVersions oldVersion = (ASESRPVersions)EditorPrefs.GetInt( LWEditorPrefsId );
|
||||
if( m_srpVersionConverter.ContainsKey( pi.version ) )
|
||||
{
|
||||
m_currentLWVersion = m_srpVersionConverter[ pi.version ];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentLWVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
}
|
||||
|
||||
EditorPrefs.SetInt( LWEditorPrefsId, (int)m_currentLWVersion );
|
||||
bool foundNewVersion = oldVersion != m_currentLWVersion;
|
||||
if( !File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.LightweigthPBRGUID ) ) ||
|
||||
!File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.LightweigthUnlitGUID ) ) ||
|
||||
foundNewVersion
|
||||
)
|
||||
{
|
||||
if( foundNewVersion )
|
||||
Debug.Log( LightweightNewVersionDetected );
|
||||
|
||||
m_importingPackage = ASEImportState.Lightweight;
|
||||
string guid = m_srpToASEPackageLW.ContainsKey( m_currentLWVersion ) ? m_srpToASEPackageLW[ m_currentLWVersion ] : m_srpToASEPackageLW[ ASESRPVersions.ASE_SRP_RECENT ];
|
||||
string packagePath = AssetDatabase.GUIDToAssetPath( guid );
|
||||
StartImporting( packagePath );
|
||||
}
|
||||
}
|
||||
|
||||
if( pi.name.Equals( UniversalPackageId ) )
|
||||
{
|
||||
m_currentLWVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
m_lwPackageInfo = pi;
|
||||
ASESRPVersions oldVersion = (ASESRPVersions)EditorPrefs.GetInt( LWEditorPrefsId );
|
||||
if( m_srpVersionConverter.ContainsKey( pi.version ) )
|
||||
{
|
||||
m_currentLWVersion = m_srpVersionConverter[ pi.version ];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentLWVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
}
|
||||
|
||||
EditorPrefs.SetInt( LWEditorPrefsId, (int)m_currentLWVersion );
|
||||
bool foundNewVersion = oldVersion != m_currentLWVersion;
|
||||
|
||||
int urpVersion = EditorPrefs.GetInt( URPTemplateVersion, m_urpTemplateVersion );
|
||||
if( urpVersion < m_urpTemplateVersion )
|
||||
foundNewVersion = true;
|
||||
EditorPrefs.SetInt( URPTemplateVersion, m_urpTemplateVersion );
|
||||
|
||||
if( !File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.UniversalPBRGUID ) ) ||
|
||||
!File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.UniversalUnlitGUID ) ) ||
|
||||
foundNewVersion
|
||||
)
|
||||
{
|
||||
if( foundNewVersion )
|
||||
Debug.Log( LightweightNewVersionDetected );
|
||||
|
||||
m_importingPackage = ASEImportState.Lightweight;
|
||||
string guid = m_srpToASEPackageLW.ContainsKey( m_currentLWVersion ) ? m_srpToASEPackageLW[ m_currentLWVersion ] : m_srpToASEPackageLW[ ASESRPVersions.ASE_SRP_RECENT ];
|
||||
string packagePath = AssetDatabase.GUIDToAssetPath( guid );
|
||||
StartImporting( packagePath );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( pi.name.Equals( HDPackageId ) )
|
||||
{
|
||||
m_currentHDVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
m_hdPackageInfo = pi;
|
||||
ASESRPVersions oldVersion = (ASESRPVersions)EditorPrefs.GetInt( HDEditorPrefsId );
|
||||
if( m_srpVersionConverter.ContainsKey( pi.version ) )
|
||||
{
|
||||
m_currentHDVersion = m_srpVersionConverter[ pi.version ];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentHDVersion = ASESRPVersions.ASE_SRP_RECENT;
|
||||
}
|
||||
|
||||
EditorPrefs.SetInt( HDEditorPrefsId, (int)m_currentHDVersion );
|
||||
bool foundNewVersion = oldVersion != m_currentHDVersion;
|
||||
|
||||
int hdrpVersion = EditorPrefs.GetInt( HDRPTemplateVersion, m_hdrpTemplateVersion );
|
||||
if( hdrpVersion < m_hdrpTemplateVersion )
|
||||
foundNewVersion = true;
|
||||
EditorPrefs.SetInt( HDRPTemplateVersion, m_hdrpTemplateVersion );
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
if( !File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.HDNewLitGUID ) ) ||
|
||||
!File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.HDNewPBRGUID ) ) ||
|
||||
!File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.HDNewUnlitGUID ) ) ||
|
||||
#else
|
||||
if( !File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.HDLitGUID ) ) ||
|
||||
!File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.HDPBRGUID ) ) ||
|
||||
!File.Exists( AssetDatabase.GUIDToAssetPath( TemplatesManager.HDUnlitGUID ) ) ||
|
||||
#endif
|
||||
foundNewVersion
|
||||
)
|
||||
{
|
||||
if( foundNewVersion )
|
||||
Debug.Log( HDNewVersionDetected );
|
||||
|
||||
m_importingPackage = m_importingPackage == ASEImportState.Lightweight ? ASEImportState.Both : ASEImportState.HD;
|
||||
string guid = m_srpToASEPackageHD.ContainsKey( m_currentHDVersion ) ? m_srpToASEPackageHD[ m_currentHDVersion ] : m_srpToASEPackageHD[ ASESRPVersions.ASE_SRP_RECENT ];
|
||||
string packagePath = AssetDatabase.GUIDToAssetPath( guid );
|
||||
StartImporting( packagePath );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetSRPInfoOnDataCollector( ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
Preferences.LoadDefaults();
|
||||
if( m_requireUpdateList )
|
||||
Update();
|
||||
|
||||
if( dataCollector.CurrentSRPType == TemplateSRPType.HD )
|
||||
{
|
||||
dataCollector.AddToDirectives( string.Format( SPKeywordFormat, (int)m_currentHDVersion ) ,-1, AdditionalLineType.Define );
|
||||
if( m_currentHDVersion < ASESRPVersions.ASE_SRP_4_9_0 )
|
||||
{
|
||||
dataCollector.AddFunction( GetNormalWSFunc[ 0 ], GetNormalWSFunc, false );
|
||||
}
|
||||
|
||||
if( m_currentHDVersion < ASESRPVersions.ASE_SRP_4_8_0 )
|
||||
{
|
||||
dataCollector.AddFunction( BuildWordTangentFunc[ 0 ], BuildWordTangentFunc, false );
|
||||
}
|
||||
}
|
||||
|
||||
if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
|
||||
dataCollector.AddToDirectives( string.Format( SPKeywordFormat, (int)m_currentLWVersion ), -1, AdditionalLineType.Define );
|
||||
}
|
||||
public static ASESRPVersions CurrentHDVersion { get { return m_currentHDVersion; } }
|
||||
public static ASESRPVersions CurrentLWVersion { get { return m_currentLWVersion; } }
|
||||
public static bool CheckImporter { get { return m_importingPackage != ASEImportState.None; } }
|
||||
public static bool IsProcessing { get { return m_requireUpdateList && m_importingPackage == ASEImportState.None; } }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f48de3e34ed250945ba8c16d98b8ca0e
|
||||
timeCreated: 1548881060
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,495 @@
|
||||
// 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;
|
||||
|
||||
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 OLDHighDefinitionGUID = "dff05fea7446d7b4e9029bfab77455d2";
|
||||
private static readonly string LightWeightGUID = "6ecbfd0a046659943a69328c98ff0442";
|
||||
private static readonly string OLDLightWeightGUID = "f7c4e22642de60d448f4e4809190f7b1";
|
||||
|
||||
private static readonly string IconGUID = "2c6536772776dd84f872779990273bfc";
|
||||
|
||||
public static readonly string ChangelogURL = "http://amplify.pt/Banner/ASEchangelog.json";
|
||||
|
||||
private static readonly string ManualURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Manual";
|
||||
private static readonly string BasicURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Tutorials#Official_-_Basics";
|
||||
private static readonly string BeginnerURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Tutorials#Official_-_Beginner_Series";
|
||||
private static readonly string NodesURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Nodes";
|
||||
private static readonly string SRPURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Scriptable_Rendering_Pipeline";
|
||||
private static readonly string FunctionsURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Manual#Shader_Functions";
|
||||
private static readonly string TemplatesURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Templates";
|
||||
private static readonly string APIURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/API";
|
||||
|
||||
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 offitial 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 static readonly string DownArrow = "\u25BC";
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
private int DownButtonSize = 22;
|
||||
#else
|
||||
private int DownButtonSize = 21;
|
||||
#endif
|
||||
|
||||
Vector2 m_scrollPosition = Vector2.zero;
|
||||
Preferences.ShowOption m_startup = Preferences.ShowOption.Never;
|
||||
bool m_showLWRP = false;
|
||||
bool m_showHDRP = false;
|
||||
|
||||
[NonSerialized]
|
||||
Texture packageIcon = null;
|
||||
[NonSerialized]
|
||||
Texture textIcon = null;
|
||||
[NonSerialized]
|
||||
Texture webIcon = null;
|
||||
|
||||
GUIContent HDRPbutton = null;
|
||||
GUIContent HDRPOLDbutton = null;
|
||||
GUIContent URPbutton = null;
|
||||
GUIContent LWRPbutton = null;
|
||||
GUIContent LWRPOLDbutton = 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 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 void OnEnable()
|
||||
{
|
||||
rt = new RenderTexture( 16, 16, 0 );
|
||||
rt.Create();
|
||||
|
||||
m_startup = (Preferences.ShowOption)EditorPrefs.GetInt( Preferences.PrefStartUp, 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 HD/URP/LW use", textIcon );
|
||||
Functionsbutton = new GUIContent( " Shader Functions", textIcon );
|
||||
Templatesbutton = new GUIContent( " Shader Templates", textIcon );
|
||||
APIbutton = new GUIContent( " Node API", textIcon );
|
||||
}
|
||||
|
||||
if( packageIcon == null )
|
||||
{
|
||||
packageIcon = EditorGUIUtility.IconContent( "BuildSettings.Editor.Small" ).image;
|
||||
HDRPbutton = new GUIContent( " HDRP Samples", packageIcon );
|
||||
HDRPOLDbutton = new GUIContent( " HDRP Samples 6.X.X", packageIcon );
|
||||
URPbutton = new GUIContent( " URP Samples", packageIcon );
|
||||
LWRPbutton = new GUIContent( " LWRP Samples 6.X.X", packageIcon );
|
||||
LWRPOLDbutton = new GUIContent( " LWRP Samples 3.X.X", 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 )
|
||||
{
|
||||
lastUpdate = changelog.text.Substring( 0, changelog.text.IndexOf( "\nv", 50 ) );// + "\n...";
|
||||
lastUpdate = lastUpdate.Replace( " *", " \u25CB" );
|
||||
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, () =>
|
||||
{
|
||||
var temp = ChangeLogInfo.CreateFromJSON( www.downloadHandler.text );
|
||||
if( temp != null && temp.Version >= m_changeLog.Version )
|
||||
{
|
||||
m_changeLog = temp;
|
||||
}
|
||||
// improve this later
|
||||
int major = m_changeLog.Version / 10000;
|
||||
int minor = ( m_changeLog.Version / 1000 ) - major * 10;
|
||||
int release = ( m_changeLog.Version / 100 ) - major * 100 - minor * 10;
|
||||
int revision = ( ( m_changeLog.Version / 10 ) - major * 1000 - minor * 100 - release * 10 ) + ( m_changeLog.Version - major * 10000 - minor * 1000 - release * 100 );
|
||||
m_newVersion = major + "." + minor + "." + release + "r" + 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 ) )
|
||||
ImportSample( HDRPbutton.text, HighDefinitionGUID );
|
||||
|
||||
if( GUILayout.Button( DownArrow, m_buttonRightStyle, GUILayout.Width( DownButtonSize ), GUILayout.Height( DownButtonSize ) ) )
|
||||
{
|
||||
m_showHDRP = !m_showHDRP;
|
||||
m_showLWRP = false;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if( m_showHDRP )
|
||||
{
|
||||
if( GUILayout.Button( HDRPOLDbutton, m_minibuttonStyle ) )
|
||||
ImportSample( HDRPOLDbutton.text, OLDHighDefinitionGUID );
|
||||
}
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if( GUILayout.Button( URPbutton, m_buttonLeftStyle ) )
|
||||
ImportSample( URPbutton.text, UniversalGUID );
|
||||
|
||||
if( GUILayout.Button( DownArrow, m_buttonRightStyle, GUILayout.Width( DownButtonSize ), GUILayout.Height( DownButtonSize ) ) )
|
||||
{
|
||||
m_showLWRP = !m_showLWRP;
|
||||
m_showHDRP = false;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if( m_showLWRP )
|
||||
{
|
||||
EditorGUILayout.BeginVertical();
|
||||
if( GUILayout.Button( LWRPbutton, m_minibuttonStyle ) )
|
||||
ImportSample( LWRPbutton.text, LightWeightGUID );
|
||||
if( GUILayout.Button( LWRPOLDbutton, m_minibuttonStyle ) )
|
||||
ImportSample( LWRPOLDbutton.text, OLDLightWeightGUID );
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
if( GUILayout.Button( BuiltInbutton, m_buttonStyle ) )
|
||||
ImportSample( BuiltInbutton.text, BuiltInGUID );
|
||||
|
||||
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 );
|
||||
}
|
||||
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.PrefStartUp, (int)m_startup );
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
// Find a better way to update link buttons without repainting the window
|
||||
Repaint();
|
||||
}
|
||||
|
||||
void ImportSample( string pipeline, string guid )
|
||||
{
|
||||
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 );
|
||||
AssetDatabase.ImportPackage( AssetDatabase.GUIDToAssetPath( guid ), false );
|
||||
}
|
||||
}
|
||||
|
||||
UnityWebRequest www;
|
||||
|
||||
IEnumerator StartRequest( string url, Action success = null )
|
||||
{
|
||||
using( www = UnityWebRequest.Get( url ) )
|
||||
{
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
yield return www.SendWebRequest();
|
||||
#else
|
||||
yield return www.Send();
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e7433fb42db4d9428571bfcd0da64f3
|
||||
timeCreated: 1585827066
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,813 @@
|
||||
// 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;
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
m_lockRatio.boolValue = GUILayout.Toggle( m_lockRatio.boolValue, "L", "minibutton", GUILayout.Width( 18 ) );
|
||||
#else
|
||||
GUILayout.Toggle( m_lockRatio.boolValue, "L", "minibutton", GUILayout.Width( 18 ) );
|
||||
m_lockRatio.boolValue = true;
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 436dc8bc09773454db57b9fbf799ec9d
|
||||
timeCreated: 1504633068
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,543 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using 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 ASEMaterialInspector : 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;
|
||||
|
||||
|
||||
// Reflection Fields
|
||||
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
|
||||
|
||||
#if UNITY_2018_2_OR_NEWER
|
||||
public override void OnClosed( Material material )
|
||||
{
|
||||
base.OnClosed( material );
|
||||
CleanUp();
|
||||
}
|
||||
#endif
|
||||
|
||||
void CleanUp()
|
||||
{
|
||||
if( m_previewRenderUtility != null )
|
||||
{
|
||||
m_previewRenderUtility.Cleanup();
|
||||
m_previewRenderUtility = null;
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoPerformed()
|
||||
{
|
||||
m_refreshOnUndo = true;
|
||||
}
|
||||
|
||||
~ASEMaterialInspector()
|
||||
{
|
||||
Undo.undoRedoPerformed -= 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;
|
||||
Undo.undoRedoPerformed += 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" ) )
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
ASEPackageManagerHelper.SetupLateMaterial( mat );
|
||||
|
||||
#else
|
||||
AmplifyShaderEditorWindow.LoadMaterialToASE( mat );
|
||||
#endif
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
if( GUILayout.Button( CopyButtonStr ) )
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
|
||||
|
||||
Shader shader = mat.shader;
|
||||
int propertyCount = UnityEditor.ShaderUtil.GetPropertyCount( shader );
|
||||
string allProperties = string.Empty;
|
||||
for( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
UnityEditor.ShaderUtil.ShaderPropertyType type = UnityEditor.ShaderUtil.GetPropertyType( shader, i );
|
||||
string name = UnityEditor.ShaderUtil.GetPropertyName( shader, i );
|
||||
string valueStr = string.Empty;
|
||||
switch( type )
|
||||
{
|
||||
case UnityEditor.ShaderUtil.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 UnityEditor.ShaderUtil.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 UnityEditor.ShaderUtil.ShaderPropertyType.Float:
|
||||
{
|
||||
float value = mat.GetFloat( name );
|
||||
valueStr = value.ToString();
|
||||
}
|
||||
break;
|
||||
case UnityEditor.ShaderUtil.ShaderPropertyType.Range:
|
||||
{
|
||||
float value = mat.GetFloat( name );
|
||||
valueStr = value.ToString();
|
||||
}
|
||||
break;
|
||||
case UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv:
|
||||
{
|
||||
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 ] ) )
|
||||
{
|
||||
UnityEditor.ShaderUtil.ShaderPropertyType type = (UnityEditor.ShaderUtil.ShaderPropertyType)Enum.Parse( typeof( UnityEditor.ShaderUtil.ShaderPropertyType ), valuesArr[ 1 ] );
|
||||
switch( type )
|
||||
{
|
||||
case UnityEditor.ShaderUtil.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 UnityEditor.ShaderUtil.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 UnityEditor.ShaderUtil.ShaderPropertyType.Float:
|
||||
{
|
||||
mat.SetFloat( valuesArr[ 0 ], Convert.ToSingle( valuesArr[ 2 ] ) );
|
||||
}
|
||||
break;
|
||||
case UnityEditor.ShaderUtil.ShaderPropertyType.Range:
|
||||
{
|
||||
mat.SetFloat( valuesArr[ 0 ], Convert.ToSingle( valuesArr[ 2 ] ) );
|
||||
}
|
||||
break;
|
||||
case UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv:
|
||||
{
|
||||
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( ( properties[ i ].flags & ( MaterialProperty.PropFlags.HideInInspector | MaterialProperty.PropFlags.PerRendererData ) ) == MaterialProperty.PropFlags.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();
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
materialEditor.EnableInstancingField();
|
||||
#endif
|
||||
#if UNITY_5_6_2 || UNITY_5_6_3 || UNITY_5_6_4 || UNITY_2017_1_OR_NEWER
|
||||
materialEditor.DoubleSidedGIField();
|
||||
#endif
|
||||
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 );
|
||||
}
|
||||
|
||||
if( materialEditor.RequiresConstantRepaint() && m_lastRenderedTime + 0.032999999821186066 < EditorApplication.timeSinceStartup )
|
||||
{
|
||||
this.m_lastRenderedTime = EditorApplication.timeSinceStartup;
|
||||
materialEditor.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
m_selectedMesh = (int)m_selectedField.GetValue( materialEditor );
|
||||
|
||||
if( m_selectedMesh != 0 )
|
||||
{
|
||||
if( m_targetMesh != null )
|
||||
{
|
||||
m_targetMesh = null;
|
||||
EditorPrefs.SetString( PreviewModelPref, "" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
m_previewRenderUtility.cameraFieldOfView = 30f;
|
||||
#else
|
||||
m_previewRenderUtility.m_CameraFieldOfView = 30f;
|
||||
#endif
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
m_previewDir = (Vector2)m_dragMethod.Invoke( m_previewGUIType, new object[] { m_previewDir, r } );
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if( m_previewSettingsType == null )
|
||||
{
|
||||
m_previewSettingsType = m_modelInspectorType.GetNestedType( "PreviewSettings",BindingFlags.NonPublic);
|
||||
}
|
||||
|
||||
if( m_previewSettingsInstance == null )
|
||||
{
|
||||
m_previewSettingsInstance = Activator.CreateInstance( m_previewSettingsType );
|
||||
previewDirInfo = m_previewSettingsType.GetField( "previewDir", BindingFlags.Instance | BindingFlags.Public );
|
||||
shadedMaterialInfo = m_previewSettingsType.GetField( "shadedPreviewMaterial", BindingFlags.Instance | BindingFlags.Public );
|
||||
activeMaterialInfo = m_previewSettingsType.GetField( "activeMaterial", BindingFlags.Instance | BindingFlags.Public );
|
||||
}
|
||||
|
||||
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; } }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1c012872b428594f95e585bd19e5347
|
||||
timeCreated: 1481126958
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,969 @@
|
||||
// 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 AmplifyShaderEditor;
|
||||
|
||||
namespace UnityEditor
|
||||
{
|
||||
[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: "
|
||||
};
|
||||
|
||||
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 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();
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
m_cameraTransform = m_previewRenderUtility.camera.transform;
|
||||
#else
|
||||
m_cameraTransform = m_previewRenderUtility.m_Camera.transform;
|
||||
#endif
|
||||
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;
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
m_previewRenderUtility.camera.Render();
|
||||
#else
|
||||
m_previewRenderUtility.m_Camera.Render();
|
||||
#endif
|
||||
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 );
|
||||
}
|
||||
|
||||
private static string GetPropertyType( Shader s, int index )
|
||||
{
|
||||
UnityEditor.ShaderUtil.ShaderPropertyType propertyType = UnityEditor.ShaderUtil.GetPropertyType( s, index );
|
||||
if ( propertyType == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv )
|
||||
{
|
||||
return CustomShaderInspector.kTextureTypes[ ( int ) UnityEditor.ShaderUtil.GetTexDim( s, 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();
|
||||
{
|
||||
if ( GUILayout.Button( "Open in Shader Editor" ) )
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
ASEPackageManagerHelper.SetupLateShader( shader );
|
||||
#else
|
||||
AmplifyShaderEditorWindow.ConvertShaderToASE( shader );
|
||||
#endif
|
||||
}
|
||||
|
||||
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 ] );
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
ShowKeywords( shader );
|
||||
srpCompatibilityCheckMaterial.SetPass( 0 );
|
||||
#endif
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
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 );
|
||||
}
|
||||
#endif
|
||||
CustomShaderInspector.ShowShaderProperties( shader );
|
||||
}
|
||||
}
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
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();
|
||||
}
|
||||
#endif
|
||||
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 = UnityEditor.ShaderUtil.GetPropertyCount( s );
|
||||
for ( int i = 0; i < propertyCount; i++ )
|
||||
{
|
||||
string propertyName = UnityEditor.ShaderUtil.GetPropertyName( s, i );
|
||||
string label = CustomShaderInspector.GetPropertyType( s, i ) + UnityEditor.ShaderUtil.GetPropertyDescription( s, 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();
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
ShaderMessage[] m_ShaderMessages;
|
||||
#endif
|
||||
private void ShowShaderErrors( Shader s )
|
||||
{
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
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 );
|
||||
#else
|
||||
int shaderErrorCount = ShaderUtilEx.GetShaderErrorCount( s );
|
||||
if ( shaderErrorCount < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
CustomShaderInspector.ShaderErrorListUI( s, ShaderUtilEx.GetShaderErrors( s ), ref this.m_ScrollPosition );
|
||||
#endif
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
ShaderUtilEx.Type.InvokeMember( "FetchCachedMessages", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
#else
|
||||
ShaderUtilEx.Type.InvokeMember( "FetchCachedErrors", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
#endif
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
return ShaderUtil.GetShaderMessageCount( s );
|
||||
#else
|
||||
return ( int ) ShaderUtilEx.Type.InvokeMember( "GetShaderErrorCount", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { s } );
|
||||
#endif
|
||||
}
|
||||
|
||||
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 } );
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
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 } );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
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; } }
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
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 } );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return EditorGUI.DropdownButton( position, content, focusType, style );
|
||||
#else
|
||||
return ( bool ) EditorGUIEx.Type.InvokeMember( "ButtonMouseDown", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { position, content, focusType, style } );
|
||||
#endif
|
||||
}
|
||||
|
||||
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 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 641dff721f3c24c4188f01fea49484cb
|
||||
timeCreated: 1481126956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
@@ -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; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d402e3c7d578ee046a5d0826b9a41c27
|
||||
timeCreated: 1487245046
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1365
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/GeneratorUtils.cs
Normal file
1365
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/GeneratorUtils.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ab31d77d200c7a4ca43f4bf159de6b3
|
||||
timeCreated: 1490798546
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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 ); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87cfef50a69ad24479fb8b472dac6d6e
|
||||
timeCreated: 1481126957
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
843
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/IOUtils.cs
Normal file
843
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/IOUtils.cs
Normal file
@@ -0,0 +1,843 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Threading;
|
||||
using UnityEditor.VersionControl;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public enum ShaderLoadResult
|
||||
{
|
||||
LOADED,
|
||||
TEMPLATE_LOADED,
|
||||
FILE_NOT_FOUND,
|
||||
ASE_INFO_NOT_FOUND,
|
||||
UNITY_NATIVE_PATHS
|
||||
}
|
||||
|
||||
public class Worker
|
||||
{
|
||||
public static readonly object locker = new object();
|
||||
public void DoWork()
|
||||
{
|
||||
while ( IOUtils.ActiveThread )
|
||||
{
|
||||
if ( IOUtils.SaveInThreadFlag )
|
||||
{
|
||||
IOUtils.SaveInThreadFlag = false;
|
||||
lock ( locker )
|
||||
{
|
||||
IOUtils.SaveInThreadShaderBody = IOUtils.ShaderCopywriteMessage + IOUtils.SaveInThreadShaderBody;
|
||||
// Add checksum
|
||||
string checksum = IOUtils.CreateChecksum( IOUtils.SaveInThreadShaderBody );
|
||||
IOUtils.SaveInThreadShaderBody += IOUtils.CHECKSUM + IOUtils.VALUE_SEPARATOR + checksum;
|
||||
|
||||
// Write to disk
|
||||
StreamWriter fileWriter = new StreamWriter( IOUtils.SaveInThreadPathName );
|
||||
try
|
||||
{
|
||||
fileWriter.Write( IOUtils.SaveInThreadShaderBody );
|
||||
Debug.Log( "Saving complete" );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
fileWriter.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Debug.Log( "Thread closed" );
|
||||
}
|
||||
}
|
||||
|
||||
public static class IOUtils
|
||||
{
|
||||
public delegate void OnShaderAction( Shader shader, bool isTemplate, string type );
|
||||
public static OnShaderAction OnShaderSavedEvent;
|
||||
public static OnShaderAction OnShaderTypeChangedEvent;
|
||||
|
||||
public static readonly string ShaderCopywriteMessage = "// Made with Amplify Shader Editor\n// Available at the Unity Asset Store - http://u3d.as/y3X \n";
|
||||
public static readonly string GrabPassEmpty = "\t\tGrabPass{ }\n";
|
||||
public static readonly string GrabPassBegin = "\t\tGrabPass{ \"";
|
||||
public static readonly string GrabPassEnd = "\" }\n";
|
||||
public static readonly string PropertiesBegin = "\tProperties\n\t{\n";
|
||||
public static readonly string PropertiesEnd = "\t}\n";
|
||||
public static readonly string PropertiesElement = "\t\t{0}\n";
|
||||
public static readonly string PropertiesElementsRaw = "{0}\n";
|
||||
|
||||
public static readonly string PragmaTargetHeader = "\t\t#pragma target {0}\n";
|
||||
public static readonly string InstancedPropertiesHeader = "multi_compile_instancing";
|
||||
public static readonly string VirtualTexturePragmaHeader = "multi_compile _ _VT_SINGLE_MODE";
|
||||
|
||||
public static readonly string InstancedPropertiesBegin = "UNITY_INSTANCING_CBUFFER_START({0})";
|
||||
public static readonly string InstancedPropertiesEnd = "UNITY_INSTANCING_CBUFFER_END";
|
||||
public static readonly string InstancedPropertiesElement = "UNITY_DEFINE_INSTANCED_PROP({0}, {1})";
|
||||
public static readonly string InstancedPropertiesData = "UNITY_ACCESS_INSTANCED_PROP({0})";
|
||||
|
||||
public static readonly string DotsInstancedPropertiesData = "\tUNITY_DOTS_INSTANCED_PROP({0}, {1})";
|
||||
public static readonly string DotsInstancedDefinesData = "#define {1} UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO({0} , Metadata_{1})";
|
||||
|
||||
public static readonly string LWSRPInstancedPropertiesBegin = "UNITY_INSTANCING_BUFFER_START({0})";
|
||||
public static readonly string LWSRPInstancedPropertiesEnd = "UNITY_INSTANCING_BUFFER_END({0})";
|
||||
public static readonly string LWSRPInstancedPropertiesElement = "UNITY_DEFINE_INSTANCED_PROP({0}, {1})";
|
||||
public static readonly string LWSRPInstancedPropertiesData = "UNITY_ACCESS_INSTANCED_PROP({0},{1})";
|
||||
|
||||
public static readonly string SRPCBufferPropertiesBegin = "CBUFFER_START( UnityPerMaterial )";//"CBUFFER_START({0})";
|
||||
public static readonly string SRPCBufferPropertiesEnd = "CBUFFER_END";
|
||||
|
||||
|
||||
public static readonly string InstancedPropertiesBeginTabs = "\t\t"+ InstancedPropertiesBegin + "\n";
|
||||
public static readonly string InstancedPropertiesEndTabs = "\t\t"+ InstancedPropertiesEnd + "\n";
|
||||
public static readonly string InstancedPropertiesElementTabs = "\t\t\t"+ InstancedPropertiesElement + "\n";
|
||||
|
||||
public static readonly string MetaBegin = "defaultTextures:";
|
||||
public static readonly string MetaEnd = "userData:";
|
||||
public static readonly string ShaderBodyBegin = "/*ASEBEGIN";
|
||||
public static readonly string ShaderBodyEnd = "ASEEND*/";
|
||||
//public static readonly float CurrentVersionFlt = 0.4f;
|
||||
//public static readonly string CurrentVersionStr = "Version=" + CurrentVersionFlt;
|
||||
|
||||
public static readonly string CHECKSUM = "//CHKSM";
|
||||
public static readonly string LAST_OPENED_OBJ_ID = "ASELASTOPENOBJID";
|
||||
|
||||
public static readonly string MAT_CLIPBOARD_ID = "ASEMATCLIPBRDID";
|
||||
public static readonly char FIELD_SEPARATOR = ';';
|
||||
public static readonly char VALUE_SEPARATOR = '=';
|
||||
public static readonly char LINE_TERMINATOR = '\n';
|
||||
public static readonly char VECTOR_SEPARATOR = ',';
|
||||
public static readonly char FLOAT_SEPARATOR = '.';
|
||||
public static readonly char CLIPBOARD_DATA_SEPARATOR = '|';
|
||||
public static readonly char MATRIX_DATA_SEPARATOR = '|';
|
||||
public readonly static string NO_TEXTURES = "<None>";
|
||||
public static readonly string SaveShaderStr = "Please enter shader name to save";
|
||||
public static readonly string FloatifyStr = ".0";
|
||||
|
||||
// Node parameter names
|
||||
public const string NodeParam = "Node";
|
||||
public const string NodePosition = "Position";
|
||||
public const string NodeId = "Id";
|
||||
public const string NodeType = "Type";
|
||||
public const string WireConnectionParam = "WireConnection";
|
||||
|
||||
public static readonly uint NodeTypeId = 1;
|
||||
|
||||
public static readonly int InNodeId = 1;
|
||||
public static readonly int InPortId = 2;
|
||||
public static readonly int OutNodeId = 3;
|
||||
public static readonly int OutPortId = 4;
|
||||
|
||||
public readonly static string DefaultASEDirtyCheckName = "__dirty";
|
||||
public readonly static string DefaultASEDirtyCheckProperty = "[HideInInspector] " + DefaultASEDirtyCheckName + "( \"\", Int ) = 1";
|
||||
public readonly static string DefaultASEDirtyCheckUniform = "uniform int " + DefaultASEDirtyCheckName + " = 1;";
|
||||
|
||||
public readonly static string MaskClipValueName = "_Cutoff";
|
||||
public readonly static string MaskClipValueProperty = MaskClipValueName + "( \"{0}\", Float ) = {1}";
|
||||
public readonly static string MaskClipValueUniform = "uniform float " + MaskClipValueName + " = {0};";
|
||||
|
||||
public readonly static string ChromaticAberrationProperty = "_ChromaticAberration";
|
||||
|
||||
//public static readonly string ASEFolderGUID = "daca988099666ec40aaa2cde22bb4935";
|
||||
//public static string ASEResourcesPath = "/Plugins/EditorResources/";
|
||||
//public static string ASEFolderPath;
|
||||
|
||||
//public static bool IsShaderFunctionWindow = false;
|
||||
|
||||
|
||||
public static int DefaultASEDirtyCheckId;
|
||||
|
||||
// this is to be used in combination with AssetDatabase.GetAssetPath, both of these include the Assets/ path so we need to remove from one of them
|
||||
public static string dataPath;
|
||||
|
||||
|
||||
public static string EditorResourcesGUID = "0932db7ec1402c2489679c4b72eab5eb";
|
||||
public static string GraphBgTextureGUID = "881c304491028ea48b5027ac6c62cf73";
|
||||
public static string GraphFgTextureGUID = "8c4a7fca2884fab419769ccc0355c0c1";
|
||||
public static string WireTextureGUID = "06e687f68dd96f0448c6d8217bbcf608";
|
||||
public static string MasterNodeOnTextureGUID = "26c64fcee91024a49980ea2ee9d1a2fb";
|
||||
public static string MasterNodeOffTextureGUID = "712aee08d999c16438e2d694f42428e8";
|
||||
public static string GPUInstancedOnTextureGUID = "4b0c2926cc71c5846ae2a29652d54fb6";
|
||||
public static string GPUInstancedOffTextureGUID = "486c7766baaf21b46afb63c1121ef03e";
|
||||
public static string MainSkinGUID = "57482289c346f104a8162a3a79aaff9d";
|
||||
|
||||
public static string UpdateOutdatedGUID = "cce638be049286c41bcbd0a26c356b18";
|
||||
public static string UpdateOFFGUID = "99d70ac09b4db9742b404c3f92d8564b";
|
||||
public static string UpdateUpToDatedGUID = "ce30b12fbb3223746bcfef9ea82effe3";
|
||||
public static string LiveOffGUID = "bb16faf366bcc6c4fbf0d7666b105354";
|
||||
public static string LiveOnGUID = "6a0ae1d7892333142aeb09585572202c";
|
||||
public static string LivePendingGUID = "e3182200efb67114eb5050f8955e1746";
|
||||
public static string CleanupOFFGUID = "f62c0c3a5ddcd844e905fb2632fdcb15";
|
||||
public static string CleanUpOnGUID = "615d853995cf2344d8641fd19cb09b5d";
|
||||
public static string TakeScreenshotOFFGUID = "7587de2e3bec8bf4d973109524ccc6b1";
|
||||
public static string TakeScreenshotONGUID = "7587de2e3bec8bf4d973109524ccc6b1";
|
||||
public static string ShareOFFGUID = "bc5bd469748466a459badfab23915cb0";
|
||||
public static string ShareONGUID = "bc5bd469748466a459badfab23915cb0";
|
||||
public static string OpenSourceCodeOFFGUID = "f7e8834b42791124095a8b7f2d4daac2";
|
||||
public static string OpenSourceCodeONGUID = "8b114792ff84f6546880c031eda42bc0";
|
||||
public static string FocusNodeGUID = "da673e6179c67d346abb220a6935e359";
|
||||
public static string FitViewGUID = "1def740f2314c6b4691529cadeee2e9c";
|
||||
public static string ShowInfoWindowGUID = "77af20044e9766840a6be568806dc22e";
|
||||
public static string ShowTipsWindowGUID = "066674048bbb1e64e8cdcc6c3b4abbeb";
|
||||
public static string ShowConsoleWindowGUID = "9a81d7df8e62c044a9d1cada0c8a2131";
|
||||
|
||||
|
||||
public static Dictionary<string, string> NodeTypeReplacer = new Dictionary<string, string>()
|
||||
{
|
||||
{"AmplifyShaderEditor.RotateAboutAxis", "AmplifyShaderEditor.RotateAboutAxisNode"},
|
||||
{"GlobalArrayNode", "AmplifyShaderEditor.GlobalArrayNode"},
|
||||
{"AmplifyShaderEditor.SimpleMaxOp", "AmplifyShaderEditor.SimpleMaxOpNode"},
|
||||
{"AmplifyShaderEditor.SimpleMinNode", "AmplifyShaderEditor.SimpleMinOpNode"},
|
||||
{"AmplifyShaderEditor.TFHCRemap", "AmplifyShaderEditor.TFHCRemapNode"},
|
||||
{"AmplifyShaderEditor.TFHCPixelateUV", "AmplifyShaderEditor.TFHCPixelate"},
|
||||
{"AmplifyShaderEditor.VirtualTexturePropertyNode", "AmplifyShaderEditor.VirtualTextureObject"}
|
||||
};
|
||||
|
||||
private static readonly string AmplifyShaderEditorDefineSymbol = "AMPLIFY_SHADER_EDITOR";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// THREAD IO UTILS
|
||||
public static bool SaveInThreadFlag = false;
|
||||
public static string SaveInThreadShaderBody;
|
||||
public static string SaveInThreadPathName;
|
||||
public static Thread SaveInThreadMainThread;
|
||||
public static bool ActiveThread = true;
|
||||
private static bool UseSaveThread = false;
|
||||
|
||||
private static bool Initialized = false;
|
||||
|
||||
public static bool FunctionNodeChanged = false;
|
||||
|
||||
public static List<AmplifyShaderEditorWindow> AllOpenedWindows = new List<AmplifyShaderEditorWindow>();
|
||||
|
||||
public static void StartSaveThread( string shaderBody, string pathName )
|
||||
{
|
||||
if( Provider.enabled && Provider.isActive )
|
||||
{
|
||||
Asset loadedAsset = Provider.GetAssetByPath( FileUtil.GetProjectRelativePath( pathName ) );
|
||||
if( loadedAsset != null )
|
||||
{
|
||||
//Task statusTask = Provider.Status( loadedAsset );
|
||||
//statusTask.Wait();
|
||||
//if( Provider.CheckoutIsValid( statusTask.assetList[ 0 ] ) )
|
||||
{
|
||||
Task checkoutTask = Provider.Checkout( loadedAsset, CheckoutMode.Both );
|
||||
checkoutTask.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( UseSaveThread )
|
||||
{
|
||||
if ( !SaveInThreadFlag )
|
||||
{
|
||||
if ( SaveInThreadMainThread == null )
|
||||
{
|
||||
Worker worker = new Worker();
|
||||
SaveInThreadMainThread = new Thread( worker.DoWork );
|
||||
SaveInThreadMainThread.Start();
|
||||
Debug.Log( "Thread created" );
|
||||
}
|
||||
|
||||
SaveInThreadShaderBody = shaderBody;
|
||||
SaveInThreadPathName = pathName;
|
||||
SaveInThreadFlag = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveTextfileToDisk( shaderBody, pathName );
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public static void SetAmplifyDefineSymbolOnBuildTargetGroup( BuildTargetGroup targetGroup )
|
||||
{
|
||||
string currData = PlayerSettings.GetScriptingDefineSymbolsForGroup( targetGroup );
|
||||
if ( !currData.Contains( AmplifyShaderEditorDefineSymbol ) )
|
||||
{
|
||||
if ( string.IsNullOrEmpty( currData ) )
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup( targetGroup, AmplifyShaderEditorDefineSymbol );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !currData[ currData.Length - 1 ].Equals( ';' ) )
|
||||
{
|
||||
currData += ';';
|
||||
}
|
||||
currData += AmplifyShaderEditorDefineSymbol;
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup( targetGroup, currData );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveAmplifyDefineSymbolOnBuildTargetGroup( BuildTargetGroup targetGroup )
|
||||
{
|
||||
string currData = PlayerSettings.GetScriptingDefineSymbolsForGroup( targetGroup );
|
||||
if( currData.Contains( AmplifyShaderEditorDefineSymbol ) )
|
||||
{
|
||||
currData = currData.Replace( AmplifyShaderEditorDefineSymbol + ";", "" );
|
||||
currData = currData.Replace( ";" + AmplifyShaderEditorDefineSymbol, "" );
|
||||
currData = currData.Replace( AmplifyShaderEditorDefineSymbol, "" );
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup( targetGroup, currData );
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if ( !Initialized )
|
||||
{
|
||||
Initialized = true;
|
||||
if( EditorPrefs.GetBool( Preferences.PrefDefineSymbol, true ) )
|
||||
SetAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
|
||||
//Array BuildTargetGroupValues = Enum.GetValues( typeof( BuildTargetGroup ));
|
||||
//for ( int i = 0; i < BuildTargetGroupValues.Length; i++ )
|
||||
//{
|
||||
// if( i != 0 && i != 15 && i != 16 )
|
||||
// SetAmplifyDefineSymbolOnBuildTargetGroup( ( BuildTargetGroup ) BuildTargetGroupValues.GetValue( i ) );
|
||||
//}
|
||||
|
||||
DefaultASEDirtyCheckId = Shader.PropertyToID( DefaultASEDirtyCheckName );
|
||||
dataPath = Application.dataPath.Remove( Application.dataPath.Length - 6 );
|
||||
|
||||
|
||||
//ASEFolderPath = AssetDatabase.GUIDToAssetPath( ASEFolderGUID );
|
||||
//ASEResourcesPath = ASEFolderPath + ASEResourcesPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void DumpTemplateManagers()
|
||||
{
|
||||
for( int i = 0; i < AllOpenedWindows.Count; i++ )
|
||||
{
|
||||
if( AllOpenedWindows[ i ].TemplatesManagerInstance != null )
|
||||
{
|
||||
Debug.Log( AllOpenedWindows[ i ].titleContent.text + ": " + AllOpenedWindows[ i ].TemplatesManagerInstance.GetInstanceID() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TemplatesManager FirstValidTemplatesManager
|
||||
{
|
||||
get
|
||||
{
|
||||
for( int i = 0; i < AllOpenedWindows.Count; i++ )
|
||||
{
|
||||
if( AllOpenedWindows[ i ].TemplatesManagerInstance != null )
|
||||
{
|
||||
return AllOpenedWindows[ i ].TemplatesManagerInstance;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateSFandRefreshWindows( AmplifyShaderFunction function )
|
||||
{
|
||||
for( int i = 0; i < AllOpenedWindows.Count; i++ )
|
||||
{
|
||||
AllOpenedWindows[ i ].LateRefreshAvailableNodes();
|
||||
if( AllOpenedWindows[ i ].IsShaderFunctionWindow )
|
||||
{
|
||||
if( AllOpenedWindows[ i ].OpenedShaderFunction == function )
|
||||
{
|
||||
AllOpenedWindows[ i ].UpdateTabTitle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateIO()
|
||||
{
|
||||
int windowCount = AllOpenedWindows.Count;
|
||||
if ( windowCount == 0 )
|
||||
{
|
||||
EditorApplication.update -= IOUtils.UpdateIO;
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < AllOpenedWindows.Count; i++ )
|
||||
{
|
||||
if ( AllOpenedWindows[i] == EditorWindow.focusedWindow )
|
||||
{
|
||||
UIUtils.CurrentWindow = AllOpenedWindows[ i ];
|
||||
}
|
||||
|
||||
if( FunctionNodeChanged )
|
||||
AllOpenedWindows[ i ].CheckFunctions = true;
|
||||
|
||||
if ( AllOpenedWindows[ i ] == null )
|
||||
{
|
||||
AllOpenedWindows.RemoveAt( i );
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
if ( FunctionNodeChanged )
|
||||
FunctionNodeChanged = false;
|
||||
}
|
||||
|
||||
public static void Destroy()
|
||||
{
|
||||
ActiveThread = false;
|
||||
if ( SaveInThreadMainThread != null )
|
||||
{
|
||||
SaveInThreadMainThread.Abort();
|
||||
SaveInThreadMainThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetShaderName( out string shaderName, out string fullPathname, string defaultName, string customDatapath )
|
||||
{
|
||||
string currDatapath = String.IsNullOrEmpty( customDatapath ) ? Application.dataPath : customDatapath;
|
||||
fullPathname = EditorUtility.SaveFilePanelInProject( "Select Shader to save", defaultName, "shader", SaveShaderStr, currDatapath );
|
||||
if ( !String.IsNullOrEmpty( fullPathname ) )
|
||||
{
|
||||
shaderName = fullPathname.Remove( fullPathname.Length - 7 ); // -7 remove .shader extension
|
||||
string[] subStr = shaderName.Split( '/' );
|
||||
if ( subStr.Length > 0 )
|
||||
{
|
||||
shaderName = subStr[ subStr.Length - 1 ]; // Remove pathname
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shaderName = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTypeToString( ref string myString, string typeName )
|
||||
{
|
||||
myString += typeName;
|
||||
}
|
||||
|
||||
public static void AddFieldToString( ref string myString, string fieldName, object fieldValue )
|
||||
{
|
||||
myString += FIELD_SEPARATOR + fieldName + VALUE_SEPARATOR + fieldValue;
|
||||
}
|
||||
|
||||
public static void AddFieldValueToString( ref string myString, object fieldValue )
|
||||
{
|
||||
myString += FIELD_SEPARATOR + fieldValue.ToString();
|
||||
}
|
||||
|
||||
public static void AddLineTerminator( ref string myString )
|
||||
{
|
||||
myString += LINE_TERMINATOR;
|
||||
}
|
||||
|
||||
public static string CreateChecksum( string buffer )
|
||||
{
|
||||
SHA1 sha1 = SHA1.Create();
|
||||
byte[] buf = System.Text.Encoding.UTF8.GetBytes( buffer );
|
||||
byte[] hash = sha1.ComputeHash( buf, 0, buf.Length );
|
||||
string hashstr = BitConverter.ToString( hash ).Replace( "-", "" );
|
||||
return hashstr;
|
||||
}
|
||||
|
||||
public static void SaveTextfileToDisk( string shaderBody, string pathName, bool addAdditionalInfo = true )
|
||||
{
|
||||
|
||||
if ( addAdditionalInfo )
|
||||
{
|
||||
shaderBody = ShaderCopywriteMessage + shaderBody;
|
||||
// Add checksum
|
||||
string checksum = CreateChecksum( shaderBody );
|
||||
shaderBody += CHECKSUM + VALUE_SEPARATOR + checksum;
|
||||
}
|
||||
|
||||
// Write to disk
|
||||
StreamWriter fileWriter = new StreamWriter( pathName );
|
||||
try
|
||||
{
|
||||
fileWriter.Write( shaderBody );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
fileWriter.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static string AddAdditionalInfo( string shaderBody )
|
||||
{
|
||||
shaderBody = ShaderCopywriteMessage + shaderBody;
|
||||
string checksum = CreateChecksum( shaderBody );
|
||||
shaderBody += CHECKSUM + VALUE_SEPARATOR + checksum;
|
||||
return shaderBody;
|
||||
}
|
||||
|
||||
public static string LoadTextFileFromDisk( string pathName )
|
||||
{
|
||||
string result = string.Empty;
|
||||
if ( !string.IsNullOrEmpty( pathName ) && File.Exists( pathName ) )
|
||||
{
|
||||
|
||||
StreamReader fileReader = null;
|
||||
try
|
||||
{
|
||||
fileReader = new StreamReader( pathName );
|
||||
result = fileReader.ReadToEnd();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if( fileReader != null)
|
||||
fileReader.Close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsASEShader( Shader shader )
|
||||
{
|
||||
string datapath = AssetDatabase.GetAssetPath( shader );
|
||||
if ( UIUtils.IsUnityNativeShader( datapath ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string buffer = LoadTextFileFromDisk( datapath );
|
||||
if ( String.IsNullOrEmpty( buffer ) || !IOUtils.HasValidShaderBody( ref buffer ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsShaderFunction( string functionInfo )
|
||||
{
|
||||
string buffer = functionInfo;
|
||||
if ( String.IsNullOrEmpty( buffer ) || !IOUtils.HasValidShaderBody( ref buffer ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool HasValidShaderBody( ref string shaderBody )
|
||||
{
|
||||
int shaderBodyBeginId = shaderBody.IndexOf( ShaderBodyBegin );
|
||||
if ( shaderBodyBeginId > -1 )
|
||||
{
|
||||
int shaderBodyEndId = shaderBody.IndexOf( ShaderBodyEnd );
|
||||
return ( shaderBodyEndId > -1 && shaderBodyEndId > shaderBodyBeginId );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int[] AllIndexesOf( this string str, string substr, bool ignoreCase = false )
|
||||
{
|
||||
if ( string.IsNullOrEmpty( str ) || string.IsNullOrEmpty( substr ) )
|
||||
{
|
||||
throw new ArgumentException( "String or substring is not specified." );
|
||||
}
|
||||
|
||||
List<int> indexes = new List<int>();
|
||||
int index = 0;
|
||||
|
||||
while ( ( index = str.IndexOf( substr, index, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal ) ) != -1 )
|
||||
{
|
||||
indexes.Add( index++ );
|
||||
}
|
||||
|
||||
return indexes.ToArray();
|
||||
}
|
||||
|
||||
public static void AddFunctionHeader( ref string function, string header )
|
||||
{
|
||||
function += "\t\t" + header + "\n\t\t{\n";
|
||||
}
|
||||
|
||||
public static void AddSingleLineFunction( ref string function, string header )
|
||||
{
|
||||
function += "\t\t" + header;
|
||||
}
|
||||
|
||||
public static void AddFunctionLine( ref string function, string line )
|
||||
{
|
||||
function += "\t\t\t" + line + "\n";
|
||||
}
|
||||
|
||||
public static void CloseFunctionBody( ref string function )
|
||||
{
|
||||
function += "\t\t}\n";
|
||||
}
|
||||
|
||||
public static string CreateFullFunction( string header, params string[] functionLines )
|
||||
{
|
||||
string result = string.Empty;
|
||||
AddFunctionHeader( ref result, header );
|
||||
for ( int i = 0; i > functionLines.Length; i++ )
|
||||
{
|
||||
AddFunctionLine( ref result, functionLines[ i ] );
|
||||
}
|
||||
CloseFunctionBody( ref result );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string CreateCodeComments( bool forceForwardSlash, params string[] comments )
|
||||
{
|
||||
string finalComment = string.Empty;
|
||||
if ( comments.Length == 1 )
|
||||
{
|
||||
finalComment = "//" + comments[ 0 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( forceForwardSlash )
|
||||
{
|
||||
for ( int i = 0; i < comments.Length; i++ )
|
||||
{
|
||||
finalComment += "//" + comments[ i ];
|
||||
if ( i < comments.Length - 1 )
|
||||
{
|
||||
finalComment += "\n\t\t\t";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finalComment = "/*";
|
||||
for ( int i = 0; i < comments.Length; i++ )
|
||||
{
|
||||
if ( i != 0 )
|
||||
finalComment += "\t\t\t";
|
||||
finalComment += comments[ i ];
|
||||
if ( i < comments.Length - 1 )
|
||||
finalComment += "\n";
|
||||
}
|
||||
finalComment += "*/";
|
||||
}
|
||||
}
|
||||
return finalComment;
|
||||
}
|
||||
|
||||
public static string GetUVChannelDeclaration( string uvName, int channelId, int set )
|
||||
{
|
||||
string uvSetStr = ( set == 0 ) ? "uv" : "uv" + Constants.AvailableUVSetsStr[ set ];
|
||||
return "float2 " + uvSetStr + uvName /*+ " : TEXCOORD" + channelId*/;
|
||||
}
|
||||
|
||||
public static string GetUVChannelName( string uvName, int set )
|
||||
{
|
||||
string uvSetStr = ( set == 0 ) ? "uv" : "uv" + Constants.AvailableUVSetsStr[ set ];
|
||||
return uvSetStr + uvName;
|
||||
}
|
||||
|
||||
public static string GetVertexUVChannelName( int set )
|
||||
{
|
||||
string uvSetStr = ( set == 0 ) ? "texcoord" : ( "texcoord" + set.ToString() );
|
||||
return uvSetStr;
|
||||
}
|
||||
|
||||
public static string Floatify( float value )
|
||||
{
|
||||
return ( value % 1 ) != 0 ? value.ToString() : ( value.ToString() + FloatifyStr );
|
||||
}
|
||||
|
||||
public static string Vector2ToString( Vector2 data )
|
||||
{
|
||||
return data.x.ToString() + VECTOR_SEPARATOR + data.y.ToString();
|
||||
}
|
||||
|
||||
public static string Vector3ToString( Vector3 data )
|
||||
{
|
||||
return data.x.ToString() + VECTOR_SEPARATOR + data.y.ToString() + VECTOR_SEPARATOR + data.z.ToString();
|
||||
}
|
||||
|
||||
public static string Vector4ToString( Vector4 data )
|
||||
{
|
||||
return data.x.ToString() + VECTOR_SEPARATOR + data.y.ToString() + VECTOR_SEPARATOR + data.z.ToString() + VECTOR_SEPARATOR + data.w.ToString();
|
||||
}
|
||||
|
||||
public static string ColorToString( Color data )
|
||||
{
|
||||
return data.r.ToString() + VECTOR_SEPARATOR + data.g.ToString() + VECTOR_SEPARATOR + data.b.ToString() + VECTOR_SEPARATOR + data.a.ToString();
|
||||
}
|
||||
|
||||
public static string Matrix3x3ToString( Matrix4x4 matrix )
|
||||
{
|
||||
return matrix[ 0, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 0, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 0, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
matrix[ 1, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 1, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 1, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
matrix[ 2, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 2, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 2, 2 ].ToString();
|
||||
}
|
||||
|
||||
public static string Matrix4x4ToString( Matrix4x4 matrix )
|
||||
{
|
||||
return matrix[ 0, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 0, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 0, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 0, 3 ].ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
matrix[ 1, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 1, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 1, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 1, 3 ].ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
matrix[ 2, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 2, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 2, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 2, 3 ].ToString() + IOUtils.VECTOR_SEPARATOR +
|
||||
matrix[ 3, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 3, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 3, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + matrix[ 3, 3 ].ToString();
|
||||
}
|
||||
|
||||
public static Vector2 StringToVector2( string data )
|
||||
{
|
||||
string[] parsedData = data.Split( VECTOR_SEPARATOR );
|
||||
if ( parsedData.Length >= 2 )
|
||||
{
|
||||
return new Vector2( Convert.ToSingle( parsedData[ 0 ] ),
|
||||
Convert.ToSingle( parsedData[ 1 ] ) );
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
public static Vector3 StringToVector3( string data )
|
||||
{
|
||||
string[] parsedData = data.Split( VECTOR_SEPARATOR );
|
||||
if ( parsedData.Length >= 3 )
|
||||
{
|
||||
return new Vector3( Convert.ToSingle( parsedData[ 0 ] ),
|
||||
Convert.ToSingle( parsedData[ 1 ] ),
|
||||
Convert.ToSingle( parsedData[ 2 ] ) );
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
public static Vector4 StringToVector4( string data )
|
||||
{
|
||||
string[] parsedData = data.Split( VECTOR_SEPARATOR );
|
||||
if ( parsedData.Length >= 4 )
|
||||
{
|
||||
return new Vector4( Convert.ToSingle( parsedData[ 0 ] ),
|
||||
Convert.ToSingle( parsedData[ 1 ] ),
|
||||
Convert.ToSingle( parsedData[ 2 ] ),
|
||||
Convert.ToSingle( parsedData[ 3 ] ) );
|
||||
}
|
||||
return Vector4.zero;
|
||||
}
|
||||
|
||||
public static Color StringToColor( string data )
|
||||
{
|
||||
string[] parsedData = data.Split( VECTOR_SEPARATOR );
|
||||
if ( parsedData.Length >= 4 )
|
||||
{
|
||||
return new Color( Convert.ToSingle( parsedData[ 0 ] ),
|
||||
Convert.ToSingle( parsedData[ 1 ] ),
|
||||
Convert.ToSingle( parsedData[ 2 ] ),
|
||||
Convert.ToSingle( parsedData[ 3 ] ) );
|
||||
}
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
public static Matrix4x4 StringToMatrix3x3( string data )
|
||||
{
|
||||
string[] parsedData = data.Split( VECTOR_SEPARATOR );
|
||||
if ( parsedData.Length == 9 )
|
||||
{
|
||||
Matrix4x4 matrix = new Matrix4x4();
|
||||
matrix[ 0, 0 ] = Convert.ToSingle( parsedData[ 0 ] );
|
||||
matrix[ 0, 1 ] = Convert.ToSingle( parsedData[ 1 ] );
|
||||
matrix[ 0, 2 ] = Convert.ToSingle( parsedData[ 2 ] );
|
||||
|
||||
matrix[ 1, 0 ] = Convert.ToSingle( parsedData[ 3 ] );
|
||||
matrix[ 1, 1 ] = Convert.ToSingle( parsedData[ 4 ] );
|
||||
matrix[ 1, 2 ] = Convert.ToSingle( parsedData[ 5 ] );
|
||||
|
||||
matrix[ 2, 0 ] = Convert.ToSingle( parsedData[ 6 ] );
|
||||
matrix[ 2, 1 ] = Convert.ToSingle( parsedData[ 7 ] );
|
||||
matrix[ 2, 2 ] = Convert.ToSingle( parsedData[ 8 ] );
|
||||
return matrix;
|
||||
}
|
||||
return Matrix4x4.identity;
|
||||
}
|
||||
|
||||
public static Matrix4x4 StringToMatrix4x4( string data )
|
||||
{
|
||||
string[] parsedData = data.Split( VECTOR_SEPARATOR );
|
||||
if ( parsedData.Length == 16 )
|
||||
{
|
||||
Matrix4x4 matrix = new Matrix4x4();
|
||||
matrix[ 0, 0 ] = Convert.ToSingle( parsedData[ 0 ] );
|
||||
matrix[ 0, 1 ] = Convert.ToSingle( parsedData[ 1 ] );
|
||||
matrix[ 0, 2 ] = Convert.ToSingle( parsedData[ 2 ] );
|
||||
matrix[ 0, 3 ] = Convert.ToSingle( parsedData[ 3 ] );
|
||||
|
||||
matrix[ 1, 0 ] = Convert.ToSingle( parsedData[ 4 ] );
|
||||
matrix[ 1, 1 ] = Convert.ToSingle( parsedData[ 5 ] );
|
||||
matrix[ 1, 2 ] = Convert.ToSingle( parsedData[ 6 ] );
|
||||
matrix[ 1, 3 ] = Convert.ToSingle( parsedData[ 7 ] );
|
||||
|
||||
matrix[ 2, 0 ] = Convert.ToSingle( parsedData[ 8 ] );
|
||||
matrix[ 2, 1 ] = Convert.ToSingle( parsedData[ 9 ] );
|
||||
matrix[ 2, 2 ] = Convert.ToSingle( parsedData[ 10 ] );
|
||||
matrix[ 2, 3 ] = Convert.ToSingle( parsedData[ 11 ] );
|
||||
|
||||
matrix[ 3, 0 ] = Convert.ToSingle( parsedData[ 12 ] );
|
||||
matrix[ 3, 1 ] = Convert.ToSingle( parsedData[ 13 ] );
|
||||
matrix[ 3, 2 ] = Convert.ToSingle( parsedData[ 14 ] );
|
||||
matrix[ 3, 3 ] = Convert.ToSingle( parsedData[ 15 ] );
|
||||
return matrix;
|
||||
}
|
||||
return Matrix4x4.identity;
|
||||
}
|
||||
|
||||
public static void SaveTextureToDisk( Texture2D tex, string pathname )
|
||||
{
|
||||
byte[] rawData = tex.GetRawTextureData();
|
||||
Texture2D newTex = new Texture2D( tex.width, tex.height, tex.format, tex.mipmapCount > 1, false );
|
||||
newTex.LoadRawTextureData( rawData );
|
||||
newTex.Apply();
|
||||
byte[] pngData = newTex.EncodeToPNG();
|
||||
File.WriteAllBytes( pathname, pngData );
|
||||
}
|
||||
|
||||
//public static void SaveObjToList( string newObj )
|
||||
//{
|
||||
// Debug.Log( UIUtils.CurrentWindow.Lastpath );
|
||||
// UIUtils.CurrentWindow.Lastpath = newObj;
|
||||
// string lastOpenedObj = EditorPrefs.GetString( IOUtils.LAST_OPENED_OBJ_ID );
|
||||
// string[] allLocations = lastOpenedObj.Split( ':' );
|
||||
|
||||
// string lastLocation = allLocations[ allLocations.Length - 1 ];
|
||||
|
||||
// string resave = string.Empty;
|
||||
// for ( int i = 0; i < allLocations.Length; i++ )
|
||||
// {
|
||||
// if ( string.IsNullOrEmpty( allLocations[ i ] ) )
|
||||
// continue;
|
||||
|
||||
// resave += allLocations[ i ];
|
||||
// resave += ":";
|
||||
// }
|
||||
|
||||
// resave += newObj;
|
||||
// EditorPrefs.SetString( IOUtils.LAST_OPENED_OBJ_ID, resave );
|
||||
//}
|
||||
|
||||
//public static void DeleteObjFromList( string newObj )
|
||||
//{
|
||||
// string lastOpenedObj = EditorPrefs.GetString( IOUtils.LAST_OPENED_OBJ_ID );
|
||||
// string[] allLocations = lastOpenedObj.Split( ':' );
|
||||
|
||||
// string resave = string.Empty;
|
||||
// for ( int i = 0; i < allLocations.Length; i++ )
|
||||
// {
|
||||
// if ( string.IsNullOrEmpty( allLocations[ i ] ) || newObj.Equals( allLocations[ i ] ) )
|
||||
// continue;
|
||||
|
||||
// resave += allLocations[ i ];
|
||||
// if ( i < allLocations.Length - 1 )
|
||||
// resave += ":";
|
||||
// }
|
||||
|
||||
// EditorPrefs.SetString( IOUtils.LAST_OPENED_OBJ_ID, resave );
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d39b4c96fb4d7f847b3a21c377d4188d
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,322 @@
|
||||
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;
|
||||
|
||||
public InlineProperty() { }
|
||||
|
||||
public InlineProperty( float val )
|
||||
{
|
||||
m_value = val;
|
||||
}
|
||||
|
||||
public InlineProperty( int val )
|
||||
{
|
||||
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.GetNodeIdByName( propertyName );
|
||||
m_nodePropertyName = propertyName;
|
||||
m_active = m_nodeId != -1;
|
||||
}
|
||||
|
||||
public void IntField( ref UndoParentNode owner, string content )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_value = owner.EditorGUILayoutIntField( content, (int)m_value );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
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 );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
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 );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
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 );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
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 );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
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 );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
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 );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPicker( ref owner, content );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CustomDrawer( ref UndoParentNode owner, DrawPropertySection Drawer, string content )
|
||||
{
|
||||
if( !m_active )
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
Drawer( owner );
|
||||
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
|
||||
m_active = !m_active;
|
||||
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;
|
||||
m_nodeId = owner.EditorGUILayoutIntPopup( content, m_nodeId, intArraysNames, intIds );
|
||||
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
|
||||
{
|
||||
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( 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 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++ ] );
|
||||
m_nodeId = Convert.ToInt32( 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 ] );
|
||||
m_nodeId = Convert.ToInt32( 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_nodeId );
|
||||
}
|
||||
|
||||
public string WriteToSingle()
|
||||
{
|
||||
return m_value.ToString( System.Globalization.CultureInfo.InvariantCulture ) + IOUtils.VECTOR_SEPARATOR + m_active + IOUtils.VECTOR_SEPARATOR + m_nodeId;
|
||||
}
|
||||
|
||||
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 && m_nodeId != -1; } }
|
||||
|
||||
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 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; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4f4421f529503243bfef5076ae82512
|
||||
timeCreated: 1519298230
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,172 @@
|
||||
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 )
|
||||
{
|
||||
Preferences.ShowOption show = Preferences.ShowOption.Never;
|
||||
if( !EditorPrefs.HasKey( Preferences.PrefStartUp ) )
|
||||
{
|
||||
show = Preferences.ShowOption.Always;
|
||||
EditorPrefs.SetInt( Preferences.PrefStartUp, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( Time.realtimeSinceStartup < 10 )
|
||||
{
|
||||
show = (Preferences.ShowOption) EditorPrefs.GetInt( Preferences.PrefStartUp, 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 ) )
|
||||
{
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
yield return www.SendWebRequest();
|
||||
#else
|
||||
yield return www.Send();
|
||||
#endif
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c71b815458d61e24184a60dbce19573d
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,284 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
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;
|
||||
Undo.undoRedoPerformed += 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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
Undo.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9b3f6c515f0e16469de89d9e22263c5
|
||||
timeCreated: 1486374353
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
163
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.cs
Normal file
163
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/Preferences.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class Preferences
|
||||
{
|
||||
public enum ShowOption
|
||||
{
|
||||
Always = 0,
|
||||
OnNewVersion = 1,
|
||||
Never = 2
|
||||
}
|
||||
|
||||
private 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 string PrefStartUp = "ASELastSession" + Application.productName;
|
||||
public static ShowOption GlobalStartUp = ShowOption.Always;
|
||||
|
||||
private 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 string PrefAutoSRP = "ASEAutoSRP" + Application.productName;
|
||||
public static bool GlobalAutoSRP = true;
|
||||
|
||||
private 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 string PrefDefineSymbol = "ASEDefineSymbol" + Application.productName;
|
||||
public static bool GlobalDefineSymbol = true;
|
||||
|
||||
private 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 string PrefClearLog = "ASEClearLog" + Application.productName;
|
||||
public static bool GlobalClearLog = true;
|
||||
|
||||
private 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 string PrefUpdateOnSceneSave = "ASEUpdateOnSceneSave" + Application.productName;
|
||||
public static bool GlobalUpdateOnSceneSave = true;
|
||||
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
private static readonly GUIContent ShowAsyncMsg = new GUIContent( "Show Shader Async. Compilation Message", "Shows message on ASE log if Asynchronous Shader Compilation is detected" );
|
||||
public static readonly string PrefShowAsyncMsg = "ASEShowAsync" + Application.productName;
|
||||
public static bool GlobalShowAsyncMsg = true;
|
||||
#endif
|
||||
private static bool PrefsLoaded = false;
|
||||
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider ImpostorsSettings()
|
||||
{
|
||||
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;
|
||||
}
|
||||
#else
|
||||
[PreferenceItem( "Amplify Shader Editor" )]
|
||||
#endif
|
||||
public static void PreferencesGUI()
|
||||
{
|
||||
if( !PrefsLoaded )
|
||||
{
|
||||
LoadDefaults();
|
||||
PrefsLoaded = true;
|
||||
}
|
||||
|
||||
var cache = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 250;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GlobalStartUp = (ShowOption)EditorGUILayout.EnumPopup( StartUp, GlobalStartUp );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetInt( PrefStartUp, (int)GlobalStartUp );
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GlobalAutoSRP = EditorGUILayout.Toggle( AutoSRP, GlobalAutoSRP );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetBool( PrefAutoSRP, GlobalAutoSRP );
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GlobalDefineSymbol = EditorGUILayout.Toggle( DefineSymbol, GlobalDefineSymbol );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetBool( PrefDefineSymbol, GlobalDefineSymbol );
|
||||
if( GlobalDefineSymbol )
|
||||
IOUtils.SetAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
|
||||
else
|
||||
IOUtils.RemoveAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GlobalClearLog = EditorGUILayout.Toggle( ClearLog, GlobalClearLog );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetBool( PrefClearLog, GlobalClearLog );
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GlobalUpdateOnSceneSave = EditorGUILayout.Toggle( UpdateOnSceneSave , GlobalUpdateOnSceneSave );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetBool( PrefUpdateOnSceneSave , GlobalUpdateOnSceneSave );
|
||||
}
|
||||
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GlobalShowAsyncMsg = EditorGUILayout.Toggle( ShowAsyncMsg, GlobalShowAsyncMsg);
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetBool( PrefShowAsyncMsg, GlobalShowAsyncMsg );
|
||||
}
|
||||
#endif
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
if( GUILayout.Button( "Reset and Forget All" ) )
|
||||
{
|
||||
EditorPrefs.DeleteKey( PrefStartUp );
|
||||
GlobalStartUp = ShowOption.Always;
|
||||
|
||||
EditorPrefs.DeleteKey( PrefAutoSRP );
|
||||
GlobalAutoSRP = true;
|
||||
|
||||
EditorPrefs.DeleteKey( PrefDefineSymbol );
|
||||
GlobalDefineSymbol = true;
|
||||
IOUtils.SetAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
|
||||
|
||||
EditorPrefs.DeleteKey( PrefClearLog );
|
||||
GlobalClearLog = true;
|
||||
|
||||
EditorPrefs.DeleteKey( PrefUpdateOnSceneSave );
|
||||
GlobalUpdateOnSceneSave = true;
|
||||
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
EditorPrefs.DeleteKey( PrefShowAsyncMsg );
|
||||
GlobalShowAsyncMsg = true;
|
||||
#endif
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUIUtility.labelWidth = cache;
|
||||
}
|
||||
|
||||
public static void LoadDefaults()
|
||||
{
|
||||
GlobalStartUp = (ShowOption)EditorPrefs.GetInt( PrefStartUp, 0 );
|
||||
GlobalAutoSRP = EditorPrefs.GetBool( PrefAutoSRP, true );
|
||||
GlobalDefineSymbol = EditorPrefs.GetBool( PrefDefineSymbol, true );
|
||||
GlobalClearLog = EditorPrefs.GetBool( PrefClearLog, true );
|
||||
GlobalUpdateOnSceneSave = EditorPrefs.GetBool( PrefUpdateOnSceneSave , true );
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
GlobalShowAsyncMsg = EditorPrefs.GetBool( PrefShowAsyncMsg, true );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d036571a581792b44951e3723aef2c01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5a7e5c0308e038448cd1a235bf840ca
|
||||
timeCreated: 1501521591
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,203 @@
|
||||
// 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 )
|
||||
{
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
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 );
|
||||
}
|
||||
#else
|
||||
m_filterMode =(InlineSamplerFilteringMode) Enum.Parse( typeof( InlineSamplerFilteringMode ), nodeParams[ index++ ] );
|
||||
m_mainWrapMode.Coordinates = (InlineSamplerWrapCoordinates)Enum.Parse( typeof( InlineSamplerWrapCoordinates ),nodeParams[ index++ ] );
|
||||
|
||||
int count = 0;
|
||||
int.TryParse( nodeParams[ index++ ], out count );
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
InlineSamplerWrapOptions option = new InlineSamplerWrapOptions();
|
||||
|
||||
option.WrapMode = ( InlineSamplerWrapMode)Enum.Parse(typeof( InlineSamplerWrapMode ), nodeParams[ index++ ] );
|
||||
option.Coordinates = ( InlineSamplerWrapCoordinates)Enum.Parse(typeof( InlineSamplerWrapCoordinates ), nodeParams[ index++ ] );
|
||||
|
||||
m_additionalWrapOptions.Add( option );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
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:
|
||||
@@ -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; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15917e71489c3ca4dbc5fdef9bb37433
|
||||
timeCreated: 1487952057
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[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/AmplifyShaderEditor/Plugins/Editor/Utils/TipsWindow.cs
Normal file
148
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/TipsWindow.cs
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 565dc3c9725b0db49b7d5ea17d151682
|
||||
timeCreated: 1504704078
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3071
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/UIUtils.cs
Normal file
3071
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/UIUtils.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23e0210afe076544ca92d761094a9119
|
||||
timeCreated: 1481126954
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/UndoUtils.cs
Normal file
12
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/UndoUtils.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Internal;
|
||||
using System;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
public class UndoUtils
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89dee7566d97f1847b9fe114e1c9a1a2
|
||||
timeCreated: 1489603190
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32dbececad3a67a4fbde694ae50ce82c
|
||||
timeCreated: 1504080603
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
260
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/WindowHelper.cs
Normal file
260
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/WindowHelper.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
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 )
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
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 } );
|
||||
#else
|
||||
var method = m_type.GetMethod( "AddTab", BindingFlags.Instance | BindingFlags.Public, null, new System.Type[] { typeof( EditorWindow ) }, null );
|
||||
if( method != null )
|
||||
method.Invoke( m_instance, new object[] { pane } );
|
||||
#endif
|
||||
}
|
||||
|
||||
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
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad6ef05d39dc39e42b8bfe0bdb826b7a
|
||||
timeCreated: 1494336778
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
148
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/WindowsUtil.cs
Normal file
148
Assets/AmplifyShaderEditor/Plugins/Editor/Utils/WindowsUtil.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
// 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;
|
||||
|
||||
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
|
||||
@@ -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