Exemplo n.º 1
0
        internal void AddEntries(List <SearchTreeEntry> cache, IEnumerable <UdonNodeDefinition> definitions, int level, bool stripToLastDot = false)
        {
            Texture2D icon = EditorGUIUtility.FindTexture("cs Script Icon");
            Dictionary <string, UdonNodeDefinition> baseNodeDefinition = new Dictionary <string, UdonNodeDefinition>();

            foreach (UdonNodeDefinition nodeDefinition in definitions.OrderBy(s => UdonGraphExtensions.PrettyFullName(s)))
            {
                string   baseIdentifier      = nodeDefinition.fullName;
                string[] splitBaseIdentifier = baseIdentifier.Split(new[] { "__" }, StringSplitOptions.None);
                if (splitBaseIdentifier.Length >= 2)
                {
                    baseIdentifier = $"{splitBaseIdentifier[0]}__{splitBaseIdentifier[1]}";
                }
                if (baseNodeDefinition.ContainsKey(baseIdentifier))
                {
                    continue;
                }
                baseNodeDefinition.Add(baseIdentifier, nodeDefinition);
            }

            // add all subTypes
            foreach (KeyValuePair <string, UdonNodeDefinition> nodeDefinitionsEntry in baseNodeDefinition)
            {
                string nodeName = UdonGraphExtensions.PrettyBaseName(nodeDefinitionsEntry.Key);
                nodeName = nodeName.UppercaseFirst();
                nodeName = nodeName.Replace("_", " ");
                if (stripToLastDot)
                {
                    int lastDotIndex = nodeName.LastIndexOf('.');
                    nodeName = nodeName.Substring(lastDotIndex + 1);
                }

                // don't add Variable or Comment nodes
                if (nodeName.StartsWithCached("Variable") || nodeName.StartsWithCached("Get Var") || nodeName.StartsWithCached("Set Var") || nodeName.StartsWithCached("Comment"))
                {
                    continue;
                }
                if (nodeName.StartsWithCached("Object"))
                {
                    nodeName = $"{nodeDefinitionsEntry.Value.type.Namespace}.{nodeName}";
                }
                cache.Add(new SearchTreeEntry(new GUIContent(nodeName, icon))
                {
                    level = level, userData = nodeDefinitionsEntry.Value
                });
            }
        }
        internal void AddEntries(List <SearchTreeEntry> cache, IEnumerable <UdonNodeDefinition> definitions, int level,
                                 bool stripToLastDot = false)
        {
            Texture2D icon = AssetPreview.GetMiniTypeThumbnail(typeof(GameObject));
            Texture2D iconGetComponents = EditorGUIUtility.FindTexture("d_ViewToolZoom");
            Texture2D iconOther         = new Texture2D(1, 1);

            iconOther.SetPixel(0, 0, new Color(0, 0, 0, 0));
            iconOther.Apply();
            Dictionary <string, UdonNodeDefinition> baseNodeDefinition = new Dictionary <string, UdonNodeDefinition>();

            foreach (UdonNodeDefinition nodeDefinition in definitions.OrderBy(
                         s => UdonGraphExtensions.PrettyFullName(s)))
            {
                string   baseIdentifier      = nodeDefinition.fullName;
                string[] splitBaseIdentifier = baseIdentifier.Split(new[] { "__" }, StringSplitOptions.None);
                if (splitBaseIdentifier.Length >= 2)
                {
                    baseIdentifier = $"{splitBaseIdentifier[0]}__{splitBaseIdentifier[1]}";
                }

                if (baseNodeDefinition.ContainsKey(baseIdentifier))
                {
                    continue;
                }

                baseNodeDefinition.Add(baseIdentifier, nodeDefinition);
            }

            var nodesOfGetComponentType = new List <SearchTreeEntry>();
            var nodesOfOtherType        = new List <SearchTreeEntry>();

            // add all subTypes
            foreach (KeyValuePair <string, UdonNodeDefinition> nodeDefinitionsEntry in baseNodeDefinition)
            {
                string nodeName = UdonGraphExtensions.PrettyBaseName(nodeDefinitionsEntry.Key);
                nodeName = nodeName.UppercaseFirst();
                nodeName = nodeName.Replace("_", " ");
                if (stripToLastDot)
                {
                    int lastDotIndex = nodeName.LastIndexOf('.');
                    nodeName = nodeName.Substring(lastDotIndex + 1);
                }

                // Skip some nodes that should be added in other ways (variables and comments)
                if (nodeName.StartsWithCached("Variable") || nodesToSkip.Contains(nodeDefinitionsEntry.Key))
                {
                    continue;
                }

                if (nodeName.StartsWithCached("Object"))
                {
                    nodeName = $"{nodeDefinitionsEntry.Value.type.Namespace}.{nodeName}";
                }

                if (nodeNamesGetComponentType.Contains(nodeName))
                {
                    nodesOfGetComponentType.Add(new SearchTreeEntry(new GUIContent(nodeName, iconGetComponents))
                    {
                        level = level + 1, userData = nodeDefinitionsEntry.Value
                    });
                    continue;
                }

                // Only put 'Equals' in the 'Other' category if this definition is not an Enum
                if (nodeNamesOtherType.Contains(nodeName) || nodeName == "Equals" && !nodeDefinitionsEntry.Value.type.IsEnum)
                {
                    nodesOfOtherType.Add(new SearchTreeEntry(new GUIContent(nodeName, iconOther))
                    {
                        level = level + 1, userData = nodeDefinitionsEntry.Value
                    });
                    continue;
                }

                cache.Add(new SearchTreeEntry(new GUIContent(nodeName, icon))
                {
                    level = level, userData = nodeDefinitionsEntry.Value
                });
            }

            // add getComponents level
            if (nodesOfGetComponentType.Count > 0)
            {
                cache.Add(new SearchTreeGroupEntry(new GUIContent("GetComponents"), level));
                foreach (var entry in nodesOfGetComponentType)
                {
                    cache.Add(entry);
                }
            }

            // add other level
            if (nodesOfOtherType.Count > 0)
            {
                cache.Add(new SearchTreeGroupEntry(new GUIContent("Other"), level));
                foreach (var entry in nodesOfOtherType)
                {
                    cache.Add(entry);
                }
            }
        }