123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #import "Foundation/Foundation.h"
- #if ENABLE_IOS_ON_DEMAND_RESOURCES
- #import "Foundation/NSBundle.h"
- #endif
- typedef void (*OnDemandResourcesRequestCompleteHandler)(void* handlerData, const char* error);
- #if ENABLE_IOS_ON_DEMAND_RESOURCES
- struct OnDemandResourcesRequestData
- {
- NSBundleResourceRequest* request;
- };
- extern "C" OnDemandResourcesRequestData* UnityOnDemandResourcesCreateRequest(NSSet * tags, OnDemandResourcesRequestCompleteHandler handler, void* handlerData)
- {
- OnDemandResourcesRequestData* data = new OnDemandResourcesRequestData();
- data->request = [[NSBundleResourceRequest alloc] initWithTags: tags];
- [data->request beginAccessingResourcesWithCompletionHandler:^(NSError* error) {
- dispatch_async(dispatch_get_main_queue(), ^{
- const char* errorMessage = error ? [[error localizedDescription] UTF8String] : NULL;
- handler(handlerData, errorMessage);
- });
- }];
- return data;
- }
- extern "C" void UnityOnDemandResourcesRelease(OnDemandResourcesRequestData* data)
- {
- [data->request endAccessingResources];
- delete data;
- }
- extern "C" float UnityOnDemandResourcesGetProgress(OnDemandResourcesRequestData* data)
- {
- return data->request.progress.fractionCompleted;
- }
- extern "C" float UnityOnDemandResourcesGetLoadingPriority(OnDemandResourcesRequestData* data)
- {
- float priority = (float)data->request.loadingPriority;
- return priority;
- }
- extern "C" void UnityOnDemandResourcesSetLoadingPriority(OnDemandResourcesRequestData* data, float priority)
- {
- if (priority < 0.0f)
- priority = 0.0f;
- if (priority > 1.0f)
- data->request.loadingPriority = NSBundleResourceRequestLoadingPriorityUrgent;
- else
- data->request.loadingPriority = (double)priority;
- }
- extern "C" NSString* UnityOnDemandResourcesGetResourcePath(OnDemandResourcesRequestData * data, const char* resource)
- {
- NSString* path = [[data->request bundle] pathForResource: [NSString stringWithUTF8String: resource] ofType: nil];
- return path;
- }
- #else // ENABLE_IOS_ON_DEMAND_RESOURCES
- struct OnDemandResourcesRequestData
- {
- };
- extern "C" OnDemandResourcesRequestData* UnityOnDemandResourcesCreateRequest(NSSet * tags, OnDemandResourcesRequestCompleteHandler handler, void* handlerData)
- {
- OnDemandResourcesRequestData* data = new OnDemandResourcesRequestData();
- if (handler)
- handler(handlerData, NULL);
- return data;
- }
- extern "C" void UnityOnDemandResourcesRelease(OnDemandResourcesRequestData* data)
- {
- delete data;
- }
- extern "C" float UnityOnDemandResourcesGetProgress(OnDemandResourcesRequestData* data)
- {
- return 1.0f;
- }
- extern "C" float UnityOnDemandResourcesGetLoadingPriority(OnDemandResourcesRequestData* data)
- {
- return 0.5;
- }
- extern "C" void UnityOnDemandResourcesSetLoadingPriority(OnDemandResourcesRequestData* data, float priority)
- {
- }
- extern "C" NSString* UnityOnDemandResourcesGetResourcePath(OnDemandResourcesRequestData * data, const char* resource)
- {
- return [NSString stringWithUTF8String: resource];
- }
- #endif // ENABLE_IOS_ON_DEMAND_RESOURCES
|