Exemplo n.º 1
0
 internal override void Load()
 {
     bundle    = Assets.LoadBundleAsync(assetBundleName);
     loadState = LoadState.LoadAssetBundle;
 }
Exemplo n.º 2
0
 public Widget(string assetPath)
 {
     _request = Assets.LoadAssetAsync(assetPath, typeof(GameObject));
     state    = State.Loading;
     WidgetManager.Add(this);
 }
Exemplo n.º 3
0
        private void Complete()
        {
            Versions.Save();

            if (_downloads.Count > 0)
            {
                for (int i = 0; i < _downloads.Count; i++)
                {
                    var item = _downloads[i];
                    if (!item.isDone)
                    {
                        break;
                    }
                    else
                    {
                        if (_serverVersions.ContainsKey(item.path))
                        {
                            _versions[item.path] = _serverVersions[item.path];
                        }
                    }
                }

                StringBuilder sb = new StringBuilder();
                foreach (var item in _versions)
                {
                    sb.AppendLine(string.Format("{0}:{1}", item.Key, item.Value));
                }

                var path = Assets.GetRelativeUpdatePath(versionsTxt);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                File.WriteAllText(path, sb.ToString());
                var request = Assets.Initialize();
                request.completed = delegate(AssetRequest req)
                {
                    if (!string.IsNullOrEmpty(req.error))
                    {
                        OnError(req.error);
                    }
                    else
                    {
                        if (completed != null)
                        {
                            completed();
                        }
                    }
                };
                state = State.Completed;

                message = string.Format("{0} files has update.", _downloads.Count);
                return;
            }

            if (completed != null)
            {
                completed();
            }

            message = "nothing to update.";
            state   = State.Completed;
        }
Exemplo n.º 4
0
 internal static string Bundles_overrideBaseDownloadingURL(string bundleName)
 {
     return(!File.Exists(Assets.GetRelativeUpdatePath(bundleName)) ? null : Assets.updatePath);
 }
Exemplo n.º 5
0
        private void OnGUI()
        {
            using (var v = new GUILayout.VerticalScope("AssetsUpdate Demo", "window"))
            {
                switch (state)
                {
                case State.Wait:
                    if (GUILayout.Button("Check"))
                    {
                        Check();
                    }

                    break;

                case State.WaitDownload:
                    if (GUILayout.Button("Download"))
                    {
                        Download();
                    }
                    break;

                case State.Completed:
                    if (GUILayout.Button("Clear"))
                    {
                        Clear();
                    }
                    break;

                default:
                    break;
                }

                GUILayout.Label(string.Format("{0}:{1}", state, message));
                if (state == State.Completed)
                {
                    GUILayout.Label("AllBundleAssets:");
                    var assets = Assets.GetAllBundleAssetPaths();
                    foreach (var item in assets)
                    {
                        if (GUILayout.Button(item))
                        {
                            assetPath = item;
                        }
                    }

                    using (var h = new GUILayout.HorizontalScope())
                    {
                        assetPath = GUILayout.TextField(assetPath, GUILayout.Width(256));
                        if (GUILayout.Button("Load"))
                        {
                            var asset = Assets.LoadAsset(assetPath, typeof(UnityEngine.Object));
                            asset.completed += OnAssetLoaded;
                        }

                        if (GUILayout.Button("LoadAsync"))
                        {
                            var asset = Assets.LoadAssetAsync(assetPath, typeof(UnityEngine.Object));
                            asset.completed += OnAssetLoaded;
                        }

                        if (GUILayout.Button("LoadScene"))
                        {
                            var asset = Assets.LoadSceneAsync(assetPath, true);
                            asset.completed += OnAssetLoaded;
                        }
                    }

                    if (loadedAssets.Count > 0)
                    {
                        if (GUILayout.Button("UnloadAll"))
                        {
                            for (int i = 0; i < loadedAssets.Count; i++)
                            {
                                var item = loadedAssets[i];
                                item.Release();
                            }

                            loadedAssets.Clear();
                        }

                        for (int i = 0; i < loadedAssets.Count; i++)
                        {
                            var item = loadedAssets[i];
                            using (var h = new GUILayout.HorizontalScope())
                            {
                                GUILayout.Label(item.url);
                                if (GUILayout.Button("Unload"))
                                {
                                    item.Release();
                                    loadedAssets.RemoveAt(i);
                                    i--;
                                }
                            }
                        }
                    }
                }
            }
        }