예제 #1
0
        private void Awake()
        {
            IOC.RegisterFallback <IEditorsMap>(this);

            var type = typeof(IComponentDescriptor);

#if !UNITY_WSA || UNITY_EDITOR
            var types = AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(s => s.GetTypes())
                        .Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract);
#else
            var types = type.GetTypeInfo().Assembly.GetTypes().
                        Where(p => type.IsAssignableFrom(p) && p.GetTypeInfo().IsClass&& !p.IsAbstract);
#endif

            m_componentDescriptors = new Dictionary <Type, IComponentDescriptor>();
            foreach (Type t in types)
            {
                IComponentDescriptor descriptor = (IComponentDescriptor)Activator.CreateInstance(t);
                if (descriptor == null)
                {
                    Debug.LogWarningFormat("Unable to instantiate descriptor of type " + t.FullName);
                    continue;
                }
                if (descriptor.ComponentType == null)
                {
                    Debug.LogWarningFormat("ComponentType is null. Descriptor Type {0}", t.FullName);
                    continue;
                }
                if (m_componentDescriptors.ContainsKey(descriptor.ComponentType))
                {
                    IComponentDescriptor alreadyAddedDescriptor = m_componentDescriptors[descriptor.ComponentType];
                    if (IsBulitIn(alreadyAddedDescriptor.GetType()))
                    {
                        //Overwrite built-in component descriptor
                        m_componentDescriptors[descriptor.ComponentType] = descriptor;
                    }
                    else if (!IsBulitIn(descriptor.GetType()))
                    {
                        Debug.LogWarningFormat("Duplicate descriptor for {0} found. Type name {1}. Using {2} instead", descriptor.ComponentType.FullName, descriptor.GetType().FullName, m_componentDescriptors[descriptor.ComponentType].GetType().FullName);
                    }
                }
                else
                {
                    m_componentDescriptors.Add(descriptor.ComponentType, descriptor);
                }
            }

            LoadMap();
        }
예제 #2
0
        public EditorsMap()
        {
            var type = typeof(IComponentDescriptor);

#if !UNITY_WSA || UNITY_EDITOR
            var types = AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(s => s.GetTypes())
                        .Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract);
#else
            var types = type.GetTypeInfo().Assembly.GetTypes().
                        Where(p => type.IsAssignableFrom(p) && p.GetTypeInfo().IsClass);
#endif

            m_componentDescriptors = new Dictionary <Type, IComponentDescriptor>();
            foreach (Type t in types)
            {
                IComponentDescriptor descriptor = (IComponentDescriptor)Activator.CreateInstance(t);
                if (descriptor == null)
                {
                    Debug.LogWarningFormat("Unable to instantiate selector of type " + t.FullName);
                    continue;
                }
                if (descriptor.ComponentType == null)
                {
                    Debug.LogWarningFormat("ComponentType is null. Selector Type {0}", t.FullName);
                    continue;
                }
                if (m_componentDescriptors.ContainsKey(descriptor.ComponentType))
                {
                    Debug.LogWarningFormat("Duplicate selector for {0} found. Type name {1}. Using {2} instead", descriptor.ComponentType.FullName, descriptor.GetType().FullName, m_componentDescriptors[descriptor.ComponentType].GetType().FullName);
                }
                else
                {
                    m_componentDescriptors.Add(descriptor.ComponentType, descriptor);
                }
            }

            LoadMap();
        }