summaryrefslogtreecommitdiff
path: root/Runtime/Export/AssetBundleBindings.txt
blob: 08f097ece6064ad193ceb26de8b25f5e03891e72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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 }