public EntityNode CreateFromExisting(Transform t, Transform parent) { var entity = Registry.CreateEntity( new UTinyId(System.Guid.NewGuid()), t.name); var entityRef = (UTinyEntity.Reference)entity; var entityGroupRef = EntityGroupRef.Dereference(Registry); Assert.IsNotNull(entityGroupRef); entity.EntityGroup = entityGroupRef; entityGroupRef.AddEntityReference(entityRef); entity.AddComponent(Registry.GetTransformType()); entity.View = t.GetComponent <UTinyEntityView>(); CreateLink(entity); var node = new EntityNode { Entity = entityRef, Graph = this }; node.Graph.Add(node); if (parent) { var parentview = parent.GetComponent <UTinyEntityView>(); Assert.IsNotNull(parentview); var parentNode = FindNode((UTinyEntity.Reference)parentview.EntityRef.Dereference(parentview.Registry)); node.SetParent(parentNode as EntityNode); } return(node); }
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 = UTinyHierarchyWindow.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); }
public void Insert(int siblingIndex, EntityNode child) { child.SetParent(siblingIndex, this); }
public void Add(EntityNode child) { child.SetParent(this); }