VesselHelper.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /************************************************/
  2. /* */
  3. /* Copyright (c) 2018 - 2021 monitor1394 */
  4. /* https://github.com/monitor1394 */
  5. /* */
  6. /************************************************/
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9. namespace XCharts
  10. {
  11. public static class VesselHelper
  12. {
  13. public static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName)
  14. {
  15. if (serie != null && vessel.autoColor)
  16. {
  17. var colorIndex = legendRealShowName.IndexOf(serie.name);
  18. return SerieHelper.GetItemColor(serie, null, theme, colorIndex, false);
  19. }
  20. else
  21. {
  22. return vessel.color;
  23. }
  24. }
  25. public static void UpdateVesselCenter(Vessel vessel, Vector3 chartPosition, float chartWidth, float chartHeight)
  26. {
  27. if (vessel.center.Length < 2) return;
  28. var centerX = vessel.center[0] <= 1 ? chartWidth * vessel.center[0] : vessel.center[0];
  29. var centerY = vessel.center[1] <= 1 ? chartHeight * vessel.center[1] : vessel.center[1];
  30. var checkWidth = Mathf.Min(chartWidth, chartHeight);
  31. vessel.runtimeCenterPos = chartPosition + new Vector3(centerX, centerY);
  32. vessel.runtimeRadius = ChartHelper.GetRuntimeRelativeOrAbsoluteValue(vessel.radius, checkWidth);
  33. vessel.runtimeInnerRadius = vessel.runtimeRadius - vessel.shapeWidth - vessel.gap;
  34. vessel.runtimeWidth = ChartHelper.GetRuntimeRelativeOrAbsoluteValue(vessel.width, checkWidth) - 2 * vessel.gap;
  35. vessel.runtimeHeight = ChartHelper.GetRuntimeRelativeOrAbsoluteValue(vessel.height, chartHeight) - 2 * vessel.gap;
  36. }
  37. }
  38. }