コード例 #1
0
        public static MusicChoice FromObject(ZEventListener obj)
        {
            var newThis = new MusicChoice();
            var success = newThis.ReadObject(obj);

            return(success ? newThis : null);
        }
コード例 #2
0
 static void Postfix(ZEventListener __instance, IVisitor visitor)
 {
     if (!__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>()))
     {
         return;
     }
     CachedMusicChoice.GetOr(__instance, () => MusicChoice.FromObject(__instance));
 }
コード例 #3
0
            private void AddOrRemove(ReferenceMap.Handle <GameObject> beforeHandle, ref ReferenceMap.Handle <GameObject> afterHandle, bool add)
            {
                LevelEditor    editor     = G.Sys.LevelEditor_;
                GameObject     gameObject = beforeHandle.Get();
                ZEventListener comp       = (!add) ? addedComponentHandle.Get() : ((ZEventListener)((object)null));

                if (!gameObject.HasComponent <LevelSettings>())
                {
                    editor.RemoveGameObjectSilent(gameObject);
                }
                if (add)
                {
                    comp = gameObject.AddComponent <ZEventListener>();
                    var choice = new MusicChoice();
                    if (gameObject.HasComponent <LevelSettings>())
                    {
                        choice.Choices.Add("Level", new MusicChoiceEntry(""));
                    }
                    if (gameObject.HasComponent <MusicTrigger>())
                    {
                        choice.Choices.Add("Trigger", new MusicChoiceEntry(""));
                    }
                    if (gameObject.HasComponent <MusicZone>())
                    {
                        choice.Choices.Add("Zone", new MusicChoiceEntry(""));
                    }
                    choice.WriteObject(comp);
                    if (componentBytes != null)
                    {
                        Serializers.BinaryDeserializer.LoadComponentContentsFromBytes(comp, null, componentBytes);
                    }
                    comp.enabled = false;
                }
                else if (comp)
                {
                    comp.Destroy();
                }
                if (gameObject.HasComponent <LevelSettings>())
                {
                    EditorPatches.NeedsRefresh = true;
                }
                if (!gameObject.HasComponent <LevelSettings>())
                {
                    editor.AddGameObjectSilent(ref afterHandle, gameObject, editor.WorkingLevel_.GetLayerOfObject(gameObject));
                }
                addedComponentHandle = (!add) ? default(ReferenceMap.Handle <ZEventListener>) : editor.ReferenceMap_.GetHandleOrNull(comp);
                gameObject.ForEachILevelEditorListenerInChildren(listener => listener.OnLevelEditorToolFinish());
                Events.StaticEvent <ObjectHadComponentAddedOrRemoved.Data> .Broadcast(new ObjectHadComponentAddedOrRemoved.Data(gameObject));

                if (!gameObject.HasComponent <LevelSettings>())
                {
                    editor.SelectObject(gameObject);
                }
            }
コード例 #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);
        }