From b82da95b5181ac8bbae38efb13e950d5e88a4caa Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Oct 2020 13:08:43 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8amplify=20shader=20editor=E5=88=B0th?= =?UTF-8?q?ird=20party=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/Editor/Nodes/NodeRestrictions.cs | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/NodeRestrictions.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/NodeRestrictions.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/NodeRestrictions.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/NodeRestrictions.cs new file mode 100644 index 00000000..d68d8eb1 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/NodeRestrictions.cs @@ -0,0 +1,119 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda + +using System; +using System.Collections.Generic; +namespace AmplifyShaderEditor +{ + public class NodeRestrictionsData + { + private bool m_allPorts; + private Dictionary m_portRestrictions; + public NodeRestrictionsData() + { + m_portRestrictions = new Dictionary(); + } + + public NodeRestrictionsData( int port ) + { + m_portRestrictions = new Dictionary(); + m_portRestrictions.Add( port, true ); + } + + public void SetAllPortRestiction( bool value ) + { + m_allPorts = value; + } + + public void AddRestriction( int port ) + { + if ( !m_portRestrictions.ContainsKey( port ) ) + m_portRestrictions.Add( port, true ); + else + m_portRestrictions[ port ] = true; + } + + public void RemoveRestriction( int port ) + { + if ( m_portRestrictions.ContainsKey( port ) ) + m_portRestrictions[ port ] = true; + } + + public bool IsPortRestricted( int port ) + { + if ( m_portRestrictions.ContainsKey( port ) ) + return m_portRestrictions[ port ]; + return false; + } + + public void Destroy() + { + m_portRestrictions.Clear(); + m_portRestrictions = null; + } + + public bool AllPortsRestricted + { + get + { + return m_allPorts; + } + } + } + + public class NodeRestrictions + { + private Dictionary m_restrictions; + + public NodeRestrictions() + { + m_restrictions = new Dictionary(); + } + + public void AddTypeRestriction( System.Type type ) + { + if ( !m_restrictions.ContainsKey( type ) ) + m_restrictions.Add( type, new NodeRestrictionsData() ); + + m_restrictions[ type ].SetAllPortRestiction( true ); + + } + + public void AddPortRestriction( System.Type type, int port ) + { + if ( !m_restrictions.ContainsKey( type ) ) + m_restrictions.Add( type, new NodeRestrictionsData( port ) ); + else + { + m_restrictions[ type ].AddRestriction( port ); + } + } + + public bool GetRestiction( System.Type type, int port ) + { + if ( m_restrictions.Count == 0 || type == null ) + return false; + + if ( m_restrictions.ContainsKey( type ) ) + { + if ( m_restrictions[ type ].AllPortsRestricted ) + return true; + + return m_restrictions[ type ].IsPortRestricted( port ); + } + + return false; + } + + public void Destroy() + { + foreach ( KeyValuePair pair in m_restrictions ) + { + pair.Value.Destroy(); + } + + m_restrictions.Clear(); + m_restrictions = null; + } + } +} -- cgit v1.1-26-g67d0