private void m_gameDocumentRegistry_DocumentAdded(object sender, ItemInsertedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; IGame game = document.Cast <IGame>(); if (document == m_gameDocumentRegistry.MasterDocument) { NativeObjectAdapter gameLevel = document.Cast <NativeObjectAdapter>(); GameEngine.CreateObject(gameLevel); GameEngine.SetGameLevel(gameLevel); gameLevel.UpdateNativeOjbect(); //create vertex buffer for grid. IGrid grid = document.As <IGame>().Grid; GridRenderer gridRender = grid.Cast <GridRenderer>(); gridRender.CreateVertices(); m_designView.Context = document.Cast <IGameContext>(); } DomNode masterNode = m_gameDocumentRegistry.MasterDocument.As <DomNode>(); DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>(); NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>(); gworld.Insert(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder"), -1); }
private void m_gameDocumentRegistry_DocumentRemoved(object sender, ItemRemovedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; document.DirtyChanged -= m_document_DirtyChanged; document.UriChanged -= m_document_UriChanged; IGame game = document.Cast <IGame>(); if (document == m_designView.Context.Cast <IGameDocument>()) {// master document. IGrid grid = document.As <IGame>().Grid; GridRenderer gridRender = grid.Cast <GridRenderer>(); gridRender.DeleteVertexBuffer(); m_designView.Context = null; GameEngine.DestroyObject(game.Cast <NativeObjectAdapter>()); GameEngine.Clear(); } else {// sub document. DomNode masterNode = m_gameDocumentRegistry.MasterDocument.As <DomNode>(); DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>(); NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>(); gworld.Remove(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder")); } }