Esempio n. 1
0
    /// <summary>
    /// 添加Component
    /// </summary>
    /// <typeparam name="EntityComponentType"></typeparam>
    /// <param name="component"></param>
    /// <returns></returns>
    protected EntityComponentType AddEntityComponent <EntityComponentType, PropertyType>(PropertyType property) where EntityComponentType : EntityComponent <PropertyType>, new()
    {
        EntityComponentType component = m_ComponentsFactory.CreateComponent <EntityComponentType, PropertyType>(property, m_EntityEventDispatcher, m_SendEventToEntity);

        if (component == null)
        {
            return(null);
        }

        int key = component.GetHashCode();

        if (m_ComponentHashCodeSet.Add(key))
        {
            m_ComponentList.Add(component);

            return(component);
        }

        return(null);
    }