private void DisplayComponents(ObservableEngineAttribute attribute) { GUILayout.Label($"Groups: {string.Join(", ", attribute.GroupNameList)}"); GUILayout.Label($"Components count: {attribute.TypeCount.ToString()}"); var componentNames = new List <string>(); if (attribute.TypeCount >= 1) { componentNames.Add(attribute.T1.Name); } if (attribute.TypeCount >= 2) { componentNames.Add(attribute.T2.Name); } if (attribute.TypeCount >= 3) { componentNames.Add(attribute.T3.Name); } if (attribute.TypeCount >= 4) { componentNames.Add(attribute.T4.Name); } GUILayout.Label($"Components: {string.Join(", ", componentNames)}"); }
private void DisplayEntityCount(ObservableEngineAttribute attribute) { if (Application.isPlaying == false) { GUILayout.Label("Entities count: -"); return; } var queryMethod = typeof(EntitiesDB) .GetMethods() .Where(x => x.Name == "QueryEntities") .First(x => x.GetGenericArguments().Length == attribute.TypeCount); MethodInfo methodRef; Type constructedClass; Type genericClass; switch (attribute.TypeCount) { case 1: methodRef = queryMethod.MakeGenericMethod(attribute.T1); genericClass = typeof(EntityCollection <>); constructedClass = genericClass.MakeGenericType(attribute.T1); break; case 2: methodRef = queryMethod.MakeGenericMethod(attribute.T1, attribute.T2); genericClass = typeof(EntityCollection <,>); constructedClass = genericClass.MakeGenericType(attribute.T1, attribute.T2); break; case 3: methodRef = queryMethod.MakeGenericMethod(attribute.T1, attribute.T2, attribute.T3); genericClass = typeof(EntityCollection <, ,>); constructedClass = genericClass.MakeGenericType(attribute.T1, attribute.T2, attribute.T3); break; case 4: methodRef = queryMethod.MakeGenericMethod(attribute.T1, attribute.T2, attribute.T3, attribute.T4); genericClass = typeof(EntityCollection <, , ,>); constructedClass = genericClass.MakeGenericType(attribute.T1, attribute.T2, attribute.T3, attribute.T4); break; default: throw new ArgumentOutOfRangeException(); } uint totalCount = 0; var entitiesDb = GetEntitiesDbFromEnginesRoot(ObservableEnginesSingletonContext.EnginesRoot); for (var i = 0; i < attribute.GroupNameList.Count; i++) { var result = methodRef.Invoke(entitiesDb, new[] { GetEcsGroupByName(attribute.GroupNameList[i], attribute.EcsGroupsType) }); var count = constructedClass.GetProperty("count")?.GetValue(result); totalCount += (uint)(count ?? 0); } GUILayout.Label($"Entities count: {totalCount.ToString()}"); }