private void Construction_Cleanup(){ FixZ(); if(TerrainCalcsJob != null){ TerrainCalcsJob.Abort(); TerrainCalcsJob = null; } if(RoadCalcsJob1 != null){ RoadCalcsJob1.Abort(); RoadCalcsJob1 = null; } if(RoadCalcsJob2 != null){ RoadCalcsJob2.Abort(); RoadCalcsJob2 = null; } Editor_bIsConstructing = false; int mCount = GSDSpline.GetNodeCount(); GSDSplineN tNode; for(int i=0;i<mCount;i++){ tNode = GSDSpline.mNodes[i]; if(tNode.bIsIntersection){ if(tNode.iConstruction != null){ tNode.iConstruction.Nullify(); tNode.iConstruction = null; } } tNode.SetupSplinationLimits(); tNode.SetupEdgeObjects(false); tNode.SetupSplinatedMeshes(false); } if(GSDSpline.HeightHistory != null){ GSDSpline.HeightHistory.Clear(); GSDSpline.HeightHistory = null; } if(RCS != null){ RCS.Nullify(); RCS = null; } if(GSDRS.opt_bSaveMeshes){ UnityEditor.AssetDatabase.SaveAssets(); } bEditorProgressBar = false; EditorUtility.ClearProgressBar(); //Make sure terrain history out of memory if necessary (redudant but keep): if(opt_SaveTerrainHistoryOnDisk && TerrainHistory != null){ TerrainHistory.Clear(); TerrainHistory = null; } //Collect: bTriggerGC = true; if (tRoadMaterialDropdownOLD != opt_tRoadMaterialDropdown) { tRoadMaterialDropdownOLD = opt_tRoadMaterialDropdown; SetAllCutsToCurrentMaterials(); } if(PiggyBacks != null && PiggyBacks.Length > 0){ for(int i=0;i<PiggyBacks.Length;i++){ if(PiggyBacks[i] == null){ PiggyBacks = null; break; } } if(PiggyBacks != null){ GSDSplineC tPiggy = PiggyBacks[0]; GSDSplineC[] NewPiggys = null; PiggyBacks[0] = null; if(PiggyBacks.Length > 1){ NewPiggys = new GSDSplineC[PiggyBacks.Length-1]; for(int i=1;i<PiggyBacks.Length;i++){ NewPiggys[i-1] = PiggyBacks[i]; } } if(NewPiggys != null){ tPiggy.tRoad.PiggyBacks = NewPiggys; } NewPiggys = null; tPiggy.Setup_Trigger(); } } }
private void ConstructRoad2(){ EditorProgress = 40; if(RCS.bTerrainOn){ //Store history: GSDTerraforming.ProcessRoad_Terrain_Hook2(GSDSpline,ref EditorTTDList); ConstructRoad_StoreTerrainHistory(); int EditorTTDListCount = EditorTTDList.Count; for(int i=0;i<EditorTTDListCount;i++){ EditorTTDList[i] = null; } EditorTTDList = null; System.GC.Collect(); } EditorProgress = 60; if(TerrainCalcsJob != null){ TerrainCalcsJob.Abort(); TerrainCalcsJob = null; } GSDRoad tRoad = this; EditorProgress = 72; RoadCalcsJob1 = new GSD.Threaded.RoadCalcs1(); RoadCalcsJob1.Setup(ref RCS, ref tRoad); RoadCalcsJob1.Start(); }
private void ConstructRoad3(){ EditorProgress = 84; RCS.MeshSetup1(); EditorProgress = 96; if(RoadCalcsJob1 != null){ RoadCalcsJob1.Abort(); RoadCalcsJob1 = null; } RoadCalcsJob2 = new GSD.Threaded.RoadCalcs2(); RoadCalcsJob2.Setup(ref RCS); RoadCalcsJob2.Start(); EditorProgress = 98; }
public void UpdateRoad(RoadUpdateTypeEnum tUpdateType = RoadUpdateTypeEnum.Full){ if (!GSDRS.opt_bAllowRoadUpdates) { GSDSpline.Setup(); Editor_bIsConstructing = false; return; } if(Editor_bIsConstructing){ return; } SetupUniqueIdentifier(); if(bProfiling){ Profiler.BeginSample("UpdateRoadPrelim"); } opt_RoadDefinition = Mathf.Clamp(opt_RoadDefinition,1f,50f); opt_LaneWidth = Mathf.Clamp(opt_LaneWidth,0.2f,500f); EditorConstructionStartTime = Time.realtimeSinceStartup; EditorTitleString = "Updating " + transform.name + "..."; System.GC.Collect(); if(opt_SaveTerrainHistoryOnDisk){ ConstructRoad_LoadTerrainHistory(); } CheckMats(); EditorUtility.ClearProgressBar(); bProfiling = true; if(GSDRS.opt_bMultithreading){ bProfiling = false; } //Set all terrains to height 0: GSD.Roads.GSDTerraforming.CheckAllTerrainsHeight0(); EditorProgress = 20; bEditorProgressBar = true; if(Editor_bIsConstructing){ if(TerrainCalcsJob != null){ TerrainCalcsJob.Abort(); TerrainCalcsJob = null; } if(RoadCalcsJob1 != null){ RoadCalcsJob1.Abort(); RoadCalcsJob1 = null; } if(RoadCalcsJob2 != null){ RoadCalcsJob2.Abort(); RoadCalcsJob2 = null; } Editor_bIsConstructing = false; } // if(Application.isPlaying || !Application.isEditor){ return; } // if(Application.isEditor && UnityEditor.EditorApplication.isPlaying){ return; } // if(Application.isEditor && UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode){ return; } //In here for intersection patching purposes: int mCount = GSDSpline.GetNodeCount(); GSDSplineN tNode = null; GSDSplineN tNode1 = null; GSDSplineN tNode2 = null; if(GSDSpline.CheckInvalidNodeCount()){ GSDSpline.Setup(); mCount = GSDSpline.GetNodeCount(); } if(mCount > 1){ for(int i=0;i<mCount;i++){ // try{ tNode = GSDSpline.mNodes[i]; // }catch{ // Editor_bIsConstructing = false; // EditorUpdateMe = true; // return; // } //If node is intersection with an invalid GSDRI, mark it at non-intersection. Just-in-case. if(tNode.bIsIntersection && tNode.GSDRI == null){ tNode.bIsIntersection = false; tNode.id_intersection_othernode = -1; tNode.Intersection_OtherNode = null; } //If node is intersection, re-setup: if(tNode.bIsIntersection && tNode.GSDRI != null){ tNode1 = tNode.GSDRI.Node1; tNode2 = tNode.GSDRI.Node2; tNode.GSDRI.Setup(tNode1,tNode2); tNode.GSDRI.DeleteRelevantChildren(tNode, tNode.GSDSpline.tRoad.transform.name); //If primary node on intersection, do more re-setup: if(tNode.GSDRI.Node1 == tNode){ tNode.GSDRI.Lanes = opt_Lanes; tNode.GSDRI.name = tNode.GSDRI.transform.name; } //Setup construction objects: tNode.GSDRI.Node1.iConstruction = new GSD.Roads.GSDIntersections.iConstructionMaker(); tNode.GSDRI.Node2.iConstruction = new GSD.Roads.GSDIntersections.iConstructionMaker(); } //Store materials and physical materials for road and or shoulder cuts on each node, if necessary: tNode.StoreCuts(); } } name = transform.name; GSDSpline.RoadWidth = RoadWidth(); // if(bProfiling){ Profiler.BeginSample("SplineSetup"); } GSDSpline.Setup(); // if(bProfiling){ Profiler.EndSample(); } mCount = GSDSpline.GetNodeCount(); if(GSDSpline == null || GSDSpline.mNodes == null){ MostRecentNodeCount = 0; }else{ MostRecentNodeCount = GSDSpline.GetNodeCount(); } if(opt_UseDefaultMaterials){ SetDefaultMats(); } if(opt_UseDefaultMaterials){ if(DetectInvalidDefaultMatsForUndo()){ SetAllCutsToCurrentMaterials(); } } //Hiding in hierarchy: for(int i=0;i<mCount;i++){ tNode = GSDSpline.mNodes[i]; if(tNode != null){ if(tNode.bIsIntersection || tNode.bSpecialEndNode){ tNode.ToggleHideFlags(true); }else{ tNode.ToggleHideFlags(false); } } } int cCount = transform.childCount; GameObject tMainMeshes = null; List<GameObject> tObjs = new List<GameObject>(); for(int i=0;i<cCount;i++){ if(transform.GetChild(i).transform.name.ToLower().Contains("mainmeshes")){ tMainMeshes = transform.GetChild(i).transform.gameObject; tObjs.Add(tMainMeshes); } } for(int i=(tObjs.Count-1);i>=0;i--){ tMainMeshes = tObjs[i]; Object.DestroyImmediate(tMainMeshes); } if(mCount < 2){ //Delete old objs and return: if(MainMeshes != null){ Object.DestroyImmediate(MainMeshes); } if(MeshRoad != null){ Object.DestroyImmediate(MeshRoad); } if(MeshShoR != null){ Object.DestroyImmediate(MeshShoR); } if(MeshShoL != null){ Object.DestroyImmediate(MeshShoL); } if(MeshiLanes != null){ Object.DestroyImmediate(MeshiLanes); } if(MeshiLanes0 != null){ Object.DestroyImmediate(MeshiLanes0); } if(MeshiLanes1 != null){ Object.DestroyImmediate(MeshiLanes1); } if(MeshiLanes2 != null){ Object.DestroyImmediate(MeshiLanes2); } if(MeshiLanes3 != null){ Object.DestroyImmediate(MeshiLanes3); } if(MeshiMainPlates != null){ Object.DestroyImmediate(MeshiMainPlates); } if(MeshiMarkerPlates != null){ Object.DestroyImmediate(MeshiMarkerPlates); } if(bProfiling){ Profiler.EndSample(); } return; } GSDSpline.HeightHistory = new List<KeyValuePair<float, float>>(); if(GSDRS == null){ GSDRS = transform.parent.GetComponent<GSDRoadSystem>(); } //Compatibility update. if(GSDRS.opt_bMultithreading){ Editor_bIsConstructing = true; }else{ Editor_bIsConstructing = false; } Editor_bConstructionID = 0; //Check if road takes place on only 1 terrain: Terrain tTerrain = GSD.Roads.GSDRoadUtil.GetTerrain(GSDSpline.mNodes[0].pos); bool bSameTerrain = true; for(int i=1;i<mCount;i++){ if(tTerrain != GSD.Roads.GSDRoadUtil.GetTerrain(GSDSpline.mNodes[0].pos)){ bSameTerrain = false; break; } } RCS = new RoadConstructorBufferMaker(this, tUpdateType); if(bSameTerrain){ RCS.tTerrain = tTerrain; }else{ RCS.tTerrain = null; } tTerrain = null; if(bProfiling){ Profiler.EndSample(); } if(GSDRS.opt_bMultithreading){ if(RCS.bTerrainOn || TerrainHistory == null){ GSDTerraforming.ProcessRoad_Terrain_Hook1(GSDSpline,this); }else{ ConstructRoad2(); } }else{ UpdateRoad_NoMultiThreading(); } }