You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.3 KiB

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. [CustomEditor(typeof(FogVolumeLight))]
  6. public class FogVolumeLightEditor : Editor
  7. {
  8. public override void OnInspectorGUI()
  9. {
  10. GUILayout.Space(10.0f);
  11. serializedObject.Update();
  12. GUILayout.BeginVertical("box");
  13. var usesNormalLight = serializedObject.FindProperty("IsAddedToNormalLight");
  14. if (usesNormalLight.boolValue)
  15. {
  16. EditorGUILayout.HelpBox("This light will use the settings of the light on this GameObject.\n\nRemove this component if the light should not be recognized by Fog Volume 3", MessageType.Info);
  17. }
  18. else
  19. {
  20. var enabled = serializedObject.FindProperty("Enabled");
  21. if (GUILayout.Button(enabled.boolValue ? "Disable the light" : "Enable the light"))
  22. {
  23. enabled.boolValue = !enabled.boolValue;
  24. }
  25. if (enabled.boolValue == true)
  26. {
  27. GUILayout.Space(10.0f);
  28. var isPointLight = serializedObject.FindProperty("IsPointLight");
  29. int selectedLightType = isPointLight.boolValue ? 0 : 1;
  30. selectedLightType =
  31. EditorGUILayout.Popup("Light Type: ",
  32. selectedLightType,
  33. m_lightTypes,
  34. EditorStyles.toolbarButton);
  35. if (selectedLightType == 0) { isPointLight.boolValue = true; }
  36. else { isPointLight.boolValue = false; }
  37. GUILayout.Space(10.0f);
  38. var color = serializedObject.FindProperty("Color");
  39. EditorGUILayout.PropertyField(color, new GUIContent("Color:"));
  40. GUILayout.Space(10.0f);
  41. var intensity = serializedObject.FindProperty("Intensity");
  42. EditorGUILayout.Slider(intensity,
  43. MinIntensity,
  44. MaxIntenstity,
  45. new GUIContent("Intensity:"));
  46. GUILayout.Space(10.0f);
  47. var range = serializedObject.FindProperty("Range");
  48. EditorGUILayout.Slider(range, MinRange, MaxRange, new GUIContent("Range:"));
  49. if (selectedLightType == 1)
  50. {
  51. GUILayout.Space(10.0f);
  52. var angle = serializedObject.FindProperty("Angle");
  53. EditorGUILayout.Slider(angle,
  54. MinSpotAngle,
  55. MaxSpotAngle,
  56. new GUIContent("SpotAngle:"));
  57. }
  58. }
  59. }
  60. GUILayout.EndVertical();
  61. serializedObject.ApplyModifiedProperties();
  62. }
  63. private const float MinIntensity = 0.0f;
  64. private const float MaxIntenstity = 50.0f;
  65. private const float MinRange = 0.0f;
  66. private const float MaxRange = 500.0f;
  67. private const float MinSpotAngle = 0.0f;
  68. private const float MaxSpotAngle = 180.0f;
  69. private readonly string[] m_lightTypes = new[]
  70. {
  71. "Point Light",
  72. "Spot Light"
  73. };
  74. }