ProjectedBoxFacePivotPointsRenderer.cs 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. namespace O3DWB
  6. {
  7. public class ProjectedBoxFacePivotPointsRenderer
  8. {
  9. #region Public Methods
  10. public void RenderGizmos(ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints, ObjectPivotPointsRenderSettings pivotPointsRenderSettings)
  11. {
  12. if (ObjectPlacementGuide.ExistsInSceneAndIsActive &&
  13. SceneViewCamera.Instance.IsGameObjectHierarchyVisible(ObjectPlacementGuide.SceneObject))
  14. {
  15. RenderPivotPointConnectionLines(projectedBoxFacePivotPoints, pivotPointsRenderSettings);
  16. RenderPivotPointProjectionLines(projectedBoxFacePivotPoints, pivotPointsRenderSettings);
  17. RenderAllPivotPoints(projectedBoxFacePivotPoints, pivotPointsRenderSettings);
  18. }
  19. }
  20. #endregion
  21. #region Private Methods
  22. private void RenderAllPivotPoints(ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints, ObjectPivotPointsRenderSettings pivotPointsRenderSettings)
  23. {
  24. List<Vector3> allPivotPoints = projectedBoxFacePivotPoints.AllPoints;
  25. if (allPivotPoints.Count != 0)
  26. {
  27. ProjectedBoxFacePivotPointsRenderSettings renderSettings = pivotPointsRenderSettings.ProjectedBoxFacePivotPointsRenderSettings;
  28. IPivotPointRenderer objectPivotPointRenderer = PivotPointRendererFactory.Create(pivotPointsRenderSettings.ShapeType);
  29. Color activePivotPointFillColor = renderSettings.ActivePivotPointRenderSettings.FillColor;
  30. Color inactivePivotPointFillColor = renderSettings.InactivePivotPointRenderSettings.FillColor;
  31. Color activePivotPointBorderLineColor = renderSettings.ActivePivotPointRenderSettings.BorderLineColor;
  32. Color inactivePivotPointBorderLineColor = renderSettings.InactivePivotPointRenderSettings.BorderLineColor;
  33. float pivotPointSizeInPixels = pivotPointsRenderSettings.PivotPointSizeInPixels;
  34. float activePivotPointScale = renderSettings.ActivePivotPointRenderSettings.Scale;
  35. float inactivePivotPointScale = renderSettings.InactivePivotPointRenderSettings.Scale;
  36. if(renderSettings.InactivePivotPointRenderSettings.IsVisible)
  37. {
  38. for (int pivotPointIndex = 0; pivotPointIndex < allPivotPoints.Count; ++pivotPointIndex)
  39. {
  40. if (pivotPointIndex != projectedBoxFacePivotPoints.IndexOfActivePoint)
  41. objectPivotPointRenderer.Render(allPivotPoints[pivotPointIndex], inactivePivotPointFillColor, inactivePivotPointBorderLineColor, pivotPointSizeInPixels * inactivePivotPointScale);
  42. }
  43. }
  44. if(renderSettings.ActivePivotPointRenderSettings.IsVisible)
  45. objectPivotPointRenderer.Render(allPivotPoints[projectedBoxFacePivotPoints.IndexOfActivePoint], activePivotPointFillColor, activePivotPointBorderLineColor, pivotPointSizeInPixels * activePivotPointScale);
  46. }
  47. }
  48. private void RenderPivotPointConnectionLines(ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints, ObjectPivotPointsRenderSettings pivotPointsRenderSettings)
  49. {
  50. ProjectedBoxFacePivotPointsRenderSettings renderSettings = pivotPointsRenderSettings.ProjectedBoxFacePivotPointsRenderSettings;
  51. if(renderSettings.RenderPivotPointConnectionLines)
  52. {
  53. List<Vector3> pivotPointsNoCenter = projectedBoxFacePivotPoints.GetAllPointsExcludingCenter();
  54. if (pivotPointsNoCenter.Count != 0) GizmosEx.RenderLinesBetweenPoints(pivotPointsNoCenter, renderSettings.PivotPointConnectionLineColor);
  55. }
  56. }
  57. private void RenderPivotPointProjectionLines(ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints, ObjectPivotPointsRenderSettings pivotPointsRenderSettings)
  58. {
  59. ProjectedBoxFacePivotPointsRenderSettings renderSettings = pivotPointsRenderSettings.ProjectedBoxFacePivotPointsRenderSettings;
  60. if(renderSettings.RenderProjectionLines)
  61. {
  62. List<Vector3> allPivotPoints = projectedBoxFacePivotPoints.AllPoints;
  63. if(allPivotPoints.Count != 0)
  64. {
  65. Color projectionLineColor = renderSettings.ProjectionLineColor;
  66. List<Vector3> unprojectedPoints = projectedBoxFacePivotPoints.GetUnprojectedPivotPoints();
  67. for(int pointIndex = 0; pointIndex < unprojectedPoints.Count; ++pointIndex)
  68. {
  69. GizmosEx.RenderLine(allPivotPoints[pointIndex], unprojectedPoints[pointIndex], projectionLineColor);
  70. }
  71. }
  72. }
  73. }
  74. #endregion
  75. }
  76. }
  77. #endif