예제 #1
0
        public static void LoadAsync(string modelName, TextureDictionary[] txds, System.Action <GeometryParts> onFinish)
        {
            modelName = modelName.ToLower();

            if (!s_asyncLoader.TryLoadObject(modelName, onFinish))
            {
                // callback is either called or registered
                return;
            }


            GeometryParts loadedGeoms = null;

            LoadingThread.RegisterJob(new LoadingThread.Job <Clump> ()
            {
                action = () => {
                    // read archive file in background thread
                    var clump = ArchiveManager.ReadFile <Clump>(modelName + ".dff");
                    return(clump);
                },
                callbackSuccess = (Clump clump) => {
                    if (clump.GeometryList == null)
                    {
                        throw new Exception("Invalid mesh");
                    }

                    // create geometry parts in main thread
                    loadedGeoms = new GeometryParts(modelName, clump, txds);
                },
                callbackFinish = (result) => {
                    s_asyncLoader.OnObjectFinishedLoading(modelName, loadedGeoms, loadedGeoms != null);
                }
            });
        }
        private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs = true)
        {
            LoadingThread obj = new LoadingThread();

            obj.toggleLoading();
            Thread aThread = new Thread(new ThreadStart(obj.Start));

            aThread.Start();

            // Get the subdirectories for the specified directory.
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName);
            }

            DirectoryInfo[] dirs = dir.GetDirectories();
            // If the destination directory doesn't exist, create it.
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }

            // Get the files in the directory and copy them to the new location.
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                string temppath = Path.Combine(destDirName, file.Name);

                try
                {
                    file.CopyTo(temppath, false);
                }
                catch (IOException e)
                {
                    var answer = ConsoleYesNo($"{file.FullName} already exists. Do you want to overwrite?");
                    if (answer)
                    {
                        file.CopyTo(temppath, true);
                    }
                }
            }

            // If copying subdirectories, copy them and their contents to new location.
            if (copySubDirs)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string temppath = Path.Combine(destDirName, subdir.Name);
                    DirectoryCopy(subdir.FullName, temppath, copySubDirs);
                }
            }

            obj.toggleLoading();
            aThread.Suspend();
        }
 private void OnDestroy()
 {
     if (current != this)
     {
         return;
     }
     current   = null;
     isRunning = false;
     resetEvent.Set();
     thread.Join();
     resetEvent.Dispose();
 }
 void Awake()
 {
     if (current != null)
     {
         Destroy(gameObject);
         return;
     }
     DontDestroyOnLoad(this);
     current    = this;
     isRunning  = true;
     resetEvent = new AutoResetEvent(false);
     thread     = new Thread(Run);
     thread.Start();
 }
예제 #5
0
        public void Dispose()
        {
            // Todo: Move this to the composite library.
            foreach (var composite in CompositeLibrary.Composites)
            {
                composite.Value.Dispose();
            }
            CompositeLibrary.Composites.Clear();

            if (LoadingThread != null && LoadingThread.IsAlive)
            {
                LoadingThread.Abort();
            }
        }