Ejemplo n.º 1
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);
                }
            }
        protected AddOrRemoveMusicChoiceAction(GameObject gameObject, ZEventListener comp)
        {
            ReferenceMap referenceMap_ = G.Sys.LevelEditor_.ReferenceMap_;

            originalHandle       = referenceMap_.GetHandleOrNull(gameObject);
            newHandle            = referenceMap_.GetHandleOrNull <GameObject>(null);
            addedComponentHandle = referenceMap_.GetHandleOrNull(comp);
            isAdd = (comp == null);
            if (!isAdd)
            {
                componentBytes = Serializers.BinarySerializer.SaveComponentToBytes(comp, null);
            }
        }