bool CFlowNode::CreatedNode(TFlowNodeId id, const char *name, TFlowNodeTypeId typeId, IFlowNodePtr pNode) { if(pNode==this) { IMonoObject *pScript = g_pScriptSystem->InstantiateScript(gEnv->pFlowSystem->GetTypeName(typeId), eScriptFlag_FlowNode); IMonoClass *pNodeInfo = g_pScriptSystem->GetCryBraryAssembly()->GetClass("NodeInfo", "CryEngine.FlowSystem.Native"); pScript->CallMethod("InternalInitialize", pNodeInfo->BoxObject(&SMonoNodeInfo(this, id, m_pActInfo->pGraph->GetGraphId()))); m_pScript = pScript; return pScript != nullptr; } return true; }
void CActorSystem::OnSpawn(IEntity *pEntity,SEntitySpawnParams ¶ms) { EMonoActorType actorType = GetMonoActorType(pEntity->GetClass()->GetName()); if(actorType != EMonoActorType_None) { if(IActor *pActor = gEnv->pGameFramework->GetIActorSystem()->GetActor(pEntity->GetId())) { IMonoObject *pScript = g_pScriptSystem->InstantiateScript(pEntity->GetClass()->GetName(), eScriptFlag_Actor); IMonoClass *pActorInfoClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("ActorInfo"); SMonoActorInfo actorInfo(pActor); pScript->CallMethod("InternalSpawn", pActorInfoClass->BoxObject(&actorInfo)); if(actorType == EMonoActorType_Managed) static_cast<CActor *>(pActor)->SetScript(pScript); } } }
bool CScriptSystem::Reload() { if((!m_bFirstReload && g_pMonoCVars->mono_realtimeScripting == 0) || m_bReloading) return false; m_bReloading = true; if(!m_bFirstReload) { for each(auto listener in m_listeners) listener->OnReloadStart(); m_pScriptManager->CallMethod("Serialize"); } IMonoDomain *pScriptDomain = CreateDomain("ScriptDomain", nullptr, true); IMonoAssembly *pCryBraryAssembly = pScriptDomain->LoadAssembly(PathUtils::GetBinaryPath() + "CryBrary.dll"); IMonoArray *pCtorParams = CreateMonoArray(2); pCtorParams->InsertAny(m_bFirstReload); pCtorParams->InsertMonoString(ToMonoString(PathUtils::GetConfigPath())); IMonoObject *pScriptManager = *pCryBraryAssembly->GetClass("ScriptManager", "CryEngine.Initialization")->CreateInstance(pCtorParams); SAFE_RELEASE(pCtorParams); auto result = pScriptManager->CallMethod("Initialize", m_bFirstReload); if(result == nullptr) return false; IMonoObject *pResult = *result; auto reloadResult = pResult->Unbox<EScriptReloadResult>(); SAFE_RELEASE(pResult); switch(reloadResult) { case EScriptReloadResult_Success: { // revert previous domain if(!m_bFirstReload) m_pScriptDomain->Release(); m_pScriptDomain = pScriptDomain; m_pScriptManager = pScriptManager; m_pCryBraryAssembly = pCryBraryAssembly; CacheManagedResources(); if(!m_bFirstReload) m_pScriptManager->CallMethod("Deserialize"); // Set Network.Editor etc. IMonoClass *pClass = m_pCryBraryAssembly->GetClass("Game"); IMonoArray *pArgs = CreateMonoArray(2); pArgs->Insert(gEnv->IsEditor()); pArgs->Insert(gEnv->IsDedicated()); pClass->GetMethod("InitializeGameStatics", 2)->InvokeArray(nullptr, pArgs); SAFE_RELEASE(pArgs); m_pScriptManager->CallMethod("ProcessWaitingScripts", m_bFirstReload); for each(auto listener in m_listeners) listener->OnReloadComplete(); if(!m_bFirstReload && gEnv->IsEditor()) gEnv->pFlowSystem->ReloadAllNodeTypes(); m_bReloading = false; m_bDetectedChanges = false; return true; } break; case EScriptReloadResult_Retry: { m_bReloading = false; return Reload(); } case EScriptReloadResult_Revert: { pScriptDomain->Release(); m_pScriptDomain->SetActive(); m_bReloading = false; m_bDetectedChanges = false; return false; } break; case EScriptReloadResult_Abort: { gEnv->pSystem->Quit(); m_bReloading = false; } break; } return false; }