コード例 #1
0
ファイル: Contexts.cs プロジェクト: v-free/Entitas-Lite
        /// Collect all Compoent-Types in current domain
        private static Dictionary <string, List <Type> > CollectAllComponents()
        {
            var compType = typeof(IComponent);
            var types    = AppDomain.CurrentDomain.GetAssemblies()
                           .SelectMany(s => s.GetTypes())
                           .Where(p => p.IsClass && p.IsPublic && !p.IsAbstract &&
                                  compType.IsAssignableFrom(p));

            Dictionary <string, List <Type> > comps = new Dictionary <string, List <Type> >();

            comps[DefaultContext.Name] = new List <Type>();

            var scopeType = typeof(ContextScope);

            foreach (var t in types)
            {
                var scopes = t.GetCustomAttributes(scopeType, false);

                if (scopes == null || scopes.Length <= 0)
                {
                    CollectComponent(comps, DefaultContext.Name, t);
                }
                else
                {
                    foreach (var scope in scopes)
                    {
                        string name = ContextScopeHelper.GetName(scope.GetType());
                        CollectComponent(comps, name, t);
                    }
                }
            }

            return(comps);
        }
コード例 #2
0
ファイル: Contexts.cs プロジェクト: v-free/Entitas-Lite
 public static Context Get <S>() where S : ContextScope
 {
     return(sharedInstance._contextLookup[ContextScopeHelper.GetName <S>()]);
 }
コード例 #3
0
ファイル: Contexts.cs プロジェクト: v-free/Entitas-Lite
 public Context GetContext <S>() where S : ContextScope
 {
     return(_contextLookup[ContextScopeHelper.GetName <S>()]);
 }
コード例 #4
0
ファイル: ContextScope.cs プロジェクト: v-free/Entitas-Lite
 static DefaultContext()
 {
     Name = ContextScopeHelper.GetName <DefaultContext>();
 }