コード例 #1
0
        /// Build contexts' list and lookup according to collected Component-Types
        private void InitAllContexts()
        {
            var defaultContextName = ContextAttribute.GetName <Default>();

            var comps = CollectAllComponents();

            var contextList = new List <Context>();

            _contextLookup = new Dictionary <string, Context>();

            foreach (var cc in comps)
            {
                var name      = cc.Key;
                var list      = cc.Value;
                var isDefault = name == defaultContextName;

                list.Sort((x, y) => string.CompareOrdinal(x.FullName, y.FullName));

                var c = new Context(list.Count, startCreationIndex, new ContextInfo(name, list.ToArray(), isDefault), GetAERC());

                _contextLookup[name] = c;
                contextList.Add(c);
            }

            _defaultContext = _contextLookup[defaultContextName];
            _contextList    = contextList.ToArray();
        }
コード例 #2
0
        /// Collect all Compoent-Types in current domain
        private static Dictionary <string, List <Type> > CollectAllComponents()
        {
            var defaultContextName = ContextAttribute.GetName <Default>();

            var compType = typeof(IComponent);
            var types    = AppDomain.CurrentDomain.GetAssemblies()
                           .SelectMany(s => s.GetTypes())
                           .Where(p => p.IsClass && p.IsPublic && !p.IsAbstract &&
                                  compType.IsAssignableFrom(p));

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

            comps[defaultContextName] = new List <Type>();

            var attrType = typeof(ContextAttribute);

            foreach (var t in types)
            {
                var attribs = t.GetCustomAttributes(attrType, false);

                if (attribs == null || attribs.Length <= 0)
                {
                    CollectComponent(comps, defaultContextName, t);
                }
                else
                {
                    foreach (var attr in attribs)
                    {
                        CollectComponent(comps, ((ContextAttribute)attr).name, t);
                    }
                }
            }

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