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); } } }); }
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 static void DestroyComponent(SEntityComponentId id) { if (id.OverrideComponent == null) { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CEntityComponent component = id.GetComponent <CEntityComponent>(); if (component != null) { component.Destroy(); } }); } else { CEntityComponent component = id.GetComponent <CEntityComponent>(); if (component != null) { component.Destroy(); } } UndoRedoUtility.Purge(null); }
private void InspectComponent(SEntityComponentId componentId) { bool bUpdateInspectorObjectList = ShouldUpdateInspectorList(componentId); CEngine engine = CEngine.Instance; CWorldOutlinerViewModel worldOutliner = CWorkspace.Instance.GetTool <CWorldOutlinerViewModel>(); engine.Dispatch(EEngineUpdatePriority.BeginFrame, () => { CUpdateScheduler scheduler = engine.CurrentWorld.UpdateScheduler; if (m_updateScope != null && m_updateScope.IsConnected()) { scheduler.Disconnect(m_updateScope); } CEntityComponent component = componentId.GetComponent(); if (component != null) { m_selectedObject = new CEditableObject(componentId); m_updateScope = scheduler.Connect(UpdateCallback, EUpdatePriority.ResourceLoading); if (bUpdateInspectorObjectList) { UpdateEntityInformation_EngineThread(new SEntityId(component.Owner.Id)); } worldOutliner.PickingComponentId.GetComponent <CScenePickingComponent>().Pick(component as CSceneComponent); Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() => { m_desiredTarget = new CEditableObject(componentId); UnmarkEverything(); MarkComponentInInspector(componentId, true); })); } else { Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() => { m_desiredTarget = null; UnmarkEverything(); })); } }); }
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(); } }
public static void PickComponent(SEntityComponentId id) { CWorldOutlinerViewModel worldOutliner = CWorkspace.Instance.GetTool <CWorldOutlinerViewModel>(); if (worldOutliner != null) { CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () => { worldOutliner.PickingComponentId.GetComponent <CScenePickingComponent>()?.Pick(id.GetComponent <CSceneComponent>()); }); } }