/// <summary> /// Populate the (all) roadList and the roadTypeList. /// </summary> private void GetRoadList() { // Reset numAllRoads = 0; numAllRoadTypes = 0; if (roadList == null) { roadList = new List <LBRoad>(50); } else { roadList.Clear(); } if (roadTypeList == null) { roadTypeList = new List <LBRoadType>(20); } else { roadTypeList.Clear(); } // Populate the list of roads LBIntegration.GetERRoadList(roadList, true); numAllRoads = roadList == null ? 0 : roadList.Count; // Populate the list of road types string roadTypeDesc = string.Empty; LBRoadType lbRoadType = null; for (int r = 0; r < numAllRoads; r++) { roadTypeDesc = roadList[r].roadTypeDesc; if (!roadTypeList.Exists(typ => typ.roadTypeDesc == roadTypeDesc && !string.IsNullOrEmpty(roadTypeDesc))) { lbRoadType = new LBRoadType(); if (lbRoadType != null) { lbRoadType.roadTypeDesc = roadTypeDesc; roadTypeList.Add(lbRoadType); } } } numAllRoadTypes = roadTypeList == null ? 0 : roadTypeList.Count; //Debug.Log("[DEBUG] roads: " + roadList.Count); }
public void PrefetchVSProSettings(string methodName) { #if VEGETATION_STUDIO_PRO vsPro = null; if (lbGroupParams.landscape.useVegetationSystem) { vsPro = LBIntegration.GetVegetationSystemPro(); if (vsPro == null && lbGroupParams.showErrors) { Debug.LogWarning("ERROR " + methodName + " - could not find the VegetationSystemPro component in the scene."); } } #endif }
/// <summary> /// Get the splines for filtered roads matching on road name. /// Assumes road names are unique in the ER road network /// </summary> private void GetERSplineForRoads() { LBRoad lbRoadToUpdate = null; if (filteredRoadList == null) { filteredRoadList = new List <LBRoad>(numAllRoads + 20); } for (int i = 0; i < numFilteredRoads; i++) { lbRoadToUpdate = filteredRoadList[i]; if (lbRoadToUpdate.isSelected) { lbRoadToUpdate.centreSpline = LBIntegration.GetERRoadSplinePoints(lbRoadToUpdate, LBRoad.SplineType.CentreSpline, splinePointFilterSize); lbRoadToUpdate.leftSpline = LBIntegration.GetERRoadSplinePoints(lbRoadToUpdate, LBRoad.SplineType.LeftSpline, splinePointFilterSize); lbRoadToUpdate.rightSpline = LBIntegration.GetERRoadSplinePoints(lbRoadToUpdate, LBRoad.SplineType.RightSpline, splinePointFilterSize); //Debug.Log("[DEBUG] GetERSplineForRoads: " + lbRoadToUpdate.roadName + " points: " + lbRoadToUpdate.leftSpline.Length); } } }
/// <summary> /// Copy the Landscape textures from LB to MegaSplat /// EDITOR-ONLY /// </summary> /// <param name="landscape"></param> /// <param name="terrainMaterialType"></param> /// <param name="showErrors"></param> public static void MegaSplatCopyTextures(LBLandscape landscape, LBLandscape.TerrainMaterialType terrainMaterialType, bool showErrors) { string methodName = "LBEditorIntegration.MegaSplatCopyTextures"; // Basic validation if (landscape == null) { if (showErrors) { Debug.LogWarning(methodName + " - landscape cannot be null"); } } else if (terrainMaterialType != LBLandscape.TerrainMaterialType.MegaSplat) { if (showErrors) { Debug.LogWarning(methodName + " - The Landscape Terrain Settings needs to have a Material Type of Mega Splat. Please set and try again."); } } else if (landscape.terrainCustomMaterial == null) { if (showErrors) { Debug.LogWarning(methodName + " - the landscape does not appear to have a MegaSplat material. Has it been initialised in the Landscape Terrain Settings?"); } } else { UnityEngine.Object obj = UnityEditor.Selection.activeObject; if (obj != null) { System.Type cfgType = obj.GetType(); System.Type cfgEditorType = null; System.Type TerrainPainterWindowType = null; System.Type ITerrainPainterUtilityType = null; System.Type TerrainToMegaSplatConfigType = null; if (cfgType.FullName == "JBooth.MegaSplat.TextureArrayConfig") { //Debug.Log("MegaSplatCopyTextures cfgType found: " + cfgType.AssemblyQualifiedName); UnityEngine.Object objTerrainToMegaSplatConfig = LBIntegration.MegaSplatCreateTerrainToMegaSplatConfig(landscape, terrainMaterialType, obj, showErrors); // Get the textures from the landscape List <LBTerrainTexture> terrainTextureList = landscape.TerrainTexturesList(); if (terrainTextureList != null) { if (terrainTextureList.Count > 0) { // Add all the non-disabled textures to a list // Previously MegaSplat uses an array of Texture2Ds. Now it has a TextureEntry class // which can hold multiple textures (diffuse, normalmap, heightmap etc) List <JBooth.MegaSplat.TextureArrayConfig.TextureEntry> textureEntryList = new List <JBooth.MegaSplat.TextureArrayConfig.TextureEntry>(); JBooth.MegaSplat.TextureArrayConfig.TextureEntry textureEntry = null; for (int t = 0; t < terrainTextureList.Count; t++) { LBTerrainTexture lbTerrainTexture = terrainTextureList[t]; if (!lbTerrainTexture.isDisabled) { Texture2D texture2D = lbTerrainTexture.texture; if (texture2D != null) { textureEntry = new JBooth.MegaSplat.TextureArrayConfig.TextureEntry(); if (textureEntry != null) { textureEntry.diffuse = texture2D; textureEntry.normal = lbTerrainTexture.normalMap; textureEntry.height = lbTerrainTexture.heightMap; textureEntryList.Add(textureEntry); } } } } try { if (textureEntryList.Count > 0) { cfgEditorType = System.Type.GetType("JBooth.MegaSplat.TextureArrayConfigEditor, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true, true); TerrainPainterWindowType = System.Type.GetType("JBooth.TerrainPainter.TerrainPainterWindow, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true, true); ITerrainPainterUtilityType = System.Type.GetType("JBooth.TerrainPainter.ITerrainPainterUtility, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true, true); TerrainToMegaSplatConfigType = objTerrainToMegaSplatConfig.GetType(); var cfgEditorWindow = UnityEditor.EditorWindow.GetWindow <UnityEditor.EditorWindow>("Inspector", false); if (cfgEditorType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find TextureArrayConfigEditor editor class. Please Report."); } } else if (TerrainPainterWindowType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find TerrainPainterWindowType editor class. Please Report."); } } else if (ITerrainPainterUtilityType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find ITerrainPainterUtilityType editor class. Please Report."); } } else if (TerrainToMegaSplatConfigType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find TerrainToMegaSplatConfigType editor class. Please Report."); } } else { // LB 2.0.6 Beta 7j add compile step back in (was previously broken and had to be done manually in the editor) //string[] shaderFeatures = { "_TERRAIN" }; //LBIntegration.MegaSplatCompileShader(landscape, shaderFeatures, false, true); // Previously MegaSplat uses an array of Texture2Ds. Now it has a TextureEntry class cfgType.GetField("sourceTextures").SetValue(obj, textureEntryList); if (cfgEditorWindow != null) { cfgEditorType.InvokeMember("CompileConfig", System.Reflection.BindingFlags.InvokeMethod, null, null, new object[] { obj }); // Select the landscape in the Hierarchy and open the Terrain Painter window UnityEditor.Selection.activeGameObject = landscape.gameObject; var windowTerrainPainter = UnityEditor.EditorWindow.GetWindow(TerrainPainterWindowType, false); if (windowTerrainPainter == null) { Debug.LogWarning("LBIntegration.MegaSplatCopyTextures - Could not open TerrainPainter window. Please Report."); } else { // Add the TextureArrayConfig to the TerrainToMegaSplatConfig file TerrainToMegaSplatConfigType.InvokeMember("config", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.Public, null, objTerrainToMegaSplatConfig, new object[] { obj }); // Updates the Paint tab in Terrain Painter TerrainPainterWindowType.InvokeMember("config", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { obj }); // Initialise Utilities (else results in a timing issue where Utilities not found first time) TerrainPainterWindowType.InvokeMember("InitPluginUtilities", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { }); // We need to give time for MegaSplat to configure the Texture Array Debug.Log("INFO: Setting up MegaSplat Texture Array..."); // Update "config" field of the Terrain Converter on the Utilities tab IList utilitiesList = (IList)TerrainPainterWindowType.InvokeMember("utilities", System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { }); if (utilitiesList == null) { if (showErrors) { Debug.LogWarning("LBIntegration.MegaSplatCopyTextures - Could not find Utilities. Please Report."); } } else if (utilitiesList != null) { if (utilitiesList.Count == 0) { if (showErrors) { Debug.LogWarning("LBIntegration.MegaSplatCopyTextures - No Utilities found. Please Report."); } } // Located the Terrain To Splat Converter utility foreach (var tPainterInterface in utilitiesList) { if (tPainterInterface.ToString() == "JBooth.MegaSplat.TerrainToSplatConverter") { //Debug.Log("Interface: " + tPainterInterface.GetType().Name); tPainterInterface.GetType().InvokeMember("config", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic, null, tPainterInterface, new object[] { objTerrainToMegaSplatConfig }); int tabIndex = LBIntegration.MegaSplatGetTerrainPainterTabIndex("Utility", true); // Show the Utilities tab TerrainPainterWindowType.InvokeMember("tab", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { tabIndex }); //var terrainJobs = TerrainPainterWindowType.InvokeMember("terrains", System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { }); ////Debug.Log("Calling OnGUI"); //tPainterInterface.GetType().InvokeMember("OnGUI", System.Reflection.BindingFlags.InvokeMethod, null, tPainterInterface, new object[] { terrainJobs }); break; } } } LBIntegration.MegaSplatUpdateShaderSplat(landscape, "Albedo", false, obj, true); } } else { Debug.LogWarning(methodName + " - Could not open TextureArrayConfigEditor window. Please Report."); } } } } catch (System.Exception ex) { if (showErrors) { Debug.LogWarning(methodName + " something has gone wrong (MegaSplat 1.73+ required). Please report. " + ex.Message); } } } } } else { Debug.LogWarning("MegaSplatCopyTextures - Please select the Texture Array Config in the Project window and try again."); } } else { Debug.LogWarning("MegaSplatCopyTextures - Please select the Texture Array Config in the Project window and try again."); } } }
/// <summary> /// Add the defines for LB so devs can use the following define in their scripts to call LB methods /// #if LANDSCAPE_BUILDER /// // Call LB APIs /// #endif /// </summary> static void DefineSymbols() { // Is LB installed in this project const string LB_Define = "LANDSCAPE_BUILDER"; // Are the LB Editor scripts installed in this project? // This is a subset of LB. See Manager\LBManager.cs const string LBEditor_Define = "LB_EDITOR"; // EasyRoads3D v3 does not have it's own #define so we add one if it is installed const string LBEditorER3_Define = "LB_EDITOR_ER3"; string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup); if (!defines.Contains(LB_Define)) { if (string.IsNullOrEmpty(defines)) { defines = LB_Define; } else if (!defines.EndsWith(";")) { defines += ";" + LB_Define; } PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines); } // Do the Landscape Builder editor scripts appear in the project? // Check for the LBGroupDesignerItem.cs System.Type groupDesignerType = System.Type.GetType("LandscapeBuilder.LBGroupDesignerItem, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false, true); // If editor scripts exist, add the Editor define if it is missing if (groupDesignerType != null) { if (!defines.Contains(LBEditor_Define)) { if (string.IsNullOrEmpty(defines)) { defines = LBEditor_Define; } else if (!defines.EndsWith(";")) { defines += ";" + LBEditor_Define; } PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines); } } // If EasyRoads3D v3.x exists, add a #defines for it. This is currently used by LBPathImporter if (LBIntegration.isEasyRoads3DInstalled(false) && !defines.Contains(LBEditorER3_Define)) { if (string.IsNullOrEmpty(defines)) { defines = LBEditorER3_Define; } else if (!defines.EndsWith(";")) { defines += ";" + LBEditorER3_Define; } PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines); } }