public static void DestroyIf(GStylizedTerrain terrain, System.Predicate <GameObject> condition) { List <Transform> parents = new List <Transform>(); foreach (Transform t in terrain.transform) { if (t.name.StartsWith("~Root")) { parents.Add(t); } } for (int i = 0; i < parents.Count; ++i) { GameObject[] children = GUtilities.GetChildrenGameObjects(parents[i]); for (int j = 0; j < children.Length; ++j) { if (condition.Invoke(children[j])) { #if UNITY_EDITOR Undo.DestroyObjectImmediate(children[j]); #else GUtilities.DestroyGameobject(children[j]); #endif } } } }
public static void DestroyIf(GStylizedTerrain terrain, GameObject prototype, System.Predicate <GameObject> condition) { Transform parent = GetRoot(terrain, prototype).transform; GameObject[] children = GUtilities.GetChildrenGameObjects(parent); for (int i = 0; i < children.Length; ++i) { if (condition.Invoke(children[i])) { #if UNITY_EDITOR Undo.DestroyObjectImmediate(children[i]); #else GUtilities.DestroyGameobject(children[i]); #endif } } }
internal void SetupLODGroup(int lodCount) { float transitionStep = 1.0f / lodCount; LOD[] lods = new LOD[lodCount]; lods[0] = new LOD( GRuntimeSettings.Instance.geometryGeneration.lodTransition.Evaluate(transitionStep), new Renderer[] { MeshRendererComponent }); for (int level = 1; level < lodCount; ++level) { int i = level; lods[i] = new LOD( GRuntimeSettings.Instance.geometryGeneration.lodTransition.Evaluate((i + 1) * transitionStep), new Renderer[] { GetChunkLOD(i).MeshRendererComponent }); GTerrainChunkLOD chunkLod = GetChunkLOD(i); chunkLod.MeshFilterComponent.sharedMesh = null; chunkLod.MeshRendererComponent.enabled = true; } LodGroupComponent.SetLODs(lods); Internal_UpdateRenderer(); List <GameObject> childLod = new List <GameObject>(); int maxIndex = transform.childCount - 1; for (int i = lodCount - 1; i <= maxIndex; ++i) { Transform child = transform.GetChild(i); if (child != null) { childLod.Add(transform.GetChild(i).gameObject); } } for (int i = 0; i < childLod.Count; ++i) { GUtilities.DestroyGameobject(childLod[i]); } }
private void CreateStaticObstacles(GStylizedTerrain t) { if (t.TerrainData == null) { return; } if (t.TerrainData.Foliage.Trees == null) { return; } if (t.TerrainData.Foliage.Trees.Prototypes.Count == 0) { return; } #if UNITY_EDITOR string title = "Creating static obstacles"; string info = t.name; GCommonGUI.CancelableProgressBar(title, info, 0); #endif Vector3 terrainSize = new Vector3( t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Height, t.TerrainData.Geometry.Length); Transform root = GUtilities.GetChildrenWithName(transform, string.Format("{0}_{1}", t.name, t.GetInstanceID())); List <GTreePrototype> prototypes = t.TerrainData.Foliage.Trees.Prototypes; GameObject[] templates = new GameObject[prototypes.Count]; for (int i = 0; i < prototypes.Count; ++i) { if (!prototypes[i].IsValid) { continue; } GameObject template = Instantiate(prototypes[i].Prefab) as GameObject; Component[] components = template.GetComponentsInChildren <Component>(); for (int j = 0; j < components.Length; ++j) { if (components[j] is Collider) { GUtilities.DestroyObject(components[j]); } if (components[j] is MeshRenderer) { MeshRenderer mr = components[j] as MeshRenderer; mr.sharedMaterials = new Material[] { GInternalMaterials.NavHelperDummyGameObjectMaterial }; mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.receiveShadows = false; } } #if UNITY_EDITOR GameObjectUtility.SetStaticEditorFlags(template, StaticEditorFlags.NavigationStatic); #endif template.name = prototypes[i].Prefab.name; templates[i] = template; } List <GTreeInstance> instances = t.TerrainData.Foliage.TreeInstances; for (int i = 0; i < instances.Count; ++i) { #if UNITY_EDITOR GCommonGUI.CancelableProgressBar(title, info, i * 1.0f / instances.Count); #endif GTreeInstance tree = instances[i]; if (templates[tree.PrototypeIndex] == null) { continue; } GameObject g = Instantiate(templates[tree.PrototypeIndex]) as GameObject; g.transform.parent = root; Vector3 localPos = new Vector3( tree.Position.x * terrainSize.x, tree.Position.y * terrainSize.y, tree.Position.z * terrainSize.z); Vector3 worldPos = t.transform.TransformPoint(localPos); g.transform.position = worldPos; g.transform.rotation = tree.Rotation; g.transform.localScale = tree.Scale; g.name = templates[tree.PrototypeIndex].name; } for (int i = 0; i < templates.Length; ++i) { GUtilities.DestroyGameobject(templates[i]); } #if UNITY_EDITOR GCommonGUI.ClearProgressBar(); #endif }
private void DeleteStaticObstacles(GStylizedTerrain t) { Transform root = GUtilities.GetChildrenWithName(transform, string.Format("{0}_{1}", t.name, t.GetInstanceID())); GUtilities.DestroyGameobject(root.gameObject); }