CinemachineColliderPrefs.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnityEngine;
  2. using UnityEditor;
  3. using Cinemachine.Editor;
  4. namespace Cinemachine
  5. {
  6. [InitializeOnLoad]
  7. internal static class CinemachineColliderPrefs
  8. {
  9. private static bool SettingsFoldedOut
  10. {
  11. get { return EditorPrefs.GetBool(kColliderSettingsFoldoutKey, false); }
  12. set
  13. {
  14. if (value != SettingsFoldedOut)
  15. {
  16. EditorPrefs.SetBool(kColliderSettingsFoldoutKey, value);
  17. }
  18. }
  19. }
  20. public static Color FeelerHitColor
  21. {
  22. get
  23. {
  24. return CinemachineSettings.UnpackColour(EditorPrefs.GetString(kFeelerHitColourKey, CinemachineSettings.PackColor(Color.yellow)));
  25. }
  26. set
  27. {
  28. if (value != FeelerHitColor)
  29. {
  30. EditorPrefs.SetString(kFeelerHitColourKey, CinemachineSettings.PackColor(value));
  31. }
  32. }
  33. }
  34. public static Color FeelerColor
  35. {
  36. get
  37. {
  38. return CinemachineSettings.UnpackColour(EditorPrefs.GetString(kFeelerColourKey, CinemachineSettings.PackColor(Color.gray)));
  39. }
  40. set
  41. {
  42. if (value != FeelerColor)
  43. {
  44. EditorPrefs.SetString(kFeelerColourKey, CinemachineSettings.PackColor(value));
  45. }
  46. }
  47. }
  48. private const string kColliderSettingsFoldoutKey = "CNMCN_Collider_Foldout";
  49. private const string kFeelerHitColourKey = "CNMCN_Collider_FeelerHit_Colour";
  50. private const string kFeelerColourKey = "CNMCN_Collider_Feeler_Colour";
  51. static CinemachineColliderPrefs()
  52. {
  53. Cinemachine.Editor.CinemachineSettings.AdditionalCategories += DrawColliderSettings;
  54. }
  55. private static void DrawColliderSettings()
  56. {
  57. SettingsFoldedOut = EditorGUILayout.Foldout(SettingsFoldedOut, "Collider Settings", true);
  58. if (SettingsFoldedOut)
  59. {
  60. EditorGUI.indentLevel++;
  61. EditorGUI.BeginChangeCheck();
  62. FeelerHitColor = EditorGUILayout.ColorField("Feeler Hit", FeelerHitColor);
  63. FeelerColor = EditorGUILayout.ColorField("Feeler", FeelerColor);
  64. if (EditorGUI.EndChangeCheck())
  65. {
  66. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
  67. }
  68. EditorGUI.indentLevel--;
  69. }
  70. }
  71. }
  72. }