Example #1
0
 private static void Registers()
 {
     if (!msInitialized)
     {
         msInitialized = true;
         GlobalReflectionCache.LoadAssemblies();
         NameToTypeUtility.Initialize();
         var allModules = GlobalReflectionCache.FindTypes <ModuleAttribute>(false);
         if (allModules != null)
         {
             allModules.Sort(EngineComparers.defaultModuleAttributeComparer);
             foreach (var m in allModules)
             {
                 //DebugUtility.Log(LoggerTags.Engine, "Module {0} Loaded.", m);
                 ModuleAttribute attr = m.GetCustomAttribute <ModuleAttribute>(true);
                 if (!string.IsNullOrEmpty(attr.entryPoint))
                 {
                     var entry = m.GetMethod(attr.entryPoint, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
                     if (entry != null)
                     {
                         //DebugUtility.Log(LoggerTags.Engine, "Module {0} Entry.", m);
                         entry.Invoke(null, null);
                     }
                 }
             }
         }
     }
 }
Example #2
0
        public static List <string> CollectTags()
        {
            if (msAllLoggerTags.Count > 0)
            {
                return(msAllLoggerTags);
            }

            var types = GlobalReflectionCache.FindTypes <LoggerTagsAttribute>(true);

            if (types != null)
            {
                foreach (var tagType in types)
                {
                    var allFields = tagType.GetFields();
                    foreach (var fieldInfo in allFields)
                    {
                        if (fieldInfo.IsStatic && fieldInfo.FieldType == typeof(string))
                        {
                            string o = fieldInfo.GetValue(null) as string;
                            if (!string.IsNullOrEmpty(o))
                            {
                                msAllLoggerTags.Union(o);
                            }
                        }
                    }
                }
            }

            // DebugUtility.LogTrace(LoggerTags.Engine, "The Logger tags count is {0}", msAllLoggerTags.Count);
            return(msAllLoggerTags);
        }
Example #3
0
        private static void AutoCollectDebugFilters()
        {
            var loggerTypes = GlobalReflectionCache.FindTypes <LoggerAttribute>(true);

            if (loggerTypes != null && loggerTypes.Count > 0)
            {
                foreach (var type in loggerTypes)
                {
                    string typeFileName = string.Concat(type.Name, ".cs");
                    msBlacklist.Union(typeFileName);
                    msFilterStrings.Union(typeFileName);

                    var loggerAttr = type.GetCustomAttribute <LoggerAttribute>(true);
                    msBlacklist.Union(loggerAttr.loggerBlacklist);
                }
            }
        }
Example #4
0
        public static void Initialize(bool force = false)
        {
            if (mInitialize)
            {
                return;
            }
            mInitialize = true;

            var types = GlobalReflectionCache.FindTypes <NameToTypeAttribute>(false, msAdditionalTypes);

            foreach (var item in types)
            {
                RegisterType(item);
            }
#if UNITY_EDITOR
            DebugUtility.Log(LoggerTags.Engine, "Register types : {0}", types.Select(type => type.Name));
#endif
        }
Example #5
0
        public static void CheckEngineConfig()
        {
            var moduleConfigs = GlobalReflectionCache.FindTypes(typeof(ModuleSettings), false);

            if (moduleConfigs == null)
            {
                return;
            }

            foreach (var config in moduleConfigs)
            {
                var getOrLoadMethod = config.GetMethod("GetOrLoad");
                if (getOrLoadMethod == null)
                {
                    DebugUtility.LogErrorTrace(LoggerTags.Engine, "The {0} must implement the static Method [public static ConfigSettingsType GetOrLoad()]", config.Name);
                    continue;
                }

                string         ModuleSettingsPath = null;
                ModuleSettings settings           = getOrLoadMethod.Invoke(null, null) as ModuleSettings;
                if (settings == null)
                {
                    settings = ScriptableObject.CreateInstance(config) as ModuleSettings;
                    if (settings == null)
                    {
                        DebugUtility.LogErrorTrace(LoggerTags.Engine, "The {0} must implement the static Method [public static From_ModuleSettings GetOrLoad()]", config.Name);
                        continue;
                    }

                    EFilePathType pathType = EFilePathType.EngineGeneratedConfigPath;                    // settings is EditorModuleSettings ? EFilePathType.EditorGeneratedConfigPath : EFilePathType.EngineGeneratedConfigPath;
                    string        path     = FileSystem.Get().GetAssetPathCheck(pathType, settings.GetAssetFileName(), true);
                    AssetDatabase.CreateAsset(settings, path);
                    settings.OnCreated();

                    ModuleSettingsPath = path;
                }
                else
                {
                    EFilePathType pathType = EFilePathType.EngineGeneratedConfigPath;                    // settings is EditorModuleSettings ? EFilePathType.EditorGeneratedConfigPath : EFilePathType.EngineGeneratedConfigPath;
                    ModuleSettingsPath = FileSystem.Get().GetAssetPathCheck(pathType, settings.GetAssetFileName(), true);
                }

                bool reimport = false;
                if (settings != null)
                {
                    UnityEngine.Object[] subAssets  = AssetDatabase.LoadAllAssetsAtPath(ModuleSettingsPath);
                    FieldInfo[]          fieldInfos = config.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                    foreach (var subAsset in subAssets)
                    {
                        bool isValid = false;
                        if (subAsset != null)
                        {
                            if (subAsset.GetType() == settings.GetType())
                            {
                                isValid = true;
                                continue;
                            }

                            foreach (var info in fieldInfos)
                            {
                                Type fieldType = info.FieldType;
                                if (fieldType.IsSubclassOf(typeof(UAssetObject)) && !fieldType.IsAbstract)
                                {
                                    if (subAsset.GetType() == fieldType)
                                    {
                                        isValid = true;

                                        object fieldValue = info.GetValue(settings);
                                        if (fieldValue == null)
                                        {
                                            info.SetValue(settings, subAsset);
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                        if (!isValid)
                        {
                            AssetDatabase.RemoveObjectFromAsset(subAsset);
                            UnityEngine.Object.DestroyImmediate(subAsset, true);
                            reimport = true;
                        }
                    }

                    foreach (var info in fieldInfos)
                    {
                        if (info.IsPublic || info.GetCustomAttribute <SerializableAttribute>() != null)
                        {
                            Type fieldType = info.FieldType;
                            if (fieldType.IsSubclassOf(typeof(UAssetObject)) && !fieldType.IsAbstract)
                            {
                                object fieldValue = info.GetValue(settings);
                                if (fieldValue == null)
                                {
                                    reimport = true;
                                    UAssetObject asset = asset = ScriptableObject.CreateInstance(fieldType) as UAssetObject;
                                    if (asset != null)
                                    {
                                        asset.name = asset.GetType().Name;
                                        info.SetValue(settings, asset);

                                        if (!asset.isSubAsset)
                                        {
                                            EFilePathType pathType = EFilePathType.EngineGeneratedConfigPath;                                             // asset is EditorModuleSettings ? EFilePathType.EditorGeneratedConfigPath : EFilePathType.EngineGeneratedConfigPath;
                                            string        path     = FileSystem.Get().GetAssetPathCheck(pathType, asset.GetAssetFileName(), true);
                                            AssetDatabase.CreateAsset(asset, path);
                                        }
                                        else
                                        {
                                            AssetDatabase.AddObjectToAsset(asset, ModuleSettingsPath);
                                        }
                                        settings.OnCreated();
                                    }
                                }
                            }
                        }
                    }
                }

                if (reimport)
                {
                    AssetDatabase.ImportAsset(ModuleSettingsPath, ImportAssetOptions.Default);
                }
            }
        }