public static void DetachEntityFromAllParents(SEntityId entityId) { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CEntity target = entityId.GetEntity(); if (target == null || target.RootComponent == null || target.RootComponent.ParentComponent == null) { return; } SEntityComponentId oldRootParent = new SEntityComponentId(target.RootComponent.ParentComponent); void Do() { CWorld world = CEngine.Instance.CurrentWorld; CEntity entity = entityId.GetEntity(); if (entity != null) { entity.Detach(); } } void Undo() { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CWorld world = CEngine.Instance.CurrentWorld; CEntity entity = entityId.GetEntity(); CSceneComponent oldParent = oldRootParent.GetComponent <CSceneComponent>(); if (oldParent == null) { LogUtility.Log("[UndoRedo] The old parent is invalid! Undo stack has been corrupted and cleared."); UndoRedoUtility.Purge(null); return; } if (entity != null) { entity.AttachToComponent(oldParent); } }); } void Redo() { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { Do(); }); } Do(); CRelayUndoItem item = new CRelayUndoItem(Undo, Redo); UndoRedoUtility.Record(item); }); }
public void AttachComponent(SEntityComponentId child, SEntityComponentId parent) { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CSceneComponent parentObj = parent.GetComponent <CSceneComponent>(); CSceneComponent childObj = child.GetComponent <CSceneComponent>(); if (parentObj != null && childObj != null) { CSceneComponent oldParent = childObj.ParentComponent; SEntityComponentId oldParentid = new SEntityComponentId(oldParent); if (childObj.AttachToComponent(parentObj)) { UpdateEntityInformation_EngineThread(m_selectedObject.GetTargetEntityId(), true); void Undo() { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CSceneComponent oldParentInst = oldParentid.GetComponent <CSceneComponent>(); CSceneComponent childInst = child.GetComponent <CSceneComponent>(); if (oldParentInst != null && childInst != null) { childInst.AttachToComponent(oldParentInst); UpdateEntityInformation_EngineThread(child.EntityId, true); } }); } void Redo() { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CSceneComponent newParentInst = parent.GetComponent <CSceneComponent>(); CSceneComponent childInst = child.GetComponent <CSceneComponent>(); if (newParentInst != null && childInst != null) { childInst.AttachToComponent(newParentInst); UpdateEntityInformation_EngineThread(child.EntityId, true); } }); } CRelayUndoItem item = new CRelayUndoItem(Undo, Redo); UndoRedoUtility.Record(item); } } }); }
private void HandleChildEntities(CSceneComponent childComponent, CSceneComponent oldParentComponent, CSceneComponent newParentComponent) { if (childComponent == childComponent.Owner.RootComponent) { if (oldParentComponent == null) { m_childEntities.Remove(childComponent.Owner); } else if (newParentComponent == null) { m_childEntities.Add(childComponent.Owner); } } }
private void OnInputEvent(ReadOnlyCollection <SInputButtonEvent> buttonevents, string textinput) { if (World.IsPlaying) { return; } foreach (var buttonEvent in buttonevents) { if (buttonEvent.button == EInputButton.MouseLeftButton && buttonEvent.buttonEvent == EButtonEvent.Pressed) { if (ImGui.GetIO().WantCaptureMouse) { return; } CViewManager viewManager = World.ViewManager; int mouseAbsX = System.Windows.Forms.Cursor.Position.X - (int)viewManager.ScreenLeft; int mouseAbsY = System.Windows.Forms.Cursor.Position.Y - (int)viewManager.ScreenTop; if (mouseAbsX < 0 || mouseAbsY < 0 || mouseAbsX > viewManager.ScreenWidth || mouseAbsY > viewManager.ScreenHeight) { return; } viewManager.GetViewInfo(out SSceneViewInfo viewInfo); if (m_gizmo.IsHovered) { return; } Ray pickRay = Ray.GetPickRay(mouseAbsX, mouseAbsY, new ViewportF(0, 0, viewManager.ScreenWidth, viewManager.ScreenHeight), viewInfo.ViewMatrix * viewInfo.ProjectionMatrix); if (CRenderer.Instance.ActiveScene.RayIntersection(pickRay, out CRenderNode node, out STriangle tri, out float dist, MarkPickedObjects > 0)) { if (node.Outer is CSceneComponent sceneComponent) { CSceneComponent rootComponent = sceneComponent.Owner.RootComponent; m_gizmo.IsActive = true; m_gizmo.SetControlledTransform(rootComponent.Transform); OnComponentPicked?.Invoke(rootComponent); } } else { m_gizmo.IsActive = false; OnComponentPicked?.Invoke(null); } }
internal void TriggerHierarchyChanged(CSceneComponent child, CSceneComponent oldParent, CSceneComponent newParent) { OnHierarchyChanged?.Invoke(child, oldParent, newParent); }
public static void MakeComponentRoot(SEntityComponentId id, bool bDispatch = true) { void Command() { CSceneComponent newRoot = id.GetComponent <CSceneComponent>(); if (newRoot == null) { return; } CSceneComponent oldRoot = newRoot.Owner.RootComponent; if (oldRoot == null) { return; } SEntityComponentId oldId = new SEntityComponentId(oldRoot); void Do() { CSceneComponent component = id.GetComponent <CSceneComponent>(); if (component != null) { CEntity owner = component.Owner; owner.SetRootComponent(component); } } void Redo() { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { Do(); Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() => { CWorkspace space = CWorkspace.Instance; space.SetSelectedObject(space.SelectedEditableObject, true); })); }); } void Undo() { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CSceneComponent component = oldId.GetComponent <CSceneComponent>(); if (component != null) { CEntity owner = component.Owner; owner.SetRootComponent(component); Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() => { CWorkspace space = CWorkspace.Instance; space.SetSelectedObject(space.SelectedEditableObject, true); })); } }); } Do(); CUndoItem item = new CRelayUndoItem(Undo, Redo); UndoRedoUtility.Record(item); } if (bDispatch) { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { Command(); }); } else { Command(); } }