internal static void Postfix(NGUIComponentInspector __instance) { if (__instance.ISerializable_ != null && __instance.ISerializable_.GetType() == typeof(ZEventListener)) { if (((ZEventListener)__instance.ISerializable_).eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { __instance.SetRemoveComponentButtonVisibility(false); } else if (((ZEventListener)__instance.ISerializable_).eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>())) { __instance.SetRemoveComponentButtonVisibility(false); } } }
static bool Prefix(NGUIComponentInspector __instance) { if (__instance.ISerializable_.GetType() == typeof(ZEventListener) && ((ZEventListener)__instance.ISerializable_).eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { EditorTools.RemoveMusicChoiceTool removeTool = G.Sys.LevelEditor_.StartNewToolJobOfType(typeof(EditorTools.RemoveMusicChoiceTool), false) as EditorTools.RemoveMusicChoiceTool; if (removeTool != null) { var ser = (ISerializable[])typeof(NGUIComponentInspector).GetField("iSerializables_", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); removeTool.SetComponents(ser.Cast <Component>().ToArray()); } return(false); } return(true); }
static void Postfix(NGUIComponentInspector __instance) { if (__instance.ISerializable_ != null && __instance.ISerializable_.GetType() == typeof(ZEventListener)) { if (((ZEventListener)__instance.ISerializable_).eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { typeof(NGUIComponentInspector).GetMethod("SetRemoveComponentButtonVisibility", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true }); } else if (((ZEventListener)__instance.ISerializable_).eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>())) { typeof(NGUIComponentInspector).GetMethod("SetRemoveComponentButtonVisibility", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { false }); } } }
internal static bool Prefix(NGUIComponentInspector __instance) { if (__instance.ISerializable_ is ZEventListener listener && listener.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { if (G.Sys.LevelEditor_.StartNewToolJobOfType(typeof(RemoveMusicChoiceTool), false) is RemoveMusicChoiceTool removeTool) { var ser = __instance.iSerializables_; removeTool.SetComponents(ser.Cast <Component>().ToArray()); } return(false); } return(true); }
internal static bool Prefix(ZEventListener __instance, IVisitor visitor) { Mod mod = Mod.Instance; if (!(visitor is NGUIComponentInspector)) { return(true); } NGUIComponentInspector inspector = visitor as NGUIComponentInspector; if (!__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { return(true); } visitor.Visit("eventName_", ref __instance.eventName_, false, null); visitor.Visit("delay_", ref __instance.delay_, false, null); var isEditing = inspector.isEditing_; var data = mod.Variables.CachedMusicChoice.GetOrCreate(__instance, () => new MusicChoice()); if (data.LastWrittenData != __instance.eventName_) { data.ReadObject(__instance); data.LastWrittenData = __instance.eventName_; data.LastWritten = data.Clone(); } else if (!isEditing) { var anyChanges = false; var old = data.LastWritten; if (data.Choices.Count != old.Choices.Count) { anyChanges = true; } foreach (var newChoice in data.Choices) { if (!old.Choices.ContainsKey(newChoice.Key) || old.Choices[newChoice.Key].Track != newChoice.Value.Track) { anyChanges = true; break; } } if (anyChanges) { data.WriteObject(__instance); data.LastWrittenData = __instance.eventName_; data.LastWritten = data.Clone(); } } for (int index = 0; index < data.Choices.Count; index++) { string key = data.Choices.Keys.ToArray()[index]; var track = data.Choices[key].Track; visitor.Visit($"{key} Track", ref track, null); } return(false); }
internal static bool Prefix(ZEventListener __instance, IVisitor visitor) { Mod mod = Mod.Instance; if (!(visitor is NGUIComponentInspector)) { return(true); } NGUIComponentInspector inspector = visitor as NGUIComponentInspector; if (!__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>())) { return(true); } visitor.Visit("eventName_", ref __instance.eventName_, false, null); visitor.Visit("delay_", ref __instance.delay_, false, null); var isEditing = inspector.isEditing_; var data = mod.Variables.CachedMusicTrack.GetOrCreate(__instance, () => new MusicTrack()); if (data.LastWrittenData != __instance.eventName_) { data.ReadObject(__instance); data.LastWrittenData = __instance.eventName_; data.EmbedFile = (data.Embedded.Length > 0 ? "Embedded" : ""); data.LastWritten = data.Clone(); } else if (!isEditing) { var anyChanges = false; var old = data.LastWritten; if (data.Name != old.Name || data.DownloadUrl != old.DownloadUrl || data.FileType != old.FileType) { anyChanges = true; } if (data.EmbedFile != old.EmbedFile) { var newRef = data.EmbedFile; if (newRef == "") { data.Embedded = new byte[0]; anyChanges = true; } else { try { newRef = newRef.Trim('"', '\''); var extension = Path.GetExtension(newRef); var file = FileEx.ReadAllBytes(newRef); data.Embedded = file ?? throw new Exception("Missing file"); data.FileType = extension; data.DownloadUrl = ""; anyChanges = true; } catch (Exception e) { data.Embedded = new byte[0]; data.FileType = ".mp3"; anyChanges = true; // TODO: warn user UnityEngine.Debug.Log($"Failed to embed {newRef} because {e}"); } } } if (anyChanges) { data.FileLocation = null; data.Attempted = false; data.EmbedFile = (data.Embedded.Length > 0 ? "Embedded" : ""); data.NewVersion(); data.WriteObject(__instance); data.LastWrittenData = __instance.eventName_; data.LastWritten = data.Clone(); var lastTrackName = mod.Variables.CurrentTrackName; if (lastTrackName == old.Name) { mod.SoundPlayer.StopCustomMusic(); } mod.SoundPlayer.DownloadAllTracks(); if (lastTrackName == data.Name || mod.SoundPlayer.GetMusicChoiceValue(G.Sys.LevelEditor_.WorkingSettings_.gameObject, "Level") == data.Name) { mod.SoundPlayer.PlayTrack(data.Name, 0f); } } } visitor.Visit("Name", ref data.Name, null); visitor.Visit("Type", ref data.FileType, null); visitor.Visit("Embed File", ref data.EmbedFile, mod.Variables.MusicTrackOptions); visitor.VisitAction("Select File", () => { var dlgOpen = new System.Windows.Forms.OpenFileDialog { Filter = "Music file (*.mp3, *.wav, *.aiff)|*.mp3;*.wav;*.aiff|All Files (*.*)|*.*", SupportMultiDottedExtensions = true, RestoreDirectory = true, Title = "Select a music file", CheckFileExists = true, CheckPathExists = true }; if (dlgOpen.ShowDialog() == System.Windows.Forms.DialogResult.OK) { data.EmbedFile = dlgOpen.FileName; } }, mod.Variables.MusicTrackButtonOptions); visitor.Visit("Download URL", ref data.DownloadUrl, null); var Error = data.GetError(); if (Error == null) { Error = "None"; } visitor.Visit("Error", ref Error, null); return(false); }