GradientSkyboxEditor.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. using UnityEditor;
  3. public class GradientSkyboxEditor : UnityEditor.MaterialEditor {
  4. public override void OnInspectorGUI() {
  5. serializedObject.Update();
  6. var theShader = serializedObject.FindProperty ("m_Shader");
  7. if (isVisible && !theShader.hasMultipleDifferentValues && theShader.objectReferenceValue != null) {
  8. EditorGUI.BeginChangeCheck();
  9. base.OnInspectorGUI();
  10. if (EditorGUI.EndChangeCheck()) {
  11. var dirPitch = GetMaterialProperty(targets, "_DirectionPitch");
  12. var dirYaw = GetMaterialProperty(targets, "_DirectionYaw");
  13. var dirPitchRad = dirPitch.floatValue * Mathf.Deg2Rad;
  14. var dirYawRad = dirYaw.floatValue * Mathf.Deg2Rad;
  15. var direction = new Vector4(Mathf.Sin(dirPitchRad) * Mathf.Sin(dirYawRad), Mathf.Cos(dirPitchRad),
  16. Mathf.Sin(dirPitchRad) * Mathf.Cos(dirYawRad), 0.0f);
  17. GetMaterialProperty(targets, "_Direction").vectorValue = direction;
  18. PropertiesChanged();
  19. }
  20. }
  21. }
  22. }