public void Load() { HierarchyHelper.GetOrGenerateScratchPad(m_Context); var workspace = m_Context.Workspace; foreach (var entityGroupRef in workspace.OpenedEntityGroups) { if (null != entityGroupRef.Dereference(Registry)) { LoadEntityGroup(entityGroupRef, -1, false); } } // The workspace was either empty or the entity groups have been removed. // Try to load the last active group and if it fails, load any scene. if (LoadedEntityGroupCount == 0) { if (null != workspace.ActiveEntityGroup.Dereference(Registry)) { LoadEntityGroup(workspace.ActiveEntityGroup, -1, false); } else { var group = Registry.FindAllByType <UTinyEntityGroup>().FirstOrDefault(); if (null != group) { LoadEntityGroup((UTinyEntityGroup.Reference)group, -1, false); } } } SetActiveEntityGroup(workspace.ActiveEntityGroup, false); if (null == workspace.ActiveEntityGroup.Dereference(m_Context.Registry)) { SetActiveEntityGroup(LoadedEntityGroups.FirstOrDefault(), false); } RebuildWorkspace(); EditorSceneManager.sceneOpening += HandleSceneOpening; EditorSceneManager.newSceneCreated += HandleSceneCreated; }
public void Load() { HierarchyHelper.GetOrGenerateScratchPad(m_Context); var workspace = m_Context.Workspace; foreach (var entityGroupRef in workspace.OpenedEntityGroups) { LoadEntityGroup(entityGroupRef, -1, false); } SetActiveEntityGroup(workspace.ActiveEntityGroup, false); if (null == workspace.ActiveEntityGroup.Dereference(m_Context.Registry)) { SetActiveEntityGroup(LoadedEntityGroups.FirstOrDefault(), false); } RebuildWorkspace(); EditorSceneManager.sceneOpening += HandleSceneOpening; EditorSceneManager.newSceneCreated += HandleSceneCreated; }
private void LoadEntityGroup(UTinyEntityGroup.Reference entityGroupRef, int index, bool rebuildWorkspace) { var entityGroup = entityGroupRef.Dereference(Registry); if (null == entityGroup) { Debug.Log($"{UTinyConstants.ApplicationName}: Could not load group named '{entityGroupRef.Name}' as the reference could not be resolved."); return; } if (m_LoadedEntityGroups.Contains(entityGroupRef)) { Debug.Log($"{UTinyConstants.ApplicationName}: Cannot load the group named '{entityGroupRef.Name}'. It is already loaded"); return; } if (HierarchyHelper.GetOrGenerateScratchPad(m_Context)) { OnWillLoadEntityGroup?.Invoke(entityGroupRef); if (index >= 0 && index < m_LoadedEntityGroups.Count) { m_LoadedEntityGroups.Insert(index, entityGroupRef); } else { m_LoadedEntityGroups.Add(entityGroupRef); } m_EntityGroupToGraph[entityGroupRef] = EntityGroupGraph.CreateFromEntityGroup(entityGroup); } if (rebuildWorkspace) { RebuildWorkspace(); } SetActiveEntityGroup(entityGroupRef, rebuildWorkspace); OnEntityGroupLoaded?.Invoke(entityGroupRef); }
public void Unload() { EditorSceneManager.sceneOpening -= HandleSceneOpening; EditorSceneManager.newSceneCreated -= HandleSceneCreated; HierarchyHelper.ReleaseScratchPad(m_Context); }