// ReSharper disable once InconsistentNaming public void LoadSabers() { foreach (string sab in Plugin.RetrieveCustomSabers()) { var tempbundle = AssetBundle.LoadFromFile(sab); GameObject sabroot = tempbundle.LoadAsset <GameObject>("_customsaber"); SaberDescriptor tempdesciptor = sabroot.GetComponent <SaberDescriptor>(); CustomSaber tempsab = new CustomSaber(); if (tempdesciptor == null) { tempsab.Name = sab.Split('/').Last().Split('.').First(); tempsab.Author = "THIS SHOULD NEVER HAPPEN"; tempsab.Path = sab; } else { tempsab.Name = tempdesciptor.SaberName; tempsab.Author = tempdesciptor.AuthorName; tempsab.Path = sab; } _sabers.Add(tempsab); tempbundle.Unload(true); } Console.WriteLine("Added all sabers"); }
public static void LoadSabers() { Logger.Log("Loading sabers!"); _defaultImage = UIUtilities.LoadSpriteFromResources("CustomSaber.Resources.fa-magic.png"); _defaultImage.texture.wrapMode = TextureWrapMode.Clamp; _defaultImageError = UIUtilities.LoadSpriteFromResources("CustomSaber.Resources.fa-magic-error.png"); _defaultImageError.texture.wrapMode = TextureWrapMode.Clamp; var defaultSabersImageFolder = "CustomSaber.Resources.DefaultSabers"; var defaultSabersImagePaths = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(file => file.StartsWith(defaultSabersImageFolder)).ToList(); var r = new System.Random(); _defaultSabersImage = UIUtilities.LoadSpriteFromResources(defaultSabersImagePaths.ElementAt(r.Next(defaultSabersImagePaths.Count))); _defaultSabersImage.texture.wrapMode = TextureWrapMode.Clamp; if (_firstRun) { _firstRun = false; foreach (var sab in Plugin.RetrieveCustomSabers()) { var tempsab = new CustomSaber(); if (sab == "DefaultSabers") { AssetBundles.Add(null); tempsab.Name = "Default Sabers"; tempsab.Author = "Beat Games"; tempsab.CoverImage = _defaultSabersImage; tempsab.Path = "DefaultSabers"; tempsab.AssetBundle = null; tempsab.GameObject = null; } else { try { var tempbundle = AssetBundle.LoadFromFile(sab); AssetBundles.Add(tempbundle); var sabroot = tempbundle.LoadAsset <GameObject>("_CustomSaber"); var tempDescriptor = sabroot.GetComponent <SaberDescriptor>(); Logger.Log($"Loading {tempDescriptor?.SaberName}"); if (tempDescriptor == null) { Logger.Log($"SaberDescriptor not found for {sab}", Logger.LogLevel.Warning); tempsab.Name = sab.Split('/').Last().Split('.').First(); tempsab.Author = "THIS SHOULD NEVER HAPPEN"; tempsab.CoverImage = _defaultImageError; tempsab.Path = sab; tempsab.AssetBundle = null; tempsab.GameObject = null; } else { tempsab.Name = tempDescriptor.SaberName; tempsab.Author = tempDescriptor.AuthorName; if (tempDescriptor.CoverImage) { tempDescriptor.CoverImage.texture.wrapMode = TextureWrapMode.Clamp; } tempsab.CoverImage = (tempDescriptor.CoverImage) ? tempDescriptor.CoverImage : _defaultImage; tempsab.Path = sab; tempsab.AssetBundle = tempbundle; tempsab.GameObject = sabroot; } } catch (Exception ex) { Logger.Log($"Saber {sab} failed to load."); Logger.Log($"{ex.Message}\n{ex.StackTrace}", Logger.LogLevel.Warning); tempsab.Name = "This saber is broken, delete it."; tempsab.Author = sab.Split('/').Last();//.Split('.').First(); tempsab.CoverImage = _defaultImageError; tempsab.Path = sab; tempsab.AssetBundle = null; tempsab.GameObject = null; } } AllSabers.Add(tempsab); } } else { foreach (var tempsab in AllSabers) { if (tempsab.Path != "DefaultSabers") { var tempbundle = AssetBundle.LoadFromFile(tempsab.Path); var sabroot = tempbundle.LoadAsset <GameObject>("_customsaber"); var tempdesciptor = sabroot.GetComponent <SaberDescriptor>(); if (tempdesciptor == null) { tempsab.AssetBundle = null; tempsab.GameObject = null; } else { tempsab.AssetBundle = tempbundle; tempsab.GameObject = sabroot; } } } } Logger.Log($"Added {AllSabers.Count - 1} sabers"); }
// ReSharper disable once InconsistentNaming public void LoadSabers(bool FirstRun) { Console.WriteLine("Loading sabers!"); if (FirstRun) { foreach (string sab in Plugin.RetrieveCustomSabers()) { CustomSaber tempsab = new CustomSaber(); if (sab == "DefaultSabers") { tempsab.Name = "Default Sabers"; tempsab.Author = "Beat Games"; tempsab.Path = "DefaultSabers"; tempsab.AssetBundle = null; tempsab.GameObject = null; } else { try { AssetBundle tempbundle = AssetBundle.LoadFromFile(sab); GameObject sabroot = tempbundle.LoadAsset <GameObject>("_customsaber"); SaberDescriptor tempdesciptor = sabroot.GetComponent <SaberDescriptor>(); if (tempdesciptor == null) { tempsab.Name = sab.Split('/').Last().Split('.').First(); tempsab.Author = "THIS SHOULD NEVER HAPPEN"; tempsab.Path = sab; tempsab.AssetBundle = null; tempsab.GameObject = null; } else { tempsab.Name = tempdesciptor.SaberName; tempsab.Author = tempdesciptor.AuthorName; tempsab.Path = sab; tempsab.AssetBundle = tempbundle; tempsab.GameObject = sabroot; } } catch (Exception e) { Console.WriteLine(e); tempsab.Name = "This saber is broken, delete it."; tempsab.Author = sab.Split('/').Last();//.Split('.').First(); tempsab.Path = sab; tempsab.AssetBundle = null; tempsab.GameObject = null; } } _sabers.Add(tempsab); } } else { foreach (CustomSaber tempsab in _sabers) { if (tempsab.Path != "DefaultSabers") { var tempbundle = AssetBundle.LoadFromFile(tempsab.Path); GameObject sabroot = tempbundle.LoadAsset <GameObject>("_customsaber"); SaberDescriptor tempdesciptor = sabroot.GetComponent <SaberDescriptor>(); if (tempdesciptor == null) { tempsab.AssetBundle = null; tempsab.GameObject = null; } else { tempsab.AssetBundle = tempbundle; tempsab.GameObject = sabroot; } } } } Console.WriteLine("Added all sabers"); }