diff options
Diffstat (limited to 'Assets/AmplifyShaderEditor/Plugins/Editor/Wires')
12 files changed, 0 insertions, 2850 deletions
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/GLDraw.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/GLDraw.cs deleted file mode 100644 index ab8011ff..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/GLDraw.cs +++ /dev/null @@ -1,156 +0,0 @@ -using UnityEngine; -using UnityEditor; -using System.Collections.Generic; - -namespace AmplifyShaderEditor -{ - public class GLDraw - { - /* - * Clipping code: http://forum.unity3d.com/threads/17066-How-to-draw-a-GUI-2D-quot-line-quot?p=230386#post230386 - * Thick line drawing code: http://unifycommunity.com/wiki/index.php?title=VectorLine - */ - public static Material LineMaterial = null; - public static bool MultiLine = false; - private static Shader LineShader = null; - private static Rect BoundBox = new Rect(); - private static Vector3[] Allv3Points = new Vector3[] { }; - private static Vector2[] AllPerpendiculars = new Vector2[] { }; - private static Color[] AllColors = new Color[] { }; - private static Vector2 StartPt = Vector2.zero; - private static Vector2 EndPt = Vector2.zero; - - private static Vector3 Up = new Vector3( 0, 1, 0 ); - private static Vector3 Zero = new Vector3( 0, 0, 0 ); - - private static Vector2 Aux1Vec2 = Vector2.zero; - - private static int HigherBoundArray = 0; - - public static void CreateMaterial() - { - if( (object)LineMaterial != null && (object)LineShader != null ) - return; - - LineShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "50fc796413bac8b40aff70fb5a886273" ) ); - LineMaterial = new Material( LineShader ); - - LineMaterial.hideFlags = HideFlags.HideAndDontSave; - } - - public static void DrawCurve( Vector3[] allPoints, Vector2[] allNormals, Color[] allColors, int pointCount ) - { - CreateMaterial(); - LineMaterial.SetPass( ( MultiLine ? 1 : 0 ) ); - - GL.Begin( GL.TRIANGLE_STRIP ); - for( int i = 0; i < pointCount; i++ ) - { - GL.Color( allColors[ i ] ); - GL.TexCoord( Zero ); - GL.Vertex3( allPoints[ i ].x - allNormals[ i ].x, allPoints[ i ].y - allNormals[ i ].y, 0 ); - GL.TexCoord( Up ); - GL.Vertex3( allPoints[ i ].x + allNormals[ i ].x, allPoints[ i ].y + allNormals[ i ].y, 0 ); - } - GL.End(); - - } - - public static Rect DrawBezier( Vector2 start, Vector2 startTangent, Vector2 end, Vector2 endTangent, Color color, float width, int type = 1 ) - { - int segments = Mathf.FloorToInt( ( start - end ).magnitude / 20 ) * 3; // Three segments per distance of 20 - return DrawBezier( start, startTangent, end, endTangent, color, width, segments, type ); - } - - public static Rect DrawBezier( Vector2 start, Vector2 startTangent, Vector2 end, Vector2 endTangent, Color color, float width, int segments, int type = 1 ) - { - return DrawBezier( start, startTangent, end, endTangent, color, color, width, segments, type ); - } - - public static Rect DrawBezier( Vector2 start, Vector2 startTangent, Vector2 end, Vector2 endTangent, Color startColor, Color endColor, float width, int segments, int type = 1 ) - { - int pointsCount = segments + 1; - int linesCount = segments; - - HigherBoundArray = HigherBoundArray > pointsCount ? HigherBoundArray : pointsCount; - - Allv3Points = Handles.MakeBezierPoints( start, end, startTangent, endTangent, pointsCount ); - if( AllColors.Length < HigherBoundArray ) - { - AllColors = new Color[ HigherBoundArray ]; - AllPerpendiculars = new Vector2[ HigherBoundArray ]; - } - - startColor.a = ( type * 0.25f ); - endColor.a = ( type * 0.25f ); - - float minX = Allv3Points[ 0 ].x; - float minY = Allv3Points[ 0 ].y; - float maxX = Allv3Points[ 0 ].x; - float maxY = Allv3Points[ 0 ].y; - - float amount = 1 / (float)linesCount; - for( int i = 0; i < pointsCount; i++ ) - { - if( i == 0 ) - { - AllColors[ 0 ] = startColor; - StartPt.Set( startTangent.y, start.x ); - EndPt.Set( start.y, startTangent.x ); - } - else if( i == pointsCount - 1 ) - { - AllColors[ pointsCount - 1 ] = endColor; - StartPt.Set( end.y, endTangent.x ); - EndPt.Set( endTangent.y, end.x ); - } - else - { - AllColors[ i ] = Color.LerpUnclamped( startColor, endColor, amount * i ); - - minX = ( Allv3Points[ i ].x < minX ) ? Allv3Points[ i ].x : minX; - minY = ( Allv3Points[ i ].y < minY ) ? Allv3Points[ i ].y : minY; - maxX = ( Allv3Points[ i ].x > maxX ) ? Allv3Points[ i ].x : maxX; - maxY = ( Allv3Points[ i ].y > maxY ) ? Allv3Points[ i ].y : maxY; - StartPt.Set( Allv3Points[ i + 1 ].y, Allv3Points[ i - 1 ].x ); - EndPt.Set( Allv3Points[ i - 1 ].y, Allv3Points[ i + 1 ].x ); - } - Aux1Vec2.Set( StartPt.x - EndPt.x, StartPt.y - EndPt.y ); - FastNormalized( ref Aux1Vec2 ); - //aux1Vec2.FastNormalized(); - Aux1Vec2.Set( Aux1Vec2.x * width, Aux1Vec2.y * width ); - AllPerpendiculars[ i ] = Aux1Vec2; - } - - BoundBox.Set( minX, minY, ( maxX - minX ), ( maxY - minY ) ); - - DrawCurve( Allv3Points, AllPerpendiculars, AllColors, pointsCount ); - return BoundBox; - } - - private static void FastNormalized( ref Vector2 v ) - { - float len = Mathf.Sqrt( v.x * v.x + v.y * v.y ); - v.Set( v.x / len, v.y / len ); - } - - public static void Destroy() - { - GameObject.DestroyImmediate( LineMaterial ); - LineMaterial = null; - - Resources.UnloadAsset( LineShader ); - LineShader = null; - } - } - - //public static class VectorEx - //{ - // public static void FastNormalized( this Vector2 v ) - // { - // float len = Mathf.Sqrt( v.x * v.x + v.y * v.y ); - // v.Set( v.x / len, v.y / len ); - // } - //} -} - diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/GLDraw.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/GLDraw.cs.meta deleted file mode 100644 index 0f466abc..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/GLDraw.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 7647d2525992b7748a587740fd596977 -timeCreated: 1481126956 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/InputPort.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/InputPort.cs deleted file mode 100644 index 385887e3..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/InputPort.cs +++ /dev/null @@ -1,1535 +0,0 @@ -// Amplify Shader Editor - Visual Shader Editing Tool -// Copyright (c) Amplify Creations, Lda <info@amplify.pt> - -using System; -using UnityEngine; -using UnityEditor; - -namespace AmplifyShaderEditor -{ - [Serializable] - public sealed class InputPort : WirePort - { - private const string InputDefaultNameStr = "Input"; - [SerializeField] - private int m_externalNodeLink = -1; - - [SerializeField] - private int m_externalPortLink = -1; - - [SerializeField] - private string m_externalLinkId = string.Empty; - - [SerializeField] - private bool m_typeLocked; - - [SerializeField] - private string m_internalData = string.Empty; - - [SerializeField] - private string m_internalDataWrapper = string.Empty; - - [SerializeField] - private string m_dataName = string.Empty; - - [SerializeField] - private string m_internalDataPropertyLabel = string.Empty; - - // this will only is important on master node - [SerializeField] - private MasterNodePortCategory m_category = MasterNodePortCategory.Fragment; - - [SerializeField] - private PortGenType m_genType; - - private string m_propertyName = string.Empty; - private int m_cachedPropertyId = -1; - - private int m_cachedIntShaderID = -1; - private int m_cachedFloatShaderID = -1; - private int m_cachedVectorShaderID = -1; - private int m_cachedColorShaderID = -1; - private int m_cached2DShaderID = -1; - private int m_cachedDefaultTexShaderID = -1; - - [SerializeField] - private bool m_drawInternalData = false; - - //[SerializeField] - //private RenderTexture m_inputPreview = null; - //[SerializeField] - private RenderTexture m_inputPreviewTexture = null; - private Material m_inputPreviewMaterial = null; - private Shader m_inputPreviewShader = null; - - [SerializeField] - private int m_previewInternalInt = 0; - [SerializeField] - private float m_previewInternalFloat = 0; - [SerializeField] - private Vector2 m_previewInternalVec2 = Vector2.zero; - [SerializeField] - private Vector3 m_previewInternalVec3 = Vector3.zero; - [SerializeField] - private Vector4 m_previewInternalVec4 = Vector4.zero; - [SerializeField] - private Color m_previewInternalColor = Color.clear; - [SerializeField] - private Matrix4x4 m_previewInternalMatrix4x4 = Matrix4x4.identity; - - private int m_propertyNameInt = 0; - private ParentNode m_node = null; - - public InputPort() : base( -1, -1, WirePortDataType.FLOAT, string.Empty ) { m_typeLocked = true; } - public InputPort( int nodeId, int portId, WirePortDataType dataType, string name, bool typeLocked, int orderId = -1, MasterNodePortCategory category = MasterNodePortCategory.Fragment, PortGenType genType = PortGenType.NonCustomLighting ) : base( nodeId, portId, dataType, name, orderId ) - { - m_dataName = name; - m_internalDataPropertyLabel = ( string.IsNullOrEmpty( name ) || name.Equals( Constants.EmptyPortValue ) ) ? InputDefaultNameStr : name; - m_typeLocked = typeLocked; - m_category = category; - m_genType = genType; - } - - public InputPort( int nodeId, int portId, WirePortDataType dataType, string name, string dataName, bool typeLocked, int orderId = -1, MasterNodePortCategory category = MasterNodePortCategory.Fragment, PortGenType genType = PortGenType.NonCustomLighting ) : base( nodeId, portId, dataType, name, orderId ) - { - m_dataName = dataName; - m_internalDataPropertyLabel = ( string.IsNullOrEmpty( name ) || name.Equals( Constants.EmptyPortValue ) ) ? InputDefaultNameStr : name; - m_typeLocked = typeLocked; - m_category = category; - m_genType = genType; - } - - public void SetExternalLink( int nodeId, int portId ) - { - m_externalNodeLink = nodeId; - m_externalPortLink = portId; - } - - public override bool CheckValidType( WirePortDataType dataType ) - { - if( m_typeLocked ) - return ( dataType == m_dataType ); - - return base.CheckValidType( dataType ); - } - - public override void FullDeleteConnections() - { - UIUtils.DeleteConnection( true, m_nodeId, m_portId, true, true ); - } - - public override void NotifyExternalRefencesOnChange() - { - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - ParentNode node = UIUtils.GetNode( m_externalReferences[ i ].NodeId ); - if( node ) - { - OutputPort port = node.GetOutputPortByUniqueId( m_externalReferences[ i ].PortId ); - port.UpdateInfoOnExternalConn( m_nodeId, m_portId, m_dataType ); - node.OnConnectedInputNodeChanges( m_externalReferences[ i ].PortId, m_nodeId, m_portId, m_name, m_dataType ); - } - } - } - - public void UpdatePreviewInternalData() - { - switch( m_dataType ) - { - case WirePortDataType.INT: m_previewInternalInt = IntInternalData; break; - case WirePortDataType.FLOAT: m_previewInternalFloat = FloatInternalData; break; - case WirePortDataType.FLOAT2: m_previewInternalVec2 = Vector2InternalData; break; - case WirePortDataType.FLOAT3: m_previewInternalVec3 = Vector3InternalData; break; - case WirePortDataType.FLOAT4: m_previewInternalVec4 = Vector4InternalData; break; - case WirePortDataType.COLOR: m_previewInternalColor = ColorInternalData; break; - } - } - - void UpdateVariablesFromInternalData() - { - string[] data = String.IsNullOrEmpty( m_internalData ) ? null : m_internalData.Split( IOUtils.VECTOR_SEPARATOR ); - bool reset = ( data == null || data.Length == 0 ); - m_internalDataUpdated = false; - try - { - switch( m_dataType ) - { - case WirePortDataType.OBJECT:break; - case WirePortDataType.FLOAT: m_previewInternalFloat = reset ? 0 : Convert.ToSingle( data[ 0 ] ); break; - case WirePortDataType.INT: - { - if( reset ) - { - m_previewInternalInt = 0; - } - else - { - if( data[ 0 ].Contains( "." ) ) - { - m_previewInternalInt = (int)Convert.ToSingle( data[ 0 ] ); - } - else - { - m_previewInternalInt = Convert.ToInt32( data[ 0 ] ); - } - } - } - break; - case WirePortDataType.FLOAT2: - { - if( reset ) - { - m_previewInternalVec2 = Vector2.zero; - } - else - { - if( data.Length < 2 ) - { - m_previewInternalVec2.x = Convert.ToSingle( data[ 0 ] ); - m_previewInternalVec2.y = 0; - } - else - { - m_previewInternalVec2.x = Convert.ToSingle( data[ 0 ] ); - m_previewInternalVec2.y = Convert.ToSingle( data[ 1 ] ); - } - } - } - break; - case WirePortDataType.FLOAT3: - { - if( reset ) - { - m_previewInternalVec3 = Vector3.zero; - } - else - { - int count = Mathf.Min( data.Length, 3 ); - for( int i = 0; i < count; i++ ) - { - m_previewInternalVec3[ i ] = Convert.ToSingle( data[ i ] ); - } - if( count < 3 ) - { - for( int i = count; i < 3; i++ ) - { - m_previewInternalVec3[ i ] = 0; - } - } - } - - } - break; - case WirePortDataType.FLOAT4: - { - if( reset ) - { - m_previewInternalVec4 = Vector4.zero; - } - else - { - int count = Mathf.Min( data.Length, 4 ); - for( int i = 0; i < count; i++ ) - { - m_previewInternalVec4[ i ] = Convert.ToSingle( data[ i ] ); - } - if( count < 4 ) - { - for( int i = count; i < 4; i++ ) - { - m_previewInternalVec4[ i ] = 0; - } - } - } - } - break; - case WirePortDataType.COLOR: - { - if( reset ) - { - m_previewInternalColor = Color.black; - } - else - { - int count = Mathf.Min( data.Length, 4 ); - for( int i = 0; i < count; i++ ) - { - m_previewInternalColor[ i ] = Convert.ToSingle( data[ i ] ); - } - if( count < 4 ) - { - for( int i = count; i < 4; i++ ) - { - m_previewInternalColor[ i ] = 0; - } - } - } - } - break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - { - if( reset ) - { - m_previewInternalMatrix4x4 = Matrix4x4.identity; - } - else - { - int count = Mathf.Min( data.Length, 16 ); - int overallIdx = 0; - for( int i = 0; i < 4; i++ ) - { - for( int j = 0; j < 4; j++ ) - { - if( overallIdx < count ) - { - m_previewInternalMatrix4x4[ i, j ] = Convert.ToSingle( data[ overallIdx ] ); - } - else - { - m_previewInternalMatrix4x4[ i, j ] = ( ( i == j ) ? 1 : 0 ); - } - overallIdx++; - } - } - } - } - break; - } - } - catch( Exception e ) - { - if( DebugConsoleWindow.DeveloperMode ) - Debug.LogException( e ); - } - } - - void UpdateInternalDataFromVariables( bool forceDecimal = false ) - { - switch( m_dataType ) - { - case WirePortDataType.OBJECT:break; - case WirePortDataType.FLOAT: - { - if( forceDecimal && m_previewInternalFloat == (int)m_previewInternalFloat ) - m_internalData = m_previewInternalFloat.ToString("0.0##############"); // to make sure integer values like 0 or 1 are generated as 0.0 and 1.0 - else - m_internalData = m_previewInternalFloat.ToString(); - m_internalDataWrapper = string.Empty; - } - break; - case WirePortDataType.INT: - { - m_internalData = m_previewInternalInt.ToString(); - m_internalDataWrapper = string.Empty; - } - break; - case WirePortDataType.FLOAT2: - { - m_internalData = m_previewInternalVec2.x.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalVec2.y.ToString(); - m_internalDataWrapper = "float2( {0} )"; - } - break; - case WirePortDataType.FLOAT3: - { - m_internalData = m_previewInternalVec3.x.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalVec3.y.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalVec3.z.ToString(); - m_internalDataWrapper = "float3( {0} )"; - } - break; - case WirePortDataType.FLOAT4: - { - m_internalData = m_previewInternalVec4.x.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalVec4.y.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalVec4.z.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalVec4.w.ToString(); - - m_internalDataWrapper = "float4( {0} )"; - } - break; - case WirePortDataType.COLOR: - { - m_internalData = m_previewInternalColor.r.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalColor.g.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalColor.b.ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalColor.a.ToString(); - - m_internalDataWrapper = "float4( {0} )"; - } - break; - case WirePortDataType.FLOAT3x3: - { - m_internalData = m_previewInternalMatrix4x4[ 0, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 0, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 0, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalMatrix4x4[ 1, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 1, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 1, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalMatrix4x4[ 2, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 2, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 2, 2 ].ToString(); - - m_internalDataWrapper = "float3x3( {0} )"; - - } - break; - case WirePortDataType.FLOAT4x4: - { - m_internalData = m_previewInternalMatrix4x4[ 0, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 0, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 0, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 0, 3 ].ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalMatrix4x4[ 1, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 1, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 1, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 1, 3 ].ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalMatrix4x4[ 2, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 2, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 2, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 2, 3 ].ToString() + IOUtils.VECTOR_SEPARATOR + - m_previewInternalMatrix4x4[ 3, 0 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 3, 1 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 3, 2 ].ToString() + IOUtils.VECTOR_SEPARATOR + m_previewInternalMatrix4x4[ 3, 3 ].ToString(); - - m_internalDataWrapper = "float4x4( {0} )"; - } - break; - } - } - - //This gets the 3x3 matrix inside of the 4x4 - private string Matrix3x3WrappedData() - { - string tempInternal = string.Empty; - - string[] data = String.IsNullOrEmpty( m_internalData ) ? null : m_internalData.Split( IOUtils.VECTOR_SEPARATOR ); - if( data.Length == 16 ) - { - int o = 0; - for( int i = 0; i < 8; i++ ) - { - if( i == 3 || i == 6 ) - o++; - tempInternal += data[ i + o ] + IOUtils.VECTOR_SEPARATOR; - } - - tempInternal += data[ 10 ]; - - return String.Format( m_internalDataWrapper, tempInternal ); - } - else - { - return String.Format( m_internalDataWrapper, m_internalData ); - } - } - - private string SamplerWrappedData( ref MasterNodeDataCollector dataCollector ) - { - m_internalData = "_Sampler" + PortId + UIUtils.GetNode( m_nodeId ).OutputId; - ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph; - if( outsideGraph.SamplingThroughMacros ) - { - if( outsideGraph.IsSRP ) - { - dataCollector.AddToUniforms( m_nodeId, string.Format( Constants.TexDeclarationNoSamplerSRPMacros[ TextureType.Texture2D ], m_internalData )); - } - else - { - dataCollector.AddToUniforms( m_nodeId, string.Format( Constants.TexDeclarationNoSamplerStandardMacros[ TextureType.Texture2D ], m_internalData )); - } - } - else - { - dataCollector.AddToUniforms( m_nodeId, "uniform sampler2D " + m_internalData + ";" ); - } - - return m_internalData; - } - - //TODO: Replace GenerateShaderForOutput(...) calls to this one - // This is a new similar method to GenerateShaderForOutput(...) which always autocasts - public string GeneratePortInstructions( ref MasterNodeDataCollector dataCollector ) - { - InputPort linkPort = ExternalLink; - if( linkPort != null ) - { - return linkPort.GeneratePortInstructions( ref dataCollector ); - } - - string result = string.Empty; - if( m_externalReferences.Count > 0 && !m_locked ) - { - result = UIUtils.GetNode( m_externalReferences[ 0 ].NodeId ).GenerateShaderForOutput( m_externalReferences[ 0 ].PortId, ref dataCollector, false ); - if( m_externalReferences[ 0 ].DataType != m_dataType ) - { - result = UIUtils.CastPortType( ref dataCollector, UIUtils.GetNode( m_nodeId ).CurrentPrecisionType, new NodeCastInfo( m_externalReferences[ 0 ].NodeId, m_externalReferences[ 0 ].PortId ), null, m_externalReferences[ 0 ].DataType, m_dataType, result ); - } - } - else - { - UpdateInternalDataFromVariables( true ); - if( DataType == WirePortDataType.FLOAT3x3 ) - result = Matrix3x3WrappedData(); - else if( DataType == WirePortDataType.SAMPLER2D ) - result = SamplerWrappedData( ref dataCollector ); - else - result = !String.IsNullOrEmpty( m_internalDataWrapper ) ? String.Format( m_internalDataWrapper, m_internalData ) : m_internalData; - } - return result; - } - - public string GenerateShaderForOutput( ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) - { - InputPort linkPort = ExternalLink; - if( linkPort != null ) - { - return linkPort.GenerateShaderForOutput( ref dataCollector, ignoreLocalVar ); - } - - string result = string.Empty; - if( m_externalReferences.Count > 0 && !m_locked ) - { - result = UIUtils.GetNode( m_externalReferences[ 0 ].NodeId ).GenerateShaderForOutput( m_externalReferences[ 0 ].PortId, ref dataCollector, ignoreLocalVar ); - } - else - { - UpdateInternalDataFromVariables( true ); - if( !String.IsNullOrEmpty( m_internalDataWrapper ) ) - { - if( DataType == WirePortDataType.FLOAT3x3 ) - result = Matrix3x3WrappedData(); - else - result = String.Format( m_internalDataWrapper, m_internalData ); - } - else - { - result = m_internalData; - } - } - return result; - } - - public string GenerateShaderForOutput( ref MasterNodeDataCollector dataCollector, WirePortDataType inputPortType, bool ignoreLocalVar, bool autoCast = false ) - { - InputPort linkPort = ExternalLink; - if( linkPort != null ) - { - return linkPort.GenerateShaderForOutput( ref dataCollector, inputPortType, ignoreLocalVar, autoCast ); - } - - string result = string.Empty; - if( m_externalReferences.Count > 0 && !m_locked ) - { - result = UIUtils.GetNode( m_externalReferences[ 0 ].NodeId ).GenerateShaderForOutput( m_externalReferences[ 0 ].PortId, ref dataCollector, ignoreLocalVar ); - if( autoCast && m_externalReferences[ 0 ].DataType != inputPortType ) - { - result = UIUtils.CastPortType( ref dataCollector, UIUtils.GetNode( m_nodeId ).CurrentPrecisionType, new NodeCastInfo( m_externalReferences[ 0 ].NodeId, m_externalReferences[ 0 ].PortId ), null, m_externalReferences[ 0 ].DataType, inputPortType, result ); - } - } - else - { - UpdateInternalDataFromVariables( true ); - if( !String.IsNullOrEmpty( m_internalDataWrapper ) ) - { - if( DataType == WirePortDataType.FLOAT3x3 ) - result = Matrix3x3WrappedData(); - else - result = String.Format( m_internalDataWrapper, m_internalData ); - } - else - { - result = m_internalData; - } - } - - return result; - } - - public OutputPort GetOutputConnection( int connID = 0 ) - { - if( connID < m_externalReferences.Count ) - { - return UIUtils.GetNode( m_externalReferences[ connID ].NodeId ).GetOutputPortByUniqueId( m_externalReferences[ connID ].PortId ); - } - return null; - } - - public ParentNode GetOutputNodeWhichIsNotRelay( int connID = 0 ) - { - if( connID < m_externalReferences.Count ) - { - ParentNode node = UIUtils.GetNode( m_externalReferences[ connID ].NodeId ); - if( node is WireNode || node is RelayNode ) - { - return node.InputPorts[ 0 ].GetOutputNodeWhichIsNotRelay( connID ); - } - - return node; - } - return null; - } - - public ParentNode GetOutputNode( int connID = 0 ) - { - if( connID < m_externalReferences.Count ) - { - return UIUtils.GetNode( m_externalReferences[ connID ].NodeId ); - } - return null; - } - - public bool TypeLocked - { - get { return m_typeLocked; } - } - - public void WriteToString( ref string myString ) - { - if( m_externalReferences.Count != 1 || m_isDummy ) - { - return; - } - - IOUtils.AddTypeToString( ref myString, IOUtils.WireConnectionParam ); - IOUtils.AddFieldValueToString( ref myString, m_nodeId ); - IOUtils.AddFieldValueToString( ref myString, m_portId ); - IOUtils.AddFieldValueToString( ref myString, m_externalReferences[ 0 ].NodeId ); - IOUtils.AddFieldValueToString( ref myString, m_externalReferences[ 0 ].PortId ); - IOUtils.AddLineTerminator( ref myString ); - } - - public void ShowInternalData( Rect rect, UndoParentNode owner, bool useCustomLabel = false, string customLabel = null ) - { - string label = ( useCustomLabel == true && customLabel != null ) ? customLabel : m_internalDataPropertyLabel; - switch( m_dataType ) - { - case WirePortDataType.OBJECT: - { - InternalData = owner.EditorGUITextField( rect, label, InternalData ); - } - break; - case WirePortDataType.FLOAT: - { - FloatInternalData = owner.EditorGUIFloatField( rect, label, FloatInternalData ); - } - break; - case WirePortDataType.FLOAT2: - { - Vector2InternalData = owner.EditorGUIVector2Field( rect, label, Vector2InternalData ); - } - break; - case WirePortDataType.FLOAT3: - { - Vector3InternalData = owner.EditorGUIVector3Field( rect, label, Vector3InternalData ); - } - break; - case WirePortDataType.FLOAT4: - { - Vector4InternalData = owner.EditorGUIVector4Field( rect, label, Vector4InternalData ); - } - break; - case WirePortDataType.FLOAT3x3: - { - Matrix4x4 matrix = Matrix4x4InternalData; - Vector3 currVec3 = Vector3.zero; - for( int i = 0; i < 3; i++ ) - { - Vector4 currVec = matrix.GetRow( i ); - currVec3.Set( currVec.x, currVec.y, currVec.z ); - EditorGUI.BeginChangeCheck(); - currVec3 = owner.EditorGUIVector3Field( rect, label + "[ " + i + " ]", currVec3 ); - rect.y += 2*EditorGUIUtility.singleLineHeight; - if( EditorGUI.EndChangeCheck() ) - { - currVec.Set( currVec3.x, currVec3.y, currVec3.z, currVec.w ); - matrix.SetRow( i, currVec ); - } - } - Matrix4x4InternalData = matrix; - } - break; - case WirePortDataType.FLOAT4x4: - { - Matrix4x4 matrix = Matrix4x4InternalData; - for( int i = 0; i < 4; i++ ) - { - Vector4 currVec = matrix.GetRow( i ); - EditorGUI.BeginChangeCheck(); - currVec = owner.EditorGUIVector4Field( rect, label + "[ " + i + " ]", currVec ); - rect.y += 2*EditorGUIUtility.singleLineHeight; - if( EditorGUI.EndChangeCheck() ) - { - matrix.SetRow( i, currVec ); - } - } - Matrix4x4InternalData = matrix; - } - break; - case WirePortDataType.COLOR: - { - ColorInternalData = owner.EditorGUIColorField( rect, label, ColorInternalData ); - } - break; - case WirePortDataType.INT: - { - IntInternalData = owner.EditorGUIIntField( rect, label, IntInternalData ); - } - break; - } - } - - public void ShowInternalData( UndoParentNode owner, bool useCustomLabel = false, string customLabel = null ) - { - string label = ( useCustomLabel == true && customLabel != null ) ? customLabel : m_internalDataPropertyLabel; - switch( m_dataType ) - { - case WirePortDataType.OBJECT: - case WirePortDataType.FLOAT: - { - FloatInternalData = owner.EditorGUILayoutFloatField( label, FloatInternalData ); - } - break; - case WirePortDataType.FLOAT2: - { - Vector2InternalData = owner.EditorGUILayoutVector2Field( label, Vector2InternalData ); - } - break; - case WirePortDataType.FLOAT3: - { - Vector3InternalData = owner.EditorGUILayoutVector3Field( label, Vector3InternalData ); - } - break; - case WirePortDataType.FLOAT4: - { - Vector4InternalData = owner.EditorGUILayoutVector4Field( label, Vector4InternalData ); - } - break; - case WirePortDataType.FLOAT3x3: - { - Matrix4x4 matrix = Matrix4x4InternalData; - Vector3 currVec3 = Vector3.zero; - for( int i = 0; i < 3; i++ ) - { - Vector4 currVec = matrix.GetRow( i ); - currVec3.Set( currVec.x, currVec.y, currVec.z ); - EditorGUI.BeginChangeCheck(); - currVec3 = owner.EditorGUILayoutVector3Field( label + "[ " + i + " ]", currVec3 ); - if( EditorGUI.EndChangeCheck() ) - { - currVec.Set( currVec3.x, currVec3.y, currVec3.z, currVec.w ); - matrix.SetRow( i, currVec ); - } - } - Matrix4x4InternalData = matrix; - } - break; - case WirePortDataType.FLOAT4x4: - { - Matrix4x4 matrix = Matrix4x4InternalData; - for( int i = 0; i < 4; i++ ) - { - Vector4 currVec = matrix.GetRow( i ); - EditorGUI.BeginChangeCheck(); - currVec = owner.EditorGUILayoutVector4Field( label + "[ " + i + " ]", currVec ); - if( EditorGUI.EndChangeCheck() ) - { - matrix.SetRow( i, currVec ); - } - } - Matrix4x4InternalData = matrix; - } - break; - case WirePortDataType.COLOR: - { - ColorInternalData = owner.EditorGUILayoutColorField( label, ColorInternalData ); - } - break; - case WirePortDataType.INT: - { - IntInternalData = owner.EditorGUILayoutIntField( label, IntInternalData ); - } - break; - } - } - public bool IsZeroInternalData - { - get - { - switch( m_dataType ) - { - - case WirePortDataType.FLOAT: return Mathf.Abs(m_previewInternalFloat) < 0.001f; - case WirePortDataType.UINT: - case WirePortDataType.INT: return m_previewInternalInt == 0; - case WirePortDataType.FLOAT2: - return (Mathf.Abs( m_previewInternalVec2.x ) < 0.001f && - Mathf.Abs( m_previewInternalVec2.y ) < 0.001f); - case WirePortDataType.FLOAT3: - return (Mathf.Abs( m_previewInternalVec3.x ) < 0.001f && - Mathf.Abs( m_previewInternalVec3.y ) < 0.001f && - Mathf.Abs( m_previewInternalVec3.z ) < 0.001f ); - case WirePortDataType.FLOAT4: - return (Mathf.Abs( m_previewInternalVec4.x ) < 0.001f && - Mathf.Abs( m_previewInternalVec4.y ) < 0.001f && - Mathf.Abs( m_previewInternalVec4.z ) < 0.001f && - Mathf.Abs( m_previewInternalVec4.w ) < 0.001f ); - case WirePortDataType.COLOR: - return (Mathf.Abs( m_previewInternalColor.r ) < 0.001f && - Mathf.Abs( m_previewInternalColor.g ) < 0.001f && - Mathf.Abs( m_previewInternalColor.b ) < 0.001f && - Mathf.Abs( m_previewInternalColor.a ) < 0.001f); - - } - return true; - } - } - public float FloatInternalData - { - set { m_previewInternalFloat = value; m_internalDataUpdated = false; } - get { return m_previewInternalFloat; } - } - - public int IntInternalData - { - set { m_previewInternalInt = value; m_internalDataUpdated = false; } - get { return m_previewInternalInt; } - } - - public Vector2 Vector2InternalData - { - set { m_previewInternalVec2 = value; m_internalDataUpdated = false; } - get { return m_previewInternalVec2; } - } - - public Vector3 Vector3InternalData - { - set { m_previewInternalVec3 = value; m_internalDataUpdated = false; } - get { return m_previewInternalVec3; } - } - - public Vector4 Vector4InternalData - { - set { m_previewInternalVec4 = value; m_internalDataUpdated = false; } - get { return m_previewInternalVec4; } - } - - public Color ColorInternalData - { - set { m_previewInternalColor = value; m_internalDataUpdated = false; } - get { return m_previewInternalColor; } - } - - public Matrix4x4 Matrix4x4InternalData - { - set { m_previewInternalMatrix4x4 = value; m_internalDataUpdated = false; } - get { return m_previewInternalMatrix4x4; } - } - - public string SamplerInternalData - { - set { InternalData = UIUtils.RemoveInvalidCharacters( value ); m_internalDataUpdated = false; } - get { return m_internalData; } - } - - public override void ForceClearConnection() - { - UIUtils.DeleteConnection( true, m_nodeId, m_portId, false, true ); - } - - private bool m_internalDataUpdated = false; - private string m_displayInternalData = string.Empty; - public string DisplayInternalData - { - get - { - if( !m_internalDataUpdated ) - { - UpdateInternalDataFromVariables(); - m_internalDataUpdated = true; - m_displayInternalData = "( "+ m_internalData + " )"; - } - return m_displayInternalData; - } - } - - public string InternalData - { - get - { - UpdateInternalDataFromVariables(); - return m_internalData; - } - set - { - m_internalData = value; - UpdateVariablesFromInternalData(); - } - } - - public string WrappedInternalData - { - get - { - UpdateInternalDataFromVariables(); - return string.IsNullOrEmpty( m_internalDataWrapper ) ? m_internalData : String.Format( m_internalDataWrapper, m_internalData ); - } - } - - public override WirePortDataType DataType - { - get { return base.DataType; } - // must be set to update internal data. do not delete - set - { - m_internalDataUpdated = false; - switch( DataType ) - { - case WirePortDataType.FLOAT: - { - switch( value ) - { - case WirePortDataType.FLOAT2: m_previewInternalVec2.x = m_previewInternalFloat; break; - case WirePortDataType.FLOAT3: m_previewInternalVec3.x = m_previewInternalFloat; break; - case WirePortDataType.FLOAT4: m_previewInternalVec4.x = m_previewInternalFloat; break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: m_previewInternalMatrix4x4[ 0 ] = m_previewInternalFloat; break; - case WirePortDataType.COLOR: m_previewInternalColor.r = m_previewInternalFloat; break; - case WirePortDataType.INT: m_previewInternalInt = (int)m_previewInternalFloat; break; - } - } - break; - case WirePortDataType.FLOAT2: - { - switch( value ) - { - case WirePortDataType.FLOAT: m_previewInternalFloat = m_previewInternalVec2.x; break; - case WirePortDataType.FLOAT3: - { - m_previewInternalVec3.x = m_previewInternalVec2.x; - m_previewInternalVec3.y = m_previewInternalVec2.y; - } - break; - case WirePortDataType.FLOAT4: - { - m_previewInternalVec4.x = m_previewInternalVec2.x; - m_previewInternalVec4.y = m_previewInternalVec2.y; - } - break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - { - m_previewInternalMatrix4x4[ 0 ] = m_previewInternalVec2.x; - m_previewInternalMatrix4x4[ 1 ] = m_previewInternalVec2.y; - } - break; - case WirePortDataType.COLOR: - { - m_previewInternalColor.r = m_previewInternalVec2.x; - m_previewInternalColor.g = m_previewInternalVec2.y; - } - break; - case WirePortDataType.INT: m_previewInternalInt = (int)m_previewInternalVec2.x; break; - } - } - break; - case WirePortDataType.FLOAT3: - { - switch( value ) - { - case WirePortDataType.FLOAT: m_previewInternalFloat = m_previewInternalVec3.x; break; - case WirePortDataType.FLOAT2: - { - m_previewInternalVec2.x = m_previewInternalVec3.x; - m_previewInternalVec2.y = m_previewInternalVec3.y; - } - break; - case WirePortDataType.FLOAT4: - { - m_previewInternalVec4.x = m_previewInternalVec3.x; - m_previewInternalVec4.y = m_previewInternalVec3.y; - m_previewInternalVec4.z = m_previewInternalVec3.z; - } - break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - { - m_previewInternalMatrix4x4[ 0 ] = m_previewInternalVec3.x; - m_previewInternalMatrix4x4[ 1 ] = m_previewInternalVec3.y; - m_previewInternalMatrix4x4[ 2 ] = m_previewInternalVec3.z; - } - break; - case WirePortDataType.COLOR: - { - m_previewInternalColor.r = m_previewInternalVec3.x; - m_previewInternalColor.g = m_previewInternalVec3.y; - m_previewInternalColor.b = m_previewInternalVec3.z; - } - break; - case WirePortDataType.INT: m_previewInternalInt = (int)m_previewInternalVec3.x; break; - } - } - break; - case WirePortDataType.FLOAT4: - { - switch( value ) - { - case WirePortDataType.FLOAT: m_previewInternalFloat = m_previewInternalVec4.x; break; - case WirePortDataType.FLOAT2: - { - m_previewInternalVec2.x = m_previewInternalVec4.x; - m_previewInternalVec2.y = m_previewInternalVec4.y; - } - break; - case WirePortDataType.FLOAT3: - { - m_previewInternalVec3.x = m_previewInternalVec4.x; - m_previewInternalVec3.y = m_previewInternalVec4.y; - m_previewInternalVec3.z = m_previewInternalVec4.z; - } - break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - { - m_previewInternalMatrix4x4[ 0 ] = m_previewInternalVec4.x; - m_previewInternalMatrix4x4[ 1 ] = m_previewInternalVec4.y; - m_previewInternalMatrix4x4[ 2 ] = m_previewInternalVec4.z; - m_previewInternalMatrix4x4[ 3 ] = m_previewInternalVec4.w; - } - break; - case WirePortDataType.COLOR: - { - m_previewInternalColor.r = m_previewInternalVec4.x; - m_previewInternalColor.g = m_previewInternalVec4.y; - m_previewInternalColor.b = m_previewInternalVec4.z; - m_previewInternalColor.a = m_previewInternalVec4.w; - } - break; - case WirePortDataType.INT: m_previewInternalInt = (int)m_previewInternalVec4.x; break; - } - } - break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - { - switch( value ) - { - case WirePortDataType.FLOAT: m_previewInternalFloat = m_previewInternalMatrix4x4[ 0 ]; break; - case WirePortDataType.FLOAT2: - { - m_previewInternalVec2.x = m_previewInternalMatrix4x4[ 0 ]; - m_previewInternalVec2.y = m_previewInternalMatrix4x4[ 1 ]; - } - break; - case WirePortDataType.FLOAT3: - { - m_previewInternalVec3.x = m_previewInternalMatrix4x4[ 0 ]; - m_previewInternalVec3.y = m_previewInternalMatrix4x4[ 1 ]; - m_previewInternalVec3.z = m_previewInternalMatrix4x4[ 2 ]; - } - break; - case WirePortDataType.FLOAT4: - { - m_previewInternalVec4.x = m_previewInternalMatrix4x4[ 0 ]; - m_previewInternalVec4.y = m_previewInternalMatrix4x4[ 1 ]; - m_previewInternalVec4.z = m_previewInternalMatrix4x4[ 2 ]; - m_previewInternalVec4.w = m_previewInternalMatrix4x4[ 3 ]; - } - break; - case WirePortDataType.COLOR: - { - m_previewInternalColor.r = m_previewInternalMatrix4x4[ 0 ]; - m_previewInternalColor.g = m_previewInternalMatrix4x4[ 1 ]; - m_previewInternalColor.b = m_previewInternalMatrix4x4[ 2 ]; - m_previewInternalColor.a = m_previewInternalMatrix4x4[ 3 ]; - } - break; - case WirePortDataType.INT: m_previewInternalInt = (int)m_previewInternalMatrix4x4[ 0 ]; break; - } - } - break; - case WirePortDataType.COLOR: - { - switch( value ) - { - case WirePortDataType.FLOAT: m_previewInternalFloat = m_previewInternalColor.r; break; - case WirePortDataType.FLOAT2: - { - m_previewInternalVec2.x = m_previewInternalColor.r; - m_previewInternalVec2.y = m_previewInternalColor.g; - } - break; - case WirePortDataType.FLOAT3: - { - m_previewInternalVec3.x = m_previewInternalColor.r; - m_previewInternalVec3.y = m_previewInternalColor.g; - m_previewInternalVec3.z = m_previewInternalColor.b; - } - break; - case WirePortDataType.FLOAT4: - { - m_previewInternalVec4.x = m_previewInternalColor.r; - m_previewInternalVec4.y = m_previewInternalColor.g; - m_previewInternalVec4.z = m_previewInternalColor.b; - m_previewInternalVec4.w = m_previewInternalColor.a; - } - break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - { - m_previewInternalMatrix4x4[ 0 ] = m_previewInternalColor.r; - m_previewInternalMatrix4x4[ 1 ] = m_previewInternalColor.g; - m_previewInternalMatrix4x4[ 2 ] = m_previewInternalColor.b; - m_previewInternalMatrix4x4[ 3 ] = m_previewInternalColor.a; - } - break; - case WirePortDataType.INT: m_previewInternalInt = (int)m_previewInternalColor.r; break; - } - } - break; - case WirePortDataType.INT: - { - switch( value ) - { - case WirePortDataType.FLOAT: m_previewInternalFloat = m_previewInternalInt; break; - case WirePortDataType.FLOAT2: m_previewInternalVec2.x = m_previewInternalInt; break; - case WirePortDataType.FLOAT3: m_previewInternalVec3.x = m_previewInternalInt; break; - case WirePortDataType.FLOAT4: m_previewInternalVec4.x = m_previewInternalInt; break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: m_previewInternalMatrix4x4[ 0 ] = m_previewInternalInt; break; - case WirePortDataType.COLOR: m_previewInternalColor.r = m_previewInternalInt; break; - } - } - break; - } - base.DataType = value; - } - } - - public string DataName - { - get { return m_dataName; } - set { m_dataName = value; } - } - - public bool IsFragment { get { return m_category == MasterNodePortCategory.Fragment || m_category == MasterNodePortCategory.Debug; } } - public MasterNodePortCategory Category - { - set { m_category = value; } - get { return m_category; } - } - - private int CachedIntPropertyID - { - get - { - if( m_cachedIntShaderID == -1 ) - m_cachedIntShaderID = Shader.PropertyToID( "_InputInt" ); - return m_cachedIntShaderID; - } - } - - private int CachedFloatPropertyID - { - get - { - if( m_cachedFloatShaderID == -1 ) - m_cachedFloatShaderID = Shader.PropertyToID( "_InputFloat" ); - return m_cachedFloatShaderID; - } - } - - private int CachedVectorPropertyID - { - get - { - if( m_cachedVectorShaderID == -1 ) - m_cachedVectorShaderID = Shader.PropertyToID( "_InputVector" ); - return m_cachedVectorShaderID; - } - } - - private int CachedColorPropertyID - { - get - { - if( m_cachedColorShaderID == -1 ) - m_cachedColorShaderID = Shader.PropertyToID( "_InputColor" ); - return m_cachedColorShaderID; - } - } - - private int CachedDefaultTexPropertyID - { - get - { - if( m_cachedDefaultTexShaderID == -1 ) - m_cachedDefaultTexShaderID = Shader.PropertyToID( "_Default" ); - return m_cachedDefaultTexShaderID; - } - } - - private int Cached2DPropertyID - { - get - { - if( m_cached2DShaderID == -1 ) - m_cached2DShaderID = Shader.PropertyToID( "_Input2D" ); - return m_cached2DShaderID; - } - } - - public int CachedPropertyId - { - get { return m_cachedPropertyId; } - } - - public bool InputNodeHasPreview( ParentGraph container ) - { - ParentNode node = null; - if( m_externalReferences.Count > 0) - { - node = container.GetNode( m_externalReferences[ 0 ].NodeId ); - } - - if( node != null ) - return node.HasPreviewShader; - - return false; - } - - public void PreparePortCacheID() - { - if( m_propertyNameInt != PortId || string.IsNullOrEmpty( m_propertyName ) ) - { - m_propertyNameInt = PortId; - m_propertyName = "_" + Convert.ToChar( PortId + 65 ); - m_cachedPropertyId = Shader.PropertyToID( m_propertyName ); - } - - if( m_cachedPropertyId == -1 ) - m_cachedPropertyId = Shader.PropertyToID( m_propertyName ); - } - - public void SetPreviewInputTexture( ParentGraph container ) - { - PreparePortCacheID(); - - if( (object)m_node == null ) - { - m_node = container.GetNode( NodeId ); - //m_node = UIUtils.GetNode( NodeId ); - } - - if( ExternalReferences.Count>0 ) - { - m_node.PreviewMaterial.SetTexture( m_cachedPropertyId, container.GetNode( ExternalReferences[ 0 ].NodeId ).GetOutputPortByUniqueId( ExternalReferences[ 0 ].PortId ).OutputPreviewTexture ); - } - //m_node.PreviewMaterial.SetTexture( m_cachedPropertyId, GetOutputConnection( 0 ).OutputPreviewTexture ); - } - - private void SetPortPreviewShader( Shader portShader ) - { - if( m_inputPreviewShader != portShader ) - { - m_inputPreviewShader = portShader; - InputPreviewMaterial.shader = portShader; - } - } - - public void SetPreviewInputValue( ParentGraph container ) - { - if( m_inputPreviewTexture == null ) - { - m_inputPreviewTexture = new RenderTexture( 128, 128, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear ); - m_inputPreviewTexture.wrapMode = TextureWrapMode.Repeat; - } - - switch( DataType ) - { - case WirePortDataType.INT: - { - SetPortPreviewShader( UIUtils.IntShader ); - - InputPreviewMaterial.SetInt( CachedIntPropertyID, m_previewInternalInt ); - } - break; - case WirePortDataType.FLOAT: - { - SetPortPreviewShader( UIUtils.FloatShader ); - //Debug.Log( m_previewInternalFloat ); - InputPreviewMaterial.SetFloat( CachedFloatPropertyID, m_previewInternalFloat ); - } - break; - case WirePortDataType.FLOAT2: - { - SetPortPreviewShader( UIUtils.Vector2Shader ); - - Vector2 v2 = m_previewInternalVec2;// Vector2InternalData; - InputPreviewMaterial.SetVector( CachedVectorPropertyID, new Vector4( v2.x, v2.y, 0, 0 ) ); - } - break; - case WirePortDataType.FLOAT3: - { - SetPortPreviewShader( UIUtils.Vector3Shader ); - - Vector3 v3 = m_previewInternalVec3;// Vector3InternalData; - InputPreviewMaterial.SetVector( CachedVectorPropertyID, new Vector4( v3.x, v3.y, v3.z, 0 ) ); - } - break; - case WirePortDataType.FLOAT4: - { - SetPortPreviewShader( UIUtils.Vector4Shader ); - - InputPreviewMaterial.SetVector( CachedVectorPropertyID, m_previewInternalVec4 ); - } - break; - case WirePortDataType.COLOR: - { - SetPortPreviewShader( UIUtils.ColorShader ); - - InputPreviewMaterial.SetColor( CachedColorPropertyID, m_previewInternalColor ); - } - break; - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - { - SetPortPreviewShader( UIUtils.FloatShader ); - - InputPreviewMaterial.SetFloat( CachedFloatPropertyID, 1 ); - } - break; - case WirePortDataType.SAMPLER2D: - { - SetPortPreviewShader( UIUtils.Texture2DShader ); - } - break; - default: - { - SetPortPreviewShader( UIUtils.FloatShader ); - - InputPreviewMaterial.SetFloat( CachedFloatPropertyID, 0 ); - } - break; - } - - RenderTexture temp = RenderTexture.active; - RenderTexture.active = m_inputPreviewTexture; - Graphics.Blit( null, m_inputPreviewTexture, InputPreviewMaterial ); - RenderTexture.active = temp; - - PreparePortCacheID(); - - //if( (object)m_node == null ) - // m_node = UIUtils.GetNode( NodeId ); - - if( (object)m_node == null ) - { - m_node = container.GetNode( NodeId ); - //m_node = UIUtils.GetNode( NodeId ); - } - //m_propertyName = "_A"; - //Debug.Log( m_propertyName ); - m_node.PreviewMaterial.SetTexture( m_propertyName, m_inputPreviewTexture ); - } - - public override void ChangePortId( int newPortId ) - { - if( IsConnected ) - { - int count = ExternalReferences.Count; - for( int connIdx = 0; connIdx < count; connIdx++ ) - { - int nodeId = ExternalReferences[ connIdx ].NodeId; - int portId = ExternalReferences[ connIdx ].PortId; - ParentNode node = UIUtils.GetNode( nodeId ); - if( node != null ) - { - OutputPort outputPort = node.GetOutputPortByUniqueId( portId ); - int outputCount = outputPort.ExternalReferences.Count; - for( int j = 0; j < outputCount; j++ ) - { - if( outputPort.ExternalReferences[ j ].NodeId == NodeId && - outputPort.ExternalReferences[ j ].PortId == PortId ) - { - outputPort.ExternalReferences[ j ].PortId = newPortId; - } - } - } - } - } - - PortId = newPortId; - } - - public override void Destroy() - { - base.Destroy(); - //if ( m_inputPreview != null ) - // UnityEngine.ScriptableObject.DestroyImmediate( m_inputPreview ); - //m_inputPreview = null; - - if( m_inputPreviewTexture != null ) - UnityEngine.ScriptableObject.DestroyImmediate( m_inputPreviewTexture ); - m_inputPreviewTexture = null; - - if( m_inputPreviewMaterial != null ) - UnityEngine.ScriptableObject.DestroyImmediate( m_inputPreviewMaterial ); - m_inputPreviewMaterial = null; - - m_inputPreviewShader = null; - - m_node = null; - } - - public Shader InputPreviewShader - { - get - { - if( m_inputPreviewShader == null ) - m_inputPreviewShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "d9ca47581ac157145bff6f72ac5dd73e" ) ); //ranged float - - if( m_inputPreviewShader == null ) - m_inputPreviewShader = Shader.Find( "Unlit/Colored Transparent" ); - - return m_inputPreviewShader; - } - set - { - m_inputPreviewShader = value; - } - } - - public Material InputPreviewMaterial - { - get - { - if( m_inputPreviewMaterial == null ) - m_inputPreviewMaterial = new Material( InputPreviewShader ); - - return m_inputPreviewMaterial; - } - //set - //{ - // m_inputPreviewMaterial = value; - //} - } - - public override string Name - { - get { return m_name; } - set - { - m_name = value; - m_internalDataPropertyLabel = ( string.IsNullOrEmpty( value ) || value.Equals( Constants.EmptyPortValue ) ) ? InputDefaultNameStr : value; - m_dirtyLabelSize = true; - } - } - - public string InternalDataName - { - get { return m_internalDataPropertyLabel; } - set { m_internalDataPropertyLabel = value; } - } - - public bool AutoDrawInternalData - { - get { return m_drawInternalData; } - set { m_drawInternalData = value; } - } - - public PortGenType GenType - { - get { return m_genType; } - set { m_genType = value; } - } - - public bool ValidInternalData - { - get - { - switch( m_dataType ) - { - case WirePortDataType.FLOAT: - case WirePortDataType.FLOAT2: - case WirePortDataType.FLOAT3: - case WirePortDataType.FLOAT4: - case WirePortDataType.FLOAT3x3: - case WirePortDataType.FLOAT4x4: - case WirePortDataType.COLOR: - case WirePortDataType.INT: return true; - case WirePortDataType.OBJECT: - case WirePortDataType.SAMPLER1D: - case WirePortDataType.SAMPLER2D: - case WirePortDataType.SAMPLER3D: - case WirePortDataType.SAMPLERCUBE: - default: return false; - } - } - } - - //public RenderTexture InputPreviewTexture - //{ - // get - // { - // if( IsConnected ) - // return GetOutputConnection( 0 ).OutputPreviewTexture; - // else - // return m_inputPreviewTexture; - // } - //} - - public RenderTexture InputPreviewTexture( ParentGraph container ) - { - if( IsConnected ) - { - if( m_externalReferences.Count > 0 ) - return container.GetNode( m_externalReferences[ 0 ].NodeId ).GetOutputPortByUniqueId( m_externalReferences[ 0 ].PortId ).OutputPreviewTexture; - else - return null; - } - else - { - return m_inputPreviewTexture; - } - } - - public string ExternalLinkId - { - get { return m_externalLinkId; } - set - { - m_externalLinkId = value; - if( string.IsNullOrEmpty( value ) ) - { - m_externalNodeLink = -1; - m_externalPortLink = -1; - } - } - } - - public bool HasOwnOrLinkConnection { get { return IsConnected || HasConnectedExternalLink; } } - public bool HasExternalLink { get { return m_externalNodeLink > -1 && m_externalPortLink > -1; } } - - public bool HasConnectedExternalLink - { - get - { - InputPort link = ExternalLink; - return ( link != null && link.IsConnected ); - } - } - - public InputPort ExternalLink - { - get - { - if( HasExternalLink ) - { - ParentNode linkNode = UIUtils.GetNode( m_externalNodeLink ); - if( linkNode != null ) - { - return linkNode.GetInputPortByUniqueId( m_externalPortLink ); - } - } - return null; - } - } - - public ParentNode ExternalLinkNode - { - get - { - if( HasExternalLink ) - { - return UIUtils.GetNode( m_externalNodeLink ); - } - return null; - } - } - } -} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/InputPort.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/InputPort.cs.meta deleted file mode 100644 index 421ab30b..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/InputPort.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: e8199169aaf7f404492a0f2353fb52f9 -timeCreated: 1481126960 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/OutputPort.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/OutputPort.cs deleted file mode 100644 index 3050aa85..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/OutputPort.cs +++ /dev/null @@ -1,306 +0,0 @@ -// Amplify Shader Editor - Visual Shader Editing Tool -// Copyright (c) Amplify Creations, Lda <info@amplify.pt> - -using UnityEditor; -using UnityEngine; - -namespace AmplifyShaderEditor -{ - [System.Serializable] - public sealed class OutputPort : WirePort - { - public delegate void OnNewPreviewRTCreated(); - public OnNewPreviewRTCreated OnNewPreviewRTCreatedEvent; - - [SerializeField] - private bool m_connectedToMasterNode; - - [SerializeField] - private bool[] m_isLocalValue = { false, false}; - - [SerializeField] - private string[] m_localOutputValue = { string.Empty,string.Empty}; - - //[SerializeField] - //private int m_isLocalWithPortType = 0; - - private RenderTexture m_outputPreview = null; - private Material m_outputMaskMaterial = null; - - private int m_indexPreviewOffset = 0; - - public OutputPort( ParentNode owner, int nodeId, int portId, WirePortDataType dataType, string name ) : base( nodeId, portId, dataType, name ) - { - LabelSize = Vector2.zero; - OnNewPreviewRTCreatedEvent += owner.SetPreviewDirtyFromOutputs; - } - - public string ErrorValue - { - get - { - string value = string.Empty; - switch( m_dataType ) - { - default: - case WirePortDataType.OBJECT: - case WirePortDataType.INT: - case WirePortDataType.FLOAT: value = "(0)"; break; - case WirePortDataType.FLOAT2: value = "half2(0,0)"; break; - case WirePortDataType.FLOAT3: value = "half3(0,0,0)"; break; - case WirePortDataType.COLOR: - case WirePortDataType.FLOAT4: value = "half4(0,0,0,0)"; break; - case WirePortDataType.FLOAT3x3: value = "half3x3(0,0,0,0,0,0,0,0,0)"; break; - case WirePortDataType.FLOAT4x4: value = "half4x4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)"; break; - } - return value; - } - } - - public bool ConnectedToMasterNode - { - get { return m_connectedToMasterNode; } - set { m_connectedToMasterNode = value; } - } - - public override void FullDeleteConnections() - { - UIUtils.DeleteConnection( false, m_nodeId, m_portId, true, true ); - } - - public bool HasConnectedNode - { - get - { - int count = m_externalReferences.Count; - for( int i = 0; i < count; i++ ) - { - if( UIUtils.GetNode( m_externalReferences[ i ].NodeId ).IsConnected ) - return true; - } - return false; - } - } - public InputPort GetInputConnection( int connID = 0 ) - { - if( connID < m_externalReferences.Count ) - { - return UIUtils.GetNode( m_externalReferences[ connID ].NodeId ).GetInputPortByUniqueId( m_externalReferences[ connID ].PortId ); - } - return null; - } - - public ParentNode GetInputNode( int connID = 0 ) - { - if( connID < m_externalReferences.Count ) - { - return UIUtils.GetNode( m_externalReferences[ connID ].NodeId ); - } - return null; - } - - public override void NotifyExternalRefencesOnChange() - { - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - ParentNode node = UIUtils.GetNode( m_externalReferences[ i ].NodeId ); - if( node ) - { - node.CheckSpherePreview(); - InputPort port = node.GetInputPortByUniqueId( m_externalReferences[ i ].PortId ); - port.UpdateInfoOnExternalConn( m_nodeId, m_portId, m_dataType ); - node.OnConnectedOutputNodeChanges( m_externalReferences[ i ].PortId, m_nodeId, m_portId, m_name, m_dataType ); - } - } - } - - public void ChangeTypeWithRestrictions( WirePortDataType newType, int restrictions ) - { - if( m_dataType != newType ) - { - DataType = newType; - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - ParentNode inNode = UIUtils.GetNode( m_externalReferences[ i ].NodeId ); - InputPort inputPort = inNode.GetInputPortByUniqueId( m_externalReferences[ i ].PortId ); - - bool valid = false; - if( restrictions == 0 ) - { - valid = true; - } - else - { - valid = ( restrictions & (int)inputPort.DataType ) != 0; - } - - if( valid ) - { - inNode.CheckSpherePreview(); - inputPort.UpdateInfoOnExternalConn( m_nodeId, m_portId, m_dataType ); - inNode.OnConnectedOutputNodeChanges( m_externalReferences[ i ].PortId, m_nodeId, m_portId, m_name, m_dataType ); - } - else - { - InvalidateConnection( m_externalReferences[ i ].NodeId, m_externalReferences[ i ].PortId ); - inputPort.InvalidateConnection( NodeId, PortId ); - i--; - } - } - } - } - - public override void ChangePortId( int newPortId ) - { - if( IsConnected ) - { - int count = ExternalReferences.Count; - for( int connIdx = 0; connIdx < count; connIdx++ ) - { - int nodeId = ExternalReferences[ connIdx ].NodeId; - int portId = ExternalReferences[ connIdx ].PortId; - ParentNode node = UIUtils.GetNode( nodeId ); - if( node != null ) - { - InputPort inputPort = node.GetInputPortByUniqueId( portId ); - int inputCount = inputPort.ExternalReferences.Count; - for( int j = 0; j < inputCount; j++ ) - { - if( inputPort.ExternalReferences[ j ].NodeId == NodeId && - inputPort.ExternalReferences[ j ].PortId == PortId ) - { - inputPort.ExternalReferences[ j ].PortId = newPortId; - } - } - } - } - } - - PortId = newPortId; - } - - public string ConfigOutputLocalValue( PrecisionType precisionType, string value, string customName, MasterNodePortCategory category ) - { - int idx = UIUtils.PortCategorytoAttayIdx( category ); - ParentGraph currentGraph = UIUtils.GetNode( NodeId ).ContainerGraph; - string autoGraphId = currentGraph.GraphId > 0 ? "_g" + currentGraph.GraphId : string.Empty; - m_localOutputValue[idx] = string.IsNullOrEmpty( customName ) ? ( "temp_output_" + m_nodeId + "_" + PortId + autoGraphId ) : customName; - m_isLocalValue[idx] = true; - //m_isLocalWithPortType |= (int)category; - return string.Format( Constants.LocalValueDecWithoutIdent, UIUtils.PrecisionWirePortToCgType( precisionType, DataType ), m_localOutputValue[idx], value ); - } - - public void SetLocalValue( string value, MasterNodePortCategory category ) - { - int idx = UIUtils.PortCategorytoAttayIdx( category ); - m_isLocalValue[idx] = true; - m_localOutputValue[ idx ] = value; - //m_isLocalWithPortType |= (int)category; - } - - public void ResetLocalValue() - { - for( int i = 0; i < m_localOutputValue.Length; i++ ) - { - m_localOutputValue[ i ] = string.Empty; - m_isLocalValue[i] = false; - } - //m_isLocalWithPortType = 0; - } - - public void ResetLocalValueIfNot( MasterNodePortCategory category ) - { - int idx = UIUtils.PortCategorytoAttayIdx( category ); - for( int i = 0; i < m_localOutputValue.Length; i++ ) - { - if( i != idx ) - { - m_localOutputValue[ i ] = string.Empty; - m_isLocalValue[ i ] = false; - } - } - } - - public void ResetLocalValueOnCategory( MasterNodePortCategory category ) - { - int idx = UIUtils.PortCategorytoAttayIdx( category ); - m_localOutputValue[ idx ] = string.Empty; - m_isLocalValue[ idx ] = false; - } - - public bool IsLocalOnCategory( MasterNodePortCategory category ) - { - int idx = UIUtils.PortCategorytoAttayIdx( category ); - return m_isLocalValue[ idx ]; - //return ( m_isLocalWithPortType & (int)category ) != 0; ; - } - - public override void ForceClearConnection() - { - UIUtils.DeleteConnection( false, m_nodeId, m_portId, false, true ); - } - - public bool IsLocalValue( MasterNodePortCategory category ) - { - int idx = UIUtils.PortCategorytoAttayIdx( category ); - return m_isLocalValue[ idx ]; - } - - public string LocalValue(MasterNodePortCategory category) - { - int idx = UIUtils.PortCategorytoAttayIdx( category ); - return m_localOutputValue[idx]; - } - - public RenderTexture OutputPreviewTexture - { - get - { - if( m_outputPreview == null ) - { - m_outputPreview = new RenderTexture( 128, 128, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear ); - m_outputPreview.wrapMode = TextureWrapMode.Repeat; - if( OnNewPreviewRTCreatedEvent != null ) - OnNewPreviewRTCreatedEvent(); - } - - return m_outputPreview; - } - set { m_outputPreview = value; } - } - - public int IndexPreviewOffset - { - get { return m_indexPreviewOffset; } - set { m_indexPreviewOffset = value; } - } - - public override void Destroy() - { - base.Destroy(); - if( m_outputPreview != null ) - UnityEngine.ScriptableObject.DestroyImmediate( m_outputPreview ); - m_outputPreview = null; - - if( m_outputMaskMaterial != null ) - UnityEngine.ScriptableObject.DestroyImmediate( m_outputMaskMaterial ); - m_outputMaskMaterial = null; - - OnNewPreviewRTCreatedEvent = null; - } - - public Material MaskingMaterial - { - get - { - if( m_outputMaskMaterial == null ) - { - //m_outputMaskMaterial = new Material( AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "9c34f18ebe2be3e48b201b748c73dec0" ) ) ); - m_outputMaskMaterial = new Material( UIUtils.MaskingShader ); - } - return m_outputMaskMaterial; - } - //set { m_outputMaskMaterial = value; } - } - } -} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/OutputPort.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/OutputPort.cs.meta deleted file mode 100644 index 9825de10..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/OutputPort.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 82722ce1ba0df314490a9362e503727c -timeCreated: 1481126957 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireBezierReference.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireBezierReference.cs deleted file mode 100644 index 6753ff02..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireBezierReference.cs +++ /dev/null @@ -1,58 +0,0 @@ -using UnityEngine; - -namespace AmplifyShaderEditor -{ - [System.Serializable] - public class WireBezierReference - { - private Rect m_boundingBox; - private int m_inNodeId; - private int m_inPortId; - private int m_outNodeId; - private int m_outPortId; - - public WireBezierReference() - { - m_boundingBox = new Rect(); - m_inNodeId = -1; - m_inPortId = -1; - m_outNodeId = -1; - m_outPortId = -1; - } - - public WireBezierReference( ref Rect area, int inNodeId, int inPortId, int outNodeId, int outPortId ) - { - UpdateInfo( ref area, inNodeId, inPortId, outNodeId, outPortId ); - } - - public void UpdateInfo( ref Rect area, int inNodeId, int inPortId, int outNodeId, int outPortId ) - { - m_boundingBox = area; - m_inNodeId = inNodeId; - m_inPortId = inPortId; - m_outNodeId = outNodeId; - m_outPortId = outPortId; - } - - public bool Contains( Vector2 position ) - { - return m_boundingBox.Contains( position ); - } - - public void DebugDraw() - { - GUI.Label( m_boundingBox, string.Empty, UIUtils.GetCustomStyle( CustomStyle.MainCanvasTitle )); - } - - public override string ToString() - { - return string.Format( "In node: {0} port: {1} -> Out node: {2} port: {3}", m_inNodeId, m_inPortId, m_outNodeId, m_outPortId ); - } - - public Rect BoundingBox { get { return m_boundingBox; } } - public int InNodeId { get { return m_inNodeId; } } - public int InPortId { get { return m_inPortId; } } - public int OutNodeId { get { return m_outNodeId; } } - public int OutPortId { get { return m_outPortId; } } - } -} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireBezierReference.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireBezierReference.cs.meta deleted file mode 100644 index df5640c3..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireBezierReference.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 499682ec40529f44480d58747ad7ab44 -timeCreated: 1481126955 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WirePort.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WirePort.cs deleted file mode 100644 index 326bc871..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WirePort.cs +++ /dev/null @@ -1,597 +0,0 @@ -// 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 enum WirePortDataType - { - OBJECT = 1 << 1, - FLOAT = 1 << 2, - FLOAT2 = 1 << 3, - FLOAT3 = 1 << 4, - FLOAT4 = 1 << 5, - FLOAT3x3 = 1 << 6, - FLOAT4x4 = 1 << 7, - COLOR = 1 << 8, - INT = 1 << 9, - SAMPLER1D = 1 << 10, - SAMPLER2D = 1 << 11, - SAMPLER3D = 1 << 12, - SAMPLERCUBE = 1 << 13, - UINT = 1 << 14 - } - - public enum VariableQualifiers - { - In = 0, - Out, - InOut - } - - public struct WirePortDataTypeComparer : IEqualityComparer<WirePortDataType> - { - public bool Equals( WirePortDataType x, WirePortDataType y ) - { - return x == y; - } - - public int GetHashCode( WirePortDataType obj ) - { - // you need to do some thinking here, - return (int)obj; - } - } - - [System.Serializable] - public class WirePort - { - private const double PortClickTime = 0.2; - - private double m_lastTimeClicked = -1; - - private Vector2 m_labelSize; - private Vector2 m_unscaledLabelSize; - protected bool m_dirtyLabelSize = true; - - private bool m_isEditable = false; - private bool m_editingName = false; - - protected int m_portRestrictions = 0; - - private bool m_repeatButtonState = false; - - [SerializeField] - private Rect m_position; - - [SerializeField] - private Rect m_labelPosition; - - [SerializeField] - protected int m_nodeId = -1; - - [SerializeField] - protected int m_portId = -1; - - [SerializeField] - protected int m_orderId = -1; - - [SerializeField] - protected WirePortDataType m_dataType = WirePortDataType.FLOAT; - - [SerializeField] - protected string m_name; - - [SerializeField] - protected List<WireReference> m_externalReferences; - - [SerializeField] - protected bool m_locked = false; - - [SerializeField] - protected bool m_visible = true; - - [SerializeField] - protected bool m_isDummy = false; - - [SerializeField] - protected bool m_hasCustomColor = false; - - [SerializeField] - protected Color m_customColor = Color.white; - - [SerializeField] - protected Rect m_activePortArea; - - public WirePort( int nodeId, int portId, WirePortDataType dataType, string name, int orderId = -1 ) - { - m_nodeId = nodeId; - m_portId = portId; - m_orderId = orderId; - m_dataType = dataType; - m_name = name; - m_externalReferences = new List<WireReference>(); - } - - public virtual void Destroy() - { - m_externalReferences.Clear(); - m_externalReferences = null; - } - - public void AddPortForbiddenTypes( params WirePortDataType[] forbiddenTypes ) - { - if( forbiddenTypes != null ) - { - if( m_portRestrictions == 0 ) - { - //if no previous restrictions are detected then we set up the bit array so we can set is bit correctly - m_portRestrictions = int.MaxValue; - } - - for( int i = 0; i < forbiddenTypes.Length; i++ ) - { - m_portRestrictions = m_portRestrictions & ( int.MaxValue - (int)forbiddenTypes[ i ] ); - } - } - } - - public void AddPortRestrictions( params WirePortDataType[] validTypes ) - { - if( validTypes != null ) - { - for( int i = 0; i < validTypes.Length; i++ ) - { - m_portRestrictions = m_portRestrictions | (int)validTypes[ i ]; - } - } - } - - public void CreatePortRestrictions( params WirePortDataType[] validTypes ) - { - m_portRestrictions = 0; - if( validTypes != null ) - { - for( int i = 0; i < validTypes.Length; i++ ) - { - m_portRestrictions = m_portRestrictions | (int)validTypes[ i ]; - } - } - } - - public virtual bool CheckValidType( WirePortDataType dataType ) - { - if( m_portRestrictions == 0 ) - { - return true; - } - - return ( m_portRestrictions & (int)dataType ) != 0; - } - - public bool ConnectTo( WireReference port ) - { - if( m_locked ) - return false; - - if( m_externalReferences.Contains( port ) ) - return false; - - m_externalReferences.Add( port ); - return true; - } - - public bool ConnectTo( int nodeId, int portId ) - { - if( m_locked ) - return false; - - - foreach( WireReference reference in m_externalReferences ) - { - if( reference.NodeId == nodeId && reference.PortId == portId ) - { - return false; - } - } - m_externalReferences.Add( new WireReference( nodeId, portId, m_dataType, false ) ); - return true; - } - - public bool ConnectTo( int nodeId, int portId, WirePortDataType dataType, bool typeLocked ) - { - if( m_locked ) - return false; - - foreach( WireReference reference in m_externalReferences ) - { - if( reference.NodeId == nodeId && reference.PortId == portId ) - { - return false; - } - } - m_externalReferences.Add( new WireReference( nodeId, portId, dataType, typeLocked ) ); - return true; - } - - public void DummyAdd( int nodeId, int portId ) - { - m_externalReferences.Insert( 0, new WireReference( nodeId, portId, WirePortDataType.OBJECT, false ) ); - m_isDummy = true; - } - - public void DummyRemove() - { - m_externalReferences.RemoveAt( 0 ); - m_isDummy = false; - } - - public void DummyClear() - { - m_externalReferences.Clear(); - m_isDummy = false; - } - - public WireReference GetConnection( int connID = 0 ) - { - if( connID < m_externalReferences.Count ) - return m_externalReferences[ connID ]; - return null; - } - - public void ChangeProperties( string newName, WirePortDataType newType, bool invalidateConnections ) - { - Name = newName; - ChangeType( newType, invalidateConnections ); - //if ( m_dataType != newType ) - //{ - // DataType = newType; - // if ( invalidateConnections ) - // { - // InvalidateAllConnections(); - // } - // else - // { - // NotifyExternalRefencesOnChange(); - // } - //} - } - - public void ChangeType( WirePortDataType newType, bool invalidateConnections ) - { - if( m_dataType != newType ) - { - //ParentNode node = UIUtils.GetNode( m_nodeId ); - //if ( node ) - //{ - // Undo.RegisterCompleteObjectUndo( node.ContainerGraph.ParentWindow, Constants.UndoChangeTypeNodesId ); - // Undo.RecordObject( node, Constants.UndoChangeTypeNodesId ); - //} - DataType = newType; - if( invalidateConnections ) - { - InvalidateAllConnections(); - } - else - { - NotifyExternalRefencesOnChange(); - } - } - } - - public virtual void ChangePortId( int newId ) { } - public virtual void NotifyExternalRefencesOnChange() { } - - public void UpdateInfoOnExternalConn( int nodeId, int portId, WirePortDataType type ) - { - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - if( m_externalReferences[ i ].NodeId == nodeId && m_externalReferences[ i ].PortId == portId ) - { - m_externalReferences[ i ].DataType = type; - } - } - } - - public void InvalidateConnection( int nodeId, int portId ) - { - int id = -1; - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - if( m_externalReferences[ i ].NodeId == nodeId && m_externalReferences[ i ].PortId == portId ) - { - id = i; - break; - } - } - - if( id > -1 ) - m_externalReferences.RemoveAt( id ); - } - - public void RemoveInvalidConnections() - { - Debug.Log( "Cleaning invalid connections" ); - List<WireReference> validConnections = new List<WireReference>(); - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - if( m_externalReferences[ i ].IsValid ) - { - validConnections.Add( m_externalReferences[ i ] ); - } - else - { - Debug.Log( "Detected invalid connection on node " + m_nodeId + " port " + m_portId ); - } - } - m_externalReferences.Clear(); - m_externalReferences = validConnections; - } - - public void InvalidateAllConnections() - { - m_externalReferences.Clear(); - } - - public virtual void FullDeleteConnections() { } - - public bool IsConnectedTo( int nodeId, int portId ) - { - if( m_locked ) - return false; - - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - if( m_externalReferences[ i ].NodeId == nodeId && m_externalReferences[ i ].PortId == portId ) - return true; - } - return false; - } - - public WirePortDataType ConnectionType( int id = 0 ) - { - return ( id < m_externalReferences.Count ) ? m_externalReferences[ id ].DataType : DataType; - } - - public bool CheckMatchConnectionType( int id = 0 ) - { - if( id < m_externalReferences.Count ) - return m_externalReferences[ id ].DataType == DataType; - - return false; - } - - public void MatchPortToConnection( int id = 0 ) - { - if( id < m_externalReferences.Count ) - { - DataType = m_externalReferences[ id ].DataType; - } - } - - public void ResetWireReferenceStatus() - { - for( int i = 0; i < m_externalReferences.Count; i++ ) - { - m_externalReferences[ i ].WireStatus = WireStatus.Default; - } - } - - public bool InsideActiveArea( Vector2 pos ) - { - return m_activePortArea.Contains( pos ); - } - - public void Click() - { - if( m_isEditable ) - { - if( ( EditorApplication.timeSinceStartup - m_lastTimeClicked ) < PortClickTime ) - { - m_editingName = true; - GUI.FocusControl( "port" + m_nodeId.ToString() + m_portId.ToString() ); - TextEditor te = (TextEditor)GUIUtility.GetStateObject( typeof( TextEditor ), GUIUtility.keyboardControl ); - if( te != null ) - { - te.SelectAll(); - } - } - - m_lastTimeClicked = EditorApplication.timeSinceStartup; - } - } - - public bool Draw( Rect textPos, GUIStyle style ) - { - bool changeFlag = false; - if( m_isEditable && m_editingName ) - { - textPos.width = m_labelSize.x; - EditorGUI.BeginChangeCheck(); - GUI.SetNextControlName( "port" + m_nodeId.ToString() + m_portId.ToString() ); - m_name = GUI.TextField( textPos, m_name, style ); - if( EditorGUI.EndChangeCheck() ) - { - m_dirtyLabelSize = true; - changeFlag = true; - } - - if( Event.current.isKey && ( Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter ) ) - { - m_editingName = false; - GUIUtility.keyboardControl = 0; - } - } - else - { - GUI.Label( textPos, m_name, style ); - } - //GUI.Label( textPos, string.Empty ); - return changeFlag; - } - - public void ResetEditing() - { - m_editingName = false; - } - - public virtual void ForceClearConnection() { } - - public bool IsConnected - { - get { return ( m_externalReferences.Count > 0 && !m_locked ); } - } - - public List<WireReference> ExternalReferences - { - get { return m_externalReferences; } - } - - public int ConnectionCount - { - get { return m_externalReferences.Count; } - } - - public Rect Position - { - get { return m_position; } - set { m_position = value; } - } - - public Rect LabelPosition - { - get { return m_labelPosition; } - set { m_labelPosition = value; } - } - - public int PortId - { - get { return m_portId; } - set { m_portId = value; } - } - - public int OrderId - { - get { return m_orderId; } - set { m_orderId = value; } - } - - - public int NodeId - { - get { return m_nodeId; } - set { m_nodeId = value; } - } - - public virtual WirePortDataType DataType - { - get { return m_dataType; } - set { m_dataType = value; } - } - - public bool Visible - { - get { return m_visible; } - set - { - m_visible = value; - if( !m_visible && IsConnected ) - { - ForceClearConnection(); - } - } - } - - public bool Locked - { - get { return m_locked; } - set - { - //if ( m_locked && IsConnected ) - //{ - // ForceClearConnection(); - //} - m_locked = value; - } - } - - public virtual string Name - { - get { return m_name; } - set { m_name = value; m_dirtyLabelSize = true; } - } - - public bool DirtyLabelSize - { - get { return m_dirtyLabelSize; } - set { m_dirtyLabelSize = value; } - } - - public bool HasCustomColor - { - get { return m_hasCustomColor; } - } - - public Color CustomColor - { - get { return m_customColor; } - set - { - m_hasCustomColor = true; - m_customColor = value; - } - } - - public Rect ActivePortArea - { - get { return m_activePortArea; } - set { m_activePortArea = value; } - } - - public Vector2 LabelSize - { - get { return m_labelSize; } - set { m_labelSize = value; } - } - - public Vector2 UnscaledLabelSize - { - get { return m_unscaledLabelSize; } - set { m_unscaledLabelSize = value; } - } - - public bool IsEditable - { - get { return m_isEditable; } - set { m_isEditable = value; } - } - - public bool Available { get { return m_visible && !m_locked; } } - public override string ToString() - { - string dump = ""; - dump += "Order: " + m_orderId + "\n"; - dump += "Name: " + m_name + "\n"; - dump += " Type: " + m_dataType; - dump += " NodeId : " + m_nodeId; - dump += " PortId : " + m_portId; - dump += "\nConnections:\n"; - foreach( WireReference wirePort in m_externalReferences ) - { - dump += wirePort + "\n"; - } - return dump; - } - - public bool RepeatButtonState - { - get { return m_repeatButtonState; } - set { m_repeatButtonState = value; } - } - public bool IsDummy { get { return m_isDummy; } } - } -} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WirePort.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WirePort.cs.meta deleted file mode 100644 index d70ad881..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WirePort.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 4709687a4844c9545a254c2ddbf3ca63 -timeCreated: 1481126955 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireReference.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireReference.cs deleted file mode 100644 index fb2b3472..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireReference.cs +++ /dev/null @@ -1,126 +0,0 @@ -// Amplify Shader Editor - Visual Shader Editing Tool -// Copyright (c) Amplify Creations, Lda <info@amplify.pt> - -using System; -using UnityEngine; - -namespace AmplifyShaderEditor -{ - public enum WireStatus - { - Default = 0, - Highlighted, - Selected - } - - [Serializable] - public sealed class WireReference - { - private WireStatus m_status = WireStatus.Default; - - - - [SerializeField] - private int m_nodeId = -1; - [SerializeField] - private int m_portId = -1; - [SerializeField] - private WirePortDataType m_dataType = WirePortDataType.FLOAT; - [SerializeField] - private bool m_typeLocked = false; - - - - public WireReference() - { - m_nodeId = -1; - m_portId = -1; - m_dataType = WirePortDataType.FLOAT; - m_typeLocked = false; - m_status = WireStatus.Default; - } - - public WireReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked ) - { - m_portId = portId; - m_nodeId = nodeId; - m_dataType = dataType; - m_typeLocked = typeLocked; - m_status = WireStatus.Default; - } - - public void Invalidate() - { - m_nodeId = -1; - m_portId = -1; - m_typeLocked = false; - m_status = WireStatus.Default; - } - - public void SetReference( int nodeId, int portId, WirePortDataType dataType, bool typeLocked ) - { - m_nodeId = nodeId; - m_portId = portId; - m_dataType = dataType; - m_typeLocked = typeLocked; - } - - public void SetReference( WirePort port ) - { - m_nodeId = port.NodeId; - m_portId = port.PortId; - m_dataType = port.DataType; - } - - public bool IsValid - { - get { return ( m_nodeId != -1 && m_portId != -1 ); } - } - - public int NodeId - { - get { return m_nodeId; } - } - - public int PortId - { - get { return m_portId; } - set { m_portId = value; } - } - - public WirePortDataType DataType - { - get { return m_dataType; } - set { m_dataType = value; } - } - - public bool TypeLocked - { - get { return m_typeLocked; } - } - - public WireStatus WireStatus - { - get { return m_status; } - set { m_status = value; } - } - - public override string ToString() - { - string dump = ""; - dump += "* Wire Reference *\n"; - dump += "NodeId : " + m_nodeId + "\n"; - dump += "PortId : " + m_portId + "\n"; - dump += "DataType " + m_dataType + "\n"; ; - return dump; - } - - public void WriteToString( ref string myString ) - { - IOUtils.AddFieldToString( ref myString, "PortId", m_portId ); - IOUtils.AddFieldToString( ref myString, "NodeID", m_nodeId ); - IOUtils.AddFieldToString( ref myString, "DataType", m_dataType ); - IOUtils.AddFieldToString( ref myString, "TypeLocked", m_typeLocked ); - } - } -} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireReference.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireReference.cs.meta deleted file mode 100644 index dee7f4d9..00000000 --- a/Assets/AmplifyShaderEditor/Plugins/Editor/Wires/WireReference.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 99fb607e60678c44da002d6b694400dc -timeCreated: 1481126957 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: |