示例#1
0
        private void OnEnable()
        {
            this.selectionEntityProxy           = CreateInstance <EntitySelectionProxy>();
            this.selectionEntityProxy.hideFlags = HideFlags.HideAndDontSave;

            //Not yet full implemented. See the comment at the selectionObjectProxy declaration on line 53
            //this.selectionObjectProxy           = CreateInstance<ObjectSelectionProxy>();
            //this.selectionObjectProxy.hideFlags = HideFlags.HideAndDontSave;

            allSystems.Clear();
            IEnumerable <Type> allTypes;

            foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    allTypes = ass.GetTypes();
                }
                catch (ReflectionTypeLoadException e)
                {
                    allTypes = e.Types.Where(t => t != null);
                    Debug.LogWarning("ECSTools failed in loading assembly: " + ass.Location);
                }

                var systemTypes = allTypes.Where(t =>
                                                 t.IsSubclassOf(typeof(ComponentSystemBase)) &&
                                                 !t.IsAbstract &&
                                                 !t.ContainsGenericParameters);
                allSystems.AddRange(systemTypes);
            }
            EditorApplication.playModeStateChanged += EditorApplicationOnPlayModeStateChanged;

            //Used internally for help in setting position values like height and width
            //PositioningWindow.Add = this;
        }
 protected override void OnCreate()
 {
     _colorIDShader             = Shader.Find("Unlit/EntityIdShader");
     _selectedPixel             = new Texture2D(1, 1, TextureFormat.RGBA32, false);
     CurrentSelectedEntityProxy = ScriptableObject.CreateInstance <EntitySelectionProxy>();
     SceneView.duringSceneGui  += UpdateView;
 }
        public void SetUp()
        {
            InspectorUtility.Settings.Backend = InspectorSettings.InspectorBackend.Normal;

            m_Entity = m_World.EntityManager.CreateEntity();

            m_Proxy  = EntitySelectionProxy.CreateInstance(m_World, m_Entity);
            m_Editor = UnityEditor.Editor.CreateEditor(m_Proxy);
        }
    private void SelectEntity(Vector2 mousePos)
    {
        var selectedEntity = new Entity
        {
            Index = ColorToIndex(GetColorAtMousePos(mousePos, _objectIDRenderTarget))
        };

        if (_entityIndexToVersion.ContainsKey(selectedEntity.Index))
        {
            selectedEntity.Version = _entityIndexToVersion[selectedEntity.Index];
            EntitySelectionProxy.SelectEntity(World, selectedEntity);
        }
        else
        {
            Selection.activeObject = null;
        }
    }
    public void OnDrawHandles()
    {
        EntitySelectionProxy entityProxy = target as EntitySelectionProxy;

        if (entityProxy == null || !entityProxy.Exists)
        {
            return;
        }

        var world = entityProxy.World;

        if (!world.EntityManager.HasComponent <WorldRenderBounds>(entityProxy.Entity))
        {
            return;
        }
        var bounds = world.EntityManager.GetComponentData <WorldRenderBounds>(entityProxy.Entity).Value;

        Handles.color = Color.green;
        Handles.DrawWireCube(bounds.Center, bounds.Size);
    }
        public IEnumerator Selection_DestroyingSelectedEntityDeselectInView()
        {
            var internalListView = WindowRoot.Q <TreeView>(Constants.EntityHierarchy.FullViewName).Q <ListView>();

            var e    = m_Manager.CreateEntity();
            var node = EntityHierarchyNodeId.FromEntity(e);

            yield return(SkipAnEditorFrameAndDiffingUtility());

            Assert.That(internalListView.currentSelectionIds, Is.Empty);

            EntitySelectionProxy.SelectEntity(m_Manager.World, e);
            yield return(null);

            Assert.That(internalListView.currentSelectionIds, Is.EquivalentTo(new[] { node.GetHashCode() }));

            m_Manager.DestroyEntity(e);
            yield return(SkipAnEditorFrameAndDiffingUtility());

            Assert.That(internalListView.selectedItems, Is.Empty);
        }
示例#7
0
        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();
        }
示例#8
0
 private void CreateEntitySelectionProxy()
 {
     selectionProxy           = ScriptableObject.CreateInstance <EntitySelectionProxy>();
     selectionProxy.hideFlags = HideFlags.HideAndDontSave;
 }