// ----------------------------------------------------------------------------------------------------------
        // INTERNAL
        // ----------------------------------------------------------------------------------------------------------

        internal EntityArchetype CreateArchetype(ComponentType *types, int count)
        {
            ComponentTypeInArchetype *typesInArchetype = stackalloc ComponentTypeInArchetype[count + 1];
            var cachedComponentCount = FillSortedArchetypeArray(typesInArchetype, types, count);

            // Lookup existing archetype (cheap)
            EntityArchetype entityArchetype;

            entityArchetype.Archetype = EntityComponentStore->GetExistingArchetype(typesInArchetype, cachedComponentCount);
            if (entityArchetype.Archetype != null)
            {
                return(entityArchetype);
            }

            // Creating an archetype invalidates all iterators / jobs etc
            // because it affects the live iteration linked lists...
            BeforeStructuralChange();
            var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

            entityArchetype.Archetype = EntityManagerCreateArchetypeUtility.GetOrCreateArchetype(typesInArchetype,
                                                                                                 cachedComponentCount, EntityComponentStore);

            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);

            EntityGroupManager.AddAdditionalArchetypes(changedArchetypes);

            return(entityArchetype);
        }
        public sealed override void Create(UTinyEntityView view, Transform t)
        {
            UTinyEntity.Reference parentRef = UTinyEntity.Reference.None;
            if (t.parent)
            {
                parentRef = t.parent.GetComponent <UTinyEntityView>()?.EntityRef ?? UTinyEntity.Reference.None;
            }

            var graph = EntityGroupManager.GetSceneGraph(
                parentRef.Equals(UTinyEntity.Reference.None) ?
                EntityGroupManager.ActiveEntityGroup
                                        : (UTinyEntityGroup.Reference)parentRef.Dereference(Registry).EntityGroup);

            if (null == graph)
            {
                return;
            }

            var transform = new UTinyObject(Registry, GetMainTinyType());

            SyncTransform(t, transform);

            var entityNode = graph.CreateFromExisting(t, t.parent);
            var entity     = entityNode.Entity.Dereference(Registry);

            var tiny = entity.GetOrAddComponent(GetMainTinyType());

            tiny.CopyFrom(transform);

            BindingsHelper.RunBindings(entity, tiny);
        }
示例#3
0
        protected override TreeViewItem BuildRoot()
        {
            var nextId = int.MaxValue;
            var root   = new HierarchyTreeItemBase()
            {
                id = nextId--, depth = -1, displayName = "Root"
            };

            if (null == m_EntityGroups || m_EntityGroups.Count == 0)
            {
                var item = new TreeViewItem {
                    id = nextId--, depth = 0, displayName = "No group Opened"
                };
                root.AddChild(item);
                return(root);
            }

            foreach (var entityGroupRef in m_EntityGroups)
            {
                var graph = EntityGroupManager.GetSceneGraph(entityGroupRef);
                if (null == graph)
                {
                    RemoveEntityGroup(entityGroupRef);
                    continue;
                }

                var entityGroup = graph.EntityGroupRef.Dereference(Registry);
                Assert.IsNotNull(entityGroup);
                var item = new HierarchyEntityGroupGraph {
                    id = nextId--, depth = 0, displayName = entityGroup.Name, Value = graph
                };
                root.AddChild(item);

                foreach (var node in graph.Roots)
                {
                    BuildFromNode(node, item);
                }

                if (graph.StaticEntities.Count > 0)
                {
                    item.AddChild(new HierarchyTreeItemBase {
                        id = nextId--, depth = 1
                    });
                }

                foreach (var node in graph.StaticEntities)
                {
                    BuildFromNode(node, item);
                }
            }

            ShouldReload = false;
            return(root);
        }
        private static void HierarchyChanged()
        {
            var changed = false;

            for (var i = 0; i < SceneManager.sceneCount; ++i)
            {
                var scene = SceneManager.GetSceneAt(i);
                if (!scene.isLoaded || !scene.IsValid())
                {
                    continue;
                }

                var graph = EntityGroupManager.GetSceneGraph(EntityGroupManager?.ActiveEntityGroup ?? UTinyEntityGroup.Reference.None);
                if (null == graph)
                {
                    continue;
                }

                var transforms = scene.GetRootGameObjects()
                                 .SelectMany(root => root.GetComponentsInChildren <Transform>(true))
                                 .NotNull()
                                 // Dealing with prefabs
                                 .Where(t => (t.root.gameObject.hideFlags & HideFlags.HideInHierarchy) != HideFlags.HideInHierarchy)
                                 .GroupBy(t => null == t.GetComponent <UTinyEntityView>());

                foreach (var group in transforms)
                {
                    // Without an entity view
                    // We will try to create an entity from the components of the object.
                    // If we couldn't (or if it is a prefab), we just display a dialog box and delete the GameObjects
                    if (group.Key)
                    {
                        changed = ProcessNewGameObjects(group);
                    }
                    // With an entity view
                    else
                    {
                        foreach (var t in group)
                        {
                            var view = t.GetComponent <UTinyEntityView>();
                            view.DestroyIfUnlinked();
                        }
                    }
                }
            }

            if (changed)
            {
                UTinyEventDispatcher <ChangeSource> .Dispatch(ChangeSource.SceneGraph);
            }
        }
