void EntitiesView() { world = EditorGUILayout.Popup(world, World.AllWorlds.Select(w => w.Name).ToArray(), GUILayout.Width(250)); verticalSplitViewComponentEditorArea.BeginSplitView(); horizontalSplitViewComponentEntitySplit.BeginSplitView(); componentTypeList.OnGUI(GetExpandingRect()); horizontalSplitViewComponentEntitySplit.Split(); entityList.OnGUI(GetExpandingRect()); horizontalSplitViewComponentEntitySplit.EndSplitView(); verticalSplitViewComponentEditorArea.Split(); scrollPosition = GUILayout.BeginScrollView(scrollPosition, Box); //Not yet full implemented See the comment at the selectionObjectProxy declaration on line 53 //var obj = selectionObjectProxy.Object; var obj = selectedComponentTypeObject; if (obj != null) { foreach (var field in obj.GetType().GetFields()) { StructDrawer.GetType(field, ref obj, field.GetValue(obj), World); } } GUILayout.EndScrollView(); if (Selection.activeObject is EntitySelectionProxy proxy) { selectionEntityProxy = proxy; } GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Component")) { EntityManager em = World.Active.EntityManager; var selection = componentTypeList.GetSelection(); var objectList = componentTypeList.GetRows().Where(a => selection.Contains(a.id)).ToArray(); //TODO: Finish Multi-Component Selection adding and setting //var typeList = new List<ComponentType>(); //foreach (var item in objectList) //{ // var ele = item as ComponentElement; // typeList.Add(ele.Type); //} //var comptypes = new ComponentTypes(typeList.ToArray()); //em.AddComponents(selectionEntityProxy.Entity, comptypes); if (objectList[0] is ComponentElement element) { if (!em.HasComponent(selectionEntityProxy.Entity, element.Type)) { em.AddComponent(selectionEntityProxy.Entity, element.Type); em.SetComponentWithType(selectionEntityProxy.Entity, element.Type, obj); } } } if (GUILayout.Button("Set Component")) { EntityManager em = World.Active.EntityManager; var selection = entityList.GetSelection(); var objectList = entityList.GetRows().Where(a => selection.Contains(a.id)).ToArray(); if (objectList[0] is EntityElement entityElementSelected) { if (!em.HasComponent(selectionEntityProxy.Entity, selectedComponentType)) { em.SetComponentWithType(entityElementSelected.Entity, selectedComponentType, obj); } //See the comments for selectedComponentType an ObjectSelectionChanged function //if(!em.HasComponent(selectionEntityProxy.Entity, selectionObjectProxy.ComponentType)) // em.SetComponentWithType(entityElementSelected.Entity, selectionObjectProxy.ComponentType, obj); else if (objectList[0] is ComponentElement element) { if (element.parent is EntityElement entityElement) { if (!em.HasComponent(selectionEntityProxy.Entity, element.Type)) { em.SetComponentWithType(entityElement.Entity, element.Type, obj); } } } } } if (GUILayout.Button("Remove Component")) { EntityManager em = World.Active.EntityManager; var selection = componentTypeList.GetSelection(); var typeList = componentTypeList.GetRows().Where(a => selection.Contains(a.id)); foreach (var type in typeList) { if (type is ComponentElement entityType) { if (!em.HasComponent(selectionEntityProxy.Entity, entityType.Type)) { em.RemoveComponent(selectionEntityProxy.Entity, entityType.Type); } } } } if (GUILayout.Button("Destroy Entity")) { if (selectionEntityProxy.Exists) { var entityManager = World.EntityManager; entityManager.DestroyEntity(selectionEntityProxy.Entity); } } if (GUILayout.Button("Create Entity With Components")) { EntityManager em = World.EntityManager; var selection = componentTypeList.GetSelection(); var typeList = componentTypeList.GetRows().Where(a => selection.Contains(a.id)); var entity = em.CreateEntity(); foreach (var type in typeList) { if (type is ComponentElement entityType) { if (!em.HasComponent(entity, entityType.Type)) { em.SetComponentWithType(entity, entityType.Type, obj); } } } } GUILayout.EndHorizontal(); verticalSplitViewComponentEditorArea.EndSplitView(); }
public static CustomDrawerAttribute CustomDrawer(StructDrawer visitor) { return(new CustomDrawerAttribute { Visitor = visitor }); }