private void AddComponent(int index) { if (ComponentTypesList.Get(index) == "Add") { return; } // if (entity.runTime) // AddComponentRuntime(index); // else AddComponentEditor(index); }
private void AddComponentEditor(int index) { var type = GetComponentType(ComponentTypesList.Get(index)); if (entity.Components.HasType(type)) { entity.lastIndex = 0; return; } var resolver = NewObject(type); entity.Components.Add(resolver); entity.lastIndex = 0; }
public override void OnInspectorGUI() { //DrawDefaultInspector(); entity = (MonoEntity)target; if (!entity.runTime) { EditorGUI.BeginChangeCheck(); } worldProviderProperty.objectReferenceValue = EditorGUILayout.ObjectField("World provider", worldProviderProperty.objectReferenceValue, typeof(EcsWorldProvider), false); if (entity.runTime) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button(new GUIContent("Kill Entity"), GUILayout.Width(154), GUILayout.Height(24))) { entity.entity.Destroy(); } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.BeginHorizontal(); entity.destroyComponent = EditorGUILayout.Toggle("Destroy MonoBeh", entity.destroyComponent); entity.destroyObject = EditorGUILayout.Toggle("Destroy GO", entity.destroyObject); EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Run Time", entity.runTime ? "✔" : "✘", EditorStyles.largeLabel); EditorGUILayout.LabelField($"ID:{entity.entity.GetInternalId().ToString()}"); EditorGUILayout.EndHorizontal(); EntityGUI.Vertical(GUI.skin.box, () => { if (entity.runTime) { if (!entity.entity.IsAlive()) { EditorGUILayout.LabelField("ENTITY DEAD", EditorStyles.whiteLargeLabel); return; } } EntityGUI.Horizontal(() => { EditorGUILayout.LabelField($"ECS Components [{entity.ComponentsCount.ToString()}]", EditorStyles.boldLabel); if (GUILayout.Button(new GUIContent("Clear", "Remove All Components"))) { RemoveAll(); } }); EntityGUI.Horizontal(() => { EditorGUILayout.LabelField("Add Component"); if (GUILayout.Button(new GUIContent("▼"), GUILayout.Width(21), GUILayout.Height(21))) { flowed = !flowed; } }); if (ComponentTypesList.Count > 1) { entity.lastIndex = EditorGUILayout.Popup(entity.lastIndex, ComponentTypesList.GetAllInArray()); } else { ComponentTypesList.Init(); } if (entity.lastIndex != 0) { AddComponent(entity.lastIndex); } EditorGUILayout.BeginVertical(GUI.skin.box); if (!flowed) { DrawComponents(); } EditorGUILayout.EndVertical(); }); if (entity.runTime) { return; } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(target); serializedObject.ApplyModifiedProperties(); } }
private void Awake() { EntityGUI.Init(); ComponentTypesList.Init(); }