Пример #1
0
        public void Load(LoadGameRequest loadGameRequest)
        {
            lock (this)
            {
                LoadGameRequests.Enqueue(loadGameRequest);
            }

            if (!IsStorageDeviceLoaded && !IsStorageDeviceLoading)
            {
                RequestStorageDevice = true;
            }
        }
Пример #2
0
        private bool DoLoad(LoadGameRequest loadGameRequest)
        {
            // If we have a storage device:
            if (StorageDevice != null && StorageDevice.IsConnected)
            {
                // Open a storage container.
                // CAN THROW GamerPrivilegeException If PlayerIndex not signed into a profile
                try
                {
                    IAsyncResult result = StorageDevice.BeginOpenContainer(loadGameRequest.ContainerName, LoadCallback, loadGameRequest);
                }
                catch (GamerPrivilegeException gpe)
                {
                    OnGamerPrivilegeExceptionWhileLoading.Invoke(gpe, EventArgs.Empty);
                }

                return(true);
            }

            return(false);
        }
Пример #3
0
        public void LoadCallback(IAsyncResult result)
        {
            StorageContainer container = StorageDevice.EndOpenContainer(result);

            LoadGameRequest loadGameRequest = (LoadGameRequest)result.AsyncState;

            // Check to see whether the save exists.
            if (!container.FileExists(loadGameRequest.SaveName))
            {
                // If not, dispose of the container and return.
                container.Dispose();
                loadGameRequest.LoadFailed = true;
                return;
            }

            try
            {
                // Open the file.
                Stream stream = container.OpenFile(loadGameRequest.SaveName, FileMode.Open);

                // Read the data from the file.
                XmlSerializer serializer = new XmlSerializer(loadGameRequest.SaveType);
                loadGameRequest.Data     = serializer.Deserialize(stream);
                loadGameRequest.IsLoaded = true;

                // Close the file.
                stream.Close();
            }
            catch (Exception e)
            {
                loadGameRequest.LoadFailed        = true;
                loadGameRequest.LoadFailException = e;
            }

            // Dispose the container.
            container.Dispose();
        }
Пример #4
0
 private int dataLoadPercentage = 0;//最大值为10
 void Awake()
 {
     LoadingProgress = transform.Find("LoadingProgress").GetComponent <Slider>();
     loadGameRequest = transform.GetComponent <LoadGameRequest>();
     percentageText  = transform.Find("PercentageText").GetComponent <Text>();
 }
Пример #5
0
        private void UpdateStorageRequests()
        {
#if XBOX
            StorageThread.SetProcessorAffinity(4);
#endif

            SaveGameRequest sg = null;
            LoadGameRequest lg = null;
            while (true)
            {
                if (RequestStorageDevice)
                {
                    RequestDevice();
                    RequestStorageDevice = false;
                }

                if (IsStorageDeviceLoaded)
                {
                    lock (this)
                    {
                        if (SaveGameRequests.Count > 0)
                        {
                            sg = SaveGameRequests.Dequeue();
                        }
                    }
                    Thread.Sleep(ThreadSleepMilliseconds);

                    if (sg != null)
                    {
                        if (!DoSave(sg))
                        {
                            lock (this)
                            {
                                SaveGameRequests.Enqueue(sg);
                            }
                            Thread.Sleep(ThreadSleepMilliseconds);
                        }
                        else
                        {
                            sg = null;
                        }
                    }


                    lock (this)
                    {
                        if (LoadGameRequests.Count > 0)
                        {
                            lg = LoadGameRequests.Dequeue();
                        }
                    }
                    Thread.Sleep(ThreadSleepMilliseconds);

                    if (lg != null)
                    {
                        if (!DoLoad(lg))
                        {
                            lock (this)
                            {
                                LoadGameRequests.Enqueue(lg);
                            }
                            Thread.Sleep(ThreadSleepMilliseconds);
                        }
                        else
                        {
                            lg = null;
                        }
                    }
                }
            }
        }