コード例 #1
0
        private void ShowSpawnSettings(SerializedProperty spawnProperty, ObjectSpawnSettings spawnSettings)
        {
            var content = new GUIContent("Min Distance", "Minimum distance between spawned object");
            SerializedProperty minDistanceProperty = spawnProperty.FindPropertyRelative("minDistance");

            EditorGUILayout.PropertyField(minDistanceProperty, content);

            content = new GUIContent("Density", "Spawn probability for an object to spawn at a given location");
            spawnSettings.spawnProbability = EditorGUILayout.Slider(content, spawnSettings.spawnProbability, 0, 1);
        }
コード例 #2
0
        private void DrawTreeList()
        {
            GUILayout.Space(10);

            GUIStyle toogleStyle = new GUIStyle(GUI.skin.button)
            {
                fixedHeight = 25
            };

            ObjectSpawnSettings treeSpawnSettings = voxelEngine.treeSpawnSettings;

            EditorGUILayout.BeginVertical();
            {
                for (int i = 0; i < treeSpawnSettings.resources.Count; i++)
                {
                    ObjectResource spawnResource = treeSpawnSettings.resources[i];

                    if (spawnResource.prefab == null)
                    {
                        continue;
                    }

                    if (i == selectedTreeIndex)
                    {
                        GUILayout.Toggle(true, spawnResource.prefab.name, toogleStyle);
                    }
                    else
                    {
                        if (GUILayout.Toggle(false, spawnResource.prefab.name, toogleStyle))
                        {
                            selectedTreeIndex = i;
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            {
                if (selectedTreeIndex >= 0)
                {
                    if (GUILayout.Button("Remove"))
                    {
                        SerializedProperty treeResourcesProperty = treeSpawnSettingsProperty.FindPropertyRelative("resources");
                        treeResourcesProperty.DeleteArrayElementAtIndex(selectedTreeIndex);
                        selectedTreeIndex = -1;
                    }
                }

                if (treeSpawnSettings.resources.Count > 0)
                {
                    if (GUILayout.Button("Remove All"))
                    {
                        SerializedProperty treeResourcesProperty = treeSpawnSettingsProperty.FindPropertyRelative("resources");
                        treeResourcesProperty.ClearArray();
                        selectedTreeIndex = -1;
                    }
                }
            }
            GUILayout.EndHorizontal();
        }