Exemplo n.º 1
0
        protected override void DrawContent()
        {
            FloatSliderAttribute attr = GetAttr <FloatSliderAttribute>();

            if (drawer == null)
            {
                drawer = new FloatSliderDrawer();
                drawer.IsExpandWidth  = attr.IsExpandWidth;
                drawer.Text           = ItemDrawer.Label;
                drawer.OnValueChanged = (value) =>
                {
                    ItemDrawer.Value = value;
                };
                drawer.Value = (float)ItemDrawer.Value;
            }

            float leftValue  = attr.MinValue;
            float rightValue = attr.MaxValue;

            if (!string.IsNullOrEmpty(attr.MinValueMemberName))
            {
                leftValue = DrawerUtility.GetMemberValue <float>(attr.MinValueMemberName, ItemDrawer.Target);
            }
            if (!string.IsNullOrEmpty(attr.MaxValueMemberName))
            {
                rightValue = DrawerUtility.GetMemberValue <float>(attr.MaxValueMemberName, ItemDrawer.Target);
            }
            drawer.MinValue = leftValue;
            drawer.MaxValue = rightValue;
            drawer.OnGUILayout();
        }
        protected void ShowHeightLayerCombinations()
        {
            if (ShizenTerrain.Heights == null)
            {
                return;
            }
            if (ShizenTerrain.Heights.Count == 0)
            {
                return;
            }
            using (new GUILayout.HorizontalScope(baseSkin.FindStyle("FinalHeightMap")))
            {
                using (new GUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
                {
                    if (ButtonDrawer.Draw(new GUIContent("Combine Height Layers",
                                                         "Combine all Height Layer Maps into one final texture."), baseSkin.FindStyle("CenteredButton")))
                    {
                        ShizenTerrain.FinalHeightmap = MainAlgorithms.CombineHeightLayers(Terrain, ShizenTerrain.Heights);
                    }

                    if (ShizenTerrain.Heights != null)
                    {
                        for (int i = 0; i < ShizenTerrain.Heights.Count; i++)
                        {
                            using (new GUILayout.HorizontalScope(baseSkin.FindStyle("Property")))
                                ShizenTerrain.Heights[i].LayerProperties.Opacity =
                                    FloatSliderDrawer.Draw(new GUIContent(string.Format("{0} Opacity", ShizenTerrain.Heights[i].Name)),
                                                           ShizenTerrain.Heights[i].LayerProperties.Opacity,
                                                           0, 1, baseSkin, false, false, 100);
                        }
                    }
                }
                using (new GUILayout.VerticalScope(baseSkin.FindStyle("CenteredImage"), GUILayout.Width(325)))
                {
                    if (ShizenTerrain.FinalHeightmap != null)
                    {
                        GUILayout.Space(300);
                        EditorGUI.DrawPreviewTexture(new Rect(EditorGUILayout.GetControlRect().position + new Vector2(10, -290), new Vector2(300, 300)), ShizenTerrain.FinalHeightmap);
                    }
                }
            }
            //if (!heightLayersOpen)
            //    GUILayout.FlexibleSpace();
        }
        protected void ShowHeightLayerVariables(HeightLayer _hLayer)
        {
            using (new GUILayout.HorizontalScope(baseSkin.FindStyle("LayerToolbar")))
            {
                GUIContent selectedContent;
                if (_hLayer.ExpandedInEditor)
                {
                    selectedContent = new GUIContent(baseSkin.FindStyle("OpenCloseSymbolsLight").hover.background);
                }
                else
                {
                    selectedContent = new GUIContent(baseSkin.FindStyle("OpenCloseSymbolsLight").normal.background);
                }
                if (GUILayout.Button(selectedContent, baseSkin.FindStyle("SymbolButton")))
                {
                    _hLayer.ExpandedInEditor = !_hLayer.ExpandedInEditor;
                }
                _hLayer.Name =
                    EditorGUILayout.TextField(_hLayer.Name, baseSkin.textField);
                EditorGUILayout.PrefixLabel("Preset:", baseSkin.FindStyle("Enum"), baseSkin.FindStyle("EnumLabel"));
                _hLayer.PlaceholderPreset = (HeightLayer.placeholderPresets)EditorGUILayout.EnumPopup(_hLayer.PlaceholderPreset, baseSkin.FindStyle("Enum"));
                GUILayout.FlexibleSpace();
            }
            GUIStyle layerStyle;

            if (_hLayer.ExpandedInEditor)
            {
                layerStyle = baseSkin.FindStyle("LayerValues");
            }
            else
            {
                layerStyle = baseSkin.FindStyle("LayerClosed");
            }
            using (new GUILayout.HorizontalScope(layerStyle))
            {
                using (new GUILayout.VerticalScope())
                {
                    if (_hLayer.ExpandedInEditor)
                    {
                        EditorGUI.indentLevel = 1;
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Frequency, baseSkin, 0.01f, 100);
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Amplitude, baseSkin, 0.1f, 2f);
                        IntPropertyDrawer.Draw(_hLayer.LayerProperties.Octaves, baseSkin, 1, 8);
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Lacunarity, baseSkin, 1, 4);
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Persistance, baseSkin, 0, 1);
                        Vector3PropertyDrawer.Draw(_hLayer.LayerProperties.Offset, baseSkin, -100, 100);
                        using (new GUILayout.HorizontalScope(baseSkin.FindStyle("Property")))
                            _hLayer.LayerProperties.Opacity =
                                FloatSliderDrawer.Draw(new GUIContent("Opacity"), _hLayer.LayerProperties.Opacity, 0, 1, baseSkin, true, false, 200);
                        EditorGUI.indentLevel = 0;
                        GUILayout.Space(5);
                    }
                }
                if (_hLayer.ExpandedInEditor)
                {
                    using (new GUILayout.VerticalScope())
                    {
                        using (new GUILayout.VerticalScope(baseSkin.FindStyle("Image"), GUILayout.Width(220)))
                        {
                            if (_hLayer.SavedMap == null)
                            {
                                GenerateHeightTexture(_hLayer);
                            }

                            EditorGUILayout.LabelField("Layer Map", baseSkin.FindStyle("labelCenter"));
                            GUILayout.Space(210);
                            EditorGUI.DrawPreviewTexture(new Rect(EditorGUILayout.GetControlRect().position + new Vector2(6, -200)
                                                                  , new Vector2(200, 200)), _hLayer.SavedMap);
                        }
                        if (ButtonDrawer.Draw(new GUIContent("Regenerate",
                                                             "Regenerate this Layer's Map. WARNING: This will override the previous map if you are using randomized values."), baseSkin.FindStyle("CenteredButton")))
                        {
                            GenerateHeightTexture(_hLayer);
                            Debug.Log("Regenerating " + _hLayer.Name);
                            lastLayer = _hLayer;
                        }
                    }
                }
            }
        }