1 using System;
2 using
UnityEditor;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.ImageEffects
6 {
7     
[CustomEditor (typeof(SunShafts))]
8     
class SunShaftsEditor : Editor
9     {
10         SerializedObject serObj;
11
12         SerializedProperty sunTransform;
13         SerializedProperty radialBlurIterations;
14         SerializedProperty sunColor;
15         SerializedProperty sunThreshold;
16         SerializedProperty sunShaftBlurRadius;
17         SerializedProperty sunShaftIntensity;
18         SerializedProperty useDepthTexture;
19         SerializedProperty resolution;
20         SerializedProperty screenBlendMode;
21         SerializedProperty maxRadius;
22
23         
void OnEnable () {
24             serObj =
new SerializedObject (target);
25
26             screenBlendMode = serObj.FindProperty(
"screenBlendMode");
27
28             sunTransform = serObj.FindProperty(
"sunTransform");
29             sunColor = serObj.FindProperty(
"sunColor");
30             sunThreshold = serObj.FindProperty(
"sunThreshold");
31
32             sunShaftBlurRadius = serObj.FindProperty(
"sunShaftBlurRadius");
33             radialBlurIterations = serObj.FindProperty(
"radialBlurIterations");
34
35             sunShaftIntensity = serObj.FindProperty(
"sunShaftIntensity");
36
37             resolution = serObj.FindProperty(
"resolution");
38
39             maxRadius = serObj.FindProperty(
"maxRadius");
40
41             useDepthTexture = serObj.FindProperty(
"useDepthTexture");
42         }
43
44
45         
public override void OnInspectorGUI () {
46             serObj.Update ();
47
48             EditorGUILayout.BeginHorizontal();
49
50             EditorGUILayout.PropertyField (useDepthTexture,
new GUIContent ("Rely on Z Buffer?"));
51             
if ((target as SunShafts).GetComponent<Camera>())
52                 GUILayout.Label(
"Current camera mode: "+ (target as SunShafts).GetComponent<Camera>().depthTextureMode, EditorStyles.miniBoldLabel);
53
54             EditorGUILayout.EndHorizontal();
55
56             
// depth buffer need
57             
/*
58         
bool newVal = useDepthTexture.boolValue;
59         
if (newVal != oldVal) {
60             
if (newVal)
61                 (target
as SunShafts).camera.depthTextureMode |= DepthTextureMode.Depth;
62             
else
63                 (target
as SunShafts).camera.depthTextureMode &= ~DepthTextureMode.Depth;
64         }
65         */

66
67             EditorGUILayout.PropertyField (resolution,
new GUIContent("Resolution"));
68             EditorGUILayout.PropertyField (screenBlendMode,
new GUIContent("Blend mode"));
69
70             EditorGUILayout.Separator ();
71
72             EditorGUILayout.BeginHorizontal();
73
74             EditorGUILayout.PropertyField (sunTransform,
new GUIContent("Shafts caster", "Chose a transform that acts as a root point for the produced sun shafts"));
75             
if ((target as SunShafts).sunTransform && (target as SunShafts).GetComponent<Camera>()) {
76                 
if (GUILayout.Button("Center on " + (target as SunShafts).GetComponent<Camera>().name)) {
77                     
if (EditorUtility.DisplayDialog ("Move sun shafts source?", "The SunShafts caster named "+ (target as SunShafts).sunTransform.name +"\n will be centered along "+(target as SunShafts).GetComponent<Camera>().name+". Are you sure? ", "Please do", "Don't")) {
78                         Ray ray = (target
as SunShafts).GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f,0.5f,0));
79                         (target
as SunShafts).sunTransform.position = ray.origin + ray.direction * 500.0f;
80                         (target
as SunShafts).sunTransform.LookAt ((target as SunShafts).transform);
81                     }
82                 }
83             }
84
85             EditorGUILayout.EndHorizontal();
86
87             EditorGUILayout.Separator ();
88
89             EditorGUILayout.PropertyField (sunThreshold,
new GUIContent ("Threshold color"));
90             EditorGUILayout.PropertyField (sunColor,
new GUIContent ("Shafts color"));
91             maxRadius.floatValue =
1.0f - EditorGUILayout.Slider ("Distance falloff", 1.0f - maxRadius.floatValue, 0.1f, 1.0f);
92
93             EditorGUILayout.Separator ();
94
95             sunShaftBlurRadius.floatValue = EditorGUILayout.Slider (
"Blur size", sunShaftBlurRadius.floatValue, 1.0f, 10.0f);
96             radialBlurIterations.intValue = EditorGUILayout.IntSlider (
"Blur iterations", radialBlurIterations.intValue, 1, 3);
97
98             EditorGUILayout.Separator ();
99
100             EditorGUILayout.PropertyField (sunShaftIntensity,
new GUIContent("Intensity"));
101
102             serObj.ApplyModifiedProperties();
103         }
104     }
105 }


Tìm kết quả nhanh