Add project files.

This commit is contained in:
2023-10-08 18:51:40 +02:00
commit 51cc9df14f
2249 changed files with 636804 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c8bcac0d66f920e49803925a85beb0ed
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,189 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
using AmplifyShaderEditor;
[Serializable]
public class AmplifyShaderFunction : ScriptableObject
{
[SerializeField]
private string m_functionInfo = string.Empty;
public string FunctionInfo
{
get { return m_functionInfo; }
set { m_functionInfo = value; }
}
[SerializeField]
private string m_functionName = string.Empty;
public string FunctionName
{
get { if( m_functionName.Length == 0 ) return name; else return m_functionName; }
set { m_functionName = value; }
}
[SerializeField]
[TextArea( 5, 15 )]
private string m_description = string.Empty;
public string Description
{
get { return m_description; }
set { m_description = value; }
}
[SerializeField]
private AdditionalIncludesHelper m_additionalIncludes = new AdditionalIncludesHelper();
//public AdditionalIncludesHelper AdditionalIncludes
//{
// get { return m_additionalIncludes; }
// set { m_additionalIncludes = value; }
//}
[SerializeField]
private AdditionalPragmasHelper m_additionalPragmas = new AdditionalPragmasHelper();
//public AdditionalPragmasHelper AdditionalPragmas
//{
// get { return m_additionalPragmas; }
// set { m_additionalPragmas = value; }
//}
[SerializeField]
private TemplateAdditionalDirectivesHelper m_additionalDirectives = new TemplateAdditionalDirectivesHelper( " Additional Directives" );
public TemplateAdditionalDirectivesHelper AdditionalDirectives
{
get { return m_additionalDirectives; }
set { m_additionalDirectives = value; }
}
[SerializeField]
private FunctionNodeCategories m_nodeCategory = FunctionNodeCategories.Functions;
public FunctionNodeCategories NodeCategory
{
get { return m_nodeCategory; }
set { m_nodeCategory = value; }
}
[SerializeField]
private string m_customNodeCategory = string.Empty;
public string CustomNodeCategory
{
get
{
if( m_nodeCategory == FunctionNodeCategories.Custom )
{
if( string.IsNullOrEmpty( m_customNodeCategory ) )
return "Functions";
else
return m_customNodeCategory;
}
else
{
return UIUtils.CategoryPresets[ (int)m_nodeCategory ];
//return new SerializedObject( this ).FindProperty( "m_nodeCategory" ).enumDisplayNames[ (int)m_nodeCategory ];
}
}
}
[SerializeField]
private PreviewLocation m_previewPosition = PreviewLocation.Auto;
public PreviewLocation PreviewPosition
{
get { return m_previewPosition; }
set { m_previewPosition = value; }
}
[SerializeField]
private bool m_hidden = false;
public bool Hidden
{
get { return m_hidden; }
set { m_hidden = value; }
}
public void UpdateDirectivesList()
{
m_additionalDirectives.CleanNullDirectives();
m_additionalDirectives.UpdateDirectivesFromSaveItems();
if( m_additionalIncludes.IncludeList.Count > 0 )
{
m_additionalDirectives.AddItems( AdditionalLineType.Include, m_additionalIncludes.IncludeList );
m_additionalIncludes.IncludeList.Clear();
}
if( m_additionalPragmas.PragmaList.Count > 0 )
{
m_additionalDirectives.AddItems( AdditionalLineType.Pragma, m_additionalPragmas.PragmaList );
m_additionalPragmas.PragmaList.Clear();
}
}
public void ResetDirectivesOrigin()
{
//if( UIUtils.CurrentShaderVersion() < 16807 )
// Although the correct version was 1.6.7 rev 07 this issue was only detected on v1.7.1. rev 00
// So to avoid potential incorrect saves over shader functions, I decided to broaden up the version range
if( UIUtils.CurrentShaderVersion() < 17101 )
{
m_additionalDirectives.ResetDirectivesOrigin();
}
}
}
public class ShaderFunctionDetector : AssetPostprocessor
{
static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths )
{
if( UIUtils.CurrentWindow == null )
return;
bool markForRefresh = false;
AmplifyShaderFunction function = null;
for( int i = 0; i < importedAssets.Length; i++ )
{
function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( importedAssets[ i ] );
if( function != null )
{
markForRefresh = true;
break;
}
}
if( deletedAssets.Length > 0 )
markForRefresh = true;
for( int i = 0; i < movedAssets.Length; i++ )
{
function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( movedAssets[ i ] );
if( function != null )
{
markForRefresh = true;
break;
}
}
for( int i = 0; i < movedFromAssetPaths.Length; i++ )
{
function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( movedFromAssetPaths[ i ] );
if( function != null )
{
markForRefresh = true;
break;
}
}
if( markForRefresh )
{
markForRefresh = false;
if( function != null )
{
IOUtils.UpdateSFandRefreshWindows( function );
}
UIUtils.CurrentWindow.LateRefreshAvailableNodes();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 78b2425a2284af743826c689403a4924
timeCreated: 1492703397
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 50be8291f9514914aa55c66c49da67cf, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,168 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
namespace AmplifyShaderEditor
{
[CustomEditor( typeof( AmplifyShaderFunction ) )]
public class AmplifyShaderFunctionEditor : Editor
{
class FunctionDependency
{
public string AssetName;
public string AssetPath;
public FunctionDependency(string name, string path)
{
AssetName = name;
AssetPath = path;
}
}
AmplifyShaderFunction m_target;
List<FunctionDependency> m_dependencies = new List<FunctionDependency>();
void OnEnable()
{
m_target = ( target as AmplifyShaderFunction );
}
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
//base.serializedObject.Update();
if( GUILayout.Button( "Open in Shader Editor" ) )
{
#if UNITY_2018_3_OR_NEWER
ASEPackageManagerHelper.SetupLateShaderFunction( m_target );
#else
AmplifyShaderEditorWindow.LoadShaderFunctionToASE( m_target, false );
#endif
}
//EditorGUILayout.Separator();
//m_target.FunctionInfo = EditorGUILayout.TextArea( m_target.FunctionInfo );
if( m_target.Description.Length > 0 )
{
EditorGUILayout.HelpBox( m_target.Description, MessageType.Info );
}
EditorGUILayout.Space();
if( GUILayout.Button( "Search Direct Dependencies" ) )
{
m_dependencies.Clear();
string guid = AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( m_target ) );
string[] allSFs = AssetDatabase.FindAssets( "t:AmplifyShaderFunction", null );
foreach( string guid1 in allSFs )
{
string sfPath = AssetDatabase.GUIDToAssetPath( guid1 );
bool found = SearchForGUID( guid, sfPath );
if( found )
{
//string n = Regex.Replace( sfPath, @"(\.\w+|[\w\d\/]+\/)", "" );
string n = Regex.Replace( sfPath, @"[\w\d\/]+\/", "" );
m_dependencies.Add(new FunctionDependency( n, sfPath ) );
}
}
string[] allSHs = AssetDatabase.FindAssets( "t:Shader", null );
foreach( string guid1 in allSHs )
{
string shPath = AssetDatabase.GUIDToAssetPath( guid1 );
bool found = SearchForGUID( guid, shPath );
if( found )
{
string n = Regex.Replace( shPath, @"[\w\d\/]+\/", "" );
m_dependencies.Add( new FunctionDependency( n, shPath ) );
}
}
}
EditorGUILayout.Space();
for( int i = 0; i < m_dependencies.Count; i++ )
{
EditorGUILayout.BeginHorizontal();
if( GUILayout.Button( m_dependencies[ i ].AssetName, "minibuttonleft" ) )
{
SelectAtPath( m_dependencies[ i ].AssetPath );
}
if( GUILayout.Button( "edit", "minibuttonright", GUILayout.Width(100) ) )
{
if( m_dependencies[ i ].AssetName.EndsWith( ".asset" ) )
{
var obj = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( m_dependencies[ i ].AssetPath );
AmplifyShaderEditorWindow.LoadShaderFunctionToASE( obj, false );
}
else
{
var obj = AssetDatabase.LoadAssetAtPath<Shader>( m_dependencies[ i ].AssetPath );
AmplifyShaderEditorWindow.ConvertShaderToASE( obj );
}
}
EditorGUILayout.EndHorizontal();
}
if( m_dependencies.Count > 0 )
{
List<string> assetPaths = new List<string>();
for( int i = 0; i < m_dependencies.Count; i++ )
{
assetPaths.Add( m_dependencies[ i ].AssetPath );
}
if( GUILayout.Button( "Open and Save All" ) )
{
bool doit = EditorUtility.DisplayDialog( "Open and Save All", "This will try to open all shader function and shaders that use this shader function and save them in quick succession, this may irreversibly break your files if something goes wrong. Are you sure you want to try?", "Yes, I'll take the risk", "No, I'll do it myself" );
if( doit )
AmplifyShaderEditorWindow.LoadAndSaveList( assetPaths.ToArray() );
}
}
}
public void SelectAtPath( string path )
{
var obj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>( path );
EditorGUIUtility.PingObject( obj );
}
public static bool SearchForGUID( string guid, string pathName )
{
bool result = false;
int count = 0;
if( !string.IsNullOrEmpty( pathName ) && File.Exists( pathName ) )
{
StreamReader fileReader = null;
try
{
fileReader = new StreamReader( pathName );
string line;
int index = -1;
while( ( line = fileReader.ReadLine() ) != null )
{
index = line.IndexOf( guid );
count++;
if( index > -1 )
{
result = true;
break;
}
}
}
catch( Exception e )
{
Debug.LogException( e );
}
finally
{
if( fileReader != null )
fileReader.Close();
}
}
return result;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8b2d6d1320661374db53aeb8057312b2
timeCreated: 1491909065
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,94 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
namespace AmplifyShaderEditor
{
public enum AutoPanLocation
{
TOP = 0,
BOTTOM,
LEFT,
RIGHT
}
public class AutoPanData
{
private Rect m_area;
private float m_size;
private Vector2 m_velocity;
private GUIStyle m_style;
private Color m_color = new Color( 1f, 0f, 0f, 0.5f );
private AutoPanLocation m_location;
private float m_adjustWidth = 0;
private float m_adjustInitialX = 0;
public AutoPanData( AutoPanLocation location, float size, Vector2 vel )
{
m_area = new Rect();
m_size = size;
m_velocity = vel;
m_location = location;
}
public bool CheckArea( Vector2 mousePosition, Rect window, bool draw )
{
float totalSize = m_size + m_adjustWidth;
switch ( m_location )
{
case AutoPanLocation.TOP:
{
m_area.x = m_adjustInitialX;
m_area.y = 0;
m_area.width = window.width;
m_area.height = totalSize;
}
break;
case AutoPanLocation.BOTTOM:
{
m_area.x = m_adjustInitialX;
m_area.y = window.height - totalSize;
m_area.width = window.width;
m_area.height = totalSize;
}
break;
case AutoPanLocation.LEFT:
{
m_area.x = m_adjustInitialX;
m_area.y = 0;
m_area.width = totalSize;
m_area.height = window.height;
}
break;
case AutoPanLocation.RIGHT:
{
m_area.x = m_adjustInitialX + window.width - totalSize;
m_area.y = 0;
m_area.width = totalSize;
m_area.height = window.height;
}
break;
}
if ( draw )
{
if ( m_style == null )
{
m_style = UIUtils.Box;
}
Color bufferedColor = GUI.color;
GUI.color = m_color;
GUI.Label( m_area, string.Empty, m_style );
GUI.color = bufferedColor;
}
return m_area.Contains( mousePosition );
}
public float AdjustWidth { set { m_adjustWidth = value; } }
public float AdjustInitialX { set { m_adjustInitialX = value; } }
public Vector2 Velocity { get { return m_velocity; } }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 711db07e8265cb740940568c4bc7345f
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,262 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
namespace AmplifyShaderEditor
{
public class ClipboardData
{
public string Data = string.Empty;
public string Connections = string.Empty;
public int OldNodeId = -1;
public int NewNodeId = -1;
public ClipboardData( string data, string connections, int oldNodeId )
{
Data = data;
Connections = connections;
OldNodeId = oldNodeId;
}
public override string ToString()
{
return Data + IOUtils.CLIPBOARD_DATA_SEPARATOR + Connections + IOUtils.CLIPBOARD_DATA_SEPARATOR + OldNodeId + IOUtils.CLIPBOARD_DATA_SEPARATOR + NewNodeId;
}
}
public class Clipboard
{
public const string ClipboardId = "AMPLIFY_CLIPBOARD_ID";
private readonly string[] ClipboardTagId = { "#CLIP_ITEM#" };
private List<ClipboardData> m_clipboardStrData;
private Dictionary<int, ClipboardData> m_clipboardAuxData;
private Dictionary<string, ClipboardData> m_multiPassMasterNodeData;
public Clipboard()
{
m_clipboardStrData = new List<ClipboardData>();
m_clipboardAuxData = new Dictionary<int, ClipboardData>();
m_multiPassMasterNodeData = new Dictionary<string, ClipboardData>();
}
public void ResetMultipassNodesData()
{
m_multiPassMasterNodeData.Clear();
}
public void AddMultiPassNodesToClipboard( List<TemplateMultiPassMasterNode> masterNodes, bool resetList, int lodId )
{
if( resetList )
m_multiPassMasterNodeData.Clear();
int templatesAmount = masterNodes.Count;
for( int i = 0; i < templatesAmount; i++ )
{
if( !masterNodes[ i ].InvalidNode )
{
string data = string.Empty;
string connection = string.Empty;
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
masterNodes[ i ].FullWriteToString( ref data, ref connection );
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
ClipboardData clipboardData = new ClipboardData( data, connection, masterNodes[ i ].UniqueId );
m_multiPassMasterNodeData.Add( masterNodes[ i ].PassUniqueName + lodId, clipboardData );
}
}
}
public void GetMultiPassNodesFromClipboard( List<TemplateMultiPassMasterNode> masterNodes, int lodId )
{
int templatesAmount = masterNodes.Count;
for( int i = 0; i < templatesAmount; i++ )
{
string clipboardDataId = masterNodes[ i ].PassUniqueName + lodId;
if( m_multiPassMasterNodeData.ContainsKey( clipboardDataId ) )
{
ClipboardData nodeData = m_multiPassMasterNodeData[ clipboardDataId ];
string[] nodeParams = nodeData.Data.Split( IOUtils.FIELD_SEPARATOR );
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
masterNodes[ i ].FullReadFromString( ref nodeParams );
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
}
}
for( int i = 0; i < templatesAmount; i++ )
{
string clipboardDataId = masterNodes[ i ].PassUniqueName + lodId;
if( m_multiPassMasterNodeData.ContainsKey( clipboardDataId ) )
{
masterNodes[ i ].SetReadOptions();
masterNodes[ i ].ForceOptionsRefresh();
}
}
}
public void AddToClipboard( List<ParentNode> selectedNodes , Vector3 initialPosition, ParentGraph graph )
{
//m_clipboardStrData.Clear();
//m_clipboardAuxData.Clear();
string clipboardData = IOUtils.Vector3ToString( initialPosition ) + ClipboardTagId[ 0 ];
int masterNodeId = UIUtils.CurrentWindow.CurrentGraph.CurrentMasterNodeId;
int count = selectedNodes.Count;
for ( int i = 0; i < count; i++ )
{
if ( UIUtils.CurrentWindow.IsShaderFunctionWindow || !graph.IsMasterNode( selectedNodes[ i ] ))
{
string nodeData = string.Empty;
string connections = string.Empty;
selectedNodes[ i ].ClipboardFullWriteToString( ref nodeData, ref connections );
clipboardData += nodeData;
if ( !string.IsNullOrEmpty( connections ) )
{
connections = connections.Substring( 0, connections.Length - 1 );
clipboardData += "\n" + connections;
}
if ( i < count - 1 )
clipboardData += ClipboardTagId[ 0 ];
//ClipboardData data = new ClipboardData( nodeData, connections, selectedNodes[ i ].UniqueId );
//m_clipboardStrData.Add( data );
//m_clipboardAuxData.Add( selectedNodes[ i ].UniqueId, data );
}
}
if ( !string.IsNullOrEmpty( clipboardData ) )
{
EditorPrefs.SetString( ClipboardId, clipboardData );
}
//for ( int i = 0; i < selectedNodes.Count; i++ )
//{
// if ( selectedNodes[ i ].UniqueId != masterNodeId )
// {
// WireNode wireNode = selectedNodes[ i ] as WireNode;
// if ( wireNode != null )
// {
// if ( !IsNodeChainValid( selectedNodes[ i ], true ) || !IsNodeChainValid( selectedNodes[ i ], false ) )
// {
// UnityEngine.Debug.Log( "found invalid wire port" );
// }
// }
// }
//}
}
public Vector3 GetDataFromEditorPrefs()
{
Vector3 initialPos = Vector3.zero;
m_clipboardStrData.Clear();
m_clipboardAuxData.Clear();
string clipboardData = EditorPrefs.GetString( ClipboardId, string.Empty );
if ( !string.IsNullOrEmpty( clipboardData ) )
{
string[] clipboardDataArray = clipboardData.Split( ClipboardTagId, StringSplitOptions.None );
initialPos = IOUtils.StringToVector3( clipboardDataArray[0] );
for ( int i = 1; i < clipboardDataArray.Length; i++ )
{
if ( !string.IsNullOrEmpty( clipboardDataArray[ i ] ) )
{
int wiresIndex = clipboardDataArray[ i ].IndexOf( IOUtils.LINE_TERMINATOR );
string nodeData = string.Empty;
string connections = string.Empty;
if ( wiresIndex < 0 )
{
nodeData = clipboardDataArray[ i ];
}
else
{
nodeData = clipboardDataArray[ i ].Substring( 0, wiresIndex );
connections = clipboardDataArray[ i ].Substring( wiresIndex + 1 );
}
string[] nodeDataArr = nodeData.Split( IOUtils.FIELD_SEPARATOR );
if ( nodeDataArr.Length > 2 )
{
int nodeId = Convert.ToInt32( nodeDataArr[ 2 ] );
ClipboardData data = new ClipboardData( nodeData, connections, nodeId );
m_clipboardStrData.Add( data );
m_clipboardAuxData.Add( nodeId, data );
}
}
}
}
return initialPos;
}
public bool IsNodeChainValid( ParentNode currentNode, bool forward )
{
WireNode wireNode = currentNode as WireNode;
if ( wireNode == null )
{
return m_clipboardAuxData.ContainsKey( currentNode.UniqueId );
}
if ( forward )
{
if ( wireNode.InputPorts[ 0 ].ExternalReferences.Count > 0 )
{
int nodeId = wireNode.InputPorts[ 0 ].ExternalReferences[ 0 ].NodeId;
if ( m_clipboardAuxData.ContainsKey( nodeId ) )
{
return IsNodeChainValid( UIUtils.GetNode( nodeId ), forward );
}
}
}
else
{
int nodeId = wireNode.OutputPorts[ 0 ].ExternalReferences[ 0 ].NodeId;
if ( m_clipboardAuxData.ContainsKey( nodeId ) )
{
return IsNodeChainValid( UIUtils.GetNode( nodeId ), forward );
}
}
return false;
}
public void GenerateFullString()
{
string data = string.Empty;
for ( int i = 0; i < m_clipboardStrData.Count; i++ )
{
data += m_clipboardStrData[ i ].ToString();
if ( i < m_clipboardStrData.Count - 1 )
{
data += IOUtils.LINE_TERMINATOR;
}
}
}
public void ClearClipboard()
{
m_clipboardStrData.Clear();
m_clipboardAuxData.Clear();
m_multiPassMasterNodeData.Clear();
}
public ClipboardData GetClipboardData( int oldNodeId )
{
if ( m_clipboardAuxData.ContainsKey( oldNodeId ) )
return m_clipboardAuxData[ oldNodeId ];
return null;
}
public int GeNewNodeId( int oldNodeId )
{
if ( m_clipboardAuxData.ContainsKey( oldNodeId ) )
return m_clipboardAuxData[ oldNodeId ].NewNodeId;
return -1;
}
public List<ClipboardData> CurrentClipboardStrData
{
get { return m_clipboardStrData; }
}
public bool HasCachedMasterNodes { get { return m_multiPassMasterNodeData.Count > 0; } }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8850a8c4f3ca99f42bbf602c671ffb7f
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,120 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEditor;
using UnityEngine;
namespace AmplifyShaderEditor
{
public class ConfirmationWindow
{
public delegate ShaderLoadResult OnConfirmationSelected( bool value, Shader shader, Material material );
public event OnConfirmationSelected OnConfirmationSelectedEvt;
private const string m_yesStr = "Yes";
private const string m_noStr = "No";
private bool m_isActive = false;
private string m_currentMessage;
private GUIStyle m_areaStyle;
private GUIContent m_content;
private GUIStyle m_buttonStyle;
private GUIStyle m_labelStyle;
private Shader m_shader;
private Material m_material;
private Rect m_area;
private bool m_autoDeactivate = true;
public ConfirmationWindow( float x, float y, float width, float height )
{
m_content = new GUIContent( GUIContent.none );
m_area = new Rect( x, y, width, height );
}
public void Destroy()
{
m_shader = null;
OnConfirmationSelectedEvt = null;
}
public void ActivateConfirmation( Shader shader, Material material, string message, OnConfirmationSelected evt, bool autoDeactivate = true )
{
OnConfirmationSelectedEvt = evt;
m_currentMessage = message;
m_shader = shader;
m_material = material;
m_autoDeactivate = autoDeactivate;
m_isActive = true;
}
public void OnGUI()
{
if ( m_areaStyle == null )
{
m_areaStyle = new GUIStyle( UIUtils.TextArea );
m_areaStyle.stretchHeight = true;
m_areaStyle.stretchWidth = true;
m_areaStyle.fontSize = ( int ) Constants.DefaultTitleFontSize;
}
if ( m_buttonStyle == null )
{
m_buttonStyle = UIUtils.Button;
}
if ( m_labelStyle == null )
{
m_labelStyle = new GUIStyle( UIUtils.Label );
m_labelStyle.alignment = TextAnchor.MiddleCenter;
m_labelStyle.wordWrap = true;
}
m_area.x = ( int ) ( 0.5f * UIUtils.CurrentWindow.CameraInfo.width );
m_area.y = ( int ) ( 0.5f * UIUtils.CurrentWindow.CameraInfo.height );
GUILayout.BeginArea( m_area, m_content, m_areaStyle );
{
EditorGUILayout.BeginVertical();
{
EditorGUILayout.Separator();
EditorGUILayout.LabelField( m_currentMessage, m_labelStyle );
EditorGUILayout.Separator();
EditorGUILayout.Separator();
EditorGUILayout.BeginHorizontal();
{
if ( GUILayout.Button( m_yesStr, m_buttonStyle ) )
{
if ( OnConfirmationSelectedEvt != null )
OnConfirmationSelectedEvt( true, m_shader, m_material );
if ( m_autoDeactivate )
Deactivate();
}
if ( GUILayout.Button( m_noStr, m_buttonStyle ) )
{
if ( OnConfirmationSelectedEvt != null )
OnConfirmationSelectedEvt( false, m_shader, m_material );
if ( m_autoDeactivate )
Deactivate();
}
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
}
GUILayout.EndArea();
}
public void Deactivate()
{
m_isActive = false;
OnConfirmationSelectedEvt = null;
}
public bool IsActive { get { return m_isActive; } }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 291cb40a04f835a4d89037cf3053c6a3
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,309 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace AmplifyShaderEditor
{
[System.Serializable]
public class Toast
{
public MessageSeverity ItemType;
public string ItemMessage;
public double ItemTime;
public int ItemOwnerId;
public Toast( MessageSeverity itemType, string itemMessage, double itemTime,int itemOwnerId )
{
ItemType = itemType;
ItemMessage = itemMessage;
ItemTime = itemTime;
ItemOwnerId = itemOwnerId;
}
}
public class ConsoleLogWindow
{
public const int MAXWIDTH = 400;
public const float FADETIME = 7;
private readonly GUIContent m_boxToggleContent = new GUIContent( "\u2261", "Toggle Message Box" );
private readonly GUIContent m_clearContent = new GUIContent( "\u00D7", "Clear Messages" );
protected AmplifyShaderEditorWindow m_parentWindow = null;
// needs to be serialized
private Vector2 m_currentScrollPos;
int lastCall = -1;
public ConsoleLogWindow( AmplifyShaderEditorWindow parentWindow )
{
m_parentWindow = parentWindow;
}
public void AddMessage( MessageSeverity itemType, string itemMessage , int itemOwnerId )
{
var toast = new Toast( itemType, itemMessage, Time.realtimeSinceStartup, itemOwnerId );
m_parentWindow.Messages.Insert( 0, toast );
m_currentScrollPos.y = Mathf.Infinity;
if( !m_parentWindow.MaximizeMessages )
lastCall = Mathf.Max( (int)itemType, lastCall );
GUIContent gc = new GUIContent( m_parentWindow.Messages.Count + ": " + itemMessage );
float maxWidth = m_parentWindow.MaxMsgWidth;
maxWidth = Mathf.Max( GUIStyle.none.CalcSize( gc ).x + 16, maxWidth );
maxWidth = Mathf.Min( maxWidth, MAXWIDTH );
m_parentWindow.MaxMsgWidth = maxWidth;
}
public void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus, float rightSide )
{
EventType currentEventType = Event.current.type;
var messages = m_parentWindow.Messages;
var maximize = m_parentWindow.MaximizeMessages;
Rect button = parentPosition;
button.width = 22;
button.height = 22;
button.x = parentPosition.x + parentPosition.width - button.width - rightSide - 8;
button.y = parentPosition.y + parentPosition.height - button.height - ( m_parentWindow.CurrentSelection == ASESelectionMode.Material ? 52 : 8 );
Rect toolbarArea = button;
toolbarArea.y -= 5;
if( maximize )
{
toolbarArea.xMin -= m_parentWindow.MaxMsgWidth;
toolbarArea.yMin -= 66;
}
toolbarArea.x -= 6;
bool needsRepaint = false;
if( maximize )
{
GUIStyle labelStyle = UIUtils.ConsoleLogLabel;
toolbarArea.y -= 16 + 8;
GUILayout.BeginArea( toolbarArea, UIUtils.ConsoleLogMessage );
EditorGUILayout.BeginVertical();
m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos );
{
int count = messages.Count;
for( int i = count - 1; i >= 0; i-- )
{
switch( messages[ i ].ItemType )
{
case MessageSeverity.Error:
labelStyle.normal.textColor = Color.red;
break;
case MessageSeverity.Warning:
labelStyle.normal.textColor = Color.yellow;
break;
default:
case MessageSeverity.Normal:
labelStyle.normal.textColor = Color.white;
break;
}
if( messages[ i ].ItemOwnerId < 0 )
{
if( Event.current.control && Event.current.shift )
{
if( GUILayout.Button( ( count - i ) + ": " + messages[ i ].ItemMessage, labelStyle ) )
{
if( Event.current.button == 1 )
{
EditorGUIUtility.systemCopyBuffer = messages[ i ].ItemMessage;
}
}
}
else
{
GUILayout.Label( ( count - i ) + ": " + messages[ i ].ItemMessage, labelStyle );
}
}
else
{
if( GUILayout.Button( ( count - i ) + ": " + messages[ i ].ItemMessage, labelStyle ) )
{
UIUtils.CurrentWindow.FocusOnNode( messages[ i ].ItemOwnerId, 1, true );
if( Event.current.button == 1 )
{
EditorGUIUtility.systemCopyBuffer = messages[ i ].ItemMessage;
}
}
}
}
}
EditorGUILayout.EndScrollView();
EditorGUILayout.EndVertical();
GUILayout.EndArea();
}
else
{
// draw toaster
int count = messages.Count;
Rect rect = toolbarArea;
rect.xMin -= 200;
float startFade = FADETIME - 1;
for( int i = 0; i < count; i++ )
{
GUIStyle msgstyle = UIUtils.ConsoleLogMessage;
float delta = (float)(Time.realtimeSinceStartup - messages[ i ].ItemTime);
if( delta > FADETIME )
continue;
if( delta < 0.1f )
{
msgstyle.normal.textColor = Color.cyan;
}
else if( delta < startFade )
{
switch( messages[ i ].ItemType )
{
case MessageSeverity.Error:
msgstyle.normal.textColor = Color.red;
break;
case MessageSeverity.Warning:
msgstyle.normal.textColor = Color.yellow;
break;
default:
case MessageSeverity.Normal:
msgstyle.normal.textColor = Color.white;
break;
}
}
else
{
switch( messages[ i ].ItemType )
{
case MessageSeverity.Error:
msgstyle.normal.textColor = new Color( 1, 0, 0, FADETIME - delta );
break;
case MessageSeverity.Warning:
msgstyle.normal.textColor = new Color( 1, 1, 0, FADETIME - delta );
break;
default:
case MessageSeverity.Normal:
msgstyle.normal.textColor = new Color( 1, 1, 1, FADETIME - delta );
break;
}
}
needsRepaint = true;
GUIContent gc = new GUIContent( messages[ i ].ItemMessage );
var sizes = msgstyle.CalcSize( gc );
rect.xMin -= sizes.x - rect.width;
rect.height = sizes.y;
rect.y -= rect.height + 2;
if( messages[ i ].ItemOwnerId < 0 )
{
GUI.Label( rect, gc, msgstyle );
}
else
{
if( GUI.Button( rect, gc, msgstyle ))
{
UIUtils.CurrentWindow.FocusOnNode( messages[ i ].ItemOwnerId, 1, true );
if( Event.current.button == 1 )
{
EditorGUIUtility.systemCopyBuffer = messages[ i ].ItemMessage;
}
}
}
}
}
//GUI.color = cached;
if( needsRepaint )
m_parentWindow.MarkToRepaint();
GUIStyle style = UIUtils.ConsoleLogCircle;
button.size = Vector2.one * 16;
switch( lastCall )
{
case 0:
style.normal.textColor = Color.cyan;
break;
case 1:
style.normal.textColor = Color.yellow;
break;
case 2:
style.normal.textColor = Color.red;
break;
default:
style.normal.textColor = new Color( 1, 1, 1, 0.5f );
break;
}
if( GUI.Button( button, m_boxToggleContent, style ) )
{
maximize = !maximize;
m_parentWindow.MaximizeMessages = maximize;
m_currentScrollPos.y = Mathf.Infinity;
lastCall = -1;
}
style.normal.textColor = new Color( 1, 1, 1, 0.5f );
//GUI.color = cached;
button.x -= button.width + 2;
if( maximize && GUI.Button( button, m_clearContent, style ) )
{
if( messages.Count == 0 )
{
maximize = false;
m_parentWindow.MaximizeMessages = maximize;
}
ClearMessages();
}
button.width += button.width + 2;
bool mouseOnTop = button.Contains( mousePosition );
if( currentEventType == EventType.MouseMove && mouseOnTop )
m_parentWindow.MarkToRepaint();
if( DebugConsoleWindow.DeveloperMode )
{
if( Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Alpha1 )
{
UIUtils.ShowMessage( "This is an info message\nwith two lines" );
}
if( Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Alpha2 )
{
UIUtils.ShowMessage( "This is a warning message", MessageSeverity.Warning );
}
if( Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Alpha3 )
{
UIUtils.ShowMessage( "THIS IS AN ERROR MESSAGE!!", MessageSeverity.Error );
}
}
}
public void ClearMessages()
{
m_parentWindow.Messages.Clear();
m_parentWindow.MaxMsgWidth = 100;
}
public void Toggle()
{
}
public void Destroy()
{
m_parentWindow = null;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ed706353a579cbb46b300406107108b1
timeCreated: 1506345180
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,81 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
namespace AmplifyShaderEditor
{
public class ContextMenuItem
{
private const string PALETTE_NAME_MOD_STR = " ";
private string m_paletteName;
private string m_name;
private string m_tags;
private string m_category;
private string m_description;
private System.Type m_type;
private GUIContent m_guiContent;
private string m_nameWithShortcut;
private AmplifyShaderFunction m_function;
private NodeAttributes m_nodeAttributes;
public ContextMenuItem( NodeAttributes nodeAttributes, System.Type type, string name, string tags, string category, string description, AmplifyShaderFunction function, KeyCode shortcut )
{
m_nodeAttributes = nodeAttributes;
m_name = name;
m_tags = name + ( string.IsNullOrEmpty( tags ) ? "" : " " + tags );
m_tags = m_tags.ToLower();
m_nameWithShortcut = shortcut != KeyCode.None ? ( name + " [ " + UIUtils.KeyCodeToString( shortcut ) + " ]" ) : name;
m_paletteName = PALETTE_NAME_MOD_STR + m_name;
m_type = type;
m_category = category;
m_description = description;
m_function = function;
m_guiContent = new GUIContent( m_nameWithShortcut, m_description );
}
public int CompareTo( ContextMenuItem item , bool useWeights )
{
if ( useWeights && NodeAttributes.SortOrderPriority > -1 && item.NodeAttributes.SortOrderPriority > -1 )
{
if ( NodeAttributes.SortOrderPriority > item.NodeAttributes.SortOrderPriority )
{
return 1;
}
else if ( NodeAttributes.SortOrderPriority == item.NodeAttributes.SortOrderPriority )
{
return m_name.CompareTo( item.Name );
}
else
{
return -1;
}
}
return m_name.CompareTo( item.Name );
}
public string PaletteName { get { return m_paletteName; } }
public string Name { get { return m_name; } }
public string Tags { get { return m_tags; } }
public string NameWithShortcut { get { return m_nameWithShortcut; } }
public string Category { get { return m_category; } }
public string Description { get { return m_description; } }
public AmplifyShaderFunction Function { get { return m_function; } }
public System.Type NodeType { get { return m_type; } }
public GUIContent ItemUIContent { get { return m_guiContent; } }
public NodeAttributes NodeAttributes { get { return m_nodeAttributes; } }
public override string ToString()
{
return m_name + ":" + m_category + ":" + m_description;
}
public void Destroy()
{
m_guiContent = null;
m_nodeAttributes = null;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 417f409230c530b468b8ab67dd6e3b8b
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
//using UnityEditor;
//using UnityEngine;
//namespace AmplifyShaderEditor
//{
// //EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector)
// // this might be a bit nonsense since I could use the GetBuiltinSkin directly but this way will bea easier to change to some custom visuals on some near future
// [System.Serializable]
// public class CustomStylesContainer
// {
// public GUIStyle FoldoutStyle
// {
// get { return EditorStyles.foldout; }
// }
// public GUIStyle Label
// {
// get { return GUI.skin.label; }
// }
// public GUIStyle Button
// {
// get { return GUI.skin.button; }
// }
// public GUIStyle TextArea
// {
// get { return GUI.skin.textArea; }
// }
// public GUIStyle Toggle
// {
// get { return GUI.skin.toggle; }
// }
// public GUIStyle Window
// {
// get { return GUI.skin.window; }
// }
// public GUIStyle Textfield
// {
// get { return GUI.skin.textField; }
// }
// public GUIStyle Box
// {
// get { return GUI.skin.box; }
// }
// }
//}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 79d0d783b532b474192b191547bee1c1
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,203 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
//#define ASE_CONSOLE_WINDOW
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace AmplifyShaderEditor
{
public sealed class DebugConsoleWindow : EditorWindow
{
private const float WindowSizeX = 250;
private const float WindowSizeY = 250;
private const float WindowPosX = 5;
private const float WindowPosY = 5;
private Rect m_availableArea;
private bool m_wikiAreaFoldout = true;
private bool m_miscAreaFoldout = true;
private Vector2 m_currentScrollPos;
private int m_minURLNode = 0;
private int m_maxURLNode = -1;
#if ASE_CONSOLE_WINDOW
public readonly static bool DeveloperMode = true;
public static bool UseShaderPanelsInfo = true;
[MenuItem( "Window/Amplify Shader Editor/Open Debug Console" )]
static void OpenMainShaderGraph()
{
OpenWindow();
}
[MenuItem( "Window/Amplify Shader Editor/Create Template Menu Items" )]
public static void CreateTemplateMenuItems()
{
UIUtils.CurrentWindow.TemplatesManagerInstance.CreateTemplateMenuItems();
}
#else
public readonly static bool DeveloperMode = false;
public static bool UseShaderPanelsInfo = false;
#endif
public static DebugConsoleWindow OpenWindow()
{
if ( DeveloperMode )
{
DebugConsoleWindow currentWindow = ( DebugConsoleWindow ) DebugConsoleWindow.GetWindow( typeof( DebugConsoleWindow ), false, "ASE Debug Console" );
currentWindow.titleContent.tooltip = "Debug Options for ASE. Intented only for ASE development team";
currentWindow.minSize = new Vector2( WindowSizeX, WindowSizeY );
currentWindow.maxSize = new Vector2( WindowSizeX, 2 * WindowSizeY ); ;
currentWindow.wantsMouseMove = true;
return currentWindow;
}
return null;
}
void OnGUI()
{
m_availableArea = new Rect( WindowPosX, WindowPosY, position.width - 2 * WindowPosX, position.height - 2 * WindowPosY );
GUILayout.BeginArea( m_availableArea );
{
m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos, GUILayout.Width( 0 ), GUILayout.Height( 0 ) );
{
EditorGUILayout.BeginVertical();
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
if ( window != null )
{
EditorGUILayout.Separator();
NodeUtils.DrawPropertyGroup( ref m_wikiAreaFoldout, "Wiki Helper", ShowWikiHelperFunctions );
EditorGUILayout.Separator();
NodeUtils.DrawPropertyGroup( ref m_miscAreaFoldout, "Misc", ShowMiscFuntions );
EditorGUILayout.Separator();
}
else
{
EditorGUILayout.LabelField( "Please open an ASE window to access debug options" );
}
}
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndScrollView();
}
GUILayout.EndArea();
}
void ShowWikiHelperFunctions()
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
EditorGUILayout.Separator();
if ( GUILayout.Button( "Nodes Screen Shots" ) )
{
window.CurrentNodeExporterUtils.ActivateAutoScreenShot( Application.dataPath + "/../NodesInfo/Shots/",0,-1 );
}
GUILayout.BeginHorizontal();
if( GUILayout.Button( "Nodes URLs" ) )
{
window.CurrentNodeExporterUtils.ActivateNodesURL( m_minURLNode, m_maxURLNode );
}
m_minURLNode = EditorGUILayout.IntField( m_minURLNode );
m_maxURLNode = EditorGUILayout.IntField( m_maxURLNode );
GUILayout.EndHorizontal();
EditorGUILayout.Separator();
if( GUILayout.Button( "Nodes Undo Test" ) )
{
window.CurrentNodeExporterUtils.ActivateAutoUndo();
}
EditorGUILayout.Separator();
if ( GUILayout.Button( "Nodes Info" ) )
{
window.CurrentPaletteWindow.DumpAvailableNodes( false, Application.dataPath + "/../NodesInfo/" );
window.CurrentPaletteWindow.DumpAvailableNodes( true, Application.dataPath + "/../NodesInfo/" );
}
EditorGUILayout.Separator();
if ( GUILayout.Button( "Shortcuts Info" ) )
{
window.ShortcutManagerInstance.DumpShortcutsToDisk( Application.dataPath + "/../NodesInfo/" );
}
}
void ShowMiscFuntions()
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
if ( GUILayout.Button( "Force Example Shader Compilation" ) )
{
UIUtils.ForceExampleShaderCompilation();
}
EditorGUILayout.Separator();
if ( GUILayout.Button( "Refresh Available Nodes" ) )
{
window.RefreshAvaibleNodes();
}
EditorGUILayout.Separator();
if ( GUILayout.Button( "Dump Uniform Names" ) )
{
//window.CurrentPaletteWindow.NewList()
window.DuplicatePrevBufferInstance.DumpUniformNames();
}
EditorGUILayout.Separator();
if ( GUILayout.Button( "Force Palette Update" ) )
{
Debug.Log( UIUtils.CurrentWindow.IsShaderFunctionWindow );
window.CurrentPaletteWindow.ForceUpdate = true;
}
EditorGUILayout.Separator();
if( GUILayout.Button( "Detect Infinite Loops" ) )
{
if( window.IsShaderFunctionWindow )
{
Debug.Log( "Starting infinite loop detection over shader functions" );
List<FunctionOutput> nodes = window.OutsideGraph.FunctionOutputNodes.NodesList;
for( int i = 0; i < nodes.Count; i++ )
{
UIUtils.DetectNodeLoopsFrom( nodes[ i ], new Dictionary<int, int>() );
}
}
else
{
if( window.OutsideGraph.MultiPassMasterNodes.Count > 0 )
{
Debug.Log( "Starting infinite loop detection over shader from template" );
List<TemplateMultiPassMasterNode> nodes = window.OutsideGraph.MultiPassMasterNodes.NodesList;
for( int i = 0; i < nodes.Count; i++ )
{
UIUtils.DetectNodeLoopsFrom( nodes[ i ], new Dictionary<int, int>() );
}
}
else
{
Debug.Log( "Starting infinite loop detection over standard shader" );
UIUtils.DetectNodeLoopsFrom( window.OutsideGraph.CurrentMasterNode, new Dictionary<int, int>() );
}
}
Debug.Log( "End infinite loop detection" );
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 52308890136cd7746a5a073c9be8f028
timeCreated: 1487850100
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEditor;
using UnityEngine;
namespace AmplifyShaderEditor
{
public class DragAndDropTool
{
public delegate void OnValidDropObject(params UnityEngine.Object[] draggedObjs );
public event OnValidDropObject OnValidDropObjectEvt;
public void Destroy()
{
OnValidDropObjectEvt = null;
}
public void TestDragAndDrop( Rect dropArea )
{
Event currentEvent = Event.current;
EventType currentEventType = currentEvent.type;
switch (currentEventType)
{
case EventType.DragUpdated:
case EventType.DragPerform:
{
if (!dropArea.Contains(currentEvent.mousePosition))
return;
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (currentEvent.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
if (OnValidDropObjectEvt != null)
{
OnValidDropObjectEvt(DragAndDrop.objectReferences);
}
}
}break;
case EventType.DragExited:DragAndDrop.PrepareStartDrag();break;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 41c9bd09aea1377459c7e62910711c22
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,375 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using System.Collections.Generic;
using UnityEngine;
namespace AmplifyShaderEditor
{
[Serializable]
public class DuplicatePreventionBuffer
{
private const string VectorNameStr = "Vector ";
private const string TextureSampleNameStr = "Texture Sample ";
private const string MatrixNameStr = "Matrix ";
private const string IntNameStr = "Int ";
private const string FloatNameStr = "Float ";
private const string ColorNameStr = "Color ";
[SerializeField]
private int[] m_availableUVChannelsArray = { -1, -1, -1, -1 };
private string[] m_availableUVChannelsNamesArray = { "null",
"null",
"null",
"null" };
private Dictionary<string, int> m_availablePropertyNames = new Dictionary<string, int>();
private Dictionary<string, int> m_availableUniformNames = new Dictionary<string, int>();
private Dictionary<string, int> m_availableLocalVariableNames = new Dictionary<string, int>();
public void ReleaseAllUVChannels()
{
for ( int i = 0; i < m_availableUVChannelsArray.Length; i++ )
{
m_availableUVChannelsArray[ i ] = -1;
}
}
public bool RegisterUVChannel( int nodeId, int channelId, string name )
{
if ( channelId < 0 ||
channelId > ( m_availableUVChannelsArray.Length - 1 ) ||
m_availableUVChannelsArray[ channelId ] >= 0 )
{
return false;
}
m_availableUVChannelsArray[ channelId ] = nodeId;
m_availableUVChannelsNamesArray[ channelId ] = name;
return true;
}
public bool ReleaseUVChannel( int nodeId, int channelId )
{
if ( channelId < 0 ||
channelId > ( m_availableUVChannelsArray.Length - 1 ) )
{
return false;
}
if ( m_availableUVChannelsArray[ channelId ] == nodeId )
{
m_availableUVChannelsArray[ channelId ] = -1;
return true;
}
return false;
}
public int RegisterFirstAvailableChannel( int nodeId , string name)
{
for ( int i = 0; i < m_availableUVChannelsArray.Length; i++ )
{
if ( m_availableUVChannelsArray[ i ] == -1 )
{
m_availableUVChannelsArray[ i ] = nodeId;
m_availableUVChannelsNamesArray[ i ] = name;
return i;
}
}
return -1;
}
public bool IsChannelAvailable( int channelId )
{
if ( channelId < 0 ||
channelId > ( m_availableUVChannelsArray.Length - 1 ) )
{
return false;
}
return ( m_availableUVChannelsArray[ channelId ] < 0 );
}
public int GetFirstOccupiedChannel()
{
for ( int i = 0; i < 4; i++ )
{
if ( m_availableUVChannelsArray[ i ] > -1 )
return i;
}
return -1;
}
public string GetChannelName( int channelId )
{
if ( channelId < 0 ||
channelId > ( m_availableUVChannelsArray.Length - 1 ) )
{
return string.Empty;
}
return m_availableUVChannelsNamesArray[ channelId ] ;
}
public void SetChannelName( int channelId , string name )
{
if ( channelId < 0 ||
channelId > ( m_availableUVChannelsArray.Length - 1 ) )
{
return;
}
m_availableUVChannelsNamesArray[ channelId ] = name;
}
public bool RegisterLocalVariableName( int nodeId, string name )
{
if ( name.Length == 0 )
return false;
if ( m_availableLocalVariableNames.ContainsKey( name ) )
{
if ( m_availableLocalVariableNames[ name ] > -1 )
{
return false;
}
else
{
m_availableLocalVariableNames[ name ] = nodeId;
return true;
}
}
m_availableLocalVariableNames.Add( name, nodeId );
return true;
}
public int CheckUniformNameOwner( string name )
{
if ( name.Length == 0 )
return -1;
if ( m_availableUniformNames.ContainsKey( name ) )
{
return m_availableUniformNames[ name ];
}
return -1;
}
public bool RegisterUniformName( int nodeId, string name )
{
if ( name.Length == 0 )
return false;
if ( m_availableUniformNames.ContainsKey( name ) )
{
if ( m_availableUniformNames[ name ] > -1 )
{
return false;
}
else
{
m_availableUniformNames[ name ] = nodeId;
return true;
}
}
m_availableUniformNames.Add( name, nodeId );
return true;
}
public void DumpUniformNames()
{
string val = "CONTENTS\n";
foreach ( KeyValuePair<string, int> kvp in m_availableUniformNames )
{
val += ( "key " + kvp.Key + " : value " + kvp.Value + "\n" );
}
}
public void DumpLocalVariableNames()
{
string val = "CONTENTS\n";
foreach ( KeyValuePair<string, int> kvp in m_availableLocalVariableNames )
{
val += ( "key " + kvp.Key + " : value " + kvp.Value + "\n" );
}
}
public bool ReleaseUniformName( int nodeId, string name )
{
if ( !string.IsNullOrEmpty(name) && name.Length == 0 )
return false;
if ( m_availableUniformNames.ContainsKey( name ) )
{
if ( m_availableUniformNames[ name ] == nodeId )
{
m_availableUniformNames.Remove( name );
return true;
}
}
return false;
}
public bool ReleaseLocalVariableName( int nodeId, string name )
{
if ( name.Length == 0 )
return false;
if ( m_availableLocalVariableNames.ContainsKey( name ) )
{
if ( m_availableLocalVariableNames[ name ] == nodeId )
{
m_availableLocalVariableNames.Remove( name );
return true;
}
}
return false;
}
public void ReleaseAllUniformNames()
{
m_availableUniformNames.Clear();
}
public void ReleaseAllLocalVariableNames()
{
m_availableLocalVariableNames.Clear();
}
public void GetFirstAvailableName( int nodeId, WirePortDataType type , out string outProperty , out string outInspector, bool useCustomPrefix = false, string customPrefix = null)
{
string name = string.Empty;
if ( useCustomPrefix && customPrefix != null )
{
name = customPrefix;
}
else
{
switch ( type )
{
case WirePortDataType.OBJECT:
case WirePortDataType.FLOAT:
{
name = FloatNameStr;
}
break;
case WirePortDataType.INT:
{
name = IntNameStr;
}
break;
case WirePortDataType.FLOAT2:
case WirePortDataType.FLOAT3:
case WirePortDataType.FLOAT4:
{
name = VectorNameStr;
}
break;
case WirePortDataType.FLOAT3x3:
case WirePortDataType.FLOAT4x4:
{
name = MatrixNameStr;
}
break;
case WirePortDataType.COLOR:
{
name = ColorNameStr;
}
break;
}
}
int count = 0;
bool foundName = false;
while ( !foundName )
{
string inspectorName = name + count;
string propertyName = UIUtils.GeneratePropertyName( inspectorName , PropertyType.Property );
if ( IsUniformNameAvailable( propertyName ) )
{
outInspector = inspectorName;
outProperty = propertyName;
RegisterUniformName( nodeId, propertyName );
return;
}
count += 1;
}
outProperty = string.Empty;
outInspector = string.Empty;
UIUtils.ShowMessage( "Could not find a valid name " + MessageSeverity.Warning );
}
public bool IsUniformNameAvailable( string name )
{
if ( m_availableUniformNames.ContainsKey( name ) && m_availableUniformNames[ name ] > -1 )
return false;
return true;
}
public bool IsLocalvariableNameAvailable( string name )
{
if ( m_availableLocalVariableNames.ContainsKey( name ) && m_availableLocalVariableNames[ name ] > -1 )
return false;
return true;
}
public bool GetPropertyName( int nodeId, string name )
{
if ( m_availablePropertyNames.ContainsKey( name ) )
{
if ( m_availablePropertyNames[ name ] > -1 )
{
return false;
}
else
{
m_availablePropertyNames[ name ] = nodeId;
return true;
}
}
m_availablePropertyNames.Add( name, nodeId );
return true;
}
public bool ReleasePropertyName( int nodeId, string name )
{
if ( m_availablePropertyNames.ContainsKey( name ) )
{
if ( m_availablePropertyNames[ name ] == nodeId )
{
m_availablePropertyNames[ name ] = -1;
return true;
}
}
return false;
}
public void ReleaseAllPropertyNames()
{
m_availablePropertyNames.Clear();
}
public bool IsPropertyNameAvailable( string name )
{
if ( m_availablePropertyNames.ContainsKey( name ) && m_availablePropertyNames[ name ] > -1 )
return false;
return true;
}
public void ReleaseAllData()
{
ReleaseAllUVChannels();
ReleaseAllUniformNames();
ReleaseAllPropertyNames();
ReleaseAllLocalVariableNames();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a4cfbb4204c63ca4e8f7cec73f6b3ef8
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,393 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
namespace AmplifyShaderEditor
{
public class ShortcutKeyData
{
public bool IsPressed;
public System.Type NodeType;
public string Name;
public ShortcutKeyData( System.Type type, string name )
{
NodeType = type;
Name = name;
IsPressed = false;
}
}
public class GraphContextMenu
{
private List<ContextMenuItem> m_items;
private List<ContextMenuItem> m_itemFunctions;
private Dictionary<System.Type, NodeAttributes> m_itemsDict;
private Dictionary<System.Type, NodeAttributes> m_deprecatedItemsDict;
private Dictionary<System.Type, System.Type> m_castTypes;
private Dictionary<KeyCode, ShortcutKeyData> m_shortcutTypes;
private KeyCode m_lastKeyPressed;
private ParentGraph m_currentGraph;
private bool m_correctlyLoaded = false;
public GraphContextMenu( ParentGraph currentGraph )
{
m_currentGraph = currentGraph;
m_correctlyLoaded = RefreshNodes( currentGraph );
}
private Type[] GetTypesInNamespace( Assembly assembly, string nameSpace )
{
return assembly.GetTypes().Where( t => String.Equals( t.Namespace, nameSpace, StringComparison.Ordinal ) ).ToArray();
}
public bool RefreshNodes( ParentGraph currentGraph )
{
if( m_items != null )
{
m_items.Clear();
m_items = null;
}
if( m_itemFunctions != null )
{
m_itemFunctions.Clear();
m_itemFunctions = null;
}
m_items = new List<ContextMenuItem>();
m_itemFunctions = new List<ContextMenuItem>();
if( m_itemsDict != null )
m_itemsDict.Clear();
m_itemsDict = new Dictionary<System.Type, NodeAttributes>();
if( m_deprecatedItemsDict != null )
m_deprecatedItemsDict.Clear();
m_deprecatedItemsDict = new Dictionary<System.Type, NodeAttributes>();
if( m_castTypes != null )
m_castTypes.Clear();
m_castTypes = new Dictionary<System.Type, System.Type>();
if( m_shortcutTypes != null )
m_shortcutTypes.Clear();
m_shortcutTypes = new Dictionary<KeyCode, ShortcutKeyData>();
m_lastKeyPressed = KeyCode.None;
// Fetch all available nodes by their attributes
try
{
//IEnumerable<System.Type> availableTypes = AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany( type => type.GetTypes() );
var mainAssembly = Assembly.GetExecutingAssembly();
Type[] availableTypes = GetTypesInNamespace( mainAssembly, "AmplifyShaderEditor" );
#if UNITY_2017_3_OR_NEWER
try
{
var editorAssembly = Assembly.Load( "Assembly-CSharp-Editor" );
if( mainAssembly != editorAssembly )
{
Type[] extraTypes = GetTypesInNamespace( editorAssembly, "AmplifyShaderEditor" );
availableTypes = availableTypes.Concat<Type>( extraTypes ).ToArray();
}
}
catch( Exception )
{
// quiet catch because we don't care if it fails to find the assembly, we'll just skip it
}
#endif
foreach( System.Type type in availableTypes )
{
foreach( NodeAttributes attribute in Attribute.GetCustomAttributes( type ).OfType<NodeAttributes>() )
{
if( attribute.Available && !attribute.Deprecated )
{
//if ( !UIUtils.CurrentWindow.IsShaderFunctionWindow && attribute.AvailableInFunctionsOnly )
// continue;
if( !UIUtils.HasColorCategory( attribute.Category ) )
{
if( !String.IsNullOrEmpty( attribute.CustomCategoryColor ) )
{
try
{
Color color = new Color();
ColorUtility.TryParseHtmlString( attribute.CustomCategoryColor, out color );
UIUtils.AddColorCategory( attribute.Category, color );
}
catch( Exception e )
{
Debug.LogException( e );
UIUtils.AddColorCategory( attribute.Category, Constants.DefaultCategoryColor );
}
}
//else
//{
// UIUtils.AddColorCategory( attribute.Category, Constants.DefaultCategoryColor );
//}
}
if( attribute.CastType != null && attribute.CastType.Length > 0 && type != null )
{
for( int i = 0; i < attribute.CastType.Length; i++ )
{
m_castTypes.Add( attribute.CastType[ i ], type );
}
}
if( attribute.ShortcutKey != KeyCode.None && type != null )
m_shortcutTypes.Add( attribute.ShortcutKey, new ShortcutKeyData( type, attribute.Name ) );
ContextMenuItem newItem = new ContextMenuItem( attribute, type, attribute.Name, attribute.Tags, attribute.Category, attribute.Description, null, attribute.ShortcutKey );
if( UIUtils.GetNodeAvailabilityInBitArray( attribute.NodeAvailabilityFlags, NodeAvailability.SurfaceShader ) )
m_items.Add( newItem );
else if( UIUtils.GetNodeAvailabilityInBitArray( attribute.NodeAvailabilityFlags, currentGraph.ParentWindow.CurrentNodeAvailability ) )
m_items.Add( newItem );
else if( UIUtils.GetNodeAvailabilityInBitArray( attribute.NodeAvailabilityFlags, currentGraph.CurrentCanvasMode ) )
m_items.Add( newItem );
m_itemsDict.Add( type, attribute );
m_itemFunctions.Add( newItem );
}
else
{
m_deprecatedItemsDict.Add( type, attribute );
}
}
}
}
catch( ReflectionTypeLoadException exception )
{
Debug.LogException( exception );
return false;
}
string[] guids = AssetDatabase.FindAssets( "t:AmplifyShaderFunction" );
List<AmplifyShaderFunction> allFunctions = new List<AmplifyShaderFunction>();
for( int i = 0; i < guids.Length; i++ )
{
allFunctions.Add( AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( AssetDatabase.GUIDToAssetPath( guids[ i ] ) ) );
}
int functionCount = allFunctions.Count;
if( functionCount > 0 )
{
m_castTypes.Add( typeof( AmplifyShaderFunction ), typeof( FunctionNode ) );
}
for( int i = 0; i < functionCount; i++ )
{
if( !allFunctions[ i ].Hidden )
{
NodeAttributes attribute = new NodeAttributes( allFunctions[ i ].FunctionName, allFunctions[ i ].CustomNodeCategory, allFunctions[ i ].Description, KeyCode.None, true, 0, int.MaxValue, typeof( AmplifyShaderFunction ) );
System.Type type = typeof( FunctionNode );
ContextMenuItem newItem = new ContextMenuItem( attribute, type, AddSpacesToSentence( attribute.Name ), attribute.Tags, attribute.Category, attribute.Description, allFunctions[ i ], attribute.ShortcutKey );
m_items.Add( newItem );
m_itemFunctions.Add( newItem );
}
}
//Sort out the final list by name
m_items.Sort( ( x, y ) => x.Category.CompareTo( y.Category ) );
m_itemFunctions.Sort( ( x, y ) => x.Category.CompareTo( y.Category ) );
return true;
}
public void Destroy()
{
for( int i = 0; i < m_items.Count; i++ )
{
m_items[ i ].Destroy();
}
for( int i = 0; i < m_itemFunctions.Count; i++ )
{
if( m_itemFunctions[ i ] != null )
m_itemFunctions[ i ].Destroy();
}
m_items.Clear();
m_items = null;
m_itemFunctions.Clear();
m_itemFunctions = null;
m_itemsDict.Clear();
m_itemsDict = null;
m_deprecatedItemsDict.Clear();
m_deprecatedItemsDict = null;
m_castTypes.Clear();
m_castTypes = null;
m_shortcutTypes.Clear();
m_shortcutTypes = null;
}
public static string AddSpacesToSentence( string text )
{
if( string.IsNullOrEmpty( text ) )
return string.Empty;
bool lastIsUpper = char.IsUpper( text, 0 );
bool lastIsLetter = char.IsLetter( text, 0 );
StringBuilder title = new StringBuilder();
title.Append( text[ 0 ] );
for( int i = 1; i < text.Length; i++ )
{
bool currIsUpper = char.IsUpper( text, i );
bool currIsLetter = char.IsLetter( text, i );
if( currIsUpper && !lastIsUpper && lastIsLetter )
{
title.Append( " " );
}
// if current is a number and previous is a letter we space it (ie: Rotation2D = Rotation 2D)
if( lastIsLetter && char.IsNumber( text, i ) )
{
title.Append( " " );
}
// if previous is upper, current is upper and the next two following are lower then we space it (ie: UVDistortion = UV Distortion)
if( i < text.Length - 1 )
{
bool nextIsLower = char.IsLower( text, i + 1 ) && char.IsLetter( text, i + 1 );
bool lastIsLower = i < text.Length - 2 ? char.IsLower( text, i + 2 ) && char.IsLetter( text, i + 2 ) : false;
if( lastIsUpper && currIsUpper && currIsLetter && nextIsLower && lastIsLower )
{
title.Append( " " );
}
}
lastIsUpper = currIsUpper;
lastIsLetter = currIsLetter;
title.Append( text[ i ] );
}
return title.ToString();
}
public NodeAttributes GetNodeAttributesForType( System.Type type )
{
if( type == null )
{
Debug.LogError( "Invalid type detected" );
return null;
}
if( m_itemsDict.ContainsKey( type ) )
return m_itemsDict[ type ];
return null;
}
public NodeAttributes GetDeprecatedNodeAttributesForType( System.Type type )
{
if( m_deprecatedItemsDict.ContainsKey( type ) )
return m_deprecatedItemsDict[ type ];
return null;
}
public void UpdateKeyPress( KeyCode key )
{
if( key == KeyCode.None )
return;
m_lastKeyPressed = key;
if( m_shortcutTypes.ContainsKey( key ) )
{
m_shortcutTypes[ key ].IsPressed = true;
}
}
public void UpdateKeyReleased( KeyCode key )
{
if( key == KeyCode.None )
return;
if( m_shortcutTypes.ContainsKey( key ) )
{
m_shortcutTypes[ key ].IsPressed = false;
}
}
public void ResetShortcutKeyStates()
{
foreach( KeyValuePair<KeyCode, ShortcutKeyData> kvp in m_shortcutTypes )
{
kvp.Value.IsPressed = false;
}
}
public ParentNode CreateNodeFromCastType( System.Type type )
{
if( m_castTypes.ContainsKey( type ) )
{
ParentNode newNode = (ParentNode)ScriptableObject.CreateInstance( m_castTypes[ type ] );
return newNode;
}
return null;
}
public ParentNode CreateNodeFromShortcutKey()
{
if( m_lastKeyPressed == KeyCode.None )
return null;
if( m_shortcutTypes.ContainsKey( m_lastKeyPressed ) && m_shortcutTypes[ m_lastKeyPressed ].IsPressed )
{
ParentNode newNode = (ParentNode)ScriptableObject.CreateInstance( m_shortcutTypes[ m_lastKeyPressed ].NodeType );
return newNode;
}
return null;
}
public bool CheckShortcutKey()
{
if( m_lastKeyPressed == KeyCode.None )
return false;
if( m_shortcutTypes.ContainsKey( m_lastKeyPressed ) && m_shortcutTypes[ m_lastKeyPressed ].IsPressed )
{
return true;
}
return false;
}
public List<ContextMenuItem> MenuItems
{
get
{
if( m_currentGraph.ParentWindow.IsShaderFunctionWindow )
return m_itemFunctions;
else
return m_items;
}
}
public List<ContextMenuItem> ItemFunctions { get { return m_itemFunctions; } }
public KeyCode LastKeyPressed
{
get { return m_lastKeyPressed; }
}
public Dictionary<KeyCode, ShortcutKeyData> NodeShortcuts { get { return m_shortcutTypes; } }
public bool CorrectlyLoaded { get { return m_correctlyLoaded; } }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5c34fc95a1ddd7d42bc74151061035f4
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,451 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
public enum MenuAnchor
{
TOP_LEFT = 0,
TOP_CENTER,
TOP_RIGHT,
MIDDLE_LEFT,
MIDDLE_CENTER,
MIDDLE_RIGHT,
BOTTOM_LEFT,
BOTTOM_CENTER,
BOTTOM_RIGHT,
NONE
}
public enum MenuAutoSize
{
MATCH_VERTICAL = 0,
MATCH_HORIZONTAL,
NONE
}
public class MenuParent
{
protected AmplifyShaderEditorWindow m_parentWindow = null;
protected const float MinimizeButtonXSpacing = 5;
protected const float MinimizeButtonYSpacing = 5.5f;
protected const float ResizeAreaWidth = 5;
protected const float MinimizeCollisionAdjust = 5;
protected GUIStyle m_style;
protected GUIContent m_content;
protected Rect m_maximizedArea;
protected Rect m_transformedArea;
protected Rect m_resizeArea;
protected MenuAnchor m_anchor;
protected MenuAutoSize m_autoSize;
protected bool m_isActive = true;
protected bool m_isMaximized = true;
protected bool m_lockOnMinimize = false;
protected bool m_preLockState = false;
protected Rect m_minimizedArea;
protected Rect m_minimizeButtonPos;
protected float m_realWidth;
protected GUIStyle m_empty = new GUIStyle();
protected float m_resizeDelta;
protected bool m_isResizing = false;
protected bool m_resizable = false;
protected GUIStyle m_resizeAreaStyle;
protected bool m_isMouseInside = false;
protected Vector2 m_currentScrollPos;
public MenuParent( AmplifyShaderEditorWindow parentWindow, float x, float y, float width, float height, string name, MenuAnchor anchor = MenuAnchor.NONE, MenuAutoSize autoSize = MenuAutoSize.NONE )
{
m_parentWindow = parentWindow;
m_anchor = anchor;
m_autoSize = autoSize;
m_maximizedArea = new Rect( x, y, width, height );
m_content = new GUIContent( GUIContent.none );
m_content.text = name;
m_transformedArea = new Rect();
m_resizeArea = new Rect();
m_resizeArea.width = ResizeAreaWidth;
m_resizeAreaStyle = GUIStyle.none;
m_currentScrollPos = Vector2.zero;
}
public void SetMinimizedArea( float x, float y, float width, float height )
{
m_minimizedArea = new Rect( x, y, width, height );
}
protected void InitDraw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId )
{
if ( m_style == null )
{
m_style = new GUIStyle( UIUtils.TextArea );
#if UNITY_2019_3_OR_NEWER
m_style.normal.background = m_style.normal.scaledBackgrounds[ 0 ];
m_style.normal.scaledBackgrounds = null;
m_style.border = new RectOffset( 4, 4, 4, 4 );
#endif
m_style.stretchHeight = true;
m_style.stretchWidth = true;
m_style.fontSize = ( int ) Constants.DefaultTitleFontSize;
m_style.fontStyle = FontStyle.Normal;
Texture minimizeTex = UIUtils.GetCustomStyle( CustomStyle.MaximizeButton ).normal.background;
m_minimizeButtonPos = new Rect( 0, 0, minimizeTex.width, minimizeTex.height );
}
Rect currentArea = m_isMaximized ? m_maximizedArea : m_minimizedArea;
if ( m_isMaximized )
{
if ( m_resizable )
{
if ( m_isResizing )
{
if ( m_anchor == MenuAnchor.TOP_LEFT )
m_resizeDelta = ( ParentWindow.CurrentEvent.mousePosition.x - m_maximizedArea.width );
else if ( m_anchor == MenuAnchor.TOP_RIGHT )
m_resizeDelta = ParentWindow.CurrentEvent.mousePosition.x - ( parentPosition.width - m_maximizedArea.width);
}
}
m_realWidth = m_maximizedArea.width;
if ( m_resizable )
{
if ( m_anchor == MenuAnchor.TOP_LEFT )
{
currentArea.width += m_resizeDelta;
m_realWidth += m_resizeDelta;
}
else if ( m_anchor == MenuAnchor.TOP_RIGHT )
{
currentArea.width -= m_resizeDelta;
m_realWidth -= m_resizeDelta;
}
}
}
else
{
if ( currentArea.x < 0 )
{
m_realWidth = currentArea.width + currentArea.x;
}
else if ( ( currentArea.x + currentArea.width ) > parentPosition.width )
{
m_realWidth = parentPosition.width - currentArea.x;
}
if ( m_realWidth < 0 )
m_realWidth = 0;
}
switch ( m_anchor )
{
case MenuAnchor.TOP_LEFT:
{
m_transformedArea.x = currentArea.x;
m_transformedArea.y = currentArea.y;
if ( m_isMaximized )
{
m_minimizeButtonPos.x = m_transformedArea.x + m_transformedArea.width - m_minimizeButtonPos.width - MinimizeButtonXSpacing;
m_minimizeButtonPos.y = m_transformedArea.y + MinimizeButtonYSpacing;
m_resizeArea.x = m_transformedArea.x + m_transformedArea.width;
m_resizeArea.y = m_minimizeButtonPos.y;
m_resizeArea.height = m_transformedArea.height;
}
else
{
float width = ( m_transformedArea.width - m_transformedArea.x );
m_minimizeButtonPos.x = m_transformedArea.x + width * 0.5f - m_minimizeButtonPos.width * 0.5f;
m_minimizeButtonPos.y = m_transformedArea.height * 0.5f - m_minimizeButtonPos.height * 0.5f;
}
}
break;
case MenuAnchor.TOP_CENTER:
{
m_transformedArea.x = parentPosition.width * 0.5f + currentArea.x;
m_transformedArea.y = currentArea.y;
}
break;
case MenuAnchor.TOP_RIGHT:
{
m_transformedArea.x = parentPosition.width - currentArea.x - currentArea.width;
m_transformedArea.y = currentArea.y;
if ( m_isMaximized )
{
m_minimizeButtonPos.x = m_transformedArea.x + MinimizeButtonXSpacing;
m_minimizeButtonPos.y = m_transformedArea.y + MinimizeButtonYSpacing;
m_resizeArea.x = m_transformedArea.x - ResizeAreaWidth;
m_resizeArea.y = m_minimizeButtonPos.y;
m_resizeArea.height = m_transformedArea.height;
}
else
{
float width = ( parentPosition.width - m_transformedArea.x );
m_minimizeButtonPos.x = m_transformedArea.x + width * 0.5f - m_minimizeButtonPos.width * 0.5f;
m_minimizeButtonPos.y = m_transformedArea.height * 0.5f - m_minimizeButtonPos.height * 0.5f;
}
}
break;
case MenuAnchor.MIDDLE_LEFT:
{
m_transformedArea.x = currentArea.x;
m_transformedArea.y = parentPosition.height * 0.5f + currentArea.y;
}
break;
case MenuAnchor.MIDDLE_CENTER:
{
m_transformedArea.x = parentPosition.width * 0.5f + currentArea.x;
m_transformedArea.y = parentPosition.height * 0.5f + currentArea.y;
}
break;
case MenuAnchor.MIDDLE_RIGHT:
{
m_transformedArea.x = parentPosition.width - currentArea.x - currentArea.width;
m_transformedArea.y = parentPosition.height * 0.5f + currentArea.y;
}
break;
case MenuAnchor.BOTTOM_LEFT:
{
m_transformedArea.x = currentArea.x;
m_transformedArea.y = parentPosition.height - currentArea.y - currentArea.height;
}
break;
case MenuAnchor.BOTTOM_CENTER:
{
m_transformedArea.x = parentPosition.width * 0.5f + currentArea.x;
m_transformedArea.y = parentPosition.height - currentArea.y - currentArea.height;
}
break;
case MenuAnchor.BOTTOM_RIGHT:
{
m_transformedArea.x = parentPosition.width - currentArea.x - currentArea.width;
m_transformedArea.y = parentPosition.height - currentArea.y - currentArea.height;
}
break;
case MenuAnchor.NONE:
{
m_transformedArea.x = currentArea.x;
m_transformedArea.y = currentArea.y;
}
break;
}
switch ( m_autoSize )
{
case MenuAutoSize.MATCH_HORIZONTAL:
{
m_transformedArea.width = parentPosition.width - m_transformedArea.x;
m_transformedArea.height = currentArea.height;
}
break;
case MenuAutoSize.MATCH_VERTICAL:
{
m_transformedArea.width = currentArea.width;
m_transformedArea.height = parentPosition.height - m_transformedArea.y;
}
break;
case MenuAutoSize.NONE:
{
m_transformedArea.width = currentArea.width;
m_transformedArea.height = currentArea.height;
}
break;
}
}
public virtual void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
{
InitDraw( parentPosition, mousePosition, mouseButtonId );
if ( ParentWindow.CurrentEvent.type == EventType.MouseDrag && ParentWindow.CurrentEvent.button > 0 /*catches both middle and right mouse button*/ )
{
m_isMouseInside = IsInside( mousePosition );
if ( m_isMouseInside )
{
m_currentScrollPos.x += Constants.MenuDragSpeed * ParentWindow.CurrentEvent.delta.x;
if ( m_currentScrollPos.x < 0 )
m_currentScrollPos.x = 0;
m_currentScrollPos.y += Constants.MenuDragSpeed * ParentWindow.CurrentEvent.delta.y;
if ( m_currentScrollPos.y < 0 )
m_currentScrollPos.y = 0;
}
}
}
public void PostDraw()
{
if ( !m_isMaximized )
{
m_transformedArea.height = 35;
GUI.Label( m_transformedArea, m_content, m_style );
}
Color colorBuffer = GUI.color;
GUI.color = EditorGUIUtility.isProSkin ? Color.white : Color.black;
bool guiEnabledBuffer = GUI.enabled;
GUI.enabled = !m_lockOnMinimize;
Rect buttonArea = m_minimizeButtonPos;
buttonArea.x -= MinimizeCollisionAdjust;
buttonArea.width += 2 * MinimizeCollisionAdjust;
buttonArea.y -= MinimizeCollisionAdjust;
buttonArea.height += 2 * MinimizeCollisionAdjust;
if ( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.Repaint )
GUI.Label( m_minimizeButtonPos, string.Empty, UIUtils.GetCustomStyle( m_isMaximized ? CustomStyle.MinimizeButton : CustomStyle.MaximizeButton ) );
if( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.MouseDown && buttonArea.Contains( m_parentWindow.CameraDrawInfo.MousePosition ) )
//if ( GUI.Button( buttonArea, string.Empty, m_empty ) )
{
m_isMaximized = !m_isMaximized;
m_resizeDelta = 0;
}
if ( m_resizable && m_isMaximized )
{
EditorGUIUtility.AddCursorRect( m_resizeArea, MouseCursor.ResizeHorizontal );
if ( !m_isResizing && GUI.RepeatButton( m_resizeArea, string.Empty, m_resizeAreaStyle ) )
{
m_isResizing = true;
}
else
{
if ( m_isResizing )
{
if ( ParentWindow.CurrentEvent.isMouse && ParentWindow.CurrentEvent.type != EventType.MouseDrag )
{
m_isResizing = false;
}
}
}
if ( m_realWidth < buttonArea.width )
{
// Auto-minimize
m_isMaximized = false;
m_resizeDelta = 0;
m_isResizing = false;
}
else
{
float halfSizeWindow = 0.5f * ParentWindow.position.width;
if ( m_realWidth > halfSizeWindow )
{
m_realWidth = 0.5f * ParentWindow.position.width;
if ( m_resizeDelta > 0 )
{
m_resizeDelta = m_realWidth - m_maximizedArea.width;
}
else
{
m_resizeDelta = m_maximizedArea.width - m_realWidth;
}
}
}
}
GUI.enabled = guiEnabledBuffer;
GUI.color = colorBuffer;
}
public void OnLostFocus()
{
if ( m_isResizing )
{
m_isResizing = false;
}
}
virtual public void Destroy()
{
m_empty = null;
m_resizeAreaStyle = null;
}
public float InitialX
{
get { return m_maximizedArea.x; }
set { m_maximizedArea.x = value; }
}
public float Width
{
get { return m_maximizedArea.width; }
set { m_maximizedArea.width = value; }
}
public float RealWidth
{
get { return m_realWidth; }
}
public float Height
{
get { return m_maximizedArea.height; }
set { m_maximizedArea.height = value; }
}
public Rect Size
{
get { return m_maximizedArea; }
}
public virtual bool IsInside( Vector2 position )
{
if ( !m_isActive )
return false;
return m_transformedArea.Contains( position );
}
public bool IsMaximized
{
get { return m_isMaximized; }
set { m_isMaximized = value; }
}
public Rect TransformedArea
{
get { return m_transformedArea; }
}
public bool Resizable { set { m_resizable = value; } }
public bool IsResizing { get { return m_isResizing; } }
public bool LockOnMinimize
{
set
{
if ( m_lockOnMinimize == value )
return;
m_lockOnMinimize = value;
if ( value )
{
m_preLockState = m_isMaximized;
m_isMaximized = false;
}
else
{
m_isMaximized = m_preLockState;
}
}
}
public bool IsActive
{
get { return m_isActive; }
}
public AmplifyShaderEditorWindow ParentWindow { get { return m_parentWindow; } set { m_parentWindow = value; } }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5d535d3799a3ef547aea607fdc8b947b
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,557 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using UnityEditorInternal;
namespace AmplifyShaderEditor
{
public sealed class NodeParametersWindow : MenuParent
{
private int m_lastSelectedNode = -1;
private const string TitleStr = "Node Properties";
private GUIStyle m_nodePropertiesStyle;
private GUIContent m_dummyContent = new GUIContent();
private GUIStyle m_propertyAdjustment;
private ReorderableList m_functionInputsReordableList = null;
private int m_functionInputsLastCount = 0;
private ReorderableList m_functionSwitchesReordableList = null;
private int m_functionSwitchesLastCount = 0;
private ReorderableList m_functionOutputsReordableList = null;
private int m_functionOutputsLastCount = 0;
private ReorderableList m_propertyReordableList = null;
private int m_lastCount = 0;
private bool m_forceUpdate = false;
[SerializeField]
private List<PropertyNode> m_propertyReordableNodes = new List<PropertyNode>();
// width and height are between [0,1] and represent a percentage of the total screen area
public NodeParametersWindow( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 285, 0, string.Empty, MenuAnchor.TOP_LEFT, MenuAutoSize.MATCH_VERTICAL )
{
SetMinimizedArea( -225, 0, 260, 0 );
}
public void OnShaderFunctionLoad()
{
m_functionInputsReordableList = null;
m_functionSwitchesReordableList = null;
m_functionOutputsReordableList = null;
}
public bool Draw( Rect parentPosition, ParentNode selectedNode, Vector2 mousePosition, int mouseButtonId, bool hasKeyboardFocus )
{
bool changeCheck = false;
base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboardFocus );
if ( m_nodePropertiesStyle == null )
{
m_nodePropertiesStyle = UIUtils.GetCustomStyle( CustomStyle.NodePropertiesTitle );
m_nodePropertiesStyle.normal.textColor = m_nodePropertiesStyle.active.textColor = EditorGUIUtility.isProSkin ? new Color( 1f, 1f, 1f ) : new Color( 0f, 0f, 0f );
}
if ( m_isMaximized )
{
KeyCode key = Event.current.keyCode;
if ( m_isMouseInside || hasKeyboardFocus )
{
if ( key == ShortcutsManager.ScrollUpKey )
{
m_currentScrollPos.y -= 10;
if ( m_currentScrollPos.y < 0 )
{
m_currentScrollPos.y = 0;
}
Event.current.Use();
}
if ( key == ShortcutsManager.ScrollDownKey )
{
m_currentScrollPos.y += 10;
Event.current.Use();
}
}
if( m_forceUpdate )
{
if( m_propertyReordableList != null )
m_propertyReordableList.ReleaseKeyboardFocus();
m_propertyReordableList = null;
if ( m_functionInputsReordableList != null )
m_functionInputsReordableList.ReleaseKeyboardFocus();
m_functionInputsReordableList = null;
if( m_functionSwitchesReordableList != null )
m_functionSwitchesReordableList.ReleaseKeyboardFocus();
m_functionSwitchesReordableList = null;
if ( m_functionOutputsReordableList != null )
m_functionOutputsReordableList.ReleaseKeyboardFocus();
m_functionOutputsReordableList = null;
m_forceUpdate = false;
}
GUILayout.BeginArea( m_transformedArea, m_content, m_style );
{
//Draw selected node parameters
if ( selectedNode != null )
{
// this hack is need because without it the several FloatFields/Textfields/... would show wrong values ( different from the ones they were assigned to show )
if ( m_lastSelectedNode != selectedNode.UniqueId )
{
m_lastSelectedNode = selectedNode.UniqueId;
GUI.FocusControl( "" );
}
EditorGUILayout.BeginVertical();
{
EditorGUILayout.Separator();
if ( selectedNode.UniqueId == ParentWindow.CurrentGraph.CurrentMasterNodeId )
{
m_dummyContent.text = "Output Node";
}
else
{
if ( selectedNode.Attributes != null )
{
m_dummyContent.text = selectedNode.Attributes.Name;
}
else if ( selectedNode is CommentaryNode )
{
m_dummyContent.text = "Commentary";
}
else
{
m_dummyContent.text = TitleStr;
}
}
EditorGUILayout.LabelField( m_dummyContent, m_nodePropertiesStyle );
EditorGUILayout.Separator();
//UIUtils.RecordObject( selectedNode , "Changing properties on node " + selectedNode.UniqueId);
m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos, GUILayout.Width( 0 ), GUILayout.Height( 0 ) );
float labelWidth = EditorGUIUtility.labelWidth;
//if( selectedNode.TextLabelWidth > 0 )
// EditorGUIUtility.labelWidth = selectedNode.TextLabelWidth;
//else
EditorGUIUtility.labelWidth = TransformedArea.width * 0.42f;
changeCheck = selectedNode.SafeDrawProperties();
EditorGUIUtility.labelWidth = labelWidth;
EditorGUILayout.EndScrollView();
}
EditorGUILayout.EndVertical();
if ( changeCheck )
{
if ( selectedNode.ConnStatus == NodeConnectionStatus.Connected )
ParentWindow.SetSaveIsDirty();
}
}
else
{
//Draw Graph Params
EditorGUILayout.BeginVertical();
{
EditorGUILayout.Separator();
EditorGUILayout.LabelField( "Graph Properties", m_nodePropertiesStyle );
EditorGUILayout.Separator();
m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos, GUILayout.Width( 0 ), GUILayout.Height( 0 ) );
float labelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 90;
bool generalIsVisible = m_parentWindow.InnerWindowVariables.ExpandedGeneralShaderOptions;
NodeUtils.DrawPropertyGroup( ref generalIsVisible, " General", DrawGeneralFunction );
m_parentWindow.InnerWindowVariables.ExpandedGeneralShaderOptions = generalIsVisible;
AmplifyShaderFunction function = ParentWindow.CurrentGraph.CurrentShaderFunction;
if( function != null )
{
//function.AdditionalIncludes.Draw( ParentWindow.CurrentGraph.CurrentOutputNode );
//function.AdditionalPragmas.Draw( ParentWindow.CurrentGraph.CurrentOutputNode );
function.AdditionalDirectives.Draw( ParentWindow.CurrentGraph.CurrentOutputNode );
}
bool inputIsVisible = m_parentWindow.InnerWindowVariables.ExpandedFunctionInputs;
NodeUtils.DrawPropertyGroup( ref inputIsVisible, " Function Inputs", DrawFunctionInputs );
m_parentWindow.InnerWindowVariables.ExpandedFunctionInputs = inputIsVisible;
bool swicthIsVisible = m_parentWindow.InnerWindowVariables.ExpandedFunctionSwitches;
NodeUtils.DrawPropertyGroup( ref swicthIsVisible, " Function Switches", DrawFunctionSwitches );
m_parentWindow.InnerWindowVariables.ExpandedFunctionSwitches = swicthIsVisible;
bool outputIsVisible = m_parentWindow.InnerWindowVariables.ExpandedFunctionOutputs;
NodeUtils.DrawPropertyGroup( ref outputIsVisible, " Function Outputs", DrawFunctionOutputs );
m_parentWindow.InnerWindowVariables.ExpandedFunctionOutputs = outputIsVisible;
bool properties = ParentWindow.InnerWindowVariables.ExpandedProperties;
NodeUtils.DrawPropertyGroup( ref properties, " Material Properties", DrawFunctionProperties );
ParentWindow.InnerWindowVariables.ExpandedProperties = properties;
EditorGUIUtility.labelWidth = labelWidth;
EditorGUILayout.EndScrollView();
}
EditorGUILayout.EndVertical();
}
}
// Close window area
GUILayout.EndArea();
}
PostDraw();
return changeCheck;
}
public void DrawGeneralFunction()
{
AmplifyShaderFunction function = ParentWindow.CurrentGraph.CurrentShaderFunction;
if ( function == null )
return;
float cacheWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 115;
SerializedObject serializedObject = new UnityEditor.SerializedObject( function );
if ( serializedObject != null )
{
SerializedProperty temo = serializedObject.FindProperty( "m_description" );
EditorGUILayout.PropertyField( temo, new GUIContent( " Description" ) );
SerializedProperty cat = serializedObject.FindProperty( "m_nodeCategory" );
SerializedProperty ppos = serializedObject.FindProperty( "m_previewPosition" );
EditorGUILayout.PropertyField( ppos, new GUIContent( "Preview Position" ) );
cat.intValue = ParentWindow.CurrentGraph.CurrentOutputNode.EditorGUILayoutPopup( "Category", cat.intValue, UIUtils.CategoryPresets );
if( cat.enumValueIndex == 0 )
{
SerializedProperty custCat = serializedObject.FindProperty( "m_customNodeCategory" );
EditorGUILayout.PropertyField( custCat, new GUIContent( "Custom" ) );
}
SerializedProperty hidden = serializedObject.FindProperty( "m_hidden" );
EditorGUILayout.PropertyField( hidden, new GUIContent( "Hidden" ) );
serializedObject.ApplyModifiedProperties();
}
EditorGUIUtility.labelWidth = cacheWidth;
}
public void DrawFunctionInputs()
{
List<FunctionInput> functionInputNodes = UIUtils.FunctionInputList();
if ( m_functionInputsReordableList == null || functionInputNodes.Count != m_functionInputsLastCount )
{
functionInputNodes.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
m_functionInputsReordableList = new ReorderableList( functionInputNodes, typeof( FunctionInput ), true, false, false, false );
m_functionInputsReordableList.headerHeight = 0;
m_functionInputsReordableList.footerHeight = 0;
m_functionInputsReordableList.showDefaultBackground = false;
m_functionInputsReordableList.drawElementCallback = ( Rect rect, int index, bool isActive, bool isFocused ) =>
{
EditorGUI.LabelField( rect, functionInputNodes[ index ].InputName );
};
m_functionInputsReordableList.onChangedCallback = ( list ) =>
{
//for ( int i = 0; i < functionInputNodes.Count; i++ )
//{
// functionInputNodes[ i ].OrderIndex = i;
//}
ForceInputReorder( ref functionInputNodes );
};
m_functionInputsLastCount = m_functionInputsReordableList.count;
}
if ( m_functionInputsReordableList != null )
{
if ( m_propertyAdjustment == null )
{
m_propertyAdjustment = new GUIStyle();
m_propertyAdjustment.padding.left = 17;
}
EditorGUILayout.BeginVertical( m_propertyAdjustment );
m_functionInputsReordableList.DoLayoutList();
EditorGUILayout.EndVertical();
}
}
public void ForceInputReorder( ref List<FunctionInput> functionInputNodes )
{
for( int i = 0; i < functionInputNodes.Count; i++ )
{
functionInputNodes[ i ].OrderIndex = i;
}
}
public void DrawFunctionSwitches()
{
List<FunctionSwitch> functionSwitchNodes = UIUtils.FunctionSwitchList();
if( m_functionSwitchesReordableList == null || functionSwitchNodes.Count != m_functionSwitchesLastCount )
{
functionSwitchNodes.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
UIUtils.UpdateFunctionSwitchArr();
m_functionSwitchesReordableList = new ReorderableList( functionSwitchNodes, typeof( FunctionSwitch ), true, false, false, false );
m_functionSwitchesReordableList.headerHeight = 0;
m_functionSwitchesReordableList.footerHeight = 0;
m_functionSwitchesReordableList.showDefaultBackground = false;
m_functionSwitchesReordableList.drawElementCallback = ( Rect rect, int index, bool isActive, bool isFocused ) =>
{
EditorGUI.LabelField( rect, functionSwitchNodes[ index ].OptionLabel );
};
m_functionSwitchesReordableList.onChangedCallback = ( list ) =>
{
ForceSwitchesReorder(ref functionSwitchNodes );
};
m_functionSwitchesLastCount = m_functionSwitchesReordableList.count;
}
if( m_functionSwitchesReordableList != null )
{
if( m_propertyAdjustment == null )
{
m_propertyAdjustment = new GUIStyle();
m_propertyAdjustment.padding.left = 17;
}
EditorGUILayout.BeginVertical( m_propertyAdjustment );
m_functionSwitchesReordableList.DoLayoutList();
EditorGUILayout.EndVertical();
}
}
public void ForceSwitchesReorder( ref List<FunctionSwitch> functionSwitchNodes )
{
for( int i = 0; i < functionSwitchNodes.Count; i++ )
{
functionSwitchNodes[ i ].OrderIndex = i;
}
UIUtils.UpdateFunctionSwitchArr();
}
public void DrawFunctionOutputs()
{
List<FunctionOutput> functionOutputNodes = UIUtils.FunctionOutputList();
if ( m_functionOutputsReordableList == null || functionOutputNodes.Count != m_functionOutputsLastCount )
{
functionOutputNodes.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
m_functionOutputsReordableList = new ReorderableList( functionOutputNodes, typeof( FunctionOutput ), true, false, false, false );
m_functionOutputsReordableList.headerHeight = 0;
m_functionOutputsReordableList.footerHeight = 0;
m_functionOutputsReordableList.showDefaultBackground = false;
m_functionOutputsReordableList.drawElementCallback = ( Rect rect, int index, bool isActive, bool isFocused ) =>
{
EditorGUI.LabelField( rect, functionOutputNodes[ index ].OutputName );
};
m_functionOutputsReordableList.onChangedCallback = ( list ) =>
{
for ( int i = 0; i < functionOutputNodes.Count; i++ )
{
functionOutputNodes[ i ].OrderIndex = i;
}
};
m_functionOutputsLastCount = m_functionOutputsReordableList.count;
}
if ( m_functionOutputsReordableList != null )
{
if ( m_propertyAdjustment == null )
{
m_propertyAdjustment = new GUIStyle();
m_propertyAdjustment.padding.left = 17;
}
EditorGUILayout.BeginVertical( m_propertyAdjustment );
m_functionOutputsReordableList.DoLayoutList();
EditorGUILayout.EndVertical();
}
}
private void RefreshVisibleList( ref List<PropertyNode> allNodes )
{
// temp reference for lambda expression
List<PropertyNode> nodes = allNodes;
m_propertyReordableNodes.Clear();
for( int i = 0; i < nodes.Count; i++ )
{
ReordenatorNode rnode = nodes[ i ] as ReordenatorNode;
if( ( rnode == null || !rnode.IsInside ) && ( !m_propertyReordableNodes.Exists( x => x.PropertyName.Equals( nodes[ i ].PropertyName ) ) ) )
m_propertyReordableNodes.Add( nodes[ i ] );
}
m_propertyReordableNodes.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
}
public void DrawFunctionProperties()
{
List<PropertyNode> nodes = UIUtils.PropertyNodesList();
if( nodes.Count != m_lastCount )
{
RefreshVisibleList( ref nodes );
m_lastCount = nodes.Count;
}
if( m_propertyReordableList == null )
{
m_propertyReordableList = new ReorderableList( m_propertyReordableNodes, typeof( PropertyNode ), true, false, false, false )
{
headerHeight = 0,
footerHeight = 0,
showDefaultBackground = false,
drawElementCallback = ( Rect rect, int index, bool isActive, bool isFocused ) =>
{
var first = rect;
first.width *= 0.60f;
EditorGUI.LabelField( first, m_propertyReordableNodes[ index ].PropertyInspectorName );
var second = rect;
second.width *= 0.4f;
second.x += first.width;
if( GUI.Button( second, m_propertyReordableNodes[ index ].PropertyName, new GUIStyle( "AssetLabel Partial" ) ) )
{
UIUtils.FocusOnNode( m_propertyReordableNodes[ index ], 1, false );
}
},
onReorderCallback = ( list ) =>
{
ReorderList( ref nodes );
}
};
ReorderList( ref nodes );
}
if( m_propertyReordableList != null )
{
if( m_propertyAdjustment == null )
{
m_propertyAdjustment = new GUIStyle();
m_propertyAdjustment.padding.left = 17;
}
EditorGUILayout.BeginVertical( m_propertyAdjustment );
m_propertyReordableList.DoLayoutList();
EditorGUILayout.EndVertical();
}
}
public void ForceReordering()
{
List<PropertyNode> nodes = UIUtils.PropertyNodesList();
ReorderList( ref nodes );
List<FunctionInput> functionInputNodes = UIUtils.FunctionInputList();
ForceInputReorder( ref functionInputNodes );
List<FunctionSwitch> functionSwitchNodes = UIUtils.FunctionSwitchList();
ForceSwitchesReorder( ref functionSwitchNodes );
//RecursiveLog();
}
private void RecursiveLog()
{
List<PropertyNode> nodes = UIUtils.PropertyNodesList();
nodes.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ); } );
for( int i = 0; i < nodes.Count; i++ )
{
if( ( nodes[ i ] is ReordenatorNode ) )
( nodes[ i ] as ReordenatorNode ).RecursiveLog();
else
Debug.Log( nodes[ i ].OrderIndex + " " + nodes[ i ].PropertyName );
}
}
private void ReorderList( ref List<PropertyNode> nodes )
{
// clear lock list before reordering because of multiple sf being used
for( int i = 0; i < nodes.Count; i++ )
{
ReordenatorNode rnode = nodes[ i ] as ReordenatorNode;
if ( rnode != null )
rnode.RecursiveClear();
}
int propoffset = 0;
int count = 0;
for ( int i = 0; i < m_propertyReordableNodes.Count; i++ )
{
ReordenatorNode renode = m_propertyReordableNodes[ i ] as ReordenatorNode;
if ( renode != null )
{
if ( !renode.IsInside )
{
m_propertyReordableNodes[ i ].OrderIndex = count + propoffset;
if ( renode.PropertyListCount > 0 )
{
propoffset += renode.RecursiveCount();
// the same reordenator can exist multiple times, apply ordering to all of them
for( int j = 0; j < nodes.Count; j++ )
{
ReordenatorNode pnode = ( nodes[ j ] as ReordenatorNode );
if ( pnode != null && pnode.PropertyName.Equals( renode.PropertyName ) )
{
pnode.OrderIndex = renode.RawOrderIndex;
pnode.RecursiveSetOrderOffset( renode.RawOrderIndex, true );
}
}
}
else
{
count++;
}
}
else
{
m_propertyReordableNodes[ i ].OrderIndex = 0;
}
}
else
{
m_propertyReordableNodes[ i ].OrderIndex = count + propoffset;
count++;
}
}
}
public override void Destroy()
{
base.Destroy();
m_functionInputsReordableList = null;
m_functionOutputsReordableList = null;
m_propertyReordableList = null;
}
public bool ForceUpdate
{
get { return m_forceUpdate; }
set { m_forceUpdate = value; }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d09f21096aa7c9f438e91a6e7f2621fb
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
using UnityEngine;
namespace AmplifyShaderEditor
{
public class NodeWireReferencesUtils
{
public WireReference InputPortReference = new WireReference();
public WireReference SwitchPortReference = new WireReference();
public WireReference OutputPortReference = new WireReference();
public Vector2 SnapPosition = Vector2.zero;
public bool SnapEnabled = false;
public WireReference SnapPort = new WireReference();
public bool ValidReferences()
{
return ( InputPortReference.IsValid || OutputPortReference.IsValid );
}
public void InvalidateReferences()
{
InputPortReference.Invalidate();
OutputPortReference.Invalidate();
SnapPort.Invalidate();
SnapEnabled = false;
}
public void SetOutputReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked )
{
if( InputPortReference.IsValid )
InputPortReference.Invalidate();
OutputPortReference.SetReference( nodeId, portId, dataType, typeLocked );
}
public void SetInputReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked )
{
if( OutputPortReference.IsValid )
OutputPortReference.Invalidate();
InputPortReference.SetReference( nodeId, portId, dataType, typeLocked );
}
public void ActivateSnap( Vector2 position, WirePort port )
{
SnapPort.SetReference( port );
SnapEnabled = true;
SnapPosition = position;
}
public void DeactivateSnap()
{
SnapEnabled = false;
SnapPort.Invalidate();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bfbc736093c900c418a7668e3003663a
timeCreated: 1500289690
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a89b03eb735b82a4da19a8381846935f
folderAsset: yes
timeCreated: 1481126946
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,101 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using System.Collections.Generic;
using System;
namespace AmplifyShaderEditor
{
public sealed class ContextPalette : PaletteParent
{
private Vector3 m_position;
private Vector2 m_startDropPosition;
public ContextPalette( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 250, 250, string.Empty, MenuAnchor.NONE, MenuAutoSize.NONE )
{
m_isActive = false;
OnPaletteNodeCreateEvt += OnOptionSelected;
m_searchFilterControl += "CONTEXTPALETTE";
}
public override void OnEnterPressed(int index = 0)
{
if ( m_searchFilter.Length > 0 && m_currentItems.Count > 0 )
{
FireNodeCreateEvent( m_currentItems[ index ].NodeType, m_currentItems[ index ].Name, m_currentItems[ index ].Function );
}
else
{
Disable();
}
}
public override void OnEscapePressed()
{
Disable();
if ( m_parentWindow.WireReferenceUtils.ValidReferences() )
{
m_parentWindow.WireReferenceUtils.InvalidateReferences();
}
}
public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
{
//if ( !_isActive )
// return;
if ( Event.current.type == EventType.MouseDown && !IsInside( Event.current.mousePosition ) )
{
Disable();
return;
}
base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus );
}
public void Show( Vector2 position, Rect cameraInfo )
{
m_startDropPosition = position;
m_maximizedArea.x = ( position.x + m_maximizedArea.width ) > cameraInfo.width ? ( cameraInfo.width - 1.1f * m_maximizedArea.width ) : position.x;
m_maximizedArea.y = ( position.y + m_maximizedArea.height ) > cameraInfo.height ? ( cameraInfo.height - 1.1f * m_maximizedArea.height ) : position.y;
m_position = new Vector3( m_maximizedArea.x, m_maximizedArea.y, 0f );
m_isActive = true;
m_focusOnSearch = true;
}
// This override is removing focus from our window ... need to figure out a workaround before re-using it
//public override bool CheckButton( GUIContent content, GUIStyle style, int buttonId )
//{
// if ( buttonId != m_validButtonId )
// return false;
// return GUILayout.Button( content, style );
//}
void OnOptionSelected( System.Type type, string name, AmplifyShaderFunction function )
{
Disable();
}
public void Disable()
{
m_isActive = false;
}
public Vector2 StartDropPosition
{
get { return m_startDropPosition; }
}
public Vector3 CurrentPosition
{
get { return m_position; }
}
public Vector2 CurrentPosition2D
{
get { return new Vector2( m_position.x, m_position.y ); }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 15597b146a1fc154abd63ac75cffb73f
timeCreated: 1481126953
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,573 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System;
using System.Text.RegularExpressions;
namespace AmplifyShaderEditor
{
public class PaletteFilterData
{
public bool Visible;
public bool HasCommunityData;
public List<ContextMenuItem> Contents;
public PaletteFilterData( bool visible )
{
Visible = visible;
Contents = new List<ContextMenuItem>();
}
}
public class PaletteParent : MenuParent
{
private const float ItemSize = 18;
public delegate void OnPaletteNodeCreate( System.Type type, string name, AmplifyShaderFunction function );
public event OnPaletteNodeCreate OnPaletteNodeCreateEvt;
private string m_searchFilterStr = "Search";
protected string m_searchFilterControl = "SHADERNAMETEXTFIELDCONTROLNAME";
protected bool m_focusOnSearch = false;
protected bool m_defaultCategoryVisible = false;
//protected List<ContextMenuItem> m_allItems;
protected List<ContextMenuItem> m_currentItems;
protected Dictionary<string, PaletteFilterData> m_currentCategories;
private bool m_forceUpdate = true;
protected string m_searchFilter = string.Empty;
private float m_searchLabelSize = -1;
private GUIStyle m_buttonStyle;
private GUIStyle m_foldoutStyle;
protected bool m_previousWindowIsFunction = false;
protected int m_validButtonId = 0;
protected int m_initialSeparatorAmount = 1;
private Vector2 m_currScrollBarDims = new Vector2( 1, 1 );
public PaletteParent( AmplifyShaderEditorWindow parentWindow, float x, float y, float width, float height, string name, MenuAnchor anchor = MenuAnchor.NONE, MenuAutoSize autoSize = MenuAutoSize.NONE ) : base( parentWindow, x, y, width, height, name, anchor, autoSize )
{
m_searchFilter = string.Empty;
m_currentCategories = new Dictionary<string, PaletteFilterData>();
//m_allItems = items;
m_currentItems = new List<ContextMenuItem>();
}
public virtual void OnEnterPressed( int index = 0 ) { }
public virtual void OnEscapePressed() { }
public void FireNodeCreateEvent( System.Type type, string name, AmplifyShaderFunction function )
{
OnPaletteNodeCreateEvt( type, name, function );
}
public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
{
base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus );
if( m_previousWindowIsFunction != ParentWindow.IsShaderFunctionWindow )
{
m_forceUpdate = true;
}
m_previousWindowIsFunction = ParentWindow.IsShaderFunctionWindow;
List<ContextMenuItem> allItems = ParentWindow.ContextMenuInstance.MenuItems;
if( m_searchLabelSize < 0 )
{
m_searchLabelSize = GUI.skin.label.CalcSize( new GUIContent( m_searchFilterStr ) ).x;
}
if( m_foldoutStyle == null )
{
m_foldoutStyle = new GUIStyle( GUI.skin.GetStyle( "foldout" ) );
m_foldoutStyle.fontStyle = FontStyle.Bold;
}
if( m_buttonStyle == null )
{
m_buttonStyle = UIUtils.Label;
}
Event currenEvent = Event.current;
GUILayout.BeginArea( m_transformedArea, m_content, m_style );
{
for( int i = 0; i < m_initialSeparatorAmount; i++ )
{
EditorGUILayout.Separator();
}
if( currenEvent.type == EventType.KeyDown )
{
KeyCode key = currenEvent.keyCode;
//if ( key == KeyCode.Return || key == KeyCode.KeypadEnter )
// OnEnterPressed();
if( ( currenEvent.keyCode == KeyCode.KeypadEnter || currenEvent.keyCode == KeyCode.Return ) && currenEvent.type == EventType.KeyDown )
{
int index = m_currentItems.FindIndex( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) );
if( index > -1 )
OnEnterPressed( index );
else
OnEnterPressed();
}
if( key == KeyCode.Escape )
OnEscapePressed();
if( m_isMouseInside || hasKeyboadFocus )
{
if( key == ShortcutsManager.ScrollUpKey )
{
m_currentScrollPos.y -= 10;
if( m_currentScrollPos.y < 0 )
{
m_currentScrollPos.y = 0;
}
currenEvent.Use();
}
if( key == ShortcutsManager.ScrollDownKey )
{
m_currentScrollPos.y += 10;
currenEvent.Use();
}
}
}
float width = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = m_searchLabelSize;
EditorGUI.BeginChangeCheck();
{
GUI.SetNextControlName( m_searchFilterControl + m_resizable );
m_searchFilter = EditorGUILayout.TextField( m_searchFilterStr, m_searchFilter );
if( m_focusOnSearch )
{
m_focusOnSearch = false;
EditorGUI.FocusTextInControl( m_searchFilterControl + m_resizable );
}
}
if( EditorGUI.EndChangeCheck() )
m_forceUpdate = true;
EditorGUIUtility.labelWidth = width;
bool usingSearchFilter = ( m_searchFilter.Length == 0 );
m_currScrollBarDims.x = m_transformedArea.width;
m_currScrollBarDims.y = m_transformedArea.height - 2 - 16 - 2 - 7 * m_initialSeparatorAmount - 2;
m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos/*, GUILayout.Width( 242 ), GUILayout.Height( 250 - 2 - 16 - 2 - 7 - 2) */);
{
if( m_forceUpdate )
{
m_forceUpdate = false;
//m_currentItems.Clear();
m_currentCategories.Clear();
if( usingSearchFilter )
{
for( int i = 0; i < allItems.Count; i++ )
{
//m_currentItems.Add( allItems[ i ] );
if( !m_currentCategories.ContainsKey( allItems[ i ].Category ) )
{
m_currentCategories.Add( allItems[ i ].Category, new PaletteFilterData( m_defaultCategoryVisible ) );
//m_currentCategories[ allItems[ i ].Category ].HasCommunityData = allItems[ i ].NodeAttributes.FromCommunity || m_currentCategories[ allItems[ i ].Category ].HasCommunityData;
}
m_currentCategories[ allItems[ i ].Category ].Contents.Add( allItems[ i ] );
}
}
else
{
for( int i = 0; i < allItems.Count; i++ )
{
var searchList = m_searchFilter.Trim( ' ' ).ToLower().Split(' ');
int matchesFound = 0;
for( int k = 0; k < searchList.Length; k++ )
{
MatchCollection wordmatch = Regex.Matches( allItems[ i ].Tags, "\\b"+searchList[ k ] );
if( wordmatch.Count > 0 )
matchesFound++;
else
break;
}
if( searchList.Length == matchesFound )
{
//m_currentItems.Add( allItems[ i ] );
if( !m_currentCategories.ContainsKey( allItems[ i ].Category ) )
{
m_currentCategories.Add( allItems[ i ].Category, new PaletteFilterData( m_defaultCategoryVisible ) );
//m_currentCategories[ allItems[ i ].Category ].HasCommunityData = allItems[ i ].NodeAttributes.FromCommunity || m_currentCategories[ allItems[ i ].Category ].HasCommunityData;
}
m_currentCategories[ allItems[ i ].Category ].Contents.Add( allItems[ i ] );
}
}
}
var categoryEnumerator = m_currentCategories.GetEnumerator();
while( categoryEnumerator.MoveNext() )
{
categoryEnumerator.Current.Value.Contents.Sort( ( x, y ) => x.CompareTo( y, usingSearchFilter ) );
}
//sort current list respecting categories
m_currentItems.Clear();
foreach( var item in m_currentCategories )
{
for( int i = 0; i < item.Value.Contents.Count; i++ )
{
m_currentItems.Add( item.Value.Contents[ i ] );
}
}
}
string watching = string.Empty;
// unselect the main search field so it can focus list elements next
if( ( currenEvent.keyCode == KeyCode.DownArrow || currenEvent.keyCode == KeyCode.UpArrow ) && m_searchFilter.Length > 0 )
{
if( GUI.GetNameOfFocusedControl().Equals( m_searchFilterControl + m_resizable ) )
{
EditorGUI.FocusTextInControl( null );
}
}
if( currenEvent.keyCode == KeyCode.DownArrow && currenEvent.type == EventType.KeyDown )
{
currenEvent.Use();
int nextIndex = m_currentItems.FindIndex( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) ) + 1;
if( nextIndex == m_currentItems.Count )
nextIndex = 0;
watching = m_currentItems[ nextIndex ].ItemUIContent.text + m_resizable;
GUI.FocusControl( watching );
}
if( currenEvent.keyCode == KeyCode.UpArrow && currenEvent.type == EventType.KeyDown )
{
currenEvent.Use();
int nextIndex = m_currentItems.FindIndex( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) ) - 1;
if( nextIndex < 0 )
nextIndex = m_currentItems.Count - 1;
watching = m_currentItems[ nextIndex ].ItemUIContent.text + m_resizable;
GUI.FocusControl( watching );
}
if( currenEvent.keyCode == KeyCode.Tab )
{
ContextMenuItem item = m_currentItems.Find( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) );
if( item != null )
{
watching = item.ItemUIContent.text + m_resizable;
}
}
float currPos = 0;
var enumerator = m_currentCategories.GetEnumerator();
float cache = EditorGUIUtility.labelWidth;
while( enumerator.MoveNext() )
{
var current = enumerator.Current;
bool visible = GUILayout.Toggle( current.Value.Visible, current.Key, m_foldoutStyle );
if( m_validButtonId == mouseButtonId )
{
current.Value.Visible = visible;
}
currPos += ItemSize;
if( m_searchFilter.Length > 0 || current.Value.Visible )
{
for( int i = 0; i < current.Value.Contents.Count; i++ )
{
//if ( !IsItemVisible( currPos ) )
//{
// // Invisible
// GUILayout.Space( ItemSize );
//}
//else
{
currPos += ItemSize;
// Visible
EditorGUILayout.BeginHorizontal();
GUILayout.Space( 16 );
//if ( m_isMouseInside )
//{
// //GUI.SetNextControlName( current.Value.Contents[ i ].ItemUIContent.text );
// if ( CheckButton( current.Value.Contents[ i ].ItemUIContent, m_buttonStyle, mouseButtonId ) )
// {
// int controlID = GUIUtility.GetControlID( FocusType.Passive );
// GUIUtility.hotControl = controlID;
// OnPaletteNodeCreateEvt( current.Value.Contents[ i ].NodeType, current.Value.Contents[ i ].Name, current.Value.Contents[ i ].Function );
// }
//}
//else
{
Rect thisRect = EditorGUILayout.GetControlRect( false, 16f, EditorStyles.label );
//if ( m_resizable )
{
if( GUI.RepeatButton( thisRect, string.Empty, EditorStyles.label ) )
{
int controlID = GUIUtility.GetControlID( FocusType.Passive );
GUIUtility.hotControl = controlID;
OnPaletteNodeCreateEvt( current.Value.Contents[ i ].NodeType, current.Value.Contents[ i ].Name, current.Value.Contents[ i ].Function );
//unfocus to make it focus the next text field correctly
GUI.FocusControl( null );
}
}
GUI.SetNextControlName( current.Value.Contents[ i ].ItemUIContent.text + m_resizable );
//EditorGUI.SelectableLabel( thisRect, current.Value.Contents[ i ].ItemUIContent.text, EditorStyles.label );
//float cache = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = thisRect.width;
EditorGUI.Toggle( thisRect, current.Value.Contents[ i ].ItemUIContent.text, false, EditorStyles.label );
EditorGUIUtility.labelWidth = cache;
if( watching == current.Value.Contents[ i ].ItemUIContent.text + m_resizable )
{
bool boundBottom = currPos - m_currentScrollPos.y > m_currScrollBarDims.y;
bool boundTop = currPos - m_currentScrollPos.y - 4 <= 0;
if( boundBottom )
m_currentScrollPos.y = currPos - m_currScrollBarDims.y + 2;
else if( boundTop )
m_currentScrollPos.y = currPos - 18;
//else if ( boundBottom && !downDirection )
// m_currentScrollPos.y = currPos - m_currScrollBarDims.y + 2;
//else if ( boundTop && downDirection )
// m_currentScrollPos.y = currPos - 18;
}
}
EditorGUILayout.EndHorizontal();
}
//currPos += ItemSize;
}
}
}
EditorGUIUtility.labelWidth = cache;
}
EditorGUILayout.EndScrollView();
}
GUILayout.EndArea();
}
public void CheckCommunityNodes()
{
var enumerator = m_currentCategories.GetEnumerator();
while( enumerator.MoveNext() )
{
var current = enumerator.Current;
current.Value.HasCommunityData = false;
int count = current.Value.Contents.Count;
for( int i = 0; i < count; i++ )
{
if( current.Value.Contents[ i ].NodeAttributes.FromCommunity )
{
current.Value.HasCommunityData = true;
break;
}
}
}
}
public void DumpAvailableNodes( bool fromCommunity, string pathname )
{
string noTOCHeader = "__NOTOC__\n";
string nodesHeader = "== Available Node Categories ==\n";
string InitialCategoriesFormat = "[[#{0}|{0}]]<br>\n";
string InitialCategories = string.Empty;
string CurrentCategoryFormat = "\n== {0} ==\n\n";
//string NodesFootFormat = "[[Unity Products:Amplify Shader Editor/{0} | Learn More]] -\n[[#Top|Back to Categories]]\n";
string NodesFootFormatSep = "[[#Top|Back to Top]]\n----\n";
string OverallFoot = "[[Category:Nodes]]";
string NodeInfoBeginFormat = "<div class=\"nodecard\">\n";
string nodeInfoBodyFormat = "{{| id=\"{2}\" class=\"wikitable\" |\n" +
"|- \n" +
"| <div>[[Unity Products:Amplify Shader Editor/{1}|<img class=\"responsive-img\" src=\"http://amplify.pt/Nodes/{0}.jpg\">]]</div>\n" +
"<div>\n" +
"{{| style=\"width: 100%; height: 150px;\"\n" +
"|-\n" +
"| [[Unity Products:Amplify Shader Editor/{1}|'''{2}''']]\n" +
"|- style=\"vertical-align:top; height: 100%;\" |\n" +
"|<p class=\"cardtext\">{3}</p>\n" +
"|- style=\"text-align:right;\" |\n" +
"|{4}[[Unity Products:Amplify Shader Editor/{1} | Learn More]]\n" +
"|}}</div>\n" +
"|}}\n";
string NodeInfoEndFormat = "</div>\n";
//string NodeInfoBeginFormat = "<span style=\"color:#c00;display:block;\">This page is under construction!</span>\n\n";
//string nodeInfoBodyFormat = "<img style=\"float:left; margin-right:10px;\" src=\"http://amplify.pt/Nodes/{0}.jpg\">\n[[Unity Products:Amplify Shader Editor/{1}|'''{2}''']]\n\n{3}";
//string NodeInfoEndFormat = "\n\n[[Unity_Products:Amplify_Shader_Editor/Nodes | Back to Node List ]]\n[[Category:Nodes]][[Category:{0}]]\n\n\n";
//string NodeInfoBeginFormat = "{| cellpadding=\"10\"\n";
//string nodeInfoBodyFormat = "|- style=\"vertical-align:top;\"\n| http://amplify.pt/Nodes/{0}.jpg\n| [[Unity Products:Amplify Shader Editor/{1} | <span style=\"font-size: 120%;\"><span id=\"{2}\"></span>'''{2}'''<span> ]] <br> {3}\n";
//string NodeInfoEndFormat = "|}\n";
string nodesInfo = string.Empty;
BuildFullList( true );
CheckCommunityNodes();
var enumerator = m_currentCategories.GetEnumerator();
while( enumerator.MoveNext() )
{
var current = enumerator.Current;
if( fromCommunity && current.Value.HasCommunityData || !fromCommunity )
{
InitialCategories += string.Format( InitialCategoriesFormat, current.Key );
nodesInfo += string.Format( CurrentCategoryFormat, current.Key );
int count = current.Value.Contents.Count;
for( int i = 0; i < count; i++ )
{
if( ( fromCommunity && current.Value.Contents[ i ].NodeAttributes.FromCommunity )
|| !fromCommunity
//|| ( !fromCommunity && !current.Value.Contents[ i ].NodeAttributes.FromCommunity )
)
{
string nodeFullName = current.Value.Contents[ i ].Name;
string pictureFilename = UIUtils.ReplaceInvalidStrings( nodeFullName );
string pageFilename = UIUtils.RemoveWikiInvalidCharacters( pictureFilename );
pictureFilename = UIUtils.RemoveInvalidCharacters( pictureFilename );
string nodeDescription = current.Value.Contents[ i ].ItemUIContent.tooltip;
string communityText = string.Empty;
if( current.Value.Contents[ i ].NodeAttributes.FromCommunity )
communityText = "<small class=\"cardauthor\">( originally by "+ current.Value.Contents[ i ].NodeAttributes.Community + " )</small> ";
string nodeInfoBody = string.Format( nodeInfoBodyFormat, pictureFilename, pageFilename, nodeFullName, nodeDescription, communityText );
//string nodeInfoFoot = string.Format( NodesFootFormat, pageFilename );
nodesInfo += ( NodeInfoBeginFormat + nodeInfoBody + NodeInfoEndFormat );
//nodesInfo += ( NodeInfoBeginFormat + nodeInfoBody + string.Format( NodeInfoEndFormat, current.Key ) );
//if ( i != ( count - 1 ) )
//{
// nodesInfo += NodesFootFormatSep;
//}
}
}
nodesInfo += NodesFootFormatSep;
}
}
string finalText = noTOCHeader + nodesHeader + InitialCategories + nodesInfo + OverallFoot;
if( !System.IO.Directory.Exists( pathname ) )
{
System.IO.Directory.CreateDirectory( pathname );
}
// Save file
string nodesPathname = pathname + ( fromCommunity ? "AvailableNodesFromCommunity.txt" : "AvailableNodes.txt" );
Debug.Log( " Creating nodes file at " + nodesPathname );
IOUtils.SaveTextfileToDisk( finalText, nodesPathname, false );
BuildFullList( false );
}
public virtual bool CheckButton( GUIContent content, GUIStyle style, int buttonId )
{
if( buttonId != m_validButtonId )
{
GUILayout.Label( content, style );
return false;
}
return GUILayout.RepeatButton( content, style );
}
public void FillList( ref List<ContextMenuItem> list, bool forceAllItems )
{
List<ContextMenuItem> allList = forceAllItems ? ParentWindow.ContextMenuInstance.ItemFunctions : ParentWindow.ContextMenuInstance.MenuItems;
list.Clear();
int count = allList.Count;
for( int i = 0; i < count; i++ )
{
list.Add( allList[ i ] );
}
}
public Dictionary<string, PaletteFilterData> BuildFullList( bool forceAllNodes = false )
{
//Only need to build if search filter is active and list is set according to it
if( m_searchFilter.Length > 0 || !m_isActive || m_currentCategories.Count == 0 )
{
m_currentItems.Clear();
m_currentCategories.Clear();
List<ContextMenuItem> allItems = forceAllNodes ? ParentWindow.ContextMenuInstance.ItemFunctions : ParentWindow.ContextMenuInstance.MenuItems;
for( int i = 0; i < allItems.Count; i++ )
{
if( allItems[ i ].Name.IndexOf( m_searchFilter, StringComparison.InvariantCultureIgnoreCase ) >= 0 ||
allItems[ i ].Category.IndexOf( m_searchFilter, StringComparison.InvariantCultureIgnoreCase ) >= 0
)
{
m_currentItems.Add( allItems[ i ] );
if( !m_currentCategories.ContainsKey( allItems[ i ].Category ) )
{
m_currentCategories.Add( allItems[ i ].Category, new PaletteFilterData( m_defaultCategoryVisible ) );
//m_currentCategories[ allItems[ i ].Category ].HasCommunityData = allItems[ i ].NodeAttributes.FromCommunity || m_currentCategories[ allItems[ i ].Category ].HasCommunityData;
}
m_currentCategories[ allItems[ i ].Category ].Contents.Add( allItems[ i ] );
}
}
var categoryEnumerator = m_currentCategories.GetEnumerator();
while( categoryEnumerator.MoveNext() )
{
categoryEnumerator.Current.Value.Contents.Sort( ( x, y ) => x.CompareTo( y, false ) );
}
//mark to force update and take search filter into account
m_forceUpdate = true;
}
return m_currentCategories;
}
private bool IsItemVisible( float currPos )
{
if( ( currPos < m_currentScrollPos.y && ( currPos + ItemSize ) < m_currentScrollPos.y ) ||
( currPos > ( m_currentScrollPos.y + m_currScrollBarDims.y ) &&
( currPos + ItemSize ) > ( m_currentScrollPos.y + m_currScrollBarDims.y ) ) )
{
return false;
}
return true;
}
public override void Destroy()
{
base.Destroy();
//m_allItems = null;
m_currentItems.Clear();
m_currentItems = null;
m_currentCategories.Clear();
m_currentCategories = null;
OnPaletteNodeCreateEvt = null;
m_buttonStyle = null;
m_foldoutStyle = null;
}
//public void Clear() {
// m_allItems.Clear();
// m_allItems = new List<ContextMenuItem>();
//}
public bool ForceUpdate { get { return m_forceUpdate; } set { m_forceUpdate = value; } }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: df4c2f840dca60a4cb118325ce2febfa
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
namespace AmplifyShaderEditor
{
public class PalettePopUp
{
private const int DeltaX = 5;
private Rect m_areaSettings;
private Vector2 m_mouseDeltaPos = new Vector2( 10, -10 );
private bool m_isActive = false;
private GUIContent m_content;
private GUIStyle m_style;
private GUIStyle m_fontStyle;
private GUIContent m_labelContent;
public PalettePopUp()
{
m_content = new GUIContent( GUIContent.none );
m_areaSettings = new Rect( 0, 0, 100, 30 );
m_labelContent = new GUIContent( "Test Label" );
}
public void Activate( string label )
{
m_labelContent.text = label;
m_areaSettings.width = -1;
m_isActive = true;
}
public void Deactivate()
{
m_isActive = false;
}
public void Draw( Vector2 mousePos )
{
if ( m_style == null )
{
m_style = UIUtils.TextArea;
}
if ( m_fontStyle == null )
{
m_fontStyle = new GUIStyle( UIUtils.Label );
m_fontStyle.fontSize = 15;
}
if ( m_areaSettings.width < 0 )
{
m_areaSettings.width = m_fontStyle.CalcSize( m_labelContent ).x + 2 * DeltaX;
}
m_areaSettings.position = mousePos + m_mouseDeltaPos;
GUI.Label( m_areaSettings, m_content, m_style );
m_areaSettings.position += new Vector2( DeltaX,DeltaX);
GUI.Label( m_areaSettings, m_labelContent, m_fontStyle );
}
public void Destroy()
{
m_content = null;
m_style = null;
}
public bool IsActive
{
get { return m_isActive; }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bc4f137f15efe1d42b7bcbf984ec1545
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System.Collections.Generic;
using UnityEngine;
namespace AmplifyShaderEditor
{
public sealed class PaletteWindow : PaletteParent
{
public PaletteWindow( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 250, 0, string.Empty, MenuAnchor.TOP_RIGHT, MenuAutoSize.MATCH_VERTICAL )
{
m_searchFilterControl += "PALETTEWINDOW";
m_initialSeparatorAmount = 4;
SetMinimizedArea( -225, 0, 260, 0 );
}
public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
{
if ( m_isMaximized )
{
base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus );
}
else
{
InitDraw( parentPosition, mousePosition, mouseButtonId );
}
PostDraw();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 63408b264ef8cb346a5ce9e559a5ed22
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,469 @@
// 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
{
class NodeDescriptionInfo
{
public bool FoldoutValue;
public string Category;
public string[,] Contents;
}
public sealed class PortLegendInfo : EditorWindow
{
private const string NoASEWindowWarning = "Please Open the ASE to get access to shortcut info";
private const float PixelSeparator = 5;
private const string EditorShortcutsTitle = "Editor Shortcuts";
private const string MenuShortcutsTitle = "Menu Shortcuts";
private const string NodesShortcutsTitle = "Nodes Shortcuts";
private const string PortShortcutsTitle = "Port Shortcuts";
private const string PortLegendTitle = "Port Legend";
private const string NodesDescTitle = "Node Info";
private const string CompatibleAssetsTitle = "Compatible Assets";
private const string KeyboardUsageTemplate = "[{0}] - {1}";
private const string m_lockedStr = "Locked Port";
private const float WindowSizeX = 350;
private const float WindowSizeY = 300;
private const float WindowPosX = 5;
private const float WindowPosY = 5;
private int TitleLabelWidth = 150;
private Rect m_availableArea;
private bool m_portAreaFoldout = true;
private bool m_editorShortcutAreaFoldout = true;
private bool m_menuShortcutAreaFoldout = true;
private bool m_nodesShortcutAreaFoldout = true;
private bool m_nodesDescriptionAreaFoldout = true;
private bool m_compatibleAssetsFoldout = true;
private Vector2 m_currentScrollPos;
private GUIStyle m_portStyle;
private GUIStyle m_labelStyleBold;
private GUIStyle m_labelStyle;
private GUIStyle m_nodeInfoLabelStyleBold;
private GUIStyle m_nodeInfoLabelStyle;
private GUIStyle m_nodeInfoFoldoutStyle;
private GUIContent m_content = new GUIContent( "Helper", "Shows helper info for ASE users" );
private bool m_init = true;
private List<ShortcutItem> m_editorShortcuts = null;
private List<ShortcutItem> m_nodesShortcuts = null;
private List<NodeDescriptionInfo> m_nodeDescriptionsInfo = null;
private List<string[]> m_compatibleAssetsInfo = null;
public static PortLegendInfo OpenWindow()
{
PortLegendInfo currentWindow = ( PortLegendInfo ) PortLegendInfo.GetWindow( typeof( PortLegendInfo ), false );
currentWindow.minSize = new Vector2( WindowSizeX, WindowSizeY );
currentWindow.maxSize = new Vector2( WindowSizeX * 2, 2 * WindowSizeY ); ;
currentWindow.wantsMouseMove = true;
return currentWindow;
}
public void Init()
{
m_init = false;
wantsMouseMove = false;
titleContent = m_content;
m_portStyle = new GUIStyle( UIUtils.GetCustomStyle( CustomStyle.PortEmptyIcon ) );
m_portStyle.alignment = TextAnchor.MiddleLeft;
m_portStyle.imagePosition = ImagePosition.ImageOnly;
m_portStyle.margin = new RectOffset( 5, 0, 5, 0 );
m_labelStyleBold = new GUIStyle( UIUtils.InputPortLabel );
m_labelStyleBold.fontStyle = FontStyle.Bold;
m_labelStyleBold.fontSize = ( int ) ( Constants.TextFieldFontSize );
m_labelStyle = new GUIStyle( UIUtils.InputPortLabel );
m_labelStyle.clipping = TextClipping.Overflow;
m_labelStyle.imagePosition = ImagePosition.TextOnly;
m_labelStyle.contentOffset = new Vector2( -10, 0 );
m_labelStyle.fontSize = ( int ) ( Constants.TextFieldFontSize );
m_nodeInfoLabelStyleBold = new GUIStyle( UIUtils.InputPortLabel );
m_nodeInfoLabelStyleBold.fontStyle = FontStyle.Bold;
m_nodeInfoLabelStyleBold.fontSize = ( int ) ( Constants.TextFieldFontSize );
m_nodeInfoLabelStyle = new GUIStyle( UIUtils.InputPortLabel );
m_nodeInfoLabelStyle.clipping = TextClipping.Clip;
m_nodeInfoLabelStyle.imagePosition = ImagePosition.TextOnly;
m_nodeInfoLabelStyle.fontSize = ( int ) ( Constants.TextFieldFontSize );
m_nodeInfoFoldoutStyle = new GUIStyle( ( GUIStyle ) "foldout" );
m_nodeInfoFoldoutStyle.fontStyle = FontStyle.Bold;
if ( !EditorGUIUtility.isProSkin )
{
m_labelStyleBold.normal.textColor = m_labelStyle.normal.textColor = Color.black;
m_nodeInfoLabelStyleBold.normal.textColor = m_labelStyle.normal.textColor = Color.black;
m_nodeInfoLabelStyle.normal.textColor = m_labelStyle.normal.textColor = Color.black;
}
m_availableArea = new Rect( WindowPosX, WindowPosY, WindowSizeX - 2 * WindowPosX, WindowSizeY - 2 * WindowPosY );
}
void DrawPort( WirePortDataType type )
{
EditorGUILayout.BeginHorizontal();
{
GUI.color = UIUtils.GetColorForDataType( type, false );
GUILayout.Box( string.Empty, m_portStyle, GUILayout.Width( UIUtils.PortsSize.x ), GUILayout.Height( UIUtils.PortsSize.y ) );
GUI.color = Color.white;
EditorGUILayout.LabelField( UIUtils.GetNameForDataType( type ), m_labelStyle );
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
}
void OnGUI()
{
if ( !UIUtils.Initialized || UIUtils.CurrentWindow == null )
{
EditorGUILayout.LabelField( NoASEWindowWarning );
return;
}
if ( m_init )
{
Init();
}
TitleLabelWidth = (int)(this.position.width * 0.42f);
KeyCode key = Event.current.keyCode;
if ( key == ShortcutsManager.ScrollUpKey )
{
m_currentScrollPos.y -= 10;
if ( m_currentScrollPos.y < 0 )
{
m_currentScrollPos.y = 0;
}
Event.current.Use();
}
if ( key == ShortcutsManager.ScrollDownKey )
{
m_currentScrollPos.y += 10;
Event.current.Use();
}
if ( Event.current.type == EventType.MouseDrag && Event.current.button > 0 )
{
m_currentScrollPos.x += Constants.MenuDragSpeed * Event.current.delta.x;
if ( m_currentScrollPos.x < 0 )
{
m_currentScrollPos.x = 0;
}
m_currentScrollPos.y += Constants.MenuDragSpeed * Event.current.delta.y;
if ( m_currentScrollPos.y < 0 )
{
m_currentScrollPos.y = 0;
}
}
m_availableArea = new Rect( WindowPosX, WindowPosY, position.width - 2 * WindowPosX, position.height - 2 * WindowPosY );
GUILayout.BeginArea( m_availableArea );
{
if ( GUILayout.Button( "Wiki Page" ) )
{
Application.OpenURL( Constants.HelpURL );
}
m_currentScrollPos = GUILayout.BeginScrollView( m_currentScrollPos );
{
EditorGUILayout.BeginVertical();
{
NodeUtils.DrawPropertyGroup( ref m_portAreaFoldout, PortLegendTitle, DrawPortInfo );
float currLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 1;
NodeUtils.DrawPropertyGroup( ref m_editorShortcutAreaFoldout, EditorShortcutsTitle, DrawEditorShortcuts );
NodeUtils.DrawPropertyGroup( ref m_menuShortcutAreaFoldout, MenuShortcutsTitle, DrawMenuShortcuts );
NodeUtils.DrawPropertyGroup( ref m_nodesShortcutAreaFoldout, NodesShortcutsTitle, DrawNodesShortcuts );
NodeUtils.DrawPropertyGroup( ref m_compatibleAssetsFoldout, CompatibleAssetsTitle, DrawCompatibleAssets );
NodeUtils.DrawPropertyGroup( ref m_nodesDescriptionAreaFoldout, NodesDescTitle, DrawNodeDescriptions );
EditorGUIUtility.labelWidth = currLabelWidth;
}
EditorGUILayout.EndVertical();
}
GUILayout.EndScrollView();
}
GUILayout.EndArea();
}
void DrawPortInfo()
{
Color originalColor = GUI.color;
DrawPort( WirePortDataType.OBJECT );
DrawPort( WirePortDataType.INT );
DrawPort( WirePortDataType.FLOAT );
DrawPort( WirePortDataType.FLOAT2 );
DrawPort( WirePortDataType.FLOAT3 );
DrawPort( WirePortDataType.FLOAT4 );
DrawPort( WirePortDataType.COLOR );
DrawPort( WirePortDataType.SAMPLER2D );
DrawPort( WirePortDataType.FLOAT3x3 );
DrawPort( WirePortDataType.FLOAT4x4 );
EditorGUILayout.BeginHorizontal();
{
GUI.color = Constants.LockedPortColor;
GUILayout.Box( string.Empty, m_portStyle, GUILayout.Width( UIUtils.PortsSize.x ), GUILayout.Height( UIUtils.PortsSize.y ) );
GUI.color = Color.white;
EditorGUILayout.LabelField( m_lockedStr, m_labelStyle );
}
EditorGUILayout.EndHorizontal();
GUI.color = originalColor;
}
public void DrawEditorShortcuts()
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
if ( window != null )
{
if ( m_editorShortcuts == null )
{
m_editorShortcuts = window.ShortcutManagerInstance.AvailableEditorShortcutsList;
}
EditorGUI.indentLevel--;
int count = m_editorShortcuts.Count;
for ( int i = 0; i < count; i++ )
{
DrawItem( m_editorShortcuts[ i ].Name, m_editorShortcuts[ i ].Description );
}
DrawItem( "Q", "Alternative Pan modifier" );
DrawItem( "Ctrl + F", "Find nodes" );
DrawItem( "LMB Drag", "Box selection" );
DrawItem( "MMB/RMB Drag", "Camera pan" );
DrawItem( "Alt + MMB/RMB Drag", "Zoom graph" );
DrawItem( "Shift/Ctrl + Node Select", "Add/Remove from selection" );
DrawItem( "Shift + Node Drag", "Node move with offset" );
DrawItem( "Ctrl + Node Drag", "Node move with snap" );
DrawItem( "MMB/RMB + Drag Panel", "Scroll panel" );
DrawItem( "Alt + LMB Drag", "Additive box selection" );
DrawItem( "Alt + Shift + Drag", "Subtractive box selection" );
DrawItem( "Alt + Node Drag", "Auto-(Dis)Connect node on existing wire connection" );
EditorGUI.indentLevel++;
}
else
{
EditorGUILayout.LabelField( NoASEWindowWarning );
}
}
public void DrawMenuShortcuts()
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
if ( window != null )
{
EditorGUI.indentLevel--;
DrawItem( ShortcutsManager.ScrollUpKey.ToString(), "Scroll Up Menu" );
DrawItem( ShortcutsManager.ScrollDownKey.ToString(), "Scroll Down Menu" );
DrawItem( "RMB Drag", "Scroll Menu" );
EditorGUI.indentLevel++;
}
else
{
EditorGUILayout.LabelField( NoASEWindowWarning );
}
}
void DrawItem( string name, string description )
{
GUILayout.BeginHorizontal();
GUILayout.Label( name, m_labelStyleBold , GUILayout.Width( TitleLabelWidth ) );
GUILayout.Label( description, m_labelStyle );
GUILayout.EndHorizontal();
GUILayout.Space( PixelSeparator );
}
public void DrawNodesShortcuts()
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
if ( window != null )
{
if ( m_nodesShortcuts == null || m_nodesShortcuts.Count == 0 )
{
m_nodesShortcuts = window.ShortcutManagerInstance.AvailableNodesShortcutsList;
}
EditorGUI.indentLevel--;
int count = m_nodesShortcuts.Count;
for ( int i = 0; i < count; i++ )
{
DrawItem( m_nodesShortcuts[ i ].Name, m_nodesShortcuts[ i ].Description );
}
EditorGUI.indentLevel++;
}
else
{
EditorGUILayout.LabelField( NoASEWindowWarning );
}
}
string CreateCompatibilityString( string source )
{
string[] split = source.Split( '.' );
if ( split != null && split.Length > 1 )
{
return split[ 1 ];
}
else
{
return source;
}
}
public void DrawCompatibleAssets()
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
if ( window != null )
{
if ( m_compatibleAssetsInfo == null )
{
m_compatibleAssetsInfo = new List<string[]>();
List<ContextMenuItem> items = window.ContextMenuInstance.MenuItems;
int count = items.Count;
for ( int i = 0; i < count; i++ )
{
if ( items[ i ].NodeAttributes != null && items[ i ].NodeAttributes.CastType != null )
{
string types = string.Empty;
if ( items[ i ].NodeAttributes.CastType.Length > 1 )
{
for ( int j = 0; j < items[ i ].NodeAttributes.CastType.Length; j++ )
{
types += CreateCompatibilityString( items[ i ].NodeAttributes.CastType[ j ].ToString() );
if ( j < items[ i ].NodeAttributes.CastType.Length - 1 )
{
types += ", ";
}
}
}
else
{
types = CreateCompatibilityString( items[ i ].NodeAttributes.CastType[ 0 ].ToString() );
}
m_compatibleAssetsInfo.Add( new string[] { items[ i ].NodeAttributes.Name + ": ", types } );
}
}
}
EditorGUI.indentLevel--;
int nodeCount = m_compatibleAssetsInfo.Count;
for ( int j = 0; j < nodeCount; j++ )
{
DrawItem( m_compatibleAssetsInfo[ j ][ 0 ], m_compatibleAssetsInfo[ j ][ 1 ] );
}
EditorGUI.indentLevel++;
}
else
{
EditorGUILayout.LabelField( NoASEWindowWarning );
}
}
public void DrawNodeDescriptions()
{
AmplifyShaderEditorWindow window = UIUtils.CurrentWindow;
if ( window != null )
{
if ( m_nodeDescriptionsInfo == null )
{
//fetch node info
m_nodeDescriptionsInfo = new List<NodeDescriptionInfo>();
Dictionary<string, PaletteFilterData> nodeData = window.CurrentPaletteWindow.BuildFullList();
var enumerator = nodeData.GetEnumerator();
while ( enumerator.MoveNext() )
{
List<ContextMenuItem> nodes = enumerator.Current.Value.Contents;
int count = nodes.Count;
NodeDescriptionInfo currInfo = new NodeDescriptionInfo();
currInfo.Contents = new string[ count, 2 ];
currInfo.Category = enumerator.Current.Key;
for ( int i = 0; i < count; i++ )
{
currInfo.Contents[ i, 0 ] = nodes[ i ].Name + ':';
currInfo.Contents[ i, 1 ] = nodes[ i ].Description;
}
m_nodeDescriptionsInfo.Add( currInfo );
}
}
//draw
{
GUILayout.Space( 5 );
int count = m_nodeDescriptionsInfo.Count;
EditorGUI.indentLevel--;
for ( int i = 0; i < count; i++ )
{
m_nodeDescriptionsInfo[ i ].FoldoutValue = EditorGUILayout.Foldout( m_nodeDescriptionsInfo[ i ].FoldoutValue, m_nodeDescriptionsInfo[ i ].Category, m_nodeInfoFoldoutStyle );
if ( m_nodeDescriptionsInfo[ i ].FoldoutValue )
{
EditorGUI.indentLevel++;
int nodeCount = m_nodeDescriptionsInfo[ i ].Contents.GetLength( 0 );
for ( int j = 0; j < nodeCount; j++ )
{
GUILayout.Label( m_nodeDescriptionsInfo[ i ].Contents[ j, 0 ], m_nodeInfoLabelStyleBold );
GUILayout.Label( m_nodeDescriptionsInfo[ i ].Contents[ j, 1 ], m_nodeInfoLabelStyle );
GUILayout.Space( PixelSeparator );
}
EditorGUI.indentLevel--;
}
GUILayout.Space( PixelSeparator );
}
EditorGUI.indentLevel++;
}
}
else
{
EditorGUILayout.LabelField( NoASEWindowWarning );
}
}
private void OnDestroy()
{
m_nodesShortcuts = null;
m_editorShortcuts = null;
m_portStyle = null;
m_labelStyle = null;
m_labelStyleBold = null;
m_nodeInfoLabelStyle = null;
m_nodeInfoLabelStyleBold = null;
m_nodeInfoFoldoutStyle = null;
m_init = false;
if ( m_nodeDescriptionsInfo != null )
{
m_nodeDescriptionsInfo.Clear();
m_nodeDescriptionsInfo = null;
}
if( m_compatibleAssetsInfo != null )
{
m_compatibleAssetsInfo.Clear();
m_compatibleAssetsInfo = null;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 20dad8f4196f0e643a9c56d1202e74dc
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
// Catch when scene is saved (Ctr+S) and also save ase shader
public class SceneSaveCallback : UnityEditor.AssetModificationProcessor
{
private const string UnityStr = ".unity";
static string[] OnWillSaveAssets( string[] paths )
{
if( !Preferences.GlobalUpdateOnSceneSave )
return paths;
bool canSave = false;
if ( paths.Length == 0 )
{
canSave = true;
}
else
{
for ( int i = 0; i < paths.Length; i++ )
{
// Only save shader when saving scenes
if ( !string.IsNullOrEmpty( paths[ i ] ) && paths[ i ].Contains( UnityStr ) )
{
canSave = true;
break;
}
}
}
if ( canSave && UIUtils.CurrentWindow )
UIUtils.CurrentWindow.SetCtrlSCallback( false );
return paths;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 708e90c98affcb04aa2fcfedf4329a7c
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,192 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
public sealed class ShaderEditorModeWindow : MenuParent
{
private static readonly Color OverallColorOn = new Color( 1f, 1f, 1f, 0.9f );
private static readonly Color OverallColorOff = new Color( 1f, 1f, 1f, 0.3f );
private static readonly Color FontColorOff = new Color( 1f, 1f, 1f, 0.4f );
private const float DeltaY = 15;
private const float DeltaX = 10;
private const float CollSizeX = 180;
private const float CollSizeY = 70;
//private static string MatFormat = "<size=20>MATERIAL</size>\n{0}";
//private static string ShaderFormat = "<size=20>SHADER</size>\n{0}";
//private const string CurrMatStr = "MATERIAL";
//private const string CurrShaderStr = "SHADER";
private const string NoMaterialStr = "No Material";
private const string NoShaderStr = "No Shader";
private bool m_init = true;
private string m_previousShaderName = string.Empty;
private string m_previousMaterialName = string.Empty;
private string m_previousShaderFunctionName = string.Empty;
private Vector2 m_auxVector2;
private GUIContent m_leftAuxContent = new GUIContent();
private GUIContent m_rightAuxContent = new GUIContent();
private GUIStyle m_leftButtonStyle = null;
private GUIStyle m_rightButtonStyle = null;
private Rect m_leftButtonRect;
private Rect m_rightButtonRect;
public ShaderEditorModeWindow( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 0, 0, "ShaderEditorModeWindow", MenuAnchor.BOTTOM_CENTER, MenuAutoSize.NONE ) { }
public void ConfigStyle( GUIStyle style )
{
style.normal.textColor = FontColorOff;
style.hover.textColor = FontColorOff;
style.active.textColor = FontColorOff;
style.focused.textColor = FontColorOff;
style.onNormal.textColor = FontColorOff;
style.onHover.textColor = FontColorOff;
style.onActive.textColor = FontColorOff;
style.onFocused.textColor = FontColorOff;
}
public void Draw( Rect graphArea, Vector2 mousePos, Shader currentShader, Material currentMaterial, float usableArea, float leftPos, float rightPos /*, bool showLastSelection*/ )
{
EventType currentEventType = Event.current.type;
if( !( currentEventType == EventType.Repaint || currentEventType == EventType.MouseDown || currentEventType == EventType.MouseMove ) )
return;
if ( m_init )
{
m_init = false;
GUIStyle shaderModeTitle = UIUtils.GetCustomStyle( CustomStyle.ShaderModeTitle );
GUIStyle shaderModeNoShader = UIUtils.GetCustomStyle( CustomStyle.ShaderModeNoShader );
GUIStyle materialModeTitle = UIUtils.GetCustomStyle( CustomStyle.MaterialModeTitle );
GUIStyle shaderNoMaterialModeTitle = UIUtils.GetCustomStyle( CustomStyle.ShaderNoMaterialModeTitle );
ConfigStyle( shaderModeTitle );
ConfigStyle( shaderModeNoShader );
ConfigStyle( materialModeTitle );
ConfigStyle( shaderNoMaterialModeTitle );
}
Color buffereredColor = GUI.color;
MasterNode currentMasterNode = ParentWindow.CurrentGraph.CurrentMasterNode;
// Shader Mode
if ( currentMasterNode != null )
{
m_leftButtonStyle = UIUtils.GetCustomStyle( currentShader == null ? CustomStyle.ShaderModeNoShader : CustomStyle.ShaderModeTitle );
m_leftButtonRect = graphArea;
m_leftButtonRect.x = 10 + leftPos;
m_leftButtonRect.y += m_leftButtonRect.height - 38 - 15;
string shaderName = ( currentShader != null ) ? ( currentShader.name ) : NoShaderStr;
if ( m_previousShaderName != shaderName )
{
m_previousShaderName = shaderName;
m_leftAuxContent.text = "<size=20>SHADER</size>\n" + shaderName;
}
m_auxVector2 = m_leftButtonStyle.CalcSize( m_leftAuxContent );
m_leftButtonRect.width = m_auxVector2.x + 30 + 4;
m_leftButtonRect.height = 38;
bool mouseOnTop = m_leftButtonRect.Contains( mousePos );
GUI.color = mouseOnTop ? OverallColorOn : OverallColorOff;
GUI.Label( m_leftButtonRect, m_leftAuxContent, m_leftButtonStyle );
if( currentEventType == EventType.MouseMove && mouseOnTop )
m_parentWindow.MarkToRepaint();
if ( currentEventType == EventType.MouseDown && mouseOnTop && currentShader != null )
{
Event.current.Use();
Selection.activeObject = currentShader;
EditorGUIUtility.PingObject( Selection.activeObject );
}
// Material Mode
if ( currentMaterial != null )
{
m_rightButtonStyle = UIUtils.GetCustomStyle( CustomStyle.MaterialModeTitle );
m_rightButtonRect = graphArea;
string matName = ( currentMaterial != null ) ? ( currentMaterial.name ) : NoMaterialStr;
if ( m_previousMaterialName != matName )
{
m_previousMaterialName = matName;
m_rightAuxContent.text = "<size=20>MATERIAL</size>\n" + matName;
}
m_auxVector2 = m_rightButtonStyle.CalcSize( m_rightAuxContent );
m_rightButtonRect.width = m_auxVector2.x + 30 + 4;
m_rightButtonRect.height = 38;
m_rightButtonRect.x = graphArea.xMax - m_rightButtonRect.width - rightPos - 10;
m_rightButtonRect.y = graphArea.yMax - 38 - 15;
bool mouseOnTopRight = m_rightButtonRect.Contains( mousePos );
GUI.color = mouseOnTopRight ? OverallColorOn : OverallColorOff;
GUI.Label( m_rightButtonRect, m_rightAuxContent, m_rightButtonStyle );
if( currentEventType == EventType.MouseMove && mouseOnTopRight )
m_parentWindow.MarkToRepaint();
if ( currentEventType == EventType.MouseDown && mouseOnTopRight )
{
Event.current.Use();
Selection.activeObject = currentMaterial;
EditorGUIUtility.PingObject( Selection.activeObject );
}
}
}
// Shader Function
else if ( currentMasterNode == null && ParentWindow.CurrentGraph.CurrentOutputNode != null )
{
m_leftButtonStyle = UIUtils.GetCustomStyle( CustomStyle.ShaderFunctionMode );
m_leftButtonRect = graphArea;
m_leftButtonRect.x = 10 + leftPos;
m_leftButtonRect.y += m_leftButtonRect.height - 38 - 15;
string functionName = ( ParentWindow.CurrentGraph.CurrentShaderFunction != null ) ? ( ParentWindow.CurrentGraph.CurrentShaderFunction.name ) : "No Shader Function";
if ( m_previousShaderFunctionName != functionName )
{
m_previousShaderFunctionName = functionName;
m_leftAuxContent.text = "<size=20>SHADER FUNCTION</size>\n" + functionName;
}
m_auxVector2 = m_leftButtonStyle.CalcSize( m_leftAuxContent );
m_leftButtonRect.width = m_auxVector2.x + 30 + 4;
m_leftButtonRect.height = 38;
bool mouseOnTop = m_leftButtonRect.Contains( mousePos );
GUI.color = mouseOnTop ? OverallColorOn : OverallColorOff;
GUI.Label( m_leftButtonRect, m_leftAuxContent, m_leftButtonStyle );
if ( currentEventType == EventType.MouseDown && mouseOnTop && ParentWindow.CurrentGraph.CurrentShaderFunction != null )
{
Event.current.Use();
Selection.activeObject = ParentWindow.CurrentGraph.CurrentShaderFunction;
EditorGUIUtility.PingObject( Selection.activeObject );
}
}
GUI.color = buffereredColor;
}
public override void Destroy()
{
base.Destroy();
m_leftAuxContent = null;
m_rightAuxContent = null;
m_leftButtonStyle = null;
m_rightButtonStyle = null;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 672d96e3a4f68d44f9456d2fc53d4d73
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEditor;
using System.Collections.Generic;
using System;
using UnityEngine;
namespace AmplifyShaderEditor
{
[Serializable]
public class ShaderLibrary : EditorWindow
{
private const string SHADER_LIB_FILE = "/AmplifyShaderEditor/Resources/ShaderLibrary/ShaderLibrary.txt";
private bool m_init = false;
private Vector2 m_scrollPos = new Vector2();
[SerializeField]
private List<string> m_shaders = new List<string>();
void Init()
{
m_init = true;
string list = IOUtils.LoadTextFileFromDisk( Application.dataPath + SHADER_LIB_FILE );
if ( String.IsNullOrEmpty( list ) )
return;
string[] listArr = list.Split( IOUtils.FIELD_SEPARATOR );
for ( int i = 0; i < listArr.Length; i++ )
{
m_shaders.Add( listArr[ i ] );
}
UIUtils.MainSkin.customStyles[ 10 ].active.background = Texture2D.whiteTexture;
UIUtils.MainSkin.customStyles[ 6 ].fixedHeight = UIUtils.MainSkin.customStyles[ 6 ].normal.background.height;
UIUtils.MainSkin.customStyles[ 6 ].fixedWidth = UIUtils.MainSkin.customStyles[ 6 ].normal.background.width;
UIUtils.MainSkin.customStyles[ 7 ].fixedHeight = UIUtils.MainSkin.customStyles[ 7 ].normal.background.height;
UIUtils.MainSkin.customStyles[ 7 ].fixedWidth = UIUtils.MainSkin.customStyles[ 7 ].normal.background.width;
UIUtils.MainSkin.customStyles[ 8 ].fixedHeight = UIUtils.MainSkin.customStyles[ 8 ].normal.background.height;
UIUtils.MainSkin.customStyles[ 8 ].fixedWidth = UIUtils.MainSkin.customStyles[ 8 ].normal.background.width;
UIUtils.MainSkin.customStyles[ 9 ].fixedHeight = UIUtils.MainSkin.customStyles[ 9 ].normal.background.height;
UIUtils.MainSkin.customStyles[ 9 ].fixedWidth = UIUtils.MainSkin.customStyles[ 9 ].normal.background.width;
}
void OnGUI()
{
if ( !m_init )
{
Init();
}
Rect availableArea = position;
availableArea.y = 100f;
availableArea.x = 0.05f * availableArea.width;
availableArea.height *= 0.5f;
availableArea.width *= 0.9f;
EditorGUILayout.BeginVertical();
{
EditorGUILayout.LabelField( "Shader Library", UIUtils.MainSkin.customStyles[ 5 ] );
GUILayout.Space( 10 );
EditorGUILayout.BeginHorizontal();
{
GUILayout.Space( 0.05f * position.width );
GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 8 ] );
GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 9 ] );
GUILayout.Space( 0.8f*position.width );
GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 7 ] );
GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 6 ] );
}
EditorGUILayout.EndHorizontal();
GUILayout.BeginArea( availableArea );
m_scrollPos = EditorGUILayout.BeginScrollView( m_scrollPos, UIUtils.MainSkin.box );
{
for ( int i = 0; i < m_shaders.Count; i++ )
{
GUILayout.Button( m_shaders[ i ], UIUtils.MainSkin.customStyles[ 10 ] );
}
}
EditorGUILayout.EndScrollView();
GUILayout.EndArea();
}
EditorGUILayout.EndVertical();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cbdd03f297692584391b9dc0625a80ed
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3857a2f02c659104fa6f0fe94cfe00dd
folderAsset: yes
timeCreated: 1481126945
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,249 @@
// 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 sealed class ToolsMenuButton : ToolsMenuButtonParent
{
public delegate void ToolButtonPressed( ToolButtonType type );
public event ToolButtonPressed ToolButtonPressedEvt;
private Rect m_buttonArea;
private List<Texture2D> m_buttonTexture;
private string m_buttonTexturePath;
private ToolButtonType m_buttonType;
private GUIStyle m_style;
private bool m_enabled = true;
private bool m_drawOnFunction = true;
private List<string> m_cachedStates;
private int m_bufferedState = -1;
private string m_bufferedTooltip = string.Empty;
public ToolsMenuButton( AmplifyShaderEditorWindow parentWindow, ToolButtonType type, float x, float y, float width, float height, string texturePath, string text, string tooltip, float buttonSpacing = -1, bool drawOnFunction = true ) : base( parentWindow, text, tooltip, buttonSpacing )
{
m_buttonArea = new Rect( x, y, width, height );
m_buttonType = type;
m_buttonTexturePath = texturePath;
m_cachedStates = new List<string>();
m_drawOnFunction = drawOnFunction;
}
public void AddState( string state )
{
m_cachedStates.Add( state );
}
public override void Destroy()
{
ToolButtonPressedEvt = null;
if ( m_buttonTexture != null )
{
for ( int i = 0; i < m_buttonTexture.Count; i++ )
{
Resources.UnloadAsset( m_buttonTexture[ i ] );
}
m_buttonTexture.Clear();
}
m_buttonTexture = null;
}
protected override void Init()
{
base.Init();
if ( m_buttonTexture == null )
{
m_buttonTexturePath = AssetDatabase.GUIDToAssetPath( m_buttonTexturePath );
m_buttonTexture = new List<Texture2D>();
m_buttonTexture.Add( AssetDatabase.LoadAssetAtPath( m_buttonTexturePath, typeof( Texture2D ) ) as Texture2D );
}
if ( m_cachedStates.Count > 0 )
{
for ( int i = 0; i < m_cachedStates.Count; i++ )
{
m_cachedStates[ i ] = AssetDatabase.GUIDToAssetPath( m_cachedStates[ i ] );
m_buttonTexture.Add( AssetDatabase.LoadAssetAtPath( m_cachedStates[ i ], typeof( Texture2D ) ) as Texture2D );
}
m_cachedStates.Clear();
}
if ( m_style == null )
{
m_style = new GUIStyle( /*UIUtils.Button*/ GUIStyle.none );
m_style.normal.background = m_buttonTexture[ 0 ];
m_style.hover.background = m_buttonTexture[ 0 ];
m_style.hover.textColor = m_style.normal.textColor;
m_style.active.background = m_buttonTexture[ 0 ];
m_style.active.textColor = m_style.normal.textColor;
m_style.onNormal.background = m_buttonTexture[ 0 ];
m_style.onNormal.textColor = m_style.normal.textColor;
m_style.onHover.background = m_buttonTexture[ 0 ];
m_style.onHover.textColor = m_style.normal.textColor;
m_style.onActive.background = m_buttonTexture[ 0 ];
m_style.onActive.textColor = m_style.normal.textColor;
m_style.clipping = TextClipping.Overflow;
m_style.fontStyle = FontStyle.Bold;
m_style.alignment = TextAnchor.LowerCenter;
m_style.contentOffset = new Vector2( 0, 15 );
m_style.fontSize = 10;
bool resizeFromTexture = false;
if ( m_buttonArea.width > 0 )
{
m_style.fixedWidth = m_buttonArea.width;
}
else
{
resizeFromTexture = true;
}
if ( m_buttonArea.height > 0 )
{
m_style.fixedHeight = m_buttonArea.height;
}
else
{
resizeFromTexture = true;
}
if ( resizeFromTexture )
{
m_buttonArea.width = m_style.fixedWidth = m_buttonTexture[ 0 ].width;
m_buttonArea.height = m_style.fixedHeight = m_buttonTexture[ 0 ].height;
}
}
}
public override void Draw()
{
base.Draw();
bool guiEnabledBuffer = GUI.enabled;
GUI.enabled = m_enabled;
if ( GUILayout.Button( m_content, m_style ) && ToolButtonPressedEvt != null )
{
ToolButtonPressedEvt( m_buttonType );
}
GUI.enabled = guiEnabledBuffer;
}
public override void Draw( float x, float y )
{
if ( !(m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.MouseDown || m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.Repaint ) )
return;
if ( m_parentWindow.CurrentGraph.CurrentMasterNode == null && !m_drawOnFunction)
return;
base.Draw( x, y );
if ( m_bufferedState > -1 )
{
if ( string.IsNullOrEmpty( m_bufferedTooltip ) )
{
SetStateOnButton( m_bufferedState );
}
else
{
SetStateOnButton( m_bufferedState, m_bufferedTooltip );
}
m_bufferedState = -1;
m_bufferedTooltip = string.Empty;
}
m_buttonArea.x = x;
m_buttonArea.y = y;
if ( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.MouseDown && m_buttonArea.Contains( m_parentWindow.CameraDrawInfo.MousePosition ) && ToolButtonPressedEvt != null )
{
ToolButtonPressedEvt( m_buttonType );
Event.current.Use();
m_parentWindow.CameraDrawInfo.CurrentEventType = EventType.Used;
}
else if ( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.Repaint )
{
GUI.Label( m_buttonArea, m_content, m_style );
}
//if ( GUI.Button( m_buttonArea, m_content, m_style ) && ToolButtonPressedEvt != null )
//{
// ToolButtonPressedEvt( m_buttonType );
//}
}
public override void Draw( Vector2 pos )
{
Draw( pos.x, pos.y );
}
public override void SetStateOnButton( int state, string tooltip )
{
if ( m_buttonTexture == null || m_style == null )
{
m_bufferedState = state;
m_bufferedTooltip = tooltip;
return;
}
if ( state < 0 || state >= m_buttonTexture.Count )
{
return;
}
base.SetStateOnButton( state, tooltip );
m_style.normal.background = m_buttonTexture[ state ];
m_style.hover.background = m_buttonTexture[ state ];
m_style.active.background = m_buttonTexture[ state ];
m_style.onNormal.background = m_buttonTexture[ state ];
m_style.onHover.background = m_buttonTexture[ state ];
m_style.onActive.background = m_buttonTexture[ state ];
}
public override void SetStateOnButton( int state )
{
if ( m_buttonTexture == null || m_style == null )
{
m_bufferedState = state;
return;
}
if ( state < 0 || state >= m_buttonTexture.Count )
{
return;
}
base.SetStateOnButton( state );
m_style.normal.background = m_buttonTexture[ state ];
m_style.hover.background = m_buttonTexture[ state ];
m_style.active.background = m_buttonTexture[ state ];
m_style.onNormal.background = m_buttonTexture[ state ];
m_style.onHover.background = m_buttonTexture[ state ];
m_style.onActive.background = m_buttonTexture[ state ];
}
public bool IsInside( Vector2 pos )
{
return m_buttonArea.Contains( pos );
}
public bool Enabled
{
get { return m_enabled; }
set { m_enabled = value; }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 890f4ed5c9f62af43bda6584705fa0be
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
namespace AmplifyShaderEditor
{
public class ToolsMenuButtonParent
{
protected AmplifyShaderEditorWindow m_parentWindow = null;
private float m_buttonSpacing = 10;
private int m_currentState = 0;
private bool m_isInitialized = false;
protected GUIContent m_content;
public ToolsMenuButtonParent( AmplifyShaderEditorWindow parentWindow, string text, string tooltip, float buttonSpacing )
{
m_parentWindow = parentWindow;
m_content = new GUIContent( text, tooltip );
if ( buttonSpacing > 0 )
m_buttonSpacing = buttonSpacing;
}
public virtual void Draw()
{
if ( !m_isInitialized )
{
Init();
}
//GUILayout.Space( m_buttonSpacing );
}
public virtual void Draw( Vector2 pos )
{
Draw( pos.x, pos.y );
}
public virtual void Draw( float x ,float y )
{
if ( !m_isInitialized )
{
Init();
}
}
protected virtual void Init()
{
m_isInitialized = false;
}
public virtual void SetStateOnButton( int state, string tooltip )
{
m_currentState = state;
m_content.tooltip = tooltip;
}
public virtual void SetStateOnButton( int state )
{
m_currentState = state;
}
public virtual void Destroy() { }
public float ButtonSpacing
{
get { return m_buttonSpacing; }
}
public int CurrentState
{
get { return m_currentState; }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a3bf3644c2c2fbb4fa0dd8b86effc6e1
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
public sealed class ToolsMenuButtonSep : ToolsMenuButtonParent
{
private Color m_splitterColor = EditorGUIUtility.isProSkin ? new Color( 0.157f, 0.157f, 0.157f ) : new Color( 0.5f, 0.5f, 0.5f );
[SerializeField]
private GUIStyle m_sepStyle;
public ToolsMenuButtonSep( AmplifyShaderEditorWindow parentWindow = null, string text = null, string tooltip = null, float buttonSpacing = -1 ) : base( parentWindow, text, tooltip, buttonSpacing ) { }
public override void Draw()
{
base.Draw();
if ( m_sepStyle == null )
{
m_sepStyle = new GUIStyle();
m_sepStyle.normal.background = Texture2D.whiteTexture;
m_sepStyle.hover.background = Texture2D.whiteTexture;
m_sepStyle.active.background = Texture2D.whiteTexture;
m_sepStyle.onNormal.background = Texture2D.whiteTexture;
m_sepStyle.onHover.background = Texture2D.whiteTexture;
m_sepStyle.onActive.background = Texture2D.whiteTexture;
m_sepStyle.stretchHeight = true;
}
Color originalColor = GUI.color;
GUI.color = m_splitterColor;
GUILayout.Box( string.Empty, m_sepStyle, GUILayout.MaxWidth( 2 ), GUILayout.ExpandHeight( true ) );
GUI.color = originalColor;
}
public override void Destroy()
{
m_sepStyle = null;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b4c65a9d96791c34eb587cea9662161f
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,632 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
namespace AmplifyShaderEditor
{
public enum ToolButtonType
{
Update = 0,
Live,
OpenSourceCode,
CleanUnusedNodes,
//SelectShader,
New,
Open,
Save,
Library,
Options,
Help,
MasterNode,
FocusOnMasterNode,
FocusOnSelection,
ShowInfoWindow,
ShowTipsWindow,
ShowConsole,
TakeScreenshot,
Share
}
public enum ToolbarType
{
File,
Help
}
public class ToolbarMenuTab
{
private Rect m_tabArea;
private GenericMenu m_tabMenu;
public ToolbarMenuTab( float x, float y, float width, float height )
{
m_tabMenu = new GenericMenu();
m_tabArea = new Rect( x, y, width, height );
}
public void ShowMenu()
{
m_tabMenu.DropDown( m_tabArea );
}
public void AddItem( string itemName, GenericMenu.MenuFunction callback )
{
m_tabMenu.AddItem( new GUIContent( itemName ), false, callback );
}
}
[Serializable]
public sealed class ToolsWindow : MenuParent
{
private static readonly Color RightIconsColorOff = new Color( 1f, 1f, 1f, 0.8f );
private static readonly Color LeftIconsColorOff = new Color( 1f, 1f, 1f, 0.5f );
private static readonly Color RightIconsColorOn = new Color( 1f, 1f, 1f, 1.0f );
private static readonly Color LeftIconsColorOn = new Color( 1f, 1f, 1f, 0.8f );
private const float TabY = 9;
private const float TabX = 5;
private const string ShaderFileTitleStr = "Current Shader";
private const string FileToolbarStr = "File";
private const string HelpToolbarStr = "Help";
private const string LiveShaderStr = "Live Shader";
private const string LoadOnSelectionStr = "Load on selection";
private const string CurrentObjectStr = "Current Object: ";
public ToolsMenuButton.ToolButtonPressed ToolButtonPressedEvt;
//private GUIStyle m_toolbarButtonStyle;
private GUIStyle m_toggleStyle;
private GUIStyle m_borderStyle;
// left
private ToolsMenuButton m_updateButton;
private ToolsMenuButton m_liveButton;
private ToolsMenuButton m_openSourceCodeButton;
//middle right
private ToolsMenuButton m_cleanUnusedNodesButton;
private ToolsMenuButton m_focusOnMasterNodeButton;
private ToolsMenuButton m_focusOnSelectionButton;
// right
private ToolsMenuButton m_shareButton;
private ToolsMenuButton m_takeScreenshotButton;
private ToolsMenuButton m_showInfoWindowButton;
// hidden
private ToolsMenuButton m_showTipsWindowButton;
private ToolsMenuButton m_showConsoleWindowButton;
//Used for collision detection to invalidate inputs on graph area
private Rect m_areaLeft = new Rect( 0, 0, 140, 40 );
private Rect m_areaRight = new Rect( 0, 0, 75, 40 );
private Rect m_boxRect;
private Rect m_borderRect;
public const double InactivityRefreshTime = 0.25;
private int m_currentSelected = 0;
//Search Bar
private const string SearchBarId = "ASE_SEARCH_BAR";
private bool m_searchBarVisible = false;
private bool m_selectSearchBarTextfield = false;
private bool m_refreshSearchResultList = false;
private Rect m_searchBarSize;
private string m_searchBarValue = string.Empty;
private List<ParentNode> m_searchResultNodes = new List<ParentNode>();
// width and height are between [0,1] and represent a percentage of the total screen area
public ToolsWindow( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 0, 64, "Tools", MenuAnchor.TOP_LEFT, MenuAutoSize.NONE )
{
m_updateButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.Update, 0, 0, -1, -1, IOUtils.UpdateOutdatedGUID, string.Empty, "Create and apply shader to material.", 5 );
m_updateButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_updateButton.AddState( IOUtils.UpdateOFFGUID );
m_updateButton.AddState( IOUtils.UpdateUpToDatedGUID );
m_liveButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.Live, 0, 0, -1, -1, IOUtils.LiveOffGUID, string.Empty, "Automatically saves shader when canvas is changed.", 50 );
m_liveButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_liveButton.AddState( IOUtils.LiveOnGUID );
m_liveButton.AddState( IOUtils.LivePendingGUID );
//ToolsMenuButton cleanUnusedNodesButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.CleanUnusedNodes, 0, 0, -1, -1, IOUtils.CleanupOFFGUID, string.Empty, "Remove all nodes not connected to the master node.", 77 );
//cleanUnusedNodesButton.ToolButtonPressedEvt += OnButtonPressedEvent;
//cleanUnusedNodesButton.AddState( IOUtils.CleanUpOnGUID );
//m_list[ ( int ) ToolButtonType.CleanUnusedNodes ] = cleanUnusedNodesButton;
m_openSourceCodeButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.OpenSourceCode, 0, 0, -1, -1, IOUtils.OpenSourceCodeOFFGUID, string.Empty, "Open shader file in your default shader editor.", 80, false );
m_openSourceCodeButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_openSourceCodeButton.AddState( IOUtils.OpenSourceCodeONGUID );
// middle right
m_cleanUnusedNodesButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.CleanUnusedNodes, 0, 0, -1, -1, IOUtils.CleanupOFFGUID, string.Empty, "Remove all nodes not connected to the master node.", 77 );
m_cleanUnusedNodesButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_cleanUnusedNodesButton.AddState( IOUtils.CleanUpOnGUID );
m_focusOnMasterNodeButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.FocusOnMasterNode, 0, 0, -1, -1, IOUtils.FocusNodeGUID, string.Empty, "Focus on active master node.", -1, false );
m_focusOnMasterNodeButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_focusOnSelectionButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.FocusOnSelection, 0, 0, -1, -1, IOUtils.FitViewGUID, string.Empty, "Focus on selection or fit to screen if none selected." );
m_focusOnSelectionButton.ToolButtonPressedEvt += OnButtonPressedEvent;
// right
m_shareButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.Share, 0, 0, -1, -1, IOUtils.ShareOFFGUID, string.Empty, "Share selection", 100 );
m_shareButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_shareButton.AddState( IOUtils.ShareONGUID );
m_takeScreenshotButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.TakeScreenshot, 0, 0, -1, -1, IOUtils.TakeScreenshotOFFGUID, string.Empty, "Take ScreenShot (WINDOWS ONLY).", 100 );
m_takeScreenshotButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_takeScreenshotButton.AddState( IOUtils.TakeScreenshotONGUID );
m_showInfoWindowButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.ShowInfoWindow, 0, 0, -1, -1, IOUtils.ShowInfoWindowGUID, string.Empty, "Open Helper Window." );
m_showInfoWindowButton.ToolButtonPressedEvt += OnButtonPressedEvent;
// hidden
m_showTipsWindowButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.ShowTipsWindow, 0, 0, -1, -1, IOUtils.ShowTipsWindowGUID, string.Empty, "Open Quick Tips!" );
m_showTipsWindowButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_showConsoleWindowButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.ShowConsole, 0, 0, -1, -1, IOUtils.ShowConsoleWindowGUID, string.Empty, "Show internal console", 74 );
m_showConsoleWindowButton.ToolButtonPressedEvt += OnButtonPressedEvent;
m_showConsoleWindowButton.AddState( IOUtils.ShowConsoleWindowGUID );
m_searchBarSize = new Rect( 0, TabY + 4, 110, 60 );
}
void OnShowPortLegend()
{
ParentWindow.ShowPortInfo();
}
override public void Destroy()
{
base.Destroy();
//for ( int i = 0; i < m_list.Length; i++ )
//{
// m_list[ i ].Destroy();
//}
//m_list = null;
m_searchResultNodes.Clear();
m_searchResultNodes = null;
m_updateButton.Destroy();
m_updateButton = null;
m_liveButton.Destroy();
m_liveButton = null;
m_openSourceCodeButton.Destroy();
m_openSourceCodeButton = null;
m_focusOnMasterNodeButton.Destroy();
m_focusOnMasterNodeButton = null;
m_focusOnSelectionButton.Destroy();
m_focusOnSelectionButton = null;
m_showInfoWindowButton.Destroy();
m_showInfoWindowButton = null;
m_takeScreenshotButton.Destroy();
m_takeScreenshotButton = null;
m_shareButton.Destroy();
m_shareButton = null;
m_showTipsWindowButton.Destroy();
m_showTipsWindowButton = null;
m_cleanUnusedNodesButton.Destroy();
m_cleanUnusedNodesButton = null;
m_showConsoleWindowButton.Destroy();
m_showConsoleWindowButton = null;
}
void OnButtonPressedEvent( ToolButtonType type )
{
if ( ToolButtonPressedEvt != null )
ToolButtonPressedEvt( type );
}
public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
{
base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus );
Color bufferedColor = GUI.color;
m_areaLeft.x = m_transformedArea.x + TabX;
m_areaRight.x = m_transformedArea.x + m_transformedArea.width - 75 - TabX;
//if ( m_toolbarButtonStyle == null )
//{
// m_toolbarButtonStyle = new GUIStyle( UIUtils.Button );
// m_toolbarButtonStyle.fixedWidth = 100;
//}
if ( m_toggleStyle == null )
{
m_toggleStyle = UIUtils.Toggle;
}
//for ( int i = 0; i < m_list.Length; i++ )
//{
// GUI.color = m_list[ i ].IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
// m_list[ i ].Draw( TabX + m_transformedArea.x + m_list[ i ].ButtonSpacing, TabY );
//}
GUI.color = m_updateButton.IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
m_updateButton.Draw( TabX + m_transformedArea.x + m_updateButton.ButtonSpacing, TabY );
GUI.color = m_liveButton.IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
m_liveButton.Draw( TabX + m_transformedArea.x + m_liveButton.ButtonSpacing, TabY );
GUI.color = m_openSourceCodeButton.IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
m_openSourceCodeButton.Draw( TabX + m_transformedArea.x + m_openSourceCodeButton.ButtonSpacing, TabY );
if ( m_searchBarVisible )
{
m_searchBarSize.x = m_transformedArea.x + m_transformedArea.width - 320 - TabX;
string currentFocus = GUI.GetNameOfFocusedControl();
if ( Event.current.type == EventType.KeyDown )
{
KeyCode keyCode = Event.current.keyCode;
if ( Event.current.shift )
{
if ( keyCode == KeyCode.F3 ||
( ( keyCode == KeyCode.KeypadEnter || keyCode == KeyCode.Return ) &&
( currentFocus.Equals( SearchBarId ) || string.IsNullOrEmpty( currentFocus ) ) ) )
SelectPrevious();
}
else
{
if ( keyCode == KeyCode.F3 ||
( ( keyCode == KeyCode.KeypadEnter || keyCode == KeyCode.Return ) &&
( currentFocus.Equals( SearchBarId ) || string.IsNullOrEmpty( currentFocus ) ) ) )
SelectNext();
}
}
if( currentFocus.Equals( SearchBarId ) || ( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.MouseDown && m_searchBarSize.Contains( m_parentWindow.CameraDrawInfo.MousePosition ) ) || m_selectSearchBarTextfield )
{
EditorGUI.BeginChangeCheck();
{
GUI.SetNextControlName( SearchBarId );
m_searchBarValue = EditorGUI.TextField( m_searchBarSize, m_searchBarValue, UIUtils.ToolbarSearchTextfield );
}
if ( EditorGUI.EndChangeCheck() )
{
m_refreshSearchResultList = true;
}
} else
{
GUI.Label( m_searchBarSize, m_searchBarValue, UIUtils.ToolbarSearchTextfield );
}
m_searchBarSize.x += m_searchBarSize.width;
if ( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.MouseDown && m_searchBarSize.Contains( m_parentWindow.CameraDrawInfo.MousePosition ) )
{
if ( string.IsNullOrEmpty( m_searchBarValue ) )
{
m_searchBarVisible = false;
m_refreshSearchResultList = false;
}
else
{
m_searchBarValue = string.Empty;
m_searchResultNodes.Clear();
m_currentSelected = -1;
}
}
GUI.Label( m_searchBarSize, string.Empty, UIUtils.ToolbarSearchCancelButton );
if ( Event.current.isKey && Event.current.keyCode == KeyCode.Escape )
{
m_searchBarVisible = false;
m_refreshSearchResultList = false;
GUI.FocusControl( null );
m_selectSearchBarTextfield = false;
}
if ( m_refreshSearchResultList && ( m_parentWindow.CurrentInactiveTime > InactivityRefreshTime ) )
{
RefreshList();
}
}
if ( m_selectSearchBarTextfield )
{
m_selectSearchBarTextfield = false;
EditorGUI.FocusTextInControl( SearchBarId );
//GUI.FocusControl( SearchBarId );
}
//if ( Event.current.control && Event.current.isKey && Event.current.keyCode == KeyCode.F && Event.current.type == EventType.KeyDown )
if( m_parentWindow.CurrentCommandName.Equals("Find") )
{
if ( !m_searchBarVisible )
{
m_searchBarVisible = true;
m_refreshSearchResultList = false;
}
m_selectSearchBarTextfield = true;
}
GUI.color = m_shareButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
m_shareButton.Draw( m_transformedArea.x + m_transformedArea.width - 195 - TabX, TabY );
GUI.color = m_takeScreenshotButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
m_takeScreenshotButton.Draw( m_transformedArea.x + m_transformedArea.width - 165 - TabX, TabY );
GUI.color = m_focusOnSelectionButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
m_focusOnSelectionButton.Draw( m_transformedArea.x + m_transformedArea.width - 120 - TabX, TabY );
GUI.color = m_focusOnMasterNodeButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
m_focusOnMasterNodeButton.Draw( m_transformedArea.x + m_transformedArea.width - 85 - TabX, TabY );
GUI.color = m_cleanUnusedNodesButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
m_cleanUnusedNodesButton.Draw( m_transformedArea.x + m_transformedArea.width - 50 - TabX, TabY );
GUI.color = m_showInfoWindowButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
m_showInfoWindowButton.Draw( m_transformedArea.x + m_transformedArea.width - 25 - TabX, TabY );
//GUI.color = m_showTipsWindowButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
//m_showTipsWindowButton.Draw( m_transformedArea.x + m_transformedArea.width - 190 - TabX, TabY );
//GUI.color = m_showConsoleWindowButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
//m_showConsoleWindowButton.Draw( m_transformedArea.x + m_transformedArea.width - 195 - TabX, TabY );
GUI.color = bufferedColor;
}
public void OnNodeRemovedFromGraph( ParentNode node )
{
m_searchResultNodes.Remove( node );
}
int m_previousNodeCount = 0;
void RefreshList()
{
m_refreshSearchResultList = false;
m_currentSelected = -1;
m_searchResultNodes.Clear();
if ( !string.IsNullOrEmpty( m_searchBarValue ) )
{
List<ParentNode> nodes = m_parentWindow.CurrentGraph.AllNodes;
int count = nodes.Count;
m_previousNodeCount = count;
for ( int i = 0; i < count; i++ )
{
if ( nodes[ i ].CheckFindText( m_searchBarValue ) )
{
m_searchResultNodes.Add( nodes[ i ] );
}
}
}
}
void SelectNext()
{
if ( m_refreshSearchResultList || m_parentWindow.CurrentGraph.AllNodes.Count != m_previousNodeCount )
{
RefreshList();
}
if ( m_searchResultNodes.Count > 0 )
{
m_currentSelected = ( m_currentSelected + 1 ) % m_searchResultNodes.Count;
m_parentWindow.FocusOnNode( m_searchResultNodes[ m_currentSelected ], 1, true ,true);
}
}
void SelectPrevious()
{
if ( m_refreshSearchResultList || m_parentWindow.CurrentGraph.AllNodes.Count != m_previousNodeCount )
{
RefreshList();
}
if ( m_searchResultNodes.Count > 0 )
{
m_currentSelected = ( m_currentSelected > 1 ) ? ( m_currentSelected - 1 ) : ( m_searchResultNodes.Count - 1 );
m_parentWindow.FocusOnNode( m_searchResultNodes[ m_currentSelected ], 1, true );
}
}
public void SetStateOnButton( ToolButtonType button, int state, string tooltip )
{
switch ( button )
{
case ToolButtonType.New:
case ToolButtonType.Open:
case ToolButtonType.Save:
case ToolButtonType.Library:
case ToolButtonType.Options:
case ToolButtonType.Help:
case ToolButtonType.MasterNode: break;
case ToolButtonType.OpenSourceCode:
{
m_openSourceCodeButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.Update:
{
m_updateButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.Live:
{
m_liveButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.TakeScreenshot:
{
m_takeScreenshotButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.CleanUnusedNodes:
//case eToolButtonType.SelectShader:
{
m_cleanUnusedNodesButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.FocusOnMasterNode:
{
m_focusOnMasterNodeButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.FocusOnSelection:
{
m_focusOnSelectionButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.Share:
{
m_shareButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.ShowInfoWindow:
{
m_showInfoWindowButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.ShowTipsWindow:
{
m_showTipsWindowButton.SetStateOnButton( state, tooltip );
}
break;
case ToolButtonType.ShowConsole:
{
m_showConsoleWindowButton.SetStateOnButton( state, tooltip );
}
break;
}
}
public void SetStateOnButton( ToolButtonType button, int state )
{
switch ( button )
{
case ToolButtonType.New:
case ToolButtonType.Open:
case ToolButtonType.Save:
case ToolButtonType.Library:
case ToolButtonType.Options:
case ToolButtonType.Help:
case ToolButtonType.MasterNode: break;
case ToolButtonType.OpenSourceCode:
{
m_openSourceCodeButton.SetStateOnButton( state );
}
break;
case ToolButtonType.Update:
{
m_updateButton.SetStateOnButton( state );
}
break;
case ToolButtonType.Live:
{
m_liveButton.SetStateOnButton( state );
}
break;
case ToolButtonType.TakeScreenshot:
{
m_takeScreenshotButton.SetStateOnButton( state );
}
break;
case ToolButtonType.CleanUnusedNodes:
//case eToolButtonType.SelectShader:
{
m_cleanUnusedNodesButton.SetStateOnButton( state );
}
break;
case ToolButtonType.FocusOnMasterNode:
{
m_focusOnMasterNodeButton.SetStateOnButton( state );
}
break;
case ToolButtonType.FocusOnSelection:
{
m_focusOnSelectionButton.SetStateOnButton( state );
}
break;
case ToolButtonType.Share:
{
m_shareButton.SetStateOnButton( state );
}
break;
case ToolButtonType.ShowInfoWindow:
{
m_showInfoWindowButton.SetStateOnButton( state );
}
break;
case ToolButtonType.ShowTipsWindow:
{
m_showTipsWindowButton.SetStateOnButton( state );
}break;
case ToolButtonType.ShowConsole:
{
m_showConsoleWindowButton.SetStateOnButton( state );
}
break;
}
}
public void DrawShaderTitle( MenuParent nodeParametersWindow, MenuParent paletteWindow, float availableCanvasWidth, float graphAreaHeight, string shaderName )
{
float leftAdjust = nodeParametersWindow.IsMaximized ? nodeParametersWindow.RealWidth : 0;
float rightAdjust = paletteWindow.IsMaximized ? 0 : paletteWindow.RealWidth;
m_boxRect = new Rect( leftAdjust + rightAdjust, 0, availableCanvasWidth, 35 );
m_boxRect.x += paletteWindow.IsMaximized ? 0 : -paletteWindow.RealWidth;
m_boxRect.width += nodeParametersWindow.IsMaximized ? 0 : nodeParametersWindow.RealWidth;
m_boxRect.width += paletteWindow.IsMaximized ? 0 : paletteWindow.RealWidth;
m_borderRect = new Rect( m_boxRect );
m_borderRect.height = graphAreaHeight;
int extra = m_searchBarVisible ? (int)m_searchBarSize.width + 20: 0;
//m_boxRect.xMax -= ( paletteWindow.IsMaximized ? 195 : 230 ) + extra;
//m_boxRect.xMin += nodeParametersWindow.IsMaximized ? 95 : 145;
UIUtils.ToolbarMainTitle.padding.right = ( paletteWindow.IsMaximized ? 195 : 230 ) + extra;
UIUtils.ToolbarMainTitle.padding.left = nodeParametersWindow.IsMaximized ? 110 : 145;
if ( m_borderStyle == null )
{
m_borderStyle = ( ParentWindow.CurrentGraph.CurrentMasterNode == null ) ? UIUtils.GetCustomStyle( CustomStyle.ShaderFunctionBorder ) : UIUtils.GetCustomStyle( CustomStyle.ShaderBorder );
}
GUI.Label( m_borderRect, shaderName, m_borderStyle );
GUI.Label( m_boxRect, shaderName, UIUtils.ToolbarMainTitle );
}
public override bool IsInside( Vector2 position )
{
if ( !m_isActive )
return false;
return m_boxRect.Contains( position ) || m_areaLeft.Contains( position ) || m_areaRight.Contains( position );
}
public GUIStyle BorderStyle
{
get { return m_borderStyle; }
set { m_borderStyle = value; }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b1c1f3bedf849cb41a1648bf895bc0f7
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: