Beispiel #1
0
        public override void OnInspectorGUI()
        {
            // Undo
            switch (Event.current.type)
            {
            case EventType.MouseUp:
            case EventType.MouseDown:
                if (Event.current.button == 0)                  // Left Click
                {
                    Undo.RecordObjects(this._undoObjects, "AssetBundleLoader");
                }
                break;

            case EventType.KeyDown:
                Undo.RecordObjects(this._undoObjects, "AssetBundleLoader");
                break;
            }

            AssetBundleLoader target = base.target as AssetBundleLoader;
            // Select AssetBundle
            var data = AssetBundleManager.GetManageData(true);

            if (data != null)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("URL");
                string url = target.URL;
                if (!string.IsNullOrEmpty(url))
                {
                    if (this._source == Source.StreamingAssets)
                    {
                        url = url.Replace(Application.streamingAssetsPath, "$(StreamingAssetPath)");
                    }
#if !NOT_USE_PLATFORM
                    if (target.PlatformFolder)
                    {
                        url = url.Replace(AssetBundleManager.GetPlatformFolder(Application.platform), AssetBundleManager.PlatformFolder);
                    }
#endif
                }
                var wordwrapLabelStyel = EditorStyles.label;
                wordwrapLabelStyel.wordWrap = true;
                GUI.enabled = false;
                EditorGUILayout.LabelField(url, wordwrapLabelStyel);
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();

                EditorGUI.BeginChangeCheck();
                var tmp = this._source;
                this._source = (Source)EditorGUILayout.EnumPopup("Source", this._source);
                if (tmp != this._source)
                {
                    // changed
                    if (this._source == Source.Network)
                    {
                        if (string.IsNullOrEmpty(this._path))
                        {
                            this._path = "http://";
                        }
                    }
                }

                EditorGUILayout.BeginHorizontal();
                var wordwrapTextAreaStyel = EditorStyles.textArea;
                wordwrapTextAreaStyel.wordWrap = true;
                var prevPath = this._path;
                if (this._source == Source.StreamingAssets)
                {
                    EditorGUILayout.PrefixLabel("Directory");
                    this._path = EditorGUILayout.TextArea(this._path, wordwrapTextAreaStyel);
                }
                else
                {
                    EditorGUILayout.PrefixLabel("Base URL");
                    this._path = EditorGUILayout.TextArea(this._path, wordwrapTextAreaStyel);
                }
                if (prevPath != this._path)
                {
                    if (target.PlatformFolder != this._path.Contains(AssetBundleManager.PlatformFolder))
                    {
                        target.PlatformFolder = this._path.Contains(AssetBundleManager.PlatformFolder);
                    }
                }
                EditorGUILayout.EndHorizontal();

#if NOT_USE_PLATFORM
                EditorGUI.BeginDisabledGroup(true);
#endif
                bool prevPlatformFolder = target.PlatformFolder;
                target.PlatformFolder = EditorGUILayout.Toggle("in platform folder", target.PlatformFolder);
                if (prevPlatformFolder != target.PlatformFolder)
                {
                    this.UpdatePlatformFolder(target.PlatformFolder);
                }
#if NOT_USE_PLATFORM
                EditorGUI.EndDisabledGroup();
#endif
                if (EditorGUI.EndChangeCheck() && 0 < this._assetbundleNo)
                {
                    this.SetURL(target, data.assetbundles[this._assetbundleNo - 1]);
                }

                if (0 < data.assetbundles.Count)
                {
                    if (this._assetbundleList == null || this._assetbundleList.Length < data.assetbundles.Count + 1)
                    {
                        this._assetbundleList    = new string[data.assetbundles.Count + 1];
                        this._assetbundleList[0] = " ";                         // use "" to select nothing.
                    }
                    else
                    {
                        System.Array.Clear(this._assetbundleList, 1, this._assetbundleList.Length - 1);
                    }
                    int i = 1;
                    foreach (var s in data.assetbundles.Select(n => string.Format("{0} [{1}\\{0}]", n.File, n.Directory.Replace('/', '\\'))))
                    {
                        this._assetbundleList[i++] = s;
                    }

                    EditorGUI.BeginChangeCheck();
                    this._assetbundleNo = EditorGUILayout.Popup("AssetBundle", this._assetbundleNo, this._assetbundleList);

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (0 < this._assetbundleNo)
                        {
                            var assetbundle = data.assetbundles[this._assetbundleNo - 1];
                            target.AssetBundleName = assetbundle.File;
                            target.PlatformFolder  = assetbundle.PlatformFolder;
                            this.SetupAssetbundle(data);
                            this.UpdatePlatformFolder(target.PlatformFolder);

                            if (!assetbundle.Separated)
                            {
                                this.SetURL(target, assetbundle);
                            }
                            else
                            {
                                if (0 < this._assetNo)
                                {
                                    this.SetURL(target, assetbundle);
                                }
                                else
                                {
                                    target.SetURL(null);
                                }
                            }
                        }
                        else
                        {
                            target.SetURL(null);
                            this._assetList = null;
                        }
                    }
                    int num = 0;
                    if (0 < this._assetbundleNo)
                    {
                        var assetbundle = data.assetbundles[this._assetbundleNo - 1];
                        num = assetbundle.GetAllContentsPath().Count();
                        if (num != this._contentNum)
                        {
                            this.SetupAssetbundle(data);
                        }
                    }
                    if (this._assetList != null)
                    {
                        EditorGUI.BeginChangeCheck();
                        this._assetNo = EditorGUILayout.Popup("Asset", this._assetNo, this._assetList);
                        if (EditorGUI.EndChangeCheck())
                        {
                            // set asset
                            if (0 < this._assetNo)
                            {
                                System.IO.FileInfo fileinfo = new System.IO.FileInfo(this._assetList[this._assetNo]);
                                target.AssetName = fileinfo.Name;                                //.Substring(0, fileinfo.Name.Length - fileinfo.Extension.Length);
                            }
                            else
                            {
                                target.AssetName = null;
                            }
                            // on case "each assetbundle for asset", load different assetbundle for asset.
                            var assetbundle = data.assetbundles[this._assetbundleNo - 1];
                            if (assetbundle.Separated)
                            {
                                if (0 < this._assetNo)
                                {
                                    this.SetURL(target, assetbundle);
                                }
                                else
                                {
                                    target.SetURL(null);
                                }
                            }
                        }
                        EditorGUILayout.Separator();
                        target.InstantiateAfterLoad = EditorGUILayout.Toggle("Instantiate After Load", target.InstantiateAfterLoad);
                    }
                    else if (this._assetbundleNo != 0)
                    {
                        EditorGUILayout.HelpBox("This AssetBundle has no asset.", MessageType.Warning);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no AssetBundle.", MessageType.Error);
                }

                bool useCache = EditorGUILayout.Toggle("Use cache", 0 <= target.Version);
                ++EditorGUI.indentLevel;
                EditorGUI.BeginDisabledGroup(!useCache);
                if (useCache)
                {
                    if (target.Version < 0)
                    {
                        target.Version = 0;
                    }
                    target.Version = EditorGUILayout.IntField("Version", target.Version);
                }
                else
                {
                    target.Version = -1;
                }
                EditorGUI.EndDisabledGroup();
                --EditorGUI.indentLevel;
            }
            else
            {
                EditorGUILayout.HelpBox("Setting isn't complete.", MessageType.Error);
            }
            EditorUtility.SetDirty(target);
        }
Beispiel #2
0
        IEnumerator LoadAssetBundle(AssetBundleContainer bundle, string url, int version, uint crc)
        {
            WWW www = null;

            var path = Path.Combine(Path.GetDirectoryName(url), url.Substring(AssetBundleLoader.GetStreamingAssetsURL("").Length).Replace('/', '_'));

            path = path.Replace("\\", "/");

            if (0 <= version)
            {
                www = WWW.LoadFromCacheOrDownload(path, version, crc);
            }
            else
            {
                www = new WWW(path);
            }
            yield return(www);

            if (www.error != null)
            {
                Debug.Log(string.Format("AssetBundleManager:\n\tload \"{0}\" error:{1}", path, www.error));
                bundle.Initialize(path, null, null);
                bundle.SetError(www.error);
            }
            else
            {
                BundleAssetList list = null;
                if (Application.HasProLicense())
                {
#if UNITY_5
                    var request = www.assetBundle.LoadAssetAsync <BundleAssetList>("list");
#else
                    var request = www.assetBundle.LoadAsync("list", typeof(BundleAssetList));
#endif
                    yield return(request);

                    list = request.asset as BundleAssetList;
                }
                else
                {
#if UNITY_5
                    list = www.assetBundle.LoadAsset <BundleAssetList>("list");
#else
                    list = www.assetBundle.Load("list", typeof(BundleAssetList)) as BundleAssetList;
#endif
                }
                if (list)
                {
                    bundle.Initialize(path, www.assetBundle, list.Assets);
                }
                else
                {
                    //Debug.LogWarning( "There is no BundleAssetList in " + www.url );
                    bundle.Initialize(path, www.assetBundle, null);
                }
            }
            if (www != null)
            {
                www.Dispose();
            }
        }