public void SetSwitchValue(bool value, BiomeSwitchMode biomeSwitchMode, string biomeName, Color previewColor) { this.value = value; this.mode = SwitchMode.Bool; this.biomeSwitchMode = biomeSwitchMode; this.biomeName = biomeName; this.previewColor = previewColor; this.biome = null; }
public void SetSwitchValue(float min, float max, BiomeSwitchMode biomeSwitchMode, string biomeName, Color previewColor) { this.min = min; this.max = max; this.mode = SwitchMode.Float; this.biomeSwitchMode = biomeSwitchMode; this.biomeName = biomeName; this.previewColor = previewColor; this.biome = null; }
public override void OnNodeGUI() { for (int i = 0; i < outputBiomes.Count; i++) { UpdatePropVisibility("outputBiomes", error ? PWVisibility.Invisible : PWVisibility.Visible, i); } if (biomeRepartitionPreview == null) { biomeRepartitionPreview = new Texture2D(previewTextureWidth, 1); } if (inputBiome == null) { error = true; EditorGUILayout.LabelField("null biome input !"); return; } EditorGUIUtility.labelWidth = 80; EditorGUI.BeginChangeCheck(); { selectedBiomeSwitchMode = EditorGUILayout.Popup("switch field", selectedBiomeSwitchMode, biomeSwitchModes); switchMode = (BiomeSwitchMode)Enum.Parse(typeof(BiomeSwitchMode), biomeSwitchModes[selectedBiomeSwitchMode]); if (currentSampler != null) { EditorGUILayout.LabelField("min: " + currentSampler.min + ", max: " + currentSampler.max); } else { EditorGUILayout.LabelField(""); } } if (EditorGUI.EndChangeCheck() || needUpdate || biomeReloadRequested) { UpdateSwitchMode(); CheckForBiomeSwitchErrors(); updatePreview = true; } if (error) { Rect errorRect = EditorGUILayout.GetControlRect(false, GUI.skin.label.lineHeight * 3.5f); EditorGUI.LabelField(errorRect, errorString); return; } if (updatePreview && currentSampler != null) { float min = currentSampler.min; float max = currentSampler.max; float range = max - min; //clear the current texture: for (int x = 0; x < previewTextureWidth; x++) { biomeRepartitionPreview.SetPixel(x, 0, Color.white); } localCoveragePercent = 0; int i = 0; foreach (var switchData in switchDatas) { float switchMin = Mathf.Max(switchData.min, min); float switchMax = Mathf.Min(switchData.max, max); float rMin = ((switchMin - min) / range) * previewTextureWidth; float rMax = ((switchMax - min) / range) * previewTextureWidth; localCoveragePercent += (rMax - rMin) / previewTextureWidth * 100; for (int x = (int)rMin; x < (int)rMax; x++) { biomeRepartitionPreview.SetPixel(x, 0, switchData.color); } i++; } //add water if there is and if switch mode is height: if (!inputBiome.isWaterless && switchMode == BiomeSwitchMode.Height) { float rMax = (inputBiome.waterLevel / range) * previewTextureWidth; for (int x = 0; x < rMax; x++) { biomeRepartitionPreview.SetPixel(x, 0, Color.blue); } } biomeRepartitionPreview.Apply(); updatePreview = false; } if (switchMode != BiomeSwitchMode.Water) { switchList.DoLayoutList(); EditorGUILayout.LabelField("repartition map: (" + localCoveragePercent.ToString("F1") + "%)"); Rect previewRect = EditorGUILayout.GetControlRect(GUILayout.ExpandWidth(true), GUILayout.Height(0)); previewRect.height = previewTextureHeight; GUILayout.Space(previewTextureHeight); PWGUI.TexturePreview(previewRect, biomeRepartitionPreview, false); PWGUI.SetScaleModeForField(-1, ScaleMode.StretchToFill); } }