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.

74 lines
2.5 KiB

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