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

View File

@@ -0,0 +1,156 @@
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 );
// }
//}
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -0,0 +1,306 @@
// 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; }
}
}
}

View File

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

View File

@@ -0,0 +1,58 @@
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; } }
}
}

View File

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

View File

@@ -0,0 +1,605 @@
// 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,
SAMPLER2DARRAY = 1 << 15,
SAMPLERSTATE = 1 << 16
}
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 SetFreeForAll()
{
m_portRestrictions = -1;
}
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; } }
public bool NotFreeForAllTypes { get { return m_portRestrictions != -1; } }
}
}

View File

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

View File

@@ -0,0 +1,126 @@
// 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 );
}
}
}

View File

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