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

103             }
104
105             serObj.ApplyModifiedProperties();
106         }
107     }
108 }