Ejemplo n.º 1
0
        public DTGroupNode EnsurePath(string path, bool includesName = false, SerializedProperty forProperty = null)
        {
            DTGroupNode node = this;

            if (!string.IsNullOrEmpty(path))
            {
                var p  = path.Split('/');
                int hi = (includesName) ? p.Length - 1 : p.Length;
                for (int i = 0; i < hi; i++)
                {
                    DTGroupNode sub = node[p[i]] as DTGroupNode;
                    if (sub == null)
                    {
                        if (forProperty != null && i == hi - 1)
                        {
                            sub = new DTGroupNode(p[i], forProperty);
                        }
                        else
                        {
                            sub = new DTGroupNode(p[i]);
                        }
                        node.Add(sub);
                    }
                    node = sub;
                }
            }
            return(node);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// builds node tree and process parsing attributes
        /// </summary>
        public void ReadNodes()
        {
            DTGroupNode._serializedObject = serializedObject;
            SerializedProperty iterator = serializedObject.GetIterator();

            mRootNode.Clear();
            mEnterChildren = true;

            DTGroupNode         baseNode          = mRootNode;
            DTGroupNode         parentNode        = baseNode;
            Stack <string>      propertyPathStack = new Stack <string>();
            Stack <DTGroupNode> baseNodeStack     = new Stack <DTGroupNode>();
            bool resetParent = false;

            while (iterator.NextVisible(mEnterChildren))
            {
                mEnterChildren = false;
                if (iterator.name != "m_Script" && iterator.name != "InspectorFoldout")
                {
                    // handle baseNode resetting (AsGroup etc...)
                    while (propertyPathStack.Count > 0 && !iterator.propertyPath.StartsWith(propertyPathStack.Peek()))
                    {
                        propertyPathStack.Pop();
                        baseNode   = baseNodeStack.Pop();
                        parentNode = baseNode;
                    }


                    var fieldNode = new DTFieldNode(iterator);

                    // get group parsing attributes
                    var groupParseAttribs = iterator.GetAttributes(typeof(IDTGroupParsingAttribute));
                    groupParseAttribs.Sort();
                    // get field parsing attributes
                    var parsingAttributes = iterator.GetAttributes(typeof(IDTFieldParsingAttribute));

                    foreach (IDTGroupParsingAttribute ga in groupParseAttribs)
                    {
                        if (ga is TabAttribute)
                        {
                            var tabA = (TabAttribute)ga;
                            parentNode = baseNode.EnsurePath(tabA.Path, false);

                            if (!string.IsNullOrEmpty(tabA.TabBarName) && !string.IsNullOrEmpty(tabA.TabName))
                            {
                                if (!parentNode[tabA.TabBarName])
                                {
                                    parentNode = (DTGroupNode)parentNode.Add(new DTGroupNode(tabA.TabBarName, null, DTInspectorNode.RenderAsEnum.TabBar));
                                }
                                else
                                {
                                    parentNode = (DTGroupNode)parentNode[tabA.TabBarName];
                                }
                                if (!parentNode[tabA.TabName])
                                {
                                    parentNode = (DTGroupNode)parentNode.Add(new DTGroupNode(tabA.TabName, iterator, DTInspectorNode.RenderAsEnum.Tab));
                                }
                                else
                                {
                                    parentNode = (DTGroupNode)parentNode[tabA.TabName];
                                }
                                if (tabA.Sort != 100)
                                {
                                    parentNode.SortOrder = tabA.Sort;
                                }
                            }
                            else
                            {
                                DTLog.LogWarningFormat("[DevTools] Skipping [Tab] on '{0}' because Path is missing TabBar or Tab!", iterator.propertyPath);
                            }
                        }
                        else if (ga is SectionAttribute)
                        {
                            var sectionA = (SectionAttribute)ga;
                            parentNode = createGroup(baseNode, sectionA.Path, iterator);
                            if (sectionA.Sort != 100)
                            {
                                parentNode.SortOrder = sectionA.Sort;
                            }
                        }
                        else if (ga is AsGroupAttribute)
                        {
                            var asGroupA = (AsGroupAttribute)ga;
                            propertyPathStack.Push(fieldNode.SerializedPropertyPath);
                            baseNodeStack.Push(baseNode);
                            parentNode = createGroup((asGroupA.PathIsAbsolute) ? baseNode : parentNode, (asGroupA.Path == null) ? fieldNode.Name : asGroupA.Path + "/" + fieldNode.Name, iterator);
                            baseNode   = parentNode;
                        }
                        else if (ga is GroupAttribute)
                        {
                            var groupA = (GroupAttribute)ga;
                            parentNode = createGroup(baseNode, groupA.Path, iterator);
                            if (groupA.Sort != 100)
                            {
                                parentNode.SortOrder = groupA.Sort;
                            }
                            resetParent = true;
                        }
                    }

                    foreach (IDTFieldParsingAttribute pa in parsingAttributes)
                    {
                        if (pa is Hide)
                        {
                            fieldNode.Visible        = false;
                            fieldNode.ContentVisible = false;
                            mEnterChildren           = false;
                        }
                        else if (pa is AsGroupAttribute || pa is Inline)
                        {
                            fieldNode.Visible        = false;
                            fieldNode.ContentVisible = false;
                            mEnterChildren           = true;
                        }
                        else if (pa is ArrayExAttribute)
                        {
                            var arrayA = (ArrayExAttribute)pa;
                            fieldNode.ArrayEx = new ReorderableList(serializedObject, iterator, arrayA.Draggable, arrayA.ShowHeader, arrayA.ShowAdd, arrayA.ShowDelete);
                            SetupArrayEx(fieldNode, arrayA);
                        }
                        else if (pa is SortOrderAttribute)
                        {
                            fieldNode.SortOrder = ((SortOrderAttribute)pa).Sort;
                        }
                    }

                    parentNode.Add(fieldNode);
                    if (resetParent)
                    {
                        parentNode  = parentNode.Parent as DTGroupNode;
                        resetParent = false;
                    }
                }
            }
            OnReadNodes();
            Node.Sort();
        }