1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using System.Collections.Generic;
namespace AmplifyShaderEditor
{
public class NodeRestrictionsData
{
private bool m_allPorts;
private Dictionary<int, bool> m_portRestrictions;
public NodeRestrictionsData()
{
m_portRestrictions = new Dictionary<int, bool>();
}
public NodeRestrictionsData( int port )
{
m_portRestrictions = new Dictionary<int, bool>();
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<System.Type, NodeRestrictionsData> m_restrictions;
public NodeRestrictions()
{
m_restrictions = new Dictionary<System.Type, NodeRestrictionsData>();
}
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<System.Type, NodeRestrictionsData> pair in m_restrictions )
{
pair.Value.Destroy();
}
m_restrictions.Clear();
m_restrictions = null;
}
}
}
|