Ejemplo n.º 1
0
 protected void DisposeAsyncOperation()
 {
     lock (_syncObj)
         if (_asyncLoadOperation != null)
         {
             _asyncLoadOperation.Dispose();
             _asyncLoadOperation = null;
         }
 }
Ejemplo n.º 2
0
 protected void AsyncOperationComplete(AsyncLoadOperation operation)
 {
     byte[] imageBuffer;
     lock (_syncObj)
     {
         if (!operation.DataAvailable)
         {
             _state = State.Failed;
             DisposeAsyncOperation();
             return;
         }
         imageBuffer = operation.ImageBuffer;
     }
     AllocateFromBuffer_NoLock(imageBuffer);
     lock (_syncObj)
         _state = State.Loaded;
 }
Ejemplo n.º 3
0
 protected void AllocateFromFileAsync(string path)
 {
     lock (_syncObj)
     {
         _state = State.LoadingAsync;
         Stream stream;
         try
         {
             stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 2048, true);
         }
         catch (Exception e)
         {
             ServiceRegistration.Get <ILogger>().Warn("TextureAssetCore: Image '{0}' could not be opened: {1}", _textureName, e);
             _state = State.Failed;
             return;
         }
         _asyncLoadOperation = new AsyncStreamLoadOperation(stream, path, AsyncOperationComplete);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Called by Unity.
        /// </summary>
        public IEnumerator Start()
        {
            // Create domain
            domain = ScriptDomain.CreateDomain("Example Domain");

            // Security load mode
            // ScriptSecurityMode.EnsureLoad - Do not perform and code validation and just load the assembly
            // ScriptSecurityMode.EnsureSecurity - Perform full code validation and discard the assembly if verification fails
            // ScriptSecurityMode.UseSettings - Use the RoslynC# settings to determine which action to take
            ScriptSecurityMode securityMode = ScriptSecurityMode.UseSettings;

            // Load an assembly async - The assembly may be verified using active security restriction depending upon the security mod specified
            // If an assembly fails verification then it will not be loaded and the load operation will contain failure information
            AsyncLoadOperation assemblyLoad = domain.LoadAssemblyAsync("path/to/assembly.dll", securityMode);

            // Wait for request to complete
            yield return(assemblyLoad);

            // Get the loaded assembly - This will be null if the load or security validation failed
            ScriptAssembly assembly = assemblyLoad.LoadedAssembly;
        }
Ejemplo n.º 5
0
 protected void AsyncOperationComplete(AsyncLoadOperation operation)
 {
   byte[] imageBuffer;
   lock (_syncObj)
   {
     if (!operation.DataAvailable)
     {
       _state = State.Failed;
       DisposeAsyncOperation();
       return;
     }
     imageBuffer = operation.ImageBuffer;
   }
   AllocateFromBuffer_NoLock(imageBuffer);
   lock (_syncObj)
     _state = State.Loaded;
 }
Ejemplo n.º 6
0
 protected void AllocateFromWeb(Uri uri)
 {
   lock (_syncObj)
     _state = State.LoadingAsync;
   _asyncLoadOperation = new AsyncWebLoadOperation(uri, AsyncOperationComplete);
 }
Ejemplo n.º 7
0
 protected void AllocateFromFileAsync(string path)
 {
   lock (_syncObj)
   {
     _state = State.LoadingAsync;
     Stream stream;
     try
     {
       stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 2048, true);
     }
     catch (Exception e)
     {
       ServiceRegistration.Get<ILogger>().Warn("TextureAssetCore: Image '{0}' could not be opened: {1}", _textureName, e);
       _state = State.Failed;
       return;
     }
     _asyncLoadOperation = new AsyncStreamLoadOperation(stream, path, AsyncOperationComplete);
   }
 }
Ejemplo n.º 8
0
 protected void DisposeAsyncOperation()
 {
   lock (_syncObj)
     if (_asyncLoadOperation != null)
     {
       _asyncLoadOperation.Dispose();
       _asyncLoadOperation = null;
     }
 }
Ejemplo n.º 9
0
 protected void AllocateFromWeb(Uri uri)
 {
     lock (_syncObj)
         _state = State.LoadingAsync;
     _asyncLoadOperation = new AsyncWebLoadOperation(uri, AsyncOperationComplete);
 }