Ejemplo n.º 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);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Add user component.
        /// </summary>
        /// <typeparam name="T">[NameToType]T.</typeparam>
        /// <param name="componentTypeName"></param>
        /// <returns></returns>
        public static T GetUserComponent <T>(this GameObject gameObject, string componentTypeName) where T : Component
        {
            if (string.IsNullOrEmpty(componentTypeName))
            {
                return(null);
            }

            if (NameToTypeUtility.TryGetValue(componentTypeName, out var type))
            {
                return(gameObject.GetComponent(type) as T);
            }

            DebugUtility.LogError(LoggerTags.Engine, "Can't get the component from {0}, please confirm that whether the class '{1}' has declared the attribute '[NameToType]'", gameObject.name, componentTypeName);
            return(null);
        }