1 using UnityEngine;
2 using
UnityEditor;
3
4 class
WaterEditorUtility
5 {
6     
// helper functions to retrieve & set material values
7
8     
public static float GetMaterialFloat(System.String name, Material mat) {
9         
return mat.GetFloat(name);
10     }
11     
public static void SetMaterialFloat(System.String name, float f, Material mat) {
12         mat.SetFloat(name, f);
13     }
14
15     
public static Color GetMaterialColor(System.String name, Material mat) {
16         
return mat.GetColor(name);
17     }
18     
public static void SetMaterialColor(System.String name, Color color, Material mat) {
19         mat.SetColor(name, color);
20     }
21     
public static Vector4 GetMaterialVector(System.String name, Material mat) {
22         
return mat.GetVector(name);
23     }
24     
public static void SetMaterialVector(System.String name, Vector4 vector, Material mat) {
25         mat.SetVector(name, vector);
26     }
27     
public static Texture GetMaterialTexture(System.String theName, Material mat) {
28         
return mat.GetTexture(theName);
29     }
30     
public static void SetMaterialTexture(System.String theName, Texture parameter, Material mat) {
31         mat.SetTexture(theName, parameter);
32     }
33     
34     
public static Material LocateValidWaterMaterial(Transform parent)
35     {
36         
if(parent.GetComponent<Renderer>() && parent.GetComponent<Renderer>().sharedMaterial)
37             
return parent.GetComponent<Renderer>().sharedMaterial;
38         
foreach( Transform t in parent)
39         {
40             
if(t.GetComponent<Renderer>() && t.GetComponent<Renderer>().sharedMaterial)
41                 
return t.GetComponent<Renderer>().sharedMaterial;
42         }
43         
return null;
44     }
45     
46     
public static void CurveGui (System.String name, SerializedObject serObj, Color color)
47     {
48         AnimationCurve curve =
new AnimationCurve(new Keyframe(0, 0.0f, 1.0f, 1.0f), new Keyframe(1, 1.0f, 1.0f, 1.0f));
49         curve = EditorGUILayout.CurveField(
new GUIContent (name), curve, color, new Rect (0.0f,0.0f,1.0f,1.0f));
50
51         
//if (GUI.changed) {
52         
// AnimationCurveChanged(((WaterBase)serObj.targetObject).sharedMaterial, curve);
53             
//((WaterBase)serObj.targetObject).gameObject.SendMessage ("AnimationCurveChanged", SendMessageOptions.DontRequireReceiver);
54        
//}
55     }
56     
/*
57     
public static void AnimationCurveChanged(Material sharedMaterial, AnimationCurve fresnelCurve)
58     {
59         Debug.Log(
"AnimationCurveChanged");
60         Texture2D fresnel = (Texture2D)sharedMaterial.GetTexture(
"_Fresnel");
61         
if(!fresnel)
62             fresnel =
new Texture2D(256,1);
63             
64         
for (int i = 0; i < 256; i++)
65         {
66             
float val = Mathf.Clamp01(fresnelCurve.Evaluate((float)i)/255.0f);
67             Debug.Log(
""+(((float)i)/255.0f) +": "+val);
68             fresnel.SetPixel(i,
0, new Color(val,val,val,val));
69         }
70         fresnel.Apply();
71         
72         sharedMaterial.SetTexture(
"_Fresnel", fresnel);
73         
74     } */

75 }


Tìm kết quả nhanh