Exemple #1
0
        private void InitEventAllocator()
        {
            var types = FindAllGameComponentType(typeof(IEvent));

            foreach (var type in types)
            {
                try
                {
                    IEvent instance = (IEvent)Activator.CreateInstance(type);

                    int id = (int)instance.EventType;
                    if (ArrayUtility.SafeGet(_types, id) != null)
                    {
                        var msg = String.Format("component id already exist id {0}, type {1}, type {2}", id, _types[id],
                                                instance.GetType());
                        AssertUtility.Assert(false, msg);
                        _logger.Error(msg);
                    }
                    else
                    {
                        ArrayUtility.SafeSet(ref _types, id, type);
                        ArrayUtility.SafeSet(ref _allocators, id, ObjectAllocators.GetAllocator(type));
                    }

                    _maxId = Mathf.Max(id, _maxId);
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("construct instance of type {0} failed {1}", type, e);
                }
            }
        }
Exemple #2
0
 static ObjectAllocatorHolder()
 {
     if (_allocator == null)
     {
         _allocator = ObjectAllocators.GetAllocator(typeof(T));
     }
 }