Beispiel #1
0
            public static LibraryBookShelf PartialGenerateLibraryBookShelf(Transform _Transform, Transform _Parent, List <Transform> Children)
            {
                if (library.TransformToBookShelves.ContainsKey(_Transform))
                {
                    return(library.TransformToBookShelves[_Transform]);
                }

                var libraryBookShelf = new LibraryBookShelf();

                libraryBookShelf.ShelfName = _Transform.gameObject.name;
                libraryBookShelf.ID        = BookShelfAID;
                BookShelfAID++;
                libraryBookShelf.Shelf  = _Transform.gameObject;
                libraryBookShelf.Parent = _Parent;
                if (_Parent != null)
                {
                    library.TransformToBookShelves[_Parent].InternalContain.Add(libraryBookShelf);
                }

                libraryBookShelf.Contains.AddRange(Children);
                IDToBookShelf[libraryBookShelf.ID] = libraryBookShelf;
                TransformToBookShelf[libraryBookShelf.Shelf.transform] = libraryBookShelf;

                return(libraryBookShelf);
            }
Beispiel #2
0
        public void RecursivePopulate(Transform Object, Transform Parent)
        {
            THISDestroy.Clear();
            Children.Clear();
            TOProcessAdd.Clear();
            TOProcessRemove.Clear();

            if (TransformToBookShelves.ContainsKey(Object))
            {
                if (Object.childCount > 0)
                {
                    for (int i = 0; i < Object.childCount; i++)
                    {
                        Children.Add(Object.GetChild(i));
                    }
                }

                var libraryBookShelf = TransformToBookShelves[Object];


                foreach (var Child in Children)
                {
                    if (libraryBookShelf.Contains.Contains(Child) == false)
                    {
                        TOProcessAdd.Add(Child);
                    }
                }

                bool DestroySelf = false;
                if (libraryBookShelf.Parent != Parent)
                {
                    if (libraryBookShelf.ParentChange())
                    {
                        DestroySelf = true;
                    }
                }

                foreach (var Child in libraryBookShelf.InternalContain)
                {
                    if (Child.Shelf == null)
                    {
                        TOProcessRemove.Add(Child);
                        continue;
                    }
                    if (Children.Contains(Child.Shelf.transform) == false)
                    {
                        TOProcessRemove.Add(Child);
                    }
                }


                foreach (var Child in TOProcessRemove)
                {
                    libraryBookShelf.Contains.RemoveAll(item => item == null);
                    if (Child.Shelf != null)
                    {
                        libraryBookShelf.Contains.Remove(Child.Shelf.transform);
                        if (TransformToBookShelves.ContainsKey(Child.Shelf.transform))
                        {
                            TransformToBookShelves[Child.Shelf.transform].ParentChange();
                        }
                    }
                    else
                    {
                        Child.DestroySelf();
                    }

                    libraryBookShelf.InternalContain.Remove(Child);
                }


                foreach (var Child in TOProcessAdd)
                {
                    libraryBookShelf.Contains.Add(Child);
                    Children.Add(Child);
                }


                foreach (var _Shelf in THISDestroy)
                {
                    _Shelf.DestroySelf();
                }

                if (DestroySelf)
                {
                    libraryBookShelf.DestroySelf();
                }

                foreach (var Child in Children.ToArray())
                {
                    RecursivePopulate(Child, Object);
                }
            }
            else
            {
                if (Object.childCount > 0)
                {
                    for (int i = 0; i < Object.childCount; i++)
                    {
                        Children.Add(Object.GetChild(i));
                    }
                }

                var libraryBookShelf = LibraryBookShelf.PartialGenerateLibraryBookShelf(Object, Parent, Children);
                TransformToBookShelves[Object] = libraryBookShelf;
                if (Parent == null)
                {
                    Roots.Add(libraryBookShelf);
                }

                foreach (var Child in Children.ToArray())
                {
                    RecursivePopulate(Child, Object);
                }
            }
        }