private void LoadSettings() { try { // create source file path string settingsFilePath = GetSettingsFilePath(); Debug.Log("Loading Bridge Settings: " + settingsFilePath); if (File.Exists(settingsFilePath)) { string dataAsJson = File.ReadAllText(settingsFilePath); settings = JsonUtility.FromJson <BridgeSettings>(dataAsJson); } else { settings = new BridgeSettings(); } } catch (System.Exception ex) { Debug.Log("Couldn't load settings: " + ex.ToString()); } }
/// <summary> /// Draws the contents of the General toolbar selection. /// </summary> private void DrawTabGeneral() { GUIStyle boxStyle = new GUIStyle(GUI.skin.box); boxStyle.alignment = TextAnchor.MiddleLeft; boxStyle.normal.textColor = EditorGUIUtility.isProSkin ? new Color(0.81f, 0.77f, 0.67f) : Color.black; boxStyle.stretchWidth = true; float spacePixels = 8; // reset settings button EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset Settings", GUILayout.Width(160))) { settings = new BridgeSettings(); } } EditorGUILayout.EndHorizontal(); GUILayout.Box("Please select the World Creator Bridge XML file that you have exported through the Standalone World Creator application.\n\nThe name of the file is 'Bridge.xml' and can be found in folder:\n\n[USER]/Documents/WorldCreator/Bridge/[PROJECT_NAME]", boxStyle); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { if (GUILayout.Button("SELECT BRIDGE XML FILE", GUILayout.Height(30))) { this.logic.SelectProjectFolder(settings); } } GUILayout.EndHorizontal(); folderScrollPosition = EditorGUILayout.BeginScrollView(folderScrollPosition); { string path = settings.IsBridgeFileValid() ? settings.bridgeFilePath : logic.projectFolderPath; GUILayout.TextField(path, GUILayout.ExpandWidth(true)); } EditorGUILayout.EndScrollView(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Box("Specify the name of the terrain asset. The World Creator Bridge will use the name to create a GameObject container that contains your terrain GameObject(s).", boxStyle); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Label("Terrain Asset Name:", GUILayout.Width(160)); settings.terrainAssetName = GUILayout.TextField(settings.terrainAssetName, GUILayout.ExpandWidth(true)); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Box("Please enable the checkbox below if you would like the World Creator Bridge to clean up non-used terrain assets.", boxStyle); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Label("Delete unused Assets:", GUILayout.Width(160)); settings.deleteUnusedAssets = GUILayout.Toggle(settings.deleteUnusedAssets, ""); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Box("Choose whether to import objects (e.g. trees, rocks).", boxStyle); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Label("Import Objects:", GUILayout.Width(160)); settings.IsImportObjects = GUILayout.Toggle(settings.IsImportObjects, ""); } GUILayout.EndHorizontal(); if (settings.IsImportObjects) { if (settings.ObjectSettings != null) { if (settings.ObjectSettings.Length > 0) { GUILayout.BeginHorizontal(); { GUILayout.Box("If your terrain has some objects applied, you might want to adjust them separately.\n\n* PREFAB\nLet's you set a custom object.\n\n* UNITY TREE\nIndicates, whether the imported object should be imported as a Unity Terrain Tree object. If unchecked, GameObject's are created instead.\n\n* NATURE SHADER\nIndicates, whether the Unity Nature Sahder should be used.\n\n* LOD\nEnables LOD typical detail changes and culling.", boxStyle); } GUILayout.EndHorizontal(); scrollPositionObjects = GUILayout.BeginScrollView(scrollPositionObjects, GUILayout.Height(150)); { GUILayout.BeginHorizontal(); { string lastLayer = null; foreach (var o in settings.ObjectSettings) { if (lastLayer != o.LayerName) { if (lastLayer != null) { GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUILayout.BeginVertical(boxStyle); GUILayout.Label("Layer: " + o.LayerName); GUILayout.BeginHorizontal(); lastLayer = o.LayerName; } const int leftSize = 100; const int rightSize = 156; GUILayout.BeginVertical(boxStyle, GUILayout.Width(leftSize + rightSize)); { GUILayout.BeginHorizontal(); { GUILayout.Label("Name:", GUILayout.Width(leftSize)); GUILayout.FlexibleSpace(); GUILayout.Label(o.Name, GUILayout.Width(rightSize)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Prefab:", GUILayout.Width(leftSize)); GUILayout.FlexibleSpace(); o.Prefab = EditorGUILayout.ObjectField(o.Prefab, typeof(GameObject), false, GUILayout.Width(rightSize)) as GameObject; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Unity Tree:", GUILayout.Width(leftSize)); GUILayout.FlexibleSpace(); o.CreateGameObjects = !GUILayout.Toggle(!o.CreateGameObjects, "", GUILayout.Width(rightSize)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Nature Shader:", GUILayout.Width(leftSize)); GUILayout.FlexibleSpace(); o.NatureShader = GUILayout.Toggle(o.NatureShader, "", GUILayout.Width(rightSize)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("LOD:", GUILayout.Width(leftSize)); GUILayout.FlexibleSpace(); o.ImportLOD = GUILayout.Toggle(o.ImportLOD, "", GUILayout.Width(rightSize)); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } if (lastLayer != null) { GUILayout.EndHorizontal(); GUILayout.EndVertical(); } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } } } GUILayout.BeginHorizontal(); { GUILayout.Box("Choose whether to import details (e.g. grass, flowers).", boxStyle); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Import Details:", GUILayout.Width(160)); settings.IsImportDetails = GUILayout.Toggle(settings.IsImportDetails, ""); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Box("Choose whether to import textures.", boxStyle); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Import Textures:", GUILayout.Width(160)); settings.IsImportTextures = GUILayout.Toggle(settings.IsImportTextures, ""); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Box("The Split Threshold specifies when to split the created Unity terrain. This might be important if you want to split your Unity terrain into smaller chunks (e.g. for streaming).", boxStyle); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Label("Split Threshold:", GUILayout.Width(160)); settings.SplitThreshold = Mathf.RoundToInt(GUILayout.HorizontalSlider(settings.SplitThreshold, 0, 5)); GUILayout.Label((128 << settings.SplitThreshold).ToString(), GUILayout.Width(32)); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Box("If the terrain size you would like to synchronize does not follow the power-of-two + 1 rule of Unity's terrain system, you can choose to clamp the values.", boxStyle); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Label("Clamp Values:", GUILayout.Width(160)); settings.ClampValues = GUILayout.Toggle(settings.ClampValues, ""); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Box("With World Scale you can scale your terrain to a different value.", boxStyle); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUIStyle textFieldStyle = new GUIStyle(GUI.skin.textField); textFieldStyle.alignment = TextAnchor.MiddleRight; GUILayout.BeginHorizontal(); { GUILayout.Label("World Scale:", GUILayout.Width(160)); float oldScale = settings.WorldScale; float newScale = GUILayout.HorizontalSlider(settings.WorldScale, 0, 8, GUILayout.ExpandWidth(true)); if (oldScale != newScale) { settings.WorldScaleString = newScale.ToString("#0.00"); settings.WorldScale = newScale; } var oldString = settings.WorldScaleString; settings.WorldScaleString = GUILayout.TextField(settings.WorldScaleString, textFieldStyle, GUILayout.Width(50)); if (oldString != settings.WorldScaleString) { float newVal; if (float.TryParse(settings.WorldScaleString, NumberStyles.Any, CultureInfo.InvariantCulture, out newVal)) { settings.WorldScale = newVal; } } GUILayout.Label("m", GUILayout.Width(14)); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Box("Select the material type. Use Standard for default 3D Unity projects, HDRP for HDRP Unity projects, LWRP for LWRP Unity projects, and URP for URP Unity projects. If you would like to plugin a custom material, please choose Custom.", boxStyle); } GUILayout.EndHorizontal(); GUILayout.Space(spacePixels); GUILayout.BeginHorizontal(); { GUILayout.Label("Material Type:", GUILayout.Width(160)); settings.MaterialType = (MaterialType)EditorGUILayout.EnumPopup(settings.MaterialType, GUILayout.ExpandWidth(true)); } GUILayout.EndHorizontal(); if (settings.MaterialType == MaterialType.Custom) { GUILayout.BeginHorizontal(); { settings.CustomMaterial = EditorGUILayout.ObjectField("", settings.CustomMaterial, typeof(Material), false, GUILayout.ExpandWidth(true)) as Material; } GUILayout.EndHorizontal(); } }