File size: 1,665 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
class ComponentsBank
{
private EntityAI m_EntityParent;
private ref Component m_Components[COMP_TYPE_COUNT];
void ComponentsBank(EntityAI entity_parent)
{
m_EntityParent = entity_parent;
}
Component GetComponent(int comp_type, string extended_class_name="")
{
if ( !Component.IsTypeExist(comp_type) )
{
Component.LogErrorBadCompType(comp_type, "EntityAI.GetComponent(int comp_type)");
return NULL;
}
if ( !IsComponentAlreadyExist(comp_type) )
{
CreateComponent(comp_type, extended_class_name);
}
return m_Components[comp_type];
}
bool DeleteComponent(int comp_type)
{
if ( IsComponentAlreadyExist(comp_type) )
{
m_Components[comp_type] = NULL;
return true;
}
return false;
}
private Component CreateComponent(int comp_type, string extended_class_name="")
{
if ( !Component.IsTypeExist(comp_type) )
{
Component.LogErrorBadCompType(comp_type, "EntityAI->CreateComponent(int comp_type)");
return NULL;
}
if ( IsComponentAlreadyExist(comp_type) )
{
Component.LogWarningAlredyExist(comp_type, "EntityAI->CreateComponent(int comp_type)");
return m_Components[comp_type];
}
string clas_name = extended_class_name;
if ( clas_name == string.Empty )
{
clas_name = Component.GetNameByType(comp_type);
}
Component comp = Component.Cast(clas_name.ToType().Spawn());
comp.SetParentEntityAI(m_EntityParent);
comp.Event_OnAwake();
m_Components[comp_type] = comp;
comp.Event_OnInit();
return comp;
}
bool IsComponentAlreadyExist(int comp_type)
{
if ( m_Components[comp_type] != NULL )
{
return true;
}
return false;
}
} |