private void InitPreviewToolbar() { #region Scale m_ScaleSlider = m_RootElement.Q <SliderInt>("scale-slider"); m_ScaleSlider.lowValue = kScaleMin; m_ScaleSlider.highValue = kScaleMax; m_ScaleSlider.value = m_Scale; m_ScaleSlider.RegisterCallback <ChangeEvent <int> >(SetScale); m_ScaleValueLabel = m_RootElement.Q <Label>("scale-value-label"); m_ScaleValueLabel.text = m_Scale.ToString(); m_FitToScreenToggle = m_RootElement.Q <ToolbarToggle>("fit-to-screen"); m_FitToScreenToggle.RegisterValueChangedCallback(FitToScreen); m_FitToScreenToggle.SetValueWithoutNotify(m_FitToScreenEnabled); #endregion #region Rotate var namePostfix = EditorGUIUtility.isProSkin ? "_dark" : "_light"; const string iconPath = "packages/com.unity.device-simulator/Editor/icons"; m_RootElement.Q <Image>("rotate-cw-image").image = AssetDatabase.LoadAssetAtPath <Texture2D>($"{iconPath}/rotate_cw{namePostfix}.png"); m_RootElement.Q <VisualElement>("rotate-cw").AddManipulator(new Clickable(RotateDeviceCW)); m_RootElement.Q <Image>("rotate-ccw-image").image = AssetDatabase.LoadAssetAtPath <Texture2D>($"{iconPath}/rotate_ccw{namePostfix}.png"); m_RootElement.Q <VisualElement>("rotate-ccw").AddManipulator(new Clickable(RotateDeviceCCW)); #endregion // Highlight safe area. var highlightSafeAreaToggle = m_RootElement.Q <Toggle>("highlight-safe-area"); highlightSafeAreaToggle.RegisterValueChangedCallback((evt) => { m_HighlightSafeArea = evt.newValue; OnStateChanged(); }); highlightSafeAreaToggle.SetValueWithoutNotify(m_HighlightSafeArea); }
public override VisualElement CreateInspectorGUI() { var rootView = new VisualElement(); string pathUxml = PackagePath + "Editor/MeshSubdivisionRenderer.uxml"; string pathUss = PackagePath + "Editor/MeshSubdivisionRenderer.uss"; var treeAsset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(pathUxml); var styleAsset = AssetDatabase.LoadAssetAtPath <StyleSheet>(pathUss); treeAsset.CloneTree(rootView); rootView.styleSheets.Add(styleAsset); _meshTypeEnum = rootView.Q <EnumField>("enumMeshType"); _meshTypeEnum.Init(MeshTypeInEditor.Quad); _meshTypeEnum.value = GetMeshType((Mesh)_meshProp.objectReferenceValue); _meshTypeEnum.RegisterCallback <ChangeEvent <Enum> >( (evt) => OnChangeMesh(evt.newValue)); _meshShadingEnum = rootView.Q <EnumField>("enumMeshShading"); _meshShadingEnum.Init(MeshShading.Lit); _meshShadingEnum.value = GetMeshShading(); _meshShadingEnum.RegisterCallback <ChangeEvent <Enum> >( (evt) => OnChangeMeshShading(evt.newValue)); _subdInterpEnum = rootView.Q <EnumField>("enumSubdInterp"); _subdInterpEnum.Init(SubdInterp.None); _subdInterpEnum.value = GetSubdInterp(); _subdInterpEnum.RegisterCallback <ChangeEvent <Enum> >( (evt) => OnChangeSubdInterp(evt.newValue)); _castShadowsToggle = rootView.Q <Toggle>("toggleCastShadows"); _castShadowsToggle.value = _castShadowsProp.boolValue; _castShadowsToggle.RegisterCallback <ChangeEvent <bool> >( (evt) => OnChangeCastShadows(evt.newValue)); _cullingToggle = rootView.Q <Toggle>("toggleCulling"); _cullingToggle.value = _enableCullingProp.boolValue; _cullingToggle.RegisterCallback <ChangeEvent <bool> >( (evt) => OnChangeDoCulling(evt.newValue)); _targetPixelSlider = rootView.Q <SliderInt>("sliderTargetPixel"); _targetPixelSlider.value = _targetPixelSizeProp.intValue; _targetPixelSlider.RegisterCallback <ChangeEvent <int> >( (evt) => OnChangeTargetPixelSize(evt.newValue)); _targetPixelText = rootView.Q <TextField>("textTargetPixel"); _targetPixelText.value = _targetPixelSizeProp.intValue.ToString(); _targetPixelText.RegisterCallback <ChangeEvent <string> >( (evt) => OnChangeTargetPixelSize(evt.newValue)); _debugCameraObject = rootView.Q <ObjectField>("objectDebugCamera"); _debugCameraObject.objectType = typeof(Camera); _debugCameraObject.value = _debugCameraProp.objectReferenceValue; _debugCameraObject.RegisterCallback <ChangeEvent <UnityEngine.Object> >( (evt) => OnChangeDebugCamera(evt.newValue)); return(rootView); }
public void OnEnable() { var root = this.rootVisualElement; root.style.paddingTop = new StyleLength(10f); root.style.paddingBottom = new StyleLength(10f); root.style.paddingLeft = new StyleLength(10f); root.style.paddingRight = new StyleLength(10f); UnityEngine.UIElements.Toggle hideSliderBool = new Toggle("Hide Slider!"); root.Add(hideSliderBool); var label = new Label(0.ToString()); root.Add(label); SliderInt slider = new SliderInt(); root.Add(slider); // Add slider as a child of root. slider.RegisterCallback <ChangeEvent <int> >(evt => { label.text = evt.newValue.ToString(); }); hideSliderBool.RegisterCallback <ChangeEvent <bool> >(evt => { // You want to easily hide/show dynamically... if (hideSliderBool.value) { slider.style.display = UnityEngine.UIElements.DisplayStyle.None; } else { slider.style.display = UnityEngine.UIElements.DisplayStyle.Flex; } }); // Or, once you're done with this element. Make it go away. //Button removeSliderButton = new Button(Hej); Button removeSliderButton = new Button(() => slider.RemoveFromHierarchy()); removeSliderButton.text = "Remove Slider?"; root.Add(removeSliderButton); // Add slider again Button addSliderButton = new Button(() => root.Add(slider)); addSliderButton.text = "Add Slider?"; root.Add(addSliderButton); }
protected SliderInt addSlider(ref VisualElement dataRoot, int minVal, int maxVal, string label, string bindingPath) { dataRoot.Add(new Spacer(30)); var slider = new SliderInt(minVal, maxVal); var sliderLabel = new Label(label + slider.value); dataRoot.Add(sliderLabel); slider.RegisterCallback <ChangeEvent <int> >((evt) => { sliderLabel.text = label + slider.value; }); slider.bindingPath = bindingPath; dataRoot.Add(slider); return(slider); }
public void OnEnable() { VisualElement root = rootVisualElement; VisualElement vt = Resources.Load <VisualTreeAsset>("Editor/SDFWizardMarkup").Instantiate(); vt.styleSheets.Add(Resources.Load <StyleSheet>("Editor/SDFWizardStyle")); root.Add(vt); Label dLabel = vt.Q <Label> (null, "dLabel"); Image dropBox = vt.Q <Image> ("DropBox"); SliderInt sizeSlider = vt.Q <SliderInt> ("SizeSlider"); IntegerField sizeField = vt.Q <IntegerField> ("SizeField"); Slider tresholdSlider = vt.Q <Slider> ("TresholdSlider"); FloatField tresholdField = vt.Q <FloatField> ("TresholdField"); SliderInt sampleSlider = vt.Q <SliderInt> ("SampleSlider"); IntegerField sampleField = vt.Q <IntegerField> ("SampleField"); EnumField channelSelect = vt.Q <EnumField> ("ChannelSelect"); Box channelDisplay = vt.Q <Box> ("ChannelDisplay"); EnumField modeSelect = vt.Q <EnumField> ("RenderingSelect"); EnumField tilingSelect = vt.Q <EnumField> ("TilingSelect"); channelSelect.Init(WizardUtils.ColorChannel.Alpha); modeSelect.Init(SDFConverter.RenderingMode.DistanceOnly); tilingSelect.Init(TextureWrapMode.Repeat); bool validated = false; dropBox.RegisterCallback <DragEnterEvent>((e) => { foreach (var item in DragAndDrop.objectReferences) { if (item.GetType() == typeof(Texture2D)) { validated = true; } } dropBox.tintColor = validated ? new Color(.6f, .94f, .2f) : new Color(.94f, .3f, .2f); dLabel.style.color = validated ? new Color(.6f, .94f, .2f) : new Color(.94f, .3f, .2f); }); dropBox.RegisterCallback <DragUpdatedEvent>((e) => { if (validated) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } }); dropBox.RegisterCallback <DragPerformEvent>((e) => { if (validated) { for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) { var item = (UnityEngine.Object)DragAndDrop.objectReferences[i]; string path = DragAndDrop.paths[i]; if (item.GetType() == typeof(Texture2D)) { string newPath = path.Substring(0, path.LastIndexOf(".")) + "_SDF.png"; string systemPath = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + newPath; var texture = item as Texture2D; texture.wrapMode = (TextureWrapMode)tilingSelect.value; var outData = SDFConverter.RenderSDF(texture, sizeField.value, tresholdField.value, sampleField.value, channelSelect.value, modeSelect.value); System.IO.File.WriteAllBytes(systemPath, outData.EncodeToPNG()); AssetDatabase.Refresh(); var importer = (TextureImporter)AssetImporter.GetAtPath(newPath); var importerSettings = new TextureImporterSettings(); ((TextureImporter)AssetImporter.GetAtPath(path)).ReadTextureSettings(importerSettings); importer.SetTextureSettings(importerSettings); importer.sRGBTexture &= modeSelect.value.Equals(SDFConverter.RenderingMode.RGBDistance); importer.textureCompression = TextureImporterCompression.Uncompressed; importer.SaveAndReimport(); AssetDatabase.ImportAsset(newPath); } } } }); dropBox.RegisterCallback <DragExitedEvent>((e) => { validated = false; dropBox.tintColor = Color.white; dLabel.style.color = Color.white; }); dropBox.RegisterCallback <DragLeaveEvent>((e) => { validated = false; dropBox.tintColor = Color.white; dLabel.style.color = Color.white; }); sizeSlider.RegisterCallback <ChangeEvent <int> >((e) => { sizeField.value = 2 << e.newValue; }); sizeField.RegisterCallback <ChangeEvent <int> >((e) => { int c = 0; int v = e.newValue; while (v > 2) { c++; v >>= 1; } sizeSlider.value = c; sizeField.value = 2 << c; }); tresholdSlider.RegisterCallback <ChangeEvent <float> >((e) => { tresholdField.value = 1f - e.newValue; }); tresholdField.RegisterCallback <ChangeEvent <float> >((e) => { tresholdSlider.value = 1f - e.newValue; }); sampleSlider.RegisterCallback <ChangeEvent <int> >((e) => { sampleField.value = e.newValue; }); sampleField.RegisterCallback <ChangeEvent <int> >((e) => { sampleSlider.value = e.newValue; }); channelSelect.RegisterCallback <ChangeEvent <Enum> >((e) => { switch (e.newValue) { case WizardUtils.ColorChannel.Red: channelDisplay.style.backgroundColor = new Color(.94f, .3f, .2f); break; case WizardUtils.ColorChannel.Green: channelDisplay.style.backgroundColor = new Color(.6f, .94f, .2f); break; case WizardUtils.ColorChannel.Blue: channelDisplay.style.backgroundColor = new Color(.2f, .6f, .94f); break; case WizardUtils.ColorChannel.Alpha: channelDisplay.style.backgroundColor = Color.grey; break; default: channelDisplay.style.backgroundColor = Color.white; break; } }); }
public NoteSubEditor(OrbitLineSubEditor orbitLineSubEditor, Note note) { this.orbitLineSubEditor = orbitLineSubEditor; this.note = note; VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Examples/StarSystemScene/Scripts/Editor/StarSystemEditor/NoteSubEditor.uxml"); visualTree.CloneTree(this); StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/StarSystemScene/Scripts/Editor/StarSystemEditor/NoteSubEditor.uss"); this.styleSheets.Add(stylesheet); this.AddToClassList("noteSubeditor"); #region Fields SliderInt octave = this.Query <SliderInt>("octave").First(); octave.value = note.octave; octave.RegisterCallback <ChangeEvent <int> >( e => { note.octave = e.newValue; EditorUtility.SetDirty(note); } ); // Find an object field with the name and set the type ObjectField synthPrefab = this.Query <ObjectField>("synthPrefab").First(); synthPrefab.objectType = typeof(GameObject); synthPrefab.value = note.synth; synthPrefab.RegisterCallback <ChangeEvent <Object> >( e => { note.synth = (GameObject)e.newValue; EditorUtility.SetDirty(note); } ); Slider velocity = this.Query <Slider>("velocity").First(); velocity.value = note.velocity; velocity.label = "Velocity " + velocity.value.ToString("F3"); velocity.RegisterCallback <ChangeEvent <float> >( e => { note.velocity = e.newValue; velocity.label = "Velocity " + e.newValue.ToString("F3"); EditorUtility.SetDirty(note); } ); Slider length = this.Query <Slider>("length").First(); length.value = note.length; length.label = "Length " + length.value.ToString("F3"); length.RegisterCallback <ChangeEvent <float> >( e => { note.length = e.newValue; length.label = "Length " + e.newValue.ToString("F3"); EditorUtility.SetDirty(note); } ); Slider size = this.Query <Slider>("size").First(); size.value = note.size; size.label = "Size " + size.value.ToString("F3"); size.RegisterCallback <ChangeEvent <float> >( e => { note.size = e.newValue; size.label = "Size " + e.newValue.ToString("F3"); EditorUtility.SetDirty(note); } ); EnumField noteValue = this.Query <EnumField>("noteValue").First(); noteValue.value = note.note; noteValue.RegisterCallback <ChangeEvent <System.Enum> >( e => { note.note = (NoteValue)e.newValue; EditorUtility.SetDirty(note); } ); #endregion #region Buttons Button btnRemoveNote = this.Query <Button>("btnRemove").First(); btnRemoveNote.clickable.clicked += RemoveNote; #endregion }
public void OnEnable() { VisualElement root = this.rootVisualElement; root.style.flexDirection = FlexDirection.Row; root.style.paddingTop = 20; root.style.paddingBottom = 20; VisualElement gameRoot = new VisualElement() { style = { width = width * 0.22f, paddingRight = 20, paddingLeft = 20 } }; VisualElement mapRoot = new VisualElement() { style = { alignContent = Align.Center, width = width * 0.56f } }; VisualElement levelRoot = new VisualElement() { style = { width = width * 0.22f, paddingLeft = 20, paddingRight = 20 } }; root.Add(gameRoot); root.Add(mapRoot); root.Add(levelRoot); //game root { gameRoot.Add(new Label("Choose a Gauntlet Game:")); gameData = new ObjectField(); gameData.objectType = typeof(GauntletGame); gameRoot.Add(gameData); gameData.RegisterCallback <ChangeEvent <UnityEngine.Object> >((evt) => { var change = (evt.target as ObjectField).value; game = change as GauntletGame; levelData.value = null; playerData.value = null; rebindLevelListView(); }); Button createGameButton = new Button(() => { var newGame = CreateInstance <GauntletGame>(); var path = "Assets/Resources/Gauntlet/GameData"; AssetDatabase.CreateAsset(newGame, AssetDatabase.GenerateUniqueAssetPath(path + "/GameData-00.asset")); EditorUtility.SetDirty(newGame); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); gameData.value = newGame; }); createGameButton.text = "Create New Game"; gameRoot.Add(createGameButton); Button saveDataButton = new Button(() => { if (game != null) { var path = EditorUtility.OpenFolderPanel("Export Game Data", "", ""); if (path == null) { return; } if (path.Length != 0) { game.saveGameData(path); } } }); saveDataButton.text = "Save Game Data"; gameRoot.Add(saveDataButton); VisualElement levelListDataRoot = new VisualElement() { style = { flexDirection = FlexDirection.Row, paddingTop = 20, paddingBottom = 40, height = 300 } }; VisualElement levelListRoot = new VisualElement() { style = { flexGrow = 0.75f } }; VisualElement levelButtonsRoot = new VisualElement() { style = { flexGrow = 0.25f, justifyContent = Justify.Center, paddingLeft = 10, paddingRight = 10 } }; levelListDataRoot.Add(levelListRoot); levelListDataRoot.Add(levelButtonsRoot); gameRoot.Add(levelListDataRoot); Label levelLabel = new Label("List of Levels:"); levelListRoot.Add(levelLabel); levelListRoot.Add(createLevelListView()); Button upButton = new Button(() => { if (game != null) { int newIndex = game.changeLevelOrder(levelListView.selectedIndex, true); rebindLevelListView(); levelListView.selectedIndex = newIndex; } }); Button downButton = new Button(() => { if (game != null) { int newIndex = game.changeLevelOrder(levelListView.selectedIndex, false); rebindLevelListView(); levelListView.selectedIndex = newIndex; } }); Button removeButton = new Button(() => { if (game != null && levelListView.selectedIndex >= 0) { game.levels.RemoveAt(levelListView.selectedIndex); rebindLevelListView(); } }); Button editButton = new Button(() => { if (game != null && levelListView.selectedIndex >= 0) { levelData.value = game.levels[levelListView.selectedIndex]; } }); upButton.text = "Move Up"; downButton.text = "Move Down"; removeButton.text = "Remove"; editButton.text = "Edit"; levelButtonsRoot.Add(upButton); levelButtonsRoot.Add(downButton); levelButtonsRoot.Add(removeButton); levelButtonsRoot.Add(editButton); gameRoot.Add(new Label("Choose a Player for this Game:")); playerData = new ObjectField(); playerData.objectType = typeof(Player); gameRoot.Add(playerData); playerData.RegisterCallback <ChangeEvent <UnityEngine.Object> >((evt) => { var change = (evt.target as ObjectField).value; if (game) { game.playerObject = change as Player; } }); // Level gameRoot.Add(new Label("Choose a Level to edit:")); levelData = new ObjectField(); levelData.objectType = typeof(GauntletLevel); gameRoot.Add(levelData); gameRoot.Add(new Label("Level Name:")); levelData.RegisterCallback <ChangeEvent <UnityEngine.Object> >((evt) => { var change = (evt.target as ObjectField).value; level = change as GauntletLevel; UpdateLevelBinding(); tileMap.createGrid(level); }); var levelName = new TextField(); levelName.bindingPath = "levelName"; gameRoot.Add(levelName); Button addLevelButton = new Button(() => { if (game != null && level != null) { game.levels.Add(level); EditorUtility.SetDirty(game); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); rebindLevelListView(); } }); addLevelButton.text = "Add Level To Game"; gameRoot.Add(addLevelButton); // New Level Button newLevelButton = new Button(() => { var newLevel = CreateInstance <GauntletLevel>(); newLevel.initialize("TestLevel", levelSizeSlider.value, 570); var path = "Assets/Resources/Gauntlet/LevelData"; AssetDatabase.CreateAsset(newLevel, AssetDatabase.GenerateUniqueAssetPath(path + "/LevelData-00.asset")); EditorUtility.SetDirty(newLevel); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); levelData.value = newLevel; }); newLevelButton.text = "Create New Level"; newLevelButton.style.marginTop = 40; gameRoot.Add(newLevelButton); levelSizeSlider = new SliderInt(5, 35); levelSizeSlider.value = 20; var levelSizeLabel = new Label("Size of New Level:" + levelSizeSlider.value); gameRoot.Add(levelSizeLabel); levelSizeSlider.RegisterCallback <ChangeEvent <int> >((evt) => { levelSizeLabel.text = "Size of New Level: " + evt.newValue; }); gameRoot.Add(levelSizeSlider); } tileMap = new TileMap(); tileMap.levelEditor = this; mapRoot.Add(tileMap.gridContainer); // Level Root levelRoot.Add(new Label("Choose a prefab to place:")); MapPrefabTypesField = new EnumField(MapPrefabTypes.GroundTile); MapPrefabTypesField.RegisterCallback <ChangeEvent <Enum> >((evt) => { rebindPrefabListView(); }); levelRoot.Add(MapPrefabTypesField); //levelRoot.Add(createSpriteList()); levelRoot.Add(createMapTileList()); var eraseToggle = new Toggle("Erase Mode"); eraseToggle.RegisterCallback <ChangeEvent <bool> >((evt) => { tileMap.eraseMode = evt.newValue; }); levelRoot.Add(eraseToggle); var timeLimit = new SliderInt(60, 600); var timeLimitLabel = new Label("Time Limit: " + timeLimit.value + " seconds"); levelRoot.Add(timeLimitLabel); timeLimit.RegisterCallback <ChangeEvent <int> >((evt) => { timeLimitLabel.text = "Time Limit: " + evt.newValue + " seconds"; }); timeLimit.bindingPath = "timeLimit"; levelRoot.Add(timeLimit); levelRoot.Add(new Label("Current Layer:")); EnumField mapLayers = new EnumField(MapLayers.Layer1); mapLayers.RegisterCallback <ChangeEvent <Enum> >((evt) => { var change = evt.newValue; tileMap.changeLayer(Convert.ToInt32(change)); }); levelRoot.Add(mapLayers); levelRoot.Add(new Label("Viewable layers in editor:")); var layer1Toggle = new Toggle("Layer 1") { value = true }; var layer2Toggle = new Toggle("Layer 2") { value = true }; var layer3Toggle = new Toggle("Layer 3") { value = true }; layer1Toggle.RegisterCallback <ChangeEvent <bool> >((evt) => { tileMap.layersOn[0] = evt.newValue; }); layer2Toggle.RegisterCallback <ChangeEvent <bool> >((evt) => { tileMap.layersOn[1] = evt.newValue; }); layer3Toggle.RegisterCallback <ChangeEvent <bool> >((evt) => { tileMap.layersOn[2] = evt.newValue; }); levelRoot.Add(layer1Toggle); levelRoot.Add(layer2Toggle); levelRoot.Add(layer3Toggle); levelRoot.Add(new Label("Type of asset to create/edit:")); EnumField prefabEnums = new EnumField(PrefabTypes.GroundTile); levelRoot.Add(prefabEnums); Button createEditPrefabButton = new Button(() => { switch (prefabEnums.value) { case PrefabTypes.Player: { assetWindow = PrefabEditor.createWindow <GauntletPlayerEditor>(_window, "Player Editor"); break; } case PrefabTypes.Enemy: { assetWindow = PrefabEditor.createWindow <GauntletEnemyEditor>(_window, "Enemy Editor"); break; } case PrefabTypes.GroundTile: { assetWindow = PrefabEditor.createWindow <GauntletGroundTileEditor>(_window, "Ground Tile Editor"); break; } case PrefabTypes.SpawnFactory: { assetWindow = PrefabEditor.createWindow <GauntletSpawnFactoryEditor>(_window, "Spawn Factory Editor"); break; } case PrefabTypes.Projectile: { assetWindow = PrefabEditor.createWindow <GauntletProjectileEditor>(_window, "Projectile Editor"); break; } case PrefabTypes.Item: { assetWindow = PrefabEditor.createWindow <GauntletItemEditor>(_window, "Item Editor"); break; } case PrefabTypes.Portal: { assetWindow = PrefabEditor.createWindow <GauntletPortalEditor>(_window, " Portal Editor"); break; } case PrefabTypes.SpawnPoint: { assetWindow = PrefabEditor.createWindow <GauntletSpawnPointEditor>(_window, "Spawn Point Editor"); break; } default: break; } }); createEditPrefabButton.text = "Create/Edit Prefab"; levelRoot.Add(createEditPrefabButton); }