示例#5
0
        private DragAndDropVisualMode DropOutsideOfItems(IEnumerable <IEntityNode> entities, DragAndDropArgs args)
        {
            var graph = EntityGroupManager.GetSceneGraph(m_EntityGroups.Last());

            graph.Add(entities.ToList());

            var ids = AsInstanceIds(entities);

            Selection.instanceIDs = ids;
            IdsToExpand           = ids;
            UTinyEventDispatcher <ChangeSource> .Dispatch(ChangeSource.SceneGraph);

            return(DragAndDropVisualMode.Link);
        }
示例#6
0
        public UTinyEntity.Reference CreateEntity(UTinyEntityGroup.Reference entityGroupRef, bool addTransform)
        {
            var graph = EntityGroupManager.GetSceneGraph(entityGroupRef);

            if (null == graph)
            {
                return(UTinyEntity.Reference.None);
            }
            var node = addTransform ? graph.Create() : graph.CreateStatic();

            var ids = AsInstanceIds(node);

            Selection.instanceIDs = ids;
            IdsToExpand           = ids;

            UTinyEventDispatcher <ChangeSource> .Dispatch(ChangeSource.SceneGraph);

            return(node.Entity);
        }
示例#7
0
 internal void Unload()
 {
     Undo.Unload();
     EntityGroupManager.Unload();
 }
示例#8
0
 internal void Load()
 {
     EntityGroupManager.Load();
 }
 private static void CreateNewEntityGroup(UTinyModule module)
 {
     EntityGroupManager.CreateNewEntityGroup();
 }
 private static void SetEntityGroupActive(UTinyEntityGroup.Reference entityGroupRef)
 {
     EntityGroupManager.SetActiveEntityGroup(entityGroupRef, true);
 }
        public static void ShowEntityGroupContextMenu(this HierarchyTree tree, UTinyEntityGroup.Reference entityGroupRef)
        {
            if (UTinyEntityGroup.Reference.None.Id == entityGroupRef.Id)
            {
                entityGroupRef = EntityGroupManager.ActiveEntityGroup;
            }

            var menu = new GenericMenu();

            if (IsEntityGroupActive(entityGroupRef))
            {
                menu.AddDisabledItem(new GUIContent("Set Active EntityGroup"));
            }
            else
            {
                menu.AddItem(new GUIContent("Set Active EntityGroup"), false, () =>
                {
                    SetEntityGroupActive(entityGroupRef);
                });
            }

            if (EntityGroupManager.LoadedEntityGroups.IndexOf(entityGroupRef) > 0)
            {
                menu.AddItem(new GUIContent("Move EntityGroup Up"), false, () =>
                {
                    EntityGroupManager.MoveUp(entityGroupRef);
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Move EntityGroup Up"));
            }

            if (EntityGroupManager.LoadedEntityGroups.IndexOf(entityGroupRef) < EntityGroupManager.LoadedEntityGroupCount - 1)
            {
                menu.AddItem(new GUIContent("Move EntityGroup Down"), false, () =>
                {
                    EntityGroupManager.MoveDown(entityGroupRef);
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Move EntityGroup Down"));
            }

            menu.AddSeparator("");

            if (EntityGroupManager.LoadedEntityGroupCount == 1)
            {
                menu.AddDisabledItem(new GUIContent("Unload EntityGroup"));
                menu.AddDisabledItem(new GUIContent("Unload Other EntityGroups"));
            }
            else
            {
                menu.AddItem(new GUIContent("Unload EntityGroup"), false, () =>
                {
                    EntityGroupManager.UnloadEntityGroup(entityGroupRef);
                });
                menu.AddItem(new GUIContent("Unload Other EntityGroups"), false, () =>
                {
                    EntityGroupManager.UnloadAllEntityGroupsExcept(entityGroupRef);
                });
            }

            menu.AddItem(new GUIContent("New EntityGroup"), false, () =>
            {
                var context = EditorContext;
                if (null == context)
                {
                    return;
                }
                var registry = context.Registry;
                var project  = context.Project;
                CreateNewEntityGroup(project.Module.Dereference(registry));
            });

            menu.AddSeparator("");

            menu.AddItem(new GUIContent("Create Entity"), false, () =>
            {
                tree.CreateEntity(entityGroupRef);
            });

            menu.AddItem(new GUIContent("Create Static Entity"), false, () =>
            {
                tree.CreateStaticEntity(entityGroupRef);
            });

            menu.ShowAsContext();
        }
示例#12
0
        private DragAndDropVisualMode HandleResourceDropped(Object obj, DragAndDropArgs args)
        {
            var        parent     = args.parentItem as HierarchyTreeItemBase;
            EntityNode entityNode = null;

            switch (args.dragAndDropPosition)
            {
            case DragAndDropPosition.UponItem:
            {
                if (parent is HierarchyEntityGroupGraph)
                {
                    var graph = (parent as HierarchyEntityGroupGraph).Value;
                    entityNode = graph.Create();
                }

                if (parent is HierarchyEntity)
                {
                    var node = (parent as HierarchyEntity).Value;
                    entityNode = node.Graph.Create(node);
                }
                // Set as last non-static sibling.
                else if (parent is HierarchyStaticEntity)
                {
                    var node = (parent as HierarchyStaticEntity).Value;
                    entityNode = node.Graph.Create();
                }
            }
            break;

            case DragAndDropPosition.BetweenItems:
            {
                if (rootItem == parent)
                {
                    if (args.insertAtIndex <= 0)
                    {
                        return(DragAndDropVisualMode.Rejected);
                    }

                    var graph = (parent.children[args.insertAtIndex - 1] as HierarchyEntityGroupGraph).Value;
                    entityNode = graph.Create();
                }
                else if (parent is HierarchyEntityGroupGraph)
                {
                    var groupItem = parent as HierarchyEntityGroupGraph;
                    var graph     = groupItem.Value;

                    var index = (args.insertAtIndex >= parent.children.Count || args.insertAtIndex >= graph.Roots.Count) ? -1 : args.insertAtIndex;

                    entityNode = graph.Create();
                    graph.Insert(index, entityNode);
                }
                else if (parent is HierarchyEntity)
                {
                    var parentNode = (parent as HierarchyEntity).Value;
                    var firstIndex = args.insertAtIndex;
                    entityNode = parentNode.Graph.Create();
                    entityNode.SetParent(firstIndex, parentNode);
                }
                // Between static entities, set as last sibling of non-static entities
                else if (parent is HierarchyStaticEntity)
                {
                    var graph = (parent as HierarchyStaticEntity).Value.Graph;
                    entityNode = graph.Create();
                }
            }
            break;

            case DragAndDropPosition.OutsideItems:
            {
                var graph = EntityGroupManager.GetSceneGraph(m_EntityGroups.Last());
                entityNode = graph.Create();
            }
            break;

            default:
            {
                return(DragAndDropVisualMode.Rejected);
            }
            }


            if (!UTinyEntity.Reference.None.Equals(entityNode.Entity))
            {
                AddToEntity(entityNode.Entity, obj);
                var ids = AsInstanceIds(entityNode);
                Selection.instanceIDs = ids;
                IdsToExpand           = ids;
                return(DragAndDropVisualMode.Link);
            }
            return(DragAndDropVisualMode.Rejected);
        }