| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Wrappers/BsScriptResources.h"
- #include "BsMonoManager.h"
- #include "BsMonoClass.h"
- #include "BsMonoMethod.h"
- #include "BsMonoUtil.h"
- #include "Resources/BsGameResourceManager.h"
- #include "BsScriptResourceManager.h"
- #include "Wrappers/BsScriptResource.h"
- #include "BsApplication.h"
- namespace bs
- {
- ScriptResources::ScriptResources(MonoObject* instance)
- :ScriptObject(instance)
- { }
- void ScriptResources::initRuntimeData()
- {
- metaData.scriptClass->addInternalCall("Internal_Load", (void*)&ScriptResources::internal_Load);
- metaData.scriptClass->addInternalCall("Internal_LoadFromUUID", (void*)&ScriptResources::internal_LoadFromUUID);
- metaData.scriptClass->addInternalCall("Internal_LoadAsync", (void*)&ScriptResources::internal_LoadAsync);
- metaData.scriptClass->addInternalCall("Internal_LoadAsyncFromUUID", (void*)&ScriptResources::internal_LoadAsyncFromUUID);
- metaData.scriptClass->addInternalCall("Internal_UnloadUnused", (void*)&ScriptResources::internal_UnloadUnused);
- metaData.scriptClass->addInternalCall("Internal_Release", (void*)&ScriptResources::internal_Release);
- metaData.scriptClass->addInternalCall("Internal_ReleaseRef", (void*)&ScriptResources::internal_ReleaseRef);
- metaData.scriptClass->addInternalCall("Internal_GetLoadProgress", (void*)&ScriptResources::internal_GetLoadProgress);
- }
- MonoObject* ScriptResources::internal_Load(MonoString* path, ResourceLoadFlag flags)
- {
- Path nativePath = MonoUtil::monoToString(path);
- HResource resource = GameResourceManager::instance().load(nativePath, flags, false);
- if (resource == nullptr)
- return nullptr;
- ScriptResourceBase* scriptResource = ScriptResourceManager::instance().getScriptResource(resource, true);
- return scriptResource->getManagedInstance();
- }
- MonoObject* ScriptResources::internal_LoadFromUUID(UUID* uuid, ResourceLoadFlag flags)
- {
- ResourceLoadFlags loadFlags = flags;
- if (gApplication().isEditor())
- loadFlags |= ResourceLoadFlag::KeepSourceData;
- HResource resource = gResources().loadFromUUID(*uuid, loadFlags);
- if (resource == nullptr)
- return nullptr;
- ScriptResourceBase* scriptResource = ScriptResourceManager::instance().getScriptResource(resource, true);
- return scriptResource->getManagedInstance();
- }
- MonoObject* ScriptResources::internal_LoadAsync(MonoString* path, ResourceLoadFlag flags)
- {
- Path nativePath = MonoUtil::monoToString(path);
- HResource resource = GameResourceManager::instance().load(nativePath, flags, true);
- if (resource == nullptr)
- return nullptr;
- ScriptRRefBase* scriptResource = ScriptResourceManager::instance().getScriptRRef(resource);
- if(scriptResource != nullptr)
- return scriptResource->getManagedInstance();
- return nullptr;
- }
- MonoObject* ScriptResources::internal_LoadAsyncFromUUID(UUID* uuid, ResourceLoadFlag flags)
- {
- ResourceLoadFlags loadFlags = flags;
- if (gApplication().isEditor())
- loadFlags |= ResourceLoadFlag::KeepSourceData;
- HResource resource = gResources().loadFromUUID(*uuid, loadFlags);
- if (resource == nullptr)
- return nullptr;
- ScriptRRefBase* scriptResource = ScriptResourceManager::instance().getScriptRRef(resource);
- if(scriptResource != nullptr)
- return scriptResource->getManagedInstance();
- return nullptr;
- }
- float ScriptResources::internal_GetLoadProgress(ScriptRRefBase* resource, bool loadDependencies)
- {
- return gResources().getLoadProgress(resource->getHandle(), loadDependencies);
- }
- void ScriptResources::internal_Release(ScriptResourceBase* resource)
- {
- resource->getGenericHandle().release();
- }
- void ScriptResources::internal_ReleaseRef(ScriptRRefBase* resourceRef)
- {
- resourceRef->getHandle().release();
- }
- void ScriptResources::internal_UnloadUnused()
- {
- gResources().unloadAllUnused();
- }
- }
|