Exemple #1
0
        public void RefreshAll()
        {
            if (!m_Caretaker.HasChanges)
            {
                return;
            }

            foreach (var system in m_Registry.FindAllByType <Tiny.UTinySystem>())
            {
                system.Refresh();
            }

            foreach (var type in m_Registry.FindAllByType <Tiny.UTinyType>())
            {
                type.Refresh();
            }

            foreach (var entity in m_Registry.FindAllByType <Tiny.UTinyEntity>())
            {
                foreach (var component in entity.Components)
                {
                    component.Refresh();
                }
            }
        }
            /// <summary>
            /// Returns the module that this enum type belongs to
            /// </summary>
            private static UTinyModule GetEnumModule(IRegistry registry, UTinyType.Reference type)
            {
                // @TODO Optimization/direct lookup... this is really bad
                var modules = registry.FindAllByType <UTinyModule>();

                return(modules.FirstOrDefault(module => module.Enums.Contains(type)));
            }
Exemple #3
0
 private static void AddRequiredModuleDependencies(IRegistry registry, UTinyModule module)
 {
     foreach (UTinyModule mod in registry.FindAllByType <UTinyModule>())
     {
         if (mod.IsRequired)
         {
             module.AddExplicitModuleDependency((UTinyModule.Reference)mod);
         }
     }
 }
        private void CreateComponentTree(bool showNotIncludedModules)
        {
            m_AnimatedTree = new UTinyAnimatedTree(TreeName());
            m_AnimatedTree.OnEscapePressed += CloseWindow;
            m_AnimatedTree.OnStateChanged  += Repaint;

            m_AnimatedTree.OnAnyLeafElementClicked += elem =>
            {
                CloseWindow();
            };

            var project = Registry.FindAllByType <UTinyProject>().FirstOrDefault();

            MainModule      = project.Module.Dereference(Registry);
            IncludedModules = new HashSet <UTinyModule>(project.Module.Dereference(Registry).EnumerateDependencies());

            foreach (var module in Registry.FindAllByType <UTinyModule>().OrderBy(m => (m.Name == "Main" ? "" : m.Name)))
            {
                var included = IncludedModules.Contains(module);

                if (!showNotIncludedModules && !included)
                {
                    continue;
                }

                var allComponentTypes = GetItems(module);
                if (!allComponentTypes.Any())
                {
                    continue;
                }

                var    element = UTinyAnimatedTree.Element.MakeGroup(module.Name == "Main" && null != project ? project.Name : module.Name, MakeTooltip(module), included);
                string warning = null;
                if (!included)
                {
                    var count = module.EnumerateDependencies().Count(m => !IncludedModules.Contains(m));
                    warning =
                        $"This will include the {module.Name} module{(count <= 1 ? "" : $", along with {count - 1} dependencies.")}.";
        /// <summary>
        /// Call this method as necessary to gather persistence changes in the given registry sources.
        /// </summary>
        /// <param name="registry">The registry to test the last changes against.</param>
        /// <param name="clearChanges">Set to false if you want to test the last state against multiple registries. Set to true when testing the last registry.</param>
        /// <returns>A RefreshResult struct. changesDetected will be true if any of the detected changes affect the given registry.</returns>
        public static Changes DetectChanges(IRegistry registry, bool clearChanges = true)
        {
            var result = new Changes
            {
                changesDetected = s_DeletionDetected || s_ChangedAssetPaths.Count > 0 || s_MovedAssetPaths.Count > 0
            };

            if (!result.changesDetected)
            {
                return(result);
            }

            var createdSources = new HashSet <string>();
            var changedSources = new HashSet <string>();
            var deletedSources = new HashSet <string>();
            var movedSources   = new HashSet <string>();

            // gather new modules even when not referenced in the registry
            foreach (var path in s_ChangedAssetPaths)
            {
                if (!path.EndsWith(ModuleFileExtension))
                {
                    continue;
                }

                if (File.Exists(path))
                {
                    changedSources.Add(AssetDatabase.AssetPathToGUID(path));
                }
            }

            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            // capture any deleted assets
            foreach (var obj in registry.FindAllByType <IPersistentObject>().Where(obj => !string.IsNullOrEmpty(obj.PersistenceId)))
            {
                var path  = AssetDatabase.GUIDToAssetPath(obj.PersistenceId);
                var asset = AssetDatabase.LoadMainAssetAtPath(path);

                if (!asset || null == asset)
                {
                    deletedSources.Add(obj.PersistenceId);
                }
            }

            var objects = registry.FindAllByType <IPersistentObject>().ToList();

            foreach (var path in s_ChangedAssetPaths)
            {
                var guid = AssetDatabase.AssetPathToGUID(path);
                if (objects.Any(obj => string.Equals(obj.PersistenceId, guid)))
                {
                    changedSources.Add(guid);
                }
                else
                {
                    createdSources.Add(guid);
                }
            }

            foreach (var path in s_MovedAssetPaths)
            {
                var guid = AssetDatabase.AssetPathToGUID(path);
                movedSources.Add(guid);
            }

            result.createdSources = createdSources;
            result.changedSources = changedSources;
            result.deletedSources = deletedSources;
            result.movedSources   = movedSources;

            if (clearChanges)
            {
                ClearChanges();
            }

            return(result);
        }
        public static IEnumerable <UTinyModule> GetModules(IRegistry registry, UTinyScript.Reference reference)
        {
            var modules = registry.FindAllByType <UTinyModule>();

            return(modules.Where(module => module.Scripts.Contains(reference)));
        }
Exemple #7
0
 /// <summary>
 /// Returns a list of modules that explicitly depend on the given module
 /// </summary>
 public static IEnumerable <UTinyModule> GetExplicitDependantModules(IRegistry registry, Reference module)
 {
     return(registry.FindAllByType <UTinyModule>().Where(m => m.ContainsExplicitModuleDependency(module)).ToList());
 }