Esempio n. 1
0
        public static Type GetNodeType(Type nodeType, Type fallback)
        {
            if (_nodeTypeCache == null)
            {
                _nodeTypeCache = new Dictionary <Type, Type>();
                Type[] nodeTypes = BaseGraphEditorWindow.GetDerivedTypes(typeof(BaseNode));
                foreach (Type tempType in nodeTypes)
                {
                    var attribs = tempType.GetCustomAttributes(typeof(CustomNodeAttribute), false);
                    if (attribs == null || attribs.Length == 0)
                    {
                        continue;
                    }
                    CustomNodeAttribute attrib = attribs[0] as CustomNodeAttribute;
                    _nodeTypeCache.Add(attrib.TargetType, tempType);
                }
            }

            if (_nodeTypeCache.TryGetValue(nodeType, out Type type))
            {
                return(type);
            }
            return(fallback);
        }