private void DrawSettingsInspector()
        {
            VegetationSystemPro vegetationSystemPro = _runtimePrefabSpawner.VegetationSystemPro;

            if (vegetationSystemPro.VegetationPackageProList.Count == 0)
            {
                EditorGUILayout.HelpBox(
                    "There is no vegetation package/biome in the vegetation system",
                    MessageType.Warning);
                return;
            }



            GUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Select biome/vegetation package", LabelStyle);
            string[] packageNameList = new string[vegetationSystemPro.VegetationPackageProList.Count];
            for (int i = 0; i <= vegetationSystemPro.VegetationPackageProList.Count - 1; i++)
            {
                if (vegetationSystemPro.VegetationPackageProList[i])
                {
                    packageNameList[i] = (i + 1).ToString() + " " +
                                         vegetationSystemPro.VegetationPackageProList[i].PackageName;
                }
                else
                {
                    packageNameList[i] = "Not found";
                }
            }

            EditorGUI.BeginChangeCheck();
            _runtimePrefabSpawner.VegetationPackageIndex = EditorGUILayout.Popup("Selected vegetation package",
                                                                                 _runtimePrefabSpawner.VegetationPackageIndex, packageNameList);
            if (EditorGUI.EndChangeCheck())
            {
                SetSceneDirty();
            }

            GUILayout.EndVertical();

            VegetationPackagePro vegetationPackagePro =
                vegetationSystemPro.VegetationPackageProList[_runtimePrefabSpawner.VegetationPackageIndex];

            if (vegetationPackagePro == null)
            {
                return;
            }
            if (vegetationPackagePro.VegetationInfoList.Count == 0)
            {
                return;
            }


            GUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Select Vegetation Item", LabelStyle);

            EditorGUI.BeginChangeCheck();
            _selectedVegetationTypeIndex = GUILayout.SelectionGrid(_selectedVegetationTypeIndex, VegetationTypeNames, 3,
                                                                   EditorStyles.toolbarButton);
            if (EditorGUI.EndChangeCheck())
            {
                _selectedGridIndex = 0;
            }

            VegetationPackageEditorTools.VegetationItemTypeSelection vegetationItemTypeSelection =
                VegetationPackageEditorTools.GetVegetationItemTypeSelection(_selectedVegetationTypeIndex);

            int selectionCount = 0;

            VegetationPackageEditorTools.DrawVegetationItemSelector(vegetationSystemPro, vegetationPackagePro,
                                                                    ref _selectedGridIndex, ref _vegIndex, ref selectionCount, vegetationItemTypeSelection, 70);

            if (_lastVegIndex != _vegIndex)
            {
                GUI.FocusControl(null);
            }
            _lastVegIndex = _vegIndex;

            GUILayout.EndVertical();

            VegetationItemInfoPro vegetationItemInfoPro = vegetationPackagePro.VegetationInfoList[_vegIndex];

            if (vegetationItemInfoPro == null)
            {
                return;
            }

            GUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Selected item", vegetationItemInfoPro.Name);


            if (GUILayout.Button("Add run-time prefab rule"))
            {
                RuntimePrefabRule newRuntimePrefabRule = new RuntimePrefabRule();
                newRuntimePrefabRule.SetSeed();

                vegetationItemInfoPro.RuntimePrefabRuleList.Add(newRuntimePrefabRule);
                _runtimePrefabSpawner.RefreshRuntimePrefabs();
                EditorUtility.SetDirty(vegetationPackagePro);
                SetSceneDirty();
            }
            GUILayout.EndVertical();

            for (int i = 0; i <= vegetationItemInfoPro.RuntimePrefabRuleList.Count - 1; i++)
            {
                RuntimePrefabRule runtimePrefabRule = vegetationItemInfoPro.RuntimePrefabRuleList[i];
                EditorGUI.BeginChangeCheck();
                GUILayout.BeginVertical("box");

                runtimePrefabRule.RuntimePrefab = EditorGUILayout.ObjectField("Runtime prefab", runtimePrefabRule.RuntimePrefab, typeof(GameObject), true) as GameObject;

                var       prefabTexture          = AssetPreview.GetAssetPreview(runtimePrefabRule.RuntimePrefab);
                Texture2D convertedPrefabTexture = new Texture2D(2, 2, TextureFormat.ARGB32, true, true);
                if (Application.isPlaying)
                {
                    convertedPrefabTexture = prefabTexture;
                }
                else
                {
                    if (prefabTexture)
                    {
                        convertedPrefabTexture.LoadImage(prefabTexture.EncodeToPNG());
                    }
                }

                if (convertedPrefabTexture)
                {
                    Rect  space = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(convertedPrefabTexture.height));
                    float width = space.width;

                    space.xMin = (width - convertedPrefabTexture.width);
                    if (space.xMin < 0)
                    {
                        space.xMin = 0;
                    }

                    space.width  = convertedPrefabTexture.width;
                    space.height = convertedPrefabTexture.height;
                    EditorGUI.DrawPreviewTexture(space, convertedPrefabTexture);
                }
                runtimePrefabRule.SpawnFrequency         = EditorGUILayout.Slider("Spawn frequency", runtimePrefabRule.SpawnFrequency, 0, 1f);
                runtimePrefabRule.PrefabScale            = EditorGUILayout.Vector3Field("Scale", runtimePrefabRule.PrefabScale);
                runtimePrefabRule.UseVegetationItemScale = EditorGUILayout.Toggle("Add vegetation item scale", runtimePrefabRule.UseVegetationItemScale);
                runtimePrefabRule.PrefabRotation         = EditorGUILayout.Vector3Field("Rotation", runtimePrefabRule.PrefabRotation);
                runtimePrefabRule.PrefabOffset           = EditorGUILayout.Vector3Field("Offset", runtimePrefabRule.PrefabOffset);
                runtimePrefabRule.PrefabLayer            = EditorGUILayout.LayerField("Prefab layer", runtimePrefabRule.PrefabLayer);
                runtimePrefabRule.Seed    = EditorGUILayout.IntSlider("Seed", runtimePrefabRule.Seed, 0, 99);
                runtimePrefabRule.UsePool = EditorGUILayout.Toggle("Use pooling system", runtimePrefabRule.UsePool);

                runtimePrefabRule.DistanceFactor = EditorGUILayout.Slider("Distance factor", runtimePrefabRule.DistanceFactor, 0, 1f);
                float currentDistance = vegetationSystemPro.VegetationSettings.GetVegetationDistance() * runtimePrefabRule.DistanceFactor;
                EditorGUILayout.LabelField("Current distance: " + currentDistance.ToString("F2") + " meters", LabelStyle);

                EditorGUILayout.HelpBox(
                    "The distance from the camera where prefabs are instantiated. Distance is a factor of the current vegetation item draw distance.",
                    MessageType.Info);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(vegetationPackagePro);
                    _runtimePrefabSpawner.RefreshRuntimePrefabs();
                    SetSceneDirty();
                }

                if (GUILayout.Button("Remove run-time prefab rule"))
                {
                    vegetationItemInfoPro.RuntimePrefabRuleList.Remove(runtimePrefabRule);
                    _runtimePrefabSpawner.RefreshRuntimePrefabs();
                    GUILayout.EndVertical();
                    return;
                }

                GUILayout.EndVertical();
            }
        }
        public override void OnInspectorGUI()
        {
            _vegetationPackagePro = (VegetationPackagePro)target;

            base.OnInspectorGUI();
            //EditorUtility.SetDirty(target);
            for (int i = 0; i <= _vegetationPackagePro.VegetationInfoList.Count - 1; i++)
            {
                bool changed = false;
                VegetationItemInfoPro vegetationItemInfo = _vegetationPackagePro.VegetationInfoList[i];
                if (vegetationItemInfo.VegetationItemID == "")
                {
                    vegetationItemInfo.VegetationItemID = System.Guid.NewGuid().ToString();
                    changed = true;
                }

                if (changed)
                {
                    EditorUtility.SetDirty(_vegetationPackagePro);
                }
            }


            GUILayout.BeginVertical("box");
            EditorGUILayout.HelpBox(
                "To edit an vegetation package add it to a vegetation system pro component",
                MessageType.Info);
            GUILayout.EndVertical();

            GUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Biome", LabelStyle);
            EditorGUI.BeginDisabledGroup(true);
            _vegetationPackagePro.BiomeType =
                (BiomeType)EditorGUILayout.EnumPopup("Select biome", _vegetationPackagePro.BiomeType);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndVertical();


            if (_vegetationPackagePro.VegetationInfoList.Count > 0)
            {
                List <string> vegetationItemIdList =
                    VegetationPackageEditorTools.CreateVegetationInfoIdList(_vegetationPackagePro);
                VegetationPackageEditorTools.DrawVegetationItemSelector(_vegetationPackagePro, vegetationItemIdList, 60,
                                                                        ref _selectedVegetationItem);

                VegetationItemInfoPro vegetationItemInfoPro =
                    _vegetationPackagePro.GetVegetationInfo(_selectedVegetationItem);

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("VegetationItemID", LabelStyle);
                EditorGUILayout.SelectableLabel(vegetationItemInfoPro.VegetationItemID);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginVertical("box");
                EditorGUILayout.HelpBox(
                    "Vegetation package has no vegetation items configured",
                    MessageType.Info);
                GUILayout.EndVertical();
            }



            if (_vegetationPackagePro.TerrainTextureCount > 0)
            {
                EditorGUILayout.LabelField("Terrain textures", LabelStyle);
                GUIContent[] textureImageButtons = new GUIContent[_vegetationPackagePro.TerrainTextureList.Count];
                for (int i = 0; i <= _vegetationPackagePro.TerrainTextureList.Count - 1; i++)
                {
                    var       textureItemTexture = AssetPreview.GetAssetPreview(_vegetationPackagePro.TerrainTextureList[i].Texture);
                    Texture2D convertedTexture   = new Texture2D(2, 2, TextureFormat.ARGB32, true, true);
                    if (textureItemTexture)
                    {
                        convertedTexture.LoadImage(textureItemTexture.EncodeToPNG());
                    }

                    textureImageButtons[i] = new GUIContent {
                        image = convertedTexture
                    };
                }
                int imageWidth = 60;
                int columns    = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - imageWidth / 2f) / imageWidth);
                int rows       = Mathf.CeilToInt((float)textureImageButtons.Length / columns);
                int gridHeight = (rows) * imageWidth;
                _currentTextureItem = GUILayout.SelectionGrid(_currentTextureItem, textureImageButtons, columns, GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight));

                GUIStyle variantStyle = new GUIStyle(EditorStyles.helpBox);

                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Terrain layer: " + (_currentTextureItem + 1).ToString(), LabelStyle);
                EditorGUI.BeginDisabledGroup(true);
                _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].Enabled = EditorGUILayout.Toggle("Enable", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].Enabled);

                EditorGUILayout.BeginHorizontal(variantStyle);
                EditorGUILayout.LabelField("Texture " + (_currentTextureItem + 1).ToString() + " Height", LabelStyle, GUILayout.Width(150));
                _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureHeightCurve = EditorGUILayout.CurveField(_vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureHeightCurve, Color.green, new Rect(0, 0, 1, 1), GUILayout.Height(75));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal(variantStyle);
                EditorGUILayout.LabelField("Texture " + (_currentTextureItem + 1).ToString() + " Steepness", LabelStyle, GUILayout.Width(150));
                _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureSteepnessCurve = EditorGUILayout.CurveField(_vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureSteepnessCurve, Color.green, new Rect(0, 0, 1, 1), GUILayout.Height(75));
                EditorGUILayout.EndHorizontal();

                _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].UseNoise = EditorGUILayout.Toggle("Use perlin noise", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].UseNoise);

                if (_vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].UseNoise)
                {
                    _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].InverseNoise = EditorGUILayout.Toggle("Inverse noise", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].InverseNoise);
                    _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseScale   = EditorGUILayout.Slider("Noise scale", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseScale, 1, 50f);
                    _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseOffset  = EditorGUILayout.Vector2Field("Noise offset", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseOffset);
                }
                _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureWeight = EditorGUILayout.Slider("Texture weight", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureWeight, 0, 5f);

                EditorGUI.EndDisabledGroup();
                GUILayout.EndVertical();
            }
            else
            {
                GUILayout.BeginVertical("box");
                EditorGUILayout.HelpBox(
                    "Vegetation package has no textures configured",
                    MessageType.Info);
                GUILayout.EndVertical();
            }
        }
Ejemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            HelpTopic             = "scene-vegetation-baker";
            _sceneVegetationBaker = (SceneVegetationBaker)target;

            ShowLogo = false;

            base.OnInspectorGUI();

            if (!_sceneVegetationBaker.VegetationSystemPro)
            {
                EditorGUILayout.HelpBox(
                    "The SceneVegetationBaker Component needs to be added to a GameObject with a VegetationSystemPro Component.",
                    MessageType.Error);
                return;
            }


            VegetationSystemPro vegetationSystemPro = _sceneVegetationBaker.VegetationSystemPro;

            GUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Select biome/vegetation package", LabelStyle);
            string[] packageNameList = new string[vegetationSystemPro.VegetationPackageProList.Count];
            for (int i = 0; i <= vegetationSystemPro.VegetationPackageProList.Count - 1; i++)
            {
                if (vegetationSystemPro.VegetationPackageProList[i])
                {
                    packageNameList[i] = (i + 1).ToString() + " " +
                                         vegetationSystemPro.VegetationPackageProList[i].PackageName + " (" + vegetationSystemPro.VegetationPackageProList[i].BiomeType.ToString() + ")";;
                }
                else
                {
                    packageNameList[i] = "Not found";
                }
            }

            EditorGUI.BeginChangeCheck();
            _sceneVegetationBaker.VegetationPackageIndex = EditorGUILayout.Popup("Selected vegetation package",
                                                                                 _sceneVegetationBaker.VegetationPackageIndex, packageNameList);
            if (EditorGUI.EndChangeCheck())
            {
                SetSceneDirty();
            }

            GUILayout.EndVertical();

            VegetationPackagePro vegetationPackagePro =
                vegetationSystemPro.VegetationPackageProList[_sceneVegetationBaker.VegetationPackageIndex];

            if (vegetationPackagePro == null)
            {
                return;
            }
            if (vegetationPackagePro.VegetationInfoList.Count == 0)
            {
                return;
            }


            GUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Select Vegetation Item", LabelStyle);

            EditorGUI.BeginChangeCheck();
            _selectedVegetationTypeIndex = GUILayout.SelectionGrid(_selectedVegetationTypeIndex, VegetationTypeNames, 3,
                                                                   EditorStyles.toolbarButton);
            if (EditorGUI.EndChangeCheck())
            {
                _selectedGridIndex = 0;
            }

            VegetationPackageEditorTools.VegetationItemTypeSelection vegetationItemTypeSelection =
                VegetationPackageEditorTools.GetVegetationItemTypeSelection(_selectedVegetationTypeIndex);

            int selectionCount = 0;

            VegetationPackageEditorTools.DrawVegetationItemSelector(vegetationSystemPro, vegetationPackagePro,
                                                                    ref _selectedGridIndex, ref _vegIndex, ref selectionCount, vegetationItemTypeSelection, 70);

            if (_lastVegIndex != _vegIndex)
            {
                GUI.FocusControl(null);
            }
            _lastVegIndex = _vegIndex;

            GUILayout.EndVertical();

            VegetationItemInfoPro vegetationItemInfoPro = vegetationPackagePro.VegetationInfoList[_vegIndex];

            if (vegetationItemInfoPro == null)
            {
                return;
            }

            GUILayout.BeginVertical("box");
            _sceneVegetationBaker.ExportStatic = EditorGUILayout.Toggle("Export as static objects", _sceneVegetationBaker.ExportStatic);
            GUILayout.EndVertical();

            GUILayout.BeginVertical("box");

            if (GUILayout.Button("Bake VegetationItem to scene"))
            {
                BakeVegetationToScene(vegetationItemInfoPro);
            }

            GUILayout.EndVertical();
        }