Ejemplo n.º 1
0
        public void OnComponentAddedToEntity <TComponent>(object sender, Entity entity, TComponent component)
        {
            Type componentType = typeof(TComponent);

            if (_componentWrapperMap.ContainsKey(componentType))
            {
                if (componentsToDelete.ContainsKey(componentType))
                {
                    componentsToDelete.Remove(componentType);
                }
                return;
            }
            Type componentWrapperType = componentType.Assembly.GetTypes()
                                        .Where(field => field.BaseType != null && field.BaseType.GetGenericArguments().Where(genericArgType => genericArgType == componentType).Any())
                                        .FirstOrDefault();

            if (componentWrapperType != null)
            {
#if !UNITY_EDITOR
                if (componentWrapperType.GetCustomAttributes(editorOnlyAttributeType, true).Any())
                {
                    return;
                }
#endif
                ComponentWrapper componentWrapper = (ComponentWrapper)gameObject.AddComponent(componentWrapperType);
                _componentWrapperMap.Add(componentType, componentWrapper);
            }
        }
        public void OnComponentAddedToEntity(object sender, Entity entity, Type componentType)
        {
            if (_componentWrapperMap.ContainsKey(componentType))
            {
                return;
            }
            Type componentWrapperType = componentType.Assembly.GetTypes()
                                        .Where(field => field.BaseType != null && field.BaseType.GetGenericArguments().Where(genericArgType => genericArgType == componentType).Any())
                                        .FirstOrDefault();

            if (componentWrapperType != null)
            {
                ComponentWrapper componentWrapper = (ComponentWrapper)gameObject.AddComponent(componentWrapperType);
                _componentWrapperMap.Add(componentType, componentWrapper);
            }
        }