diff options
Diffstat (limited to 'Runtime/Export/AssetBundleBindings.txt')
-rw-r--r-- | Runtime/Export/AssetBundleBindings.txt | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/Runtime/Export/AssetBundleBindings.txt b/Runtime/Export/AssetBundleBindings.txt new file mode 100644 index 0000000..08f097e --- /dev/null +++ b/Runtime/Export/AssetBundleBindings.txt @@ -0,0 +1,175 @@ +C++RAW + + +#include "UnityPrefix.h" +#include "Configuration/UnityConfigure.h" +#include "Runtime/Misc/AssetBundle.h" +#include "Runtime/Misc/AssetBundleUtility.h" +#include "Runtime/Scripting/ScriptingUtility.h" +#include "Runtime/Scripting/ScriptingExportUtility.h" +#include "Runtime/Scripting/Backend/ScriptingBackendApi.h" +#include "Runtime/Misc/SaveAndLoadHelper.h" +#include "Runtime/Misc/AsyncOperation.h" +#include "Runtime/Scripting/Scripting.h" + + +using namespace std; + + +CSRAW +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; +using System.Collections.Generic; +using UnityEngineInternal; + +namespace UnityEngine +{ + + +// Asynchronous create request for an [[AssetBundle]]. +CONDITIONAL ENABLE_WWW +CLASS AssetBundleCreateRequest : AsyncOperation + + C++RAW + #define GET_REQUEST(variableName) \ + AssetBundleCreateRequest* variableName; \ + MarshallManagedStructIntoNative (self, &variableName); + + // Asset object being loaded (RO). + CUSTOM_PROP AssetBundle assetBundle + { + GET_REQUEST (ptr); + return Scripting::ScriptingWrapperFor(ptr->GetAssetBundle()); + } + + CUSTOM internal void DisableCompatibilityChecks() + { + GET_REQUEST (ptr); + ptr->SetEnableCompatibilityChecks (false); + } + + C++RAW + #undef GET_REQUEST + +END + +// Asynchronous load request from an [[AssetBundle]]. +CSRAW [StructLayout (LayoutKind.Sequential)] +CLASS AssetBundleRequest : AsyncOperation + C++RAW + #define GET ExtractMonoObjectData<PreloadManagerOperation*> (self) + + CSRAW internal AssetBundle m_AssetBundle; + CSRAW internal string m_Path; + CSRAW internal Type m_Type; + + // Asset object being loaded (RO). + CSRAW public Object asset { get { return m_AssetBundle.Load(m_Path, m_Type); } } + + C++RAW + #undef GET + +END + +// AssetBundles let you stream additional assets via the WWW class and instantiate them at runtime. AssetBundles are created via BuildPipeline.BuildAssetBundle. + +CLASS AssetBundle : Object + + // Asynchronously create an AssetBundle from a memory region. + CONDITIONAL ENABLE_WWW + CUSTOM static AssetBundleCreateRequest CreateFromMemory(byte[] binary) + { + if (!binary) + return SCRIPTING_NULL; + + int dataSize = GetScriptingArraySize(binary); + UInt8* dataPtr = Scripting::GetScriptingArrayStart<UInt8>(binary); + + AsyncOperation* req = new AssetBundleCreateRequest(dataPtr, dataSize); + + + return CreateScriptingObjectFromNativeStruct(MONO_COMMON.assetBundleCreateRequest,req); + } + + // Loads an asset bundle from a disk. + CUSTOM static AssetBundle CreateFromFile(string path) + { + return Scripting::ScriptingWrapperFor(ExtractAssetBundle(path)); + } + + // Main asset that was supplied when building the asset bundle (RO). + CUSTOM_PROP Object mainAsset { return Scripting::ScriptingWrapperFor(LoadMainObjectFromAssetBundle(*self)); } + + // Check if an AssetBundle contains a specific object. + CUSTOM bool Contains (string name) + { + string lowerName = ToLower(name.AsUTF8()); + AssetBundle::range found = self->GetPathRange(lowerName); + return found.first != found.second; + } + + // Loads object with /name/ from the bundle. + CSRAW public Object Load (string name) + { + return Load(name, typeof(Object)); + } + + // Loads object with /name/ of a given /type/ from the bundle. + CSRAW + [TypeInferenceRule(TypeInferenceRules.TypeReferencedBySecondArgument)] + CONSTRUCTOR_SAFE + CUSTOM Object Load (string name, Type type) + { + Scripting::RaiseIfNull (type); + Object* o = LoadNamedObjectFromAssetBundle(*self, name, type); + if (o==0) return SCRIPTING_NULL; + return Scripting::ScriptingWrapperFor(o); + } + + // Asynchronously loads object with /name/ of a given /type/ from the bundle. + CUSTOM AssetBundleRequest LoadAsync (string name, Type type) + { + AsyncOperation* result = PreloadLevelOperation::LoadAssetBundle(*self, name); + #if ENABLE_MONO || UNITY_WINRT + ScriptingObjectPtr mono = scripting_object_new(MONO_COMMON.assetBundleRequest); + AssetBundleRequestMono data; + data.m_Result = result; + data.m_Path = name.GetNativeString(); + data.m_Type = type; + data.m_AssetBundle = Scripting::ScriptingWrapperFor((AssetBundle*)self); + MarshallNativeStructIntoManaged(data, mono); + + return mono; + #else + return SCRIPTING_NULL; + #endif + + } + + // Loads all objects contained in the asset bundle that inherit from /type/. + CUSTOM Object[] LoadAll (Type type) + { + Scripting::RaiseIfNull (type); + + vector<Object* > objects; + LoadAllFromAssetBundle(*self, type, objects); + return CreateScriptingArrayFromUnityObjects(objects, ClassID(Object)); + } + + // Loads all objects contained in the asset bundle. + CSRAW public Object[] LoadAll () + { + return LoadAll(typeof(Object)); + } + + // Unloads all assets in the bundle. + CUSTOM void Unload (bool unloadAllLoadedObjects) + { + AssetBundle& file = *self; + UnloadAssetBundle(file, unloadAllLoadedObjects); + } +END + +CSRAW } |