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 dir = pack.GetPathForCategory <PackBundleCategory>(); if (!Directory.Exists(dir)) { return(null); } foreach (var bundlePath in Directory.GetFiles(dir)) { try { SL.Log("Loading Pack AssetBundle: " + bundlePath); var assetbundle = AssetBundle.LoadFromFile(bundlePath); var bundlePack = new SLPackBundle(Path.GetFileName(bundlePath), pack, assetbundle); pack.PackBundles.Add(bundlePack.Name, bundlePack); s_loadedBundles.Add(bundlePath, bundlePack); //SL.Log($"Added bundle '{bundlePack.Name}' to pack '{pack.Name}' (Bundle count: {pack.PackBundles.Count})"); } catch (Exception ex) { SL.LogWarning("Exception loading Pack Bundle: " + bundlePath); SL.LogInnerException(ex); } } return(null); }
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); }
internal void Save() { if (RefPack == null) { SL.LogWarning("Error - RefPack is null on TemplateInspector.Save!"); return; } var directory = RefPack.GetPathForCategory(Template.PackCategory.GetType()); if (Template.TemplateAllowedInSubfolder && !string.IsNullOrEmpty(this.Template.SerializedSubfolderName)) { directory += $@"\{this.Template.SerializedSubfolderName}"; } if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); Serializer.SaveToXml(directory, this.Template.SerializedFilename, Target); }
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); }
private void ConstructGenerator(GameObject leftPane) { m_generateObj = UIFactory.CreateVerticalGroup(leftPane, new Color(0.1f, 0.1f, 0.1f)); var genLabelObj = UIFactory.CreateLabel(m_generateObj, TextAnchor.MiddleLeft); m_generatorTitle = genLabelObj.GetComponent <Text>(); m_generatorTitle.text = "Template Generator"; m_generatorTitle.fontSize = 16; // Generator dropdown type // (callback added below) var genDropObj = UIFactory.CreateDropdown(m_generateObj, out m_genDropdown); var genDropLayout = genDropObj.AddComponent <LayoutElement>(); genDropLayout.minHeight = 25; var genGroupLayout = m_generateObj.AddComponent <LayoutElement>(); genGroupLayout.minHeight = 50; genGroupLayout.flexibleWidth = 9999; var genGroup = m_generateObj.GetComponent <VerticalLayoutGroup>(); genGroup.childForceExpandHeight = true; genGroup.childForceExpandWidth = true; genGroup.padding = new RectOffset(3, 3, 3, 3); genGroup.spacing = 5; // Generator input field for target var targetInputFieldObj = UIFactory.CreateInputField(m_generateObj, 14, 3, 0, typeof(AutoCompleteInputField)); targetInputFieldObj.name = "AutoCompleterInput"; m_generatorTargetInput = targetInputFieldObj.GetComponent <AutoCompleteInputField>(); (m_generatorTargetInput.placeholder as Text).text = "Clone target ID"; var genTargetLayout = m_generatorTargetInput.gameObject.AddComponent <LayoutElement>(); genTargetLayout.minHeight = 25; m_generatorTargetInput.onValueChanged.AddListener((string val) => { UpdateAutocompletes(); }); // subfolder input field var subfolderInputObj = UIFactory.CreateInputField(m_generateObj); var subfolderLayout = subfolderInputObj.AddComponent <LayoutElement>(); subfolderLayout.minHeight = 25; var subfolderInput = subfolderInputObj.GetComponent <InputField>(); (subfolderInput.placeholder as Text).text = "Subfolder (blank for auto)"; // add this generator callback now that subfolder has been declared m_genDropdown.onValueChanged.AddListener((int val) => { m_currentGeneratorType = s_currentTemplateTypes[val]; targetInputFieldObj.SetActive(CanSelectedTypeCloneFromTarget()); subfolderInputObj.SetActive(CanSelectedTypeBeInSubfolder()); }); // name input var nameInputObj = UIFactory.CreateInputField(m_generateObj); var nameLayout = nameInputObj.AddComponent <LayoutElement>(); nameLayout.minHeight = 25; var nameInput = nameInputObj.GetComponent <InputField>(); (nameInput.placeholder as Text).text = "Filename (blank for auto)"; bool exportIconsWanted = true; bool exportTexturesWanted = true; var toggleIconObj = UIFactory.CreateToggle(m_generateObj, out Toggle toggleIcon, out Text toggleIconTxt); var iconLayout = toggleIconObj.AddComponent <LayoutElement>(); iconLayout.minHeight = 25; toggleIconTxt.text = "Export Icons if possible?"; toggleIcon.onValueChanged.AddListener((bool val) => { exportIconsWanted = val; }); var toggleTexObj = UIFactory.CreateToggle(m_generateObj, out Toggle toggleTex, out Text toggleTexText); var toggleTexLayout = toggleTexObj.AddComponent <LayoutElement>(); toggleTexLayout.minHeight = 25; toggleTexText.text = "Export Textures if possible?"; toggleTex.onValueChanged.AddListener((bool val) => { exportTexturesWanted = val; }); // generate button var genBtnObj = UIFactory.CreateButton(m_generateObj, new Color(0.15f, 0.45f, 0.15f)); var genBtnLayout = genBtnObj.AddComponent <LayoutElement>(); genBtnLayout.minHeight = 25; var genBtn = genBtnObj.GetComponent <Button>(); genBtn.onClick.AddListener(() => { if (m_currentPack == null) { SL.LogWarning("Cannot generate a template without an inspected SLPack!"); return; } var newTemplate = (ContentTemplate)Activator.CreateInstance(this.m_currentGeneratorType); if (newTemplate.CanParseContent) { var content = newTemplate.GetContentFromID(m_generatorTargetInput.text); if (content != null && newTemplate.ParseToTemplate(content) is ContentTemplate parsed) { newTemplate = parsed; } else if (!newTemplate.DoesTargetExist) { SL.LogWarning("Could not find any content from target ID '" + m_generatorTargetInput.text + "'"); newTemplate = null; } } if (newTemplate != null) { if (!CheckTemplateName(newTemplate, subfolderInput, nameInput)) { SL.LogWarning("A folder/filename already exists with that name, try again"); return; } // EXPORT ICONS/TEXTURES IF ITEM/STATUS/IMBUE if (exportIconsWanted || exportTexturesWanted) { if (newTemplate is SL_Item slitem) { if (string.IsNullOrEmpty(slitem.SerializedSubfolderName)) { SL.LogWarning("You need to set a subfolder name to export icons/textures!"); return; } var item = ResourcesPrefabManager.Instance.GetItemPrefab(slitem.Target_ItemID); var dir = m_currentPack.GetPathForCategory <ItemCategory>(); dir += $@"\{slitem.SerializedSubfolderName}\Textures"; if (exportIconsWanted) { SL_Item.SaveItemIcons(item, dir); } if (exportTexturesWanted) { SL_Item.SaveItemTextures(item, dir, out slitem.m_serializedMaterials); } } else if (exportIconsWanted && newTemplate is SL_StatusBase slstatus) { var template = slstatus as ContentTemplate; if (string.IsNullOrEmpty(template.SerializedSubfolderName)) { SL.LogWarning("You need to set a subfolder name to export icons!"); return; } var dir = m_currentPack.GetPathForCategory <StatusCategory>(); dir += $@"\{template.SerializedSubfolderName}"; Component comp; if (template is SL_StatusEffect sl_Status) { comp = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(sl_Status.TargetStatusIdentifier); } else { comp = ResourcesPrefabManager.Instance.GetEffectPreset((template as SL_ImbueEffect).TargetStatusID) as ImbueEffectPreset; } slstatus.ExportIcons(comp, dir); } } var inspector = InspectorManager.Instance.Inspect(newTemplate, m_currentPack); (inspector as TemplateInspector).Save(); } }); var genBtnText = genBtnObj.GetComponentInChildren <Text>(); genBtnText.text = "Create Template"; }