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.

102 lines
4.8 KiB

  1. using UnityEngine;
  2. using System;
  3. using UnityEditor;
  4. [CustomEditor(typeof(GerstnerDisplace))]
  5. public class GerstnerDisplaceEditor : Editor
  6. {
  7. private SerializedObject serObj;
  8. public void OnEnable ()
  9. {
  10. serObj = new SerializedObject (target);
  11. }
  12. public override void OnInspectorGUI ()
  13. {
  14. serObj.Update();
  15. GameObject go = ((GerstnerDisplace)serObj.targetObject).gameObject;
  16. WaterBase wb = (WaterBase)go.GetComponent(typeof(WaterBase));
  17. Material sharedWaterMaterial = wb.sharedMaterial;
  18. GUILayout.Label ("Animates vertices using up 4 generated waves", EditorStyles.miniBoldLabel);
  19. if(sharedWaterMaterial)
  20. {
  21. Vector4 amplitude = WaterEditorUtility.GetMaterialVector("_GAmplitude", sharedWaterMaterial);
  22. Vector4 frequency = WaterEditorUtility.GetMaterialVector("_GFrequency", sharedWaterMaterial);
  23. Vector4 steepness = WaterEditorUtility.GetMaterialVector("_GSteepness", sharedWaterMaterial);
  24. Vector4 speed = WaterEditorUtility.GetMaterialVector("_GSpeed", sharedWaterMaterial);
  25. Vector4 directionAB = WaterEditorUtility.GetMaterialVector("_GDirectionAB", sharedWaterMaterial);
  26. Vector4 directionCD = WaterEditorUtility.GetMaterialVector("_GDirectionCD", sharedWaterMaterial);
  27. amplitude = EditorGUILayout.Vector4Field("Amplitude (Height offset)", amplitude);
  28. frequency = EditorGUILayout.Vector4Field("Frequency (Tiling)", frequency);
  29. steepness = EditorGUILayout.Vector4Field("Steepness", steepness);
  30. speed = EditorGUILayout.Vector4Field("Speed", speed);
  31. directionAB = EditorGUILayout.Vector4Field("Direction scale (Wave 1 (X,Y) and 2 (Z,W))", directionAB);
  32. directionCD = EditorGUILayout.Vector4Field("Direction scale (Wave 3 (X,Y) and 4 (Z,W))", directionCD);
  33. if (GUI.changed) {
  34. WaterEditorUtility.SetMaterialVector("_GAmplitude", amplitude, sharedWaterMaterial);
  35. WaterEditorUtility.SetMaterialVector("_GFrequency", frequency, sharedWaterMaterial);
  36. WaterEditorUtility.SetMaterialVector("_GSteepness", steepness, sharedWaterMaterial);
  37. WaterEditorUtility.SetMaterialVector("_GSpeed", speed, sharedWaterMaterial);
  38. WaterEditorUtility.SetMaterialVector("_GDirectionAB", directionAB, sharedWaterMaterial);
  39. WaterEditorUtility.SetMaterialVector("_GDirectionCD", directionCD, sharedWaterMaterial);
  40. }
  41. /*
  42. Vector4 animationTiling = WaterEditorUtility.GetMaterialVector("_AnimationTiling", sharedWaterMaterial);
  43. Vector4 animationDirection = WaterEditorUtility.GetMaterialVector("_AnimationDirection", sharedWaterMaterial);
  44. float firstTilingU = animationTiling.x*100.0F;
  45. float firstTilingV = animationTiling.y*100.0F;
  46. float firstDirectionU = animationDirection.x;
  47. float firstDirectionV = animationDirection.y;
  48. float secondTilingU = animationTiling.z*100.0F;
  49. float secondTilingV = animationTiling.w*100.0F;
  50. float secondDirectionU = animationDirection.z;
  51. float secondDirectionV = animationDirection.w;
  52. EditorGUILayout.BeginHorizontal ();
  53. firstTilingU = EditorGUILayout.FloatField("First Tiling U", firstTilingU);
  54. firstTilingV = EditorGUILayout.FloatField("First Tiling V", firstTilingV);
  55. EditorGUILayout.EndHorizontal ();
  56. EditorGUILayout.BeginHorizontal ();
  57. secondTilingU = EditorGUILayout.FloatField("Second Tiling U", secondTilingU);
  58. secondTilingV = EditorGUILayout.FloatField("Second Tiling V", secondTilingV);
  59. EditorGUILayout.EndHorizontal ();
  60. EditorGUILayout.BeginHorizontal ();
  61. firstDirectionU = EditorGUILayout.FloatField("1st Animation U", firstDirectionU);
  62. firstDirectionV = EditorGUILayout.FloatField("1st Animation V", firstDirectionV);
  63. EditorGUILayout.EndHorizontal ();
  64. EditorGUILayout.BeginHorizontal ();
  65. secondDirectionU = EditorGUILayout.FloatField("2nd Animation U", secondDirectionU);
  66. secondDirectionV = EditorGUILayout.FloatField("2nd Animation V", secondDirectionV);
  67. EditorGUILayout.EndHorizontal ();
  68. animationDirection = new Vector4(firstDirectionU,firstDirectionV, secondDirectionU,secondDirectionV);
  69. animationTiling = new Vector4(firstTilingU/100.0F,firstTilingV/100.0F, secondTilingU/100.0F,secondTilingV/100.0F);
  70. WaterEditorUtility.SetMaterialVector("_AnimationTiling", animationTiling, sharedWaterMaterial);
  71. WaterEditorUtility.SetMaterialVector("_AnimationDirection", animationDirection, sharedWaterMaterial);
  72. EditorGUILayout.Separator ();
  73. GUILayout.Label ("Displacement Strength", EditorStyles.boldLabel);
  74. float heightDisplacement = WaterEditorUtility.GetMaterialFloat("_HeightDisplacement", sharedWaterMaterial);
  75. heightDisplacement = EditorGUILayout.Slider("Height", heightDisplacement, 0.0F, 5.0F);
  76. WaterEditorUtility.SetMaterialFloat("_HeightDisplacement", heightDisplacement, sharedWaterMaterial);
  77. */
  78. }
  79. serObj.ApplyModifiedProperties();
  80. }
  81. }