public static bool TryRaycastTerrain(Vector3 pos, Vector3 direction, out Vector3 hitpoint, bool andNetBuildings = false)
 {
     ToolBase.RaycastInput rayInput = new ToolBase.RaycastInput(new Ray(pos, direction), 10000);
     if (andNetBuildings)
     {
         // BloodyPenguin's code
         // from Prop Snapping tool
         // https://github.com/bloodypenguin/Skylines-PropSnapping/blob/master/PropSnapping/Detour/PropToolDetour.cs#L65
         rayInput.m_ignoreBuildingFlags = Building.Flags.None;
         rayInput.m_ignoreNodeFlags     = NetNode.Flags.None;
         rayInput.m_ignoreSegmentFlags  = NetSegment.Flags.None;
         rayInput.m_buildingService     = new ProceduralTool.RaycastService(ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Layer.Default);
         rayInput.m_netService          = new ProceduralTool.RaycastService(ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Layer.Default);
         rayInput.m_netService2         = new ProceduralTool.RaycastService(ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Layer.Default);
     }
     ToolBase.RaycastOutput rayOutput;
     if (ProceduralTool.TerrainRaycast(rayInput, out rayOutput))
     {
         hitpoint = rayOutput.m_hitPos;
         return(true);
     }
     else
     {
         rayInput = new ToolBase.RaycastInput(new Ray(pos, -direction), 10000);
         if (ProceduralTool.TerrainRaycast(rayInput, out rayOutput))
         {
             hitpoint = rayOutput.m_hitPos;
             return(true);
         }
     }
     hitpoint = pos;
     return(false);
 }
예제 #2
0
 public static void SnapToGround(this ProceduralObject obj)
 {
     obj.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.position, null);
     ToolBase.RaycastInput  rayInput = new ToolBase.RaycastInput(new Ray(obj.m_position, Vector3.down), 10000);
     ToolBase.RaycastOutput rayOutput;
     if (ProceduralTool.TerrainRaycast(rayInput, out rayOutput))
     {
         obj.m_position = rayOutput.m_hitPos;
     }
     else
     {
         rayInput = new ToolBase.RaycastInput(new Ray(obj.m_position, Vector3.up), 10000);
         if (ProceduralTool.TerrainRaycast(rayInput, out rayOutput))
         {
             obj.m_position = rayOutput.m_hitPos;
         }
     }
     obj.historyEditionBuffer.ConfirmNewStep(null);
 }