private void ConstrainSurfaceToPlatform(LevelEntity_Platform platform, bool constrainAbovePlatform) { // If editing isn't possible, then the surface can just be hierarchically contstrained #if NO_EDITING SurfaceRenderer.transform.SetParent(platform.transform); if (constrainAbovePlatform) { SurfaceRenderer.transform.localPosition = new Vector3( 0f, (HighElevation - LowElevation) / GeometryUtilities.WorldUnitIncrementsPerMeter, 0f); } else { SurfaceRenderer.transform.localPosition = Vector3.zero; } #else var constraint = SurfaceRenderer.gameObject.AddComponent <PlatformConstraint>(); constraint.Parent = platform.transform; if (constrainAbovePlatform) { constraint.WorldOffsetFromParent = new Vector3( 0f, (HighElevation - LowElevation) / GeometryUtilities.WorldUnitIncrementsPerMeter, 0f); } else { constraint.WorldOffsetFromParent = Vector3.zero; } constraint.ApplyConstraint(); platformConstraint = constraint; #endif }
public override void ApplyPlatform() { if (platformComponent) { switch (dataSource) { case LevelEntity_Polygon.DataSources.Floor: if (polygonEntity.ParentLevel.FloorPlatforms.ContainsKey(platformComponent.NativeIndex)) { polygonEntity.ParentLevel.FloorPlatforms.Remove(platformComponent.NativeIndex); } break; case LevelEntity_Polygon.DataSources.Ceiling: if (polygonEntity.ParentLevel.CeilingPlatforms.ContainsKey(platformComponent.NativeIndex)) { polygonEntity.ParentLevel.CeilingPlatforms.Remove(platformComponent.NativeIndex); } break; case LevelEntity_Polygon.DataSources.Media: // Media surfaces don't have platforms return; default: throw new NotImplementedException($"DataSource '{dataSource}' is not implemented."); } platformComponent.PrepareForDestruction(); UnityEngine.Object.Destroy(platformComponent); } IsStaticBatchable = true; var platform = GeometryUtilities.GetPlatformForPolygon(polygonEntity.ParentLevel.Level, polygonEntity.NativeObject); if (platform != null) { switch (dataSource) { case LevelEntity_Polygon.DataSources.Floor: if (platform.ComesFromFloor) { var runtimePlatform = SurfaceRenderer.gameObject.AddComponent <LevelEntity_Platform>(); runtimePlatform.InitializeEntity( polygonEntity.ParentLevel, polygonEntity.NativeObject.Permutation, platform); runtimePlatform.UpdatePlatformValues(LevelEntity_Platform.LinkedSurfaces.Floor); polygonEntity.ParentLevel.FloorPlatforms[polygonEntity.NativeObject.Permutation] = runtimePlatform; platformComponent = runtimePlatform; IsStaticBatchable = false; runtimePlatform.BeginRuntimeStyleBehavior(); } break; case LevelEntity_Polygon.DataSources.Ceiling: if (platform.ComesFromCeiling) { var runtimePlatform = SurfaceRenderer.gameObject.AddComponent <LevelEntity_Platform>(); runtimePlatform.InitializeEntity( polygonEntity.ParentLevel, polygonEntity.NativeObject.Permutation, platform); runtimePlatform.UpdatePlatformValues(LevelEntity_Platform.LinkedSurfaces.Ceiling); polygonEntity.ParentLevel.CeilingPlatforms[polygonEntity.NativeObject.Permutation] = runtimePlatform; platformComponent = runtimePlatform; IsStaticBatchable = false; runtimePlatform.BeginRuntimeStyleBehavior(); } break; case LevelEntity_Polygon.DataSources.Media: // Media surfaces don't have platforms return; default: throw new NotImplementedException($"DataSource '{dataSource}' is not implemented."); } } if (platformComponent) { ApplyTransformPosition(); } }