public GameObject CreateTrack() { GameObject gameObject = Resource.LoadPrefabInstance("Group", true); gameObject.GetComponent <CustomName>().customName_ = "Music Track"; var component = gameObject.AddComponent <ZEventListener>(); var track = new MusicTrack() { Name = "Unknown" }; track.NewVersion(); track.WriteObject(component); gameObject.ForEachILevelEditorListener(delegate(ILevelEditorListener listener) { listener.LevelEditorStart(true); }); MonoBehaviour[] components = gameObject.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour monoBehaviour in components) { monoBehaviour.enabled = false; } LevelEditor editor = G.Sys.LevelEditor_; editor.AddGameObjectSilent(ref objectHandle, gameObject, null); return(gameObject); }
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); } }