本文整理汇总了C#中Entity.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.GetComponents方法的具体用法?C# Entity.GetComponents怎么用?C# Entity.GetComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity.GetComponents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: assertHasNotComponentA
void assertHasNotComponentA(Entity e) {
var components = e.GetComponents();
components.Length.should_be(0);
var indices = e.GetComponentIndices();
indices.Length.should_be(0);
e.HasComponentA().should_be_false();
e.HasComponents(_indicesA).should_be_false();
e.HasAnyComponent(_indicesA).should_be_false();
}
示例2: assertHasComponentA
void assertHasComponentA(Entity e, IComponent component = null) {
if (component == null) {
component = Component.A;
}
e.GetComponentA().should_be_same(component);
var components = e.GetComponents();
components.Length.should_be(1);
components.should_contain(component);
var indices = e.GetComponentIndices();
indices.Length.should_be(1);
indices.should_contain(CID.ComponentA);
e.HasComponentA().should_be_true();
e.HasComponents(_indicesA).should_be_true();
e.HasAnyComponent(_indicesA).should_be_true();
}
示例3: DrawComponents
public static void DrawComponents(Pool pool, Entity entity)
{
bool[] unfoldedComponents;
if (!_poolToUnfoldedComponents.TryGetValue(pool, out unfoldedComponents)) {
unfoldedComponents = new bool[pool.totalComponents];
for (int i = 0; i < unfoldedComponents.Length; i++) {
unfoldedComponents[i] = true;
}
_poolToUnfoldedComponents.Add(pool, unfoldedComponents);
}
EntitasEditorLayout.BeginVerticalBox();
{
EntitasEditorLayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel);
if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) {
for (int i = 0; i < unfoldedComponents.Length; i++) {
unfoldedComponents[i] = false;
}
}
if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) {
for (int i = 0; i < unfoldedComponents.Length; i++) {
unfoldedComponents[i] = true;
}
}
}
EntitasEditorLayout.EndHorizontal();
EditorGUILayout.Space();
var componentNames = entity.poolMetaData.componentNames;
var index = EditorGUILayout.Popup("Add Component", -1, componentNames);
if (index >= 0) {
var componentType = entity.poolMetaData.componentTypes[index];
var component = (IComponent)Activator.CreateInstance(componentType);
entity.AddComponent(index, component);
}
EditorGUILayout.Space();
EntitasEditorLayout.BeginHorizontal();
{
_componentNameSearchTerm = EditorGUILayout.TextField("Search", _componentNameSearchTerm);
const string clearButtonControlName = "Clear Button";
GUI.SetNextControlName(clearButtonControlName);
if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) {
_componentNameSearchTerm = string.Empty;
GUI.FocusControl(clearButtonControlName);
}
}
EntitasEditorLayout.EndHorizontal();
EditorGUILayout.Space();
var indices = entity.GetComponentIndices();
var components = entity.GetComponents();
for (int i = 0; i < components.Length; i++) {
DrawComponent(unfoldedComponents, entity, indices[i], components[i]);
}
}
EntitasEditorLayout.EndVertical();
}
示例4: DrawEntity
public static void DrawEntity(Pool pool, Entity entity)
{
var bgColor = GUI.backgroundColor;
GUI.backgroundColor = Color.red;
if (GUILayout.Button("Destroy Entity")) {
pool.DestroyEntity(entity);
}
GUI.backgroundColor = bgColor;
bool[] unfoldedComponents;
if (!_poolToUnfoldedComponents.TryGetValue(pool, out unfoldedComponents)) {
unfoldedComponents = new bool[pool.totalComponents];
for (int i = 0; i < unfoldedComponents.Length; i++) {
unfoldedComponents[i] = true;
}
_poolToUnfoldedComponents.Add(pool, unfoldedComponents);
}
EntitasEditorLayout.BeginVerticalBox();
{
EntitasEditorLayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel);
if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) {
for (int i = 0; i < unfoldedComponents.Length; i++) {
unfoldedComponents[i] = false;
}
}
if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) {
for (int i = 0; i < unfoldedComponents.Length; i++) {
unfoldedComponents[i] = true;
}
}
}
EntitasEditorLayout.EndHorizontal();
EditorGUILayout.Space();
var componentNames = entity.poolMetaData.componentNames;
var index = EditorGUILayout.Popup("Add Component", -1, componentNames);
if (index >= 0) {
var componentType = entity.poolMetaData.componentTypes[index];
var component = (IComponent)Activator.CreateInstance(componentType);
entity.AddComponent(index, component);
}
EditorGUILayout.Space();
_componentNameSearchTerm = EditorGUILayout.TextField("Search", _componentNameSearchTerm);
EditorGUILayout.Space();
var indices = entity.GetComponentIndices();
var components = entity.GetComponents();
for (int i = 0; i < components.Length; i++) {
DrawComponent(unfoldedComponents, entity, indices[i], components[i]);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Retained by (" + entity.retainCount + ")", EditorStyles.boldLabel);
#if !ENTITAS_FAST_AND_UNSAFE
EntitasEditorLayout.BeginVerticalBox();
{
foreach (var owner in entity.owners.ToArray()) {
EntitasEditorLayout.BeginHorizontal();
{
EditorGUILayout.LabelField(owner.ToString());
if (GUILayout.Button("Release", GUILayout.Width(88), GUILayout.Height(14))) {
entity.Release(owner);
}
EntitasEditorLayout.EndHorizontal();
}
}
}
EntitasEditorLayout.EndVertical();
#endif
}
EntitasEditorLayout.EndVertical();
}