Ejemplo n.º 1
0
        private static int Cleanup <T>(T audioRoot, Action <T, HashSet <MonoBehaviour> > traverse) where T : MonoBehaviour
        {
            if (audioRoot == null)
            {
                return(0);
            }


            HashSet <MonoBehaviour> objects = new HashSet <MonoBehaviour>();
            var allNodes = audioRoot.GetComponents <MonoBehaviour>();

            for (int i = 0; i < allNodes.Length; ++i)
            {
                objects.Add(allNodes[i]);
            }

            HashSet <MonoBehaviour> inUse = new HashSet <MonoBehaviour>();

            traverse(audioRoot, inUse);

            int deleted = 0;

            //Delete all objects not in use
            foreach (MonoBehaviour node in objects)
            {
                if (!inUse.Contains(node))
                {
                    deleted += 1;
                    UndoHelper.PureDestroy(node);
                }
            }
            return(deleted);
        }
Ejemplo n.º 2
0
        private static int DeleteUnusedBanks(InAudioBankLink bankRoot)
        {
            #region Standard cleanup
            Action <InAudioBankLink, HashSet <MonoBehaviour> > bankAction = null;
            bankAction = (node, set) =>
            {
                set.Add(node);
                for (int i = 0; i < node.Children.Count; ++i)
                {
                    bankAction(node.Children[i], set);
                }
            };
            int deleteCount = 0;
            HashSet <MonoBehaviour> objects = new HashSet <MonoBehaviour>();
            if (bankRoot != null)
            {
                var allNodes = bankRoot.GetComponents <MonoBehaviour>();
                for (int i = 0; i < allNodes.Length; ++i)
                {
                    objects.Add(allNodes[i]);
                }


                HashSet <MonoBehaviour> inUse = new HashSet <MonoBehaviour>();

                bankAction(bankRoot, inUse);
                List <string> toDelete = new List <string>();
                //Delete all objects not in use
                foreach (InAudioBankLink node in objects)
                {
                    if (!inUse.Contains(node))
                    {
                        ++deleteCount;
                        toDelete.Add(node.ID.ToString());
                        UndoHelper.PureDestroy(node);
                    }
                }
            }

            #endregion

            deleteCount += SystemFolderHelper.DeleteUnusedBanks(bankRoot);


            return(deleteCount);
        }