private void CreateEntityFromGameObject(GameObject go, EntityReference reference) { // create the entity var entity = m_WorldManager.CreateEntity(go.name, m_ArchetypeManager.FromGameObject(go)); m_WorldManager.SetEntityGuid(entity, reference.Guid); m_WorldManager.EntityManager.SetComponentData(entity, DomainCache.GetDefaultValue <SiblingIndex>()); // add it to the currently active scene var scene = m_SceneManager.GetActiveScene(); scene.AddEntityReference(m_WorldManager.EntityManager, entity); // prime the entity binding configuration (usually primed when running bindings the other way around) var bindingConfig = GenerateBindingConfiguration(entity); EntityToBindingConfiguration[reference.Guid.ToEntityGuid()] = bindingConfig; // create the link between the existing GO and the new entity m_ComponentCache.CreateLink(reference.Guid, reference); }
public void ShowSceneContextMenu(SceneItem item) { if (item.Scene == Scene.Null) { return; } var project = Application.AuthoringProject; var scenes = project.GetScenes(); var menu = new GenericMenu(); if (m_SceneManager.GetActiveScene() == item.Scene) { menu.AddDisabledItem(new GUIContent("Set as Active Scene"), true); } else { menu.AddItem(new GUIContent("Set as Active Scene"), false, () => { m_SceneManager.SetActiveScene(item.Scene); }); } menu.AddItem(new GUIContent("Unload Scene"), false, () => { m_SceneManager.UnloadSceneWithDialog(item.Scene); }); menu.AddItem(new GUIContent("Unload Other Scenes"), false, () => { using (var scenesToUnload = ListPool <Scene> .GetDisposable()) { for (var i = 0; i < m_SceneManager.LoadedSceneCount; ++i) { var scene = m_SceneManager.GetLoadedSceneAtIndex(i); if (scene != item.Scene) { scenesToUnload.List.Add(scene); } } foreach (var scene in scenesToUnload.List) { m_SceneManager.UnloadSceneWithDialog(scene); } } }); menu.AddSeparator(""); if (m_SceneManager.GetLoadedSceneAtIndex(0) == item.Scene) { menu.AddDisabledItem(new GUIContent("Move Up")); } else { menu.AddItem(new GUIContent("Move Up"), false, () => { m_SceneManager.MoveSceneUp(item.Scene); }); } if (m_SceneManager.GetLoadedSceneAtIndex(m_SceneManager.LoadedSceneCount - 1) == item.Scene) { menu.AddDisabledItem(new GUIContent("Move Down")); } else { menu.AddItem(new GUIContent("Move Down"), false, () => { m_SceneManager.MoveSceneDown(item.Scene); }); } menu.AddSeparator(""); var sceneReference = new SceneReference { SceneGuid = item.Scene.SceneGuid.Guid }; if (scenes.Contains(sceneReference)) { var startupScenes = project.GetStartupScenes(); menu.AddItem(new GUIContent($"Remove Scene from {project.Name}"), false, () => { project.RemoveScene(sceneReference); }); if (startupScenes.Contains(sceneReference)) { menu.AddItem(new GUIContent($"Remove Scene from {project.Name} Startup Scenes"), false, () => { project.RemoveStartupScene(sceneReference); }); } else { menu.AddItem(new GUIContent($"Add Scene to {project.Name} Startup Scenes"), false, () => { project.AddStartupScene(sceneReference); }); } } else { menu.AddItem(new GUIContent($"Add Scene to {project.Name}"), false, () => { project.AddScene(sceneReference); }); menu.AddDisabledItem(new GUIContent($"Add Scene to {project.Name} Startup Scenes")); } menu.ShowAsContext(); }