コード例 #1
0
 static void Postfix(ZEventListener __instance, IVisitor visitor)
 {
     if (!__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>()))
     {
         return;
     }
     CachedMusicChoice.GetOr(__instance, () => MusicChoice.FromObject(__instance));
 }
コード例 #2
0
            static bool Prefix(ZEventListener __instance, IVisitor visitor, ISerializable prefabComp, int version)
            {
                if (!(visitor is NGUIComponentInspector))
                {
                    return(true);
                }
                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 = (bool)typeof(NGUIComponentInspector).GetField("isEditing_", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(visitor);
                var data      = CachedMusicChoice.GetOr(__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();
                    }
                }

                foreach (var choice in data.Choices)
                {
                    visitor.Visit($"{choice.Key} Track", ref choice.Value.Track, null);
                }
                return(false);
            }
コード例 #3
0
 static bool Prefix(ZEventListener __instance, ref string __result)
 {
     if (__instance == null)
     {
         return(true);
     }
     if (__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>()))
     {
         __result = "Custom music track choice";
         return(false);
     }
     else if (__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>()))
     {
         __result = "Custom music track data";
         return(false);
     }
     return(true);
 }
コード例 #4
0
        public static string GetMusicChoiceValue(UnityEngine.GameObject obj, string key)
        {
            var listener = obj.GetComponent <ZEventListener>();

            if (listener == null || !listener.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>()))
            {
                return(null);
            }
            var choice = CachedMusicChoice.GetOr(listener, () => MusicChoice.FromObject(listener));

            if (choice == null)
            {
                return(null);
            }
            MusicChoiceEntry entry = null;

            choice.Choices.TryGetValue(key, out entry);
            if (entry == null)
            {
                return(null);
            }
            return(entry.Track);
        }
コード例 #5
0
            static bool Prefix(UnityEngine.GameObject gameObject, ref string __result)
            {
                if (gameObject == null)
                {
                    return(true);
                }
                var component = gameObject.GetComponent <ZEventListener>();

                if (component == null)
                {
                    return(true);
                }
                if (component.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>()))
                {
                    var track = Entry.CachedMusicTrack.GetOr(component, () => MusicTrack.FromObject(component));
                    if (track == null)
                    {
                        __result = "Music Track?";
                    }
                    __result = $"Music Track: {track.Name}";
                    return(false);
                }
                return(true);
            }
コード例 #6
0
            static bool Prefix(ZEventListener __instance, IVisitor visitor, ISerializable prefabComp, int version)
            {
                if (!(visitor is NGUIComponentInspector))
                {
                    return(true);
                }
                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 = (bool)typeof(NGUIComponentInspector).GetField("isEditing_", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(visitor);
                var data      = CachedMusicTrack.GetOr(__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 = CurrentTrackName;
                        if (lastTrackName == old.Name)
                        {
                            StopCustomMusic();
                        }
                        DownloadAllTracks();
                        if (lastTrackName == data.Name || GetMusicChoiceValue(G.Sys.LevelEditor_.WorkingSettings_.gameObject, "Level") == data.Name)
                        {
                            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, MusicTrackOptions);
                visitor.VisitAction("Select File", () =>
                {
                    var dlgOpen    = new System.Windows.Forms.OpenFileDialog();
                    dlgOpen.Filter = "Distance Music (*.mp3, *.wav, *.aiff)|*.mp3;*.wav;*.aiff|All Files (*.*)|*.*";
                    dlgOpen.SupportMultiDottedExtensions = true;
                    dlgOpen.RestoreDirectory             = true;
                    dlgOpen.Title           = "Pick Distance music file";
                    dlgOpen.CheckFileExists = true;
                    dlgOpen.CheckPathExists = true;
                    if (dlgOpen.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        data.EmbedFile = dlgOpen.FileName;
                    }
                }, 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);
            }
コード例 #7
0
 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);
 }
コード例 #8
0
 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 });
         }
     }
 }