示例#1
0
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dict = new Dictionary <string, object>();

            var dirPath = pack.GetPathForCategory <Texture2DCategory>();

            if (!pack.DirectoryExists(dirPath))
            {
                return(dict);
            }

            foreach (var texPath in pack.GetFiles(dirPath, ".png"))
            {
                LoadTexture(pack, dict, dirPath, texPath, true);
            }

            var localDir = dirPath + @"\Local";

            if (Directory.Exists(localDir))
            {
                foreach (var localTex in pack.GetFiles(localDir, ".png"))
                {
                    LoadTexture(pack, dict, localDir, localTex, false);
                }
            }

            return(dict);
        }
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dict = new Dictionary <string, object>();

            var dirPath = pack.GetPathForCategory <AudioClipCategory>();

            if (!pack.DirectoryExists(dirPath))
            {
                return(dict);
            }

            foreach (var clipPath in pack.GetFiles(dirPath, ".wav"))
            {
                //SL.Log($"Loading audio clip from '{clipPath}'");

                pack.LoadAudioClip(dirPath,
                                   Path.GetFileName(clipPath),
                                   (AudioClip clip) =>
                {
                    if (clip)
                    {
                        dict.Add(clipPath, clip);
                    }
                }
                                   );
            }

            return(dict);
        }
        private void DeserializePack(SLPack pack, List <ContentTemplate> list)
        {
            try
            {
                var dict = new Dictionary <string, object>();

                var dirPath = pack.GetPathForCategory(this.GetType());

                if (!pack.DirectoryExists(dirPath))
                {
                    return;
                }

                // load root directory templates
                foreach (var filepath in pack.GetFiles(dirPath, ".xml"))
                {
                    DeserializeTemplate(dirPath, filepath);
                }

                // load one-subfolder templates
                foreach (var subDir in pack.GetDirectories(dirPath))
                {
                    foreach (var filepath in pack.GetFiles(subDir, ".xml"))
                    {
                        DeserializeTemplate(subDir, filepath, subDir);
                    }
                }

                AddToSLPackDictionary(pack, dict);

                void DeserializeTemplate(string directory, string filepath, string subfolder = null)
                {
                    //SL.Log($@"Deserializing template from '{directory}\{filepath}'");

                    var template = pack.ReadXmlDocument <T>(directory, Path.GetFileName(filepath));

                    dict.Add(filepath, template);
                    list.Add(template);

                    template.SerializedSLPackName = pack.Name;
                    template.SerializedFilename   = Path.GetFileNameWithoutExtension(filepath);

                    if (!string.IsNullOrEmpty(subfolder))
                    {
                        template.SerializedSubfolderName = Path.GetFileName(subfolder);
                    }
                }
            }
            catch (Exception ex)
            {
                SL.LogWarning("Exception loading " + this.FolderName + " from '" + pack.Name + "'");
                SL.LogInnerException(ex);
            }
        }
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dict = new Dictionary <string, object>();

            // AssetBundle does not use hot reload at the moment.
            if (isHotReload)
            {
                return(dict);
            }

            var dirPath = pack.GetPathForCategory <AssetBundleCategory>();

            if (!pack.DirectoryExists(dirPath))
            {
                return(dict);
            }

            var fileQuery = pack.GetFiles(dirPath)
                            .Where(x => !x.EndsWith(".meta") &&
                                   !x.EndsWith(".manifest"));

            foreach (var bundlePath in fileQuery)
            {
                try
                {
                    string name = Path.GetFileName(bundlePath);

                    if (pack.LoadAssetBundle(dirPath, name) is AssetBundle bundle)
                    {
                        pack.AssetBundles.Add(name, bundle);

                        dict.Add(bundlePath, bundle);
                        SL.Log("Loaded assetbundle " + name);
                    }
                    else
                    {
                        throw new Exception($"Unknown error (Bundle '{Path.GetFileName(bundlePath)}' was null)");
                    }
                }
                catch (Exception e)
                {
                    SL.LogError("Error loading asset bundle! Message: " + e.Message + "\r\nStack: " + e.StackTrace);
                }
            }

            return(dict);
        }