Beispiel #1
0
        private SerializedProperty IterateNode(SerializedProperty property, VariantNode parent, ref int index)
        {
            foreach (var node in parent.Children)
            {
                var prop = property.FindPropertyRelative(node.Name);
                if (prop == null)
                {
                    return(null);
                }

                if (prop.arraySize == 0)
                {
                    continue;
                }

                prop = prop.GetArrayElementAtIndex(0);

                if (node.Index != 0)
                {
                    index = node.Index;
                    return(prop);
                }

                if (node.Children != null)
                {
                    return(IterateNode(prop, node, ref index));
                }
            }
            return(null);
        }
Beispiel #2
0
        private void AddChildren(List <GUIContent> options, VariantNode parent, Stack <VariantNode> path)
        {
            var fields = parent.Type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (var field in fields)
            {
                var fieldType = field.FieldType;
                if (!fieldType.IsArray)
                {
                    continue;
                }

                var node = new VariantNode
                {
                    Type     = fieldType.GetElementType(),
                    Name     = field.Name,
                    FullName = $"{parent.FullName}{field.Name}",
                };
                parent.Children.Add(node);
                path.Push(node);

                // Is a "namespace" struct?
                if (node.Type.IsValueType)
                {
                    node.Children = new List <VariantNode>();
                    node.FullName = $"{node.FullName}.Array.data[0].";
                    AddChildren(options, node, path);
                    node.FullName = null;                     // unused after that
                }
                else
                {
                    node.Index = options.Count;
                    node.Path  = new Stack <VariantNode>(path);

                    var optionName = node.Type.FullName.Replace('.', '/');

                    options.Add(new GUIContent(optionName));
                    Nodes.Add(node);
                }

                path.Pop();
            }
        }