Exemplo n.º 1
0
        public static void Bake(ReflectorProbe[] probes)
        {
            try
            {
                string path;
                if (!CreateDirectory(out path))
                {
                    return;
                }

                int count = 0;
                for (int i = 0; i < probes.Length; i++)
                {
                    if (probes[i].Baked)
                    {
                        count++;
                    }
                }

                int current = 0;
                for (int i = 0; i < probes.Length; i++)
                {
                    ReflectorProbe probe = probes[i];

                    current++;
                    EditorUtility.DisplayProgressBar("Baking Deferred Probe", "Baking: " + probe.name, current / (float)count);

                    Texture previous = probe.GetComponent <ReflectionProbe>().customBakedTexture;
                    string  existing = AssetDatabase.GetAssetPath(previous);

                    Cubemap cubemap = probe.BakeReflection();
                    if (cubemap == null)
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(existing))
                    {
                        string asset = "Assets" + path + '/' + probe.name + Guid.NewGuid().ToString() + ".asset";
                        AssetDatabase.CreateAsset(cubemap, asset);
                    }
                    else
                    {
                        AssetDatabase.CreateAsset(cubemap, existing);
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            EditorSceneManager.MarkAllScenesDirty();
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            reflectionProbes.Update();
            serializedObject.Update();

            EditorGUILayout.LabelField("Runtime");
            EditorGUI.indentLevel++;

            EditorGUILayout.PropertyField(importance, new GUIContent("Importance"));
            EditorGUILayout.PropertyField(intensity, new GUIContent("Intensity"));
            EditorGUILayout.PropertyField(projection, new GUIContent("Box Projection"));
            EditorGUILayout.PropertyField(blend, new GUIContent("Blend Distance"));
            EditorGUILayout.PropertyField(size, new GUIContent("Size"));
            EditorGUILayout.PropertyField(offset, new GUIContent("Offset"));

            EditorGUI.indentLevel--;

            EditorGUILayout.LabelField("Render");
            EditorGUI.indentLevel++;

            EditorGUILayout.IntPopup(resolution, resolutionNames, resolutionValues);
            EditorGUILayout.PropertyField(customCamera, new GUIContent("Camera Override"));
            if (customCamera.objectReferenceValue == null && !customCamera.hasMultipleDifferentValues)
            {
                EditorGUILayout.PropertyField(clear, new GUIContent("Clear Flags"));
                if (clear.intValue == 2)
                {
                    EditorGUILayout.PropertyField(background, new GUIContent("Background Color"));
                }

                //EditorGUILayout.PropertyField(culling, new GUIContent("Culling Mask"));
                EditorGUILayout.PropertyField(nearClip, new GUIContent("Near Clip"));
                EditorGUILayout.PropertyField(farClip, new GUIContent("Far Clip"));
                EditorGUILayout.PropertyField(occlusion, new GUIContent("Occlusion Culling"));
                EditorGUILayout.PropertyField(hdr, new GUIContent("HDR"));
            }

            EditorGUI.indentLevel--;

            EditorGUILayout.LabelField("Bake");
            EditorGUI.indentLevel++;

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(bakeable, new GUIContent("Bakeable"));
            Object objectReferenceValue = EditorGUILayout.ObjectField(new GUIContent("Baked Cubemap"), baked.objectReferenceValue, typeof(Cubemap), false);

            if (EditorGUI.EndChangeCheck())
            {
                baked.objectReferenceValue = objectReferenceValue;
            }

            EditorGUI.indentLevel--;

            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(EditorGUIUtility.labelWidth);

            if (GUILayout.Button("Bake"))
            {
                ReflectorProbe[] probes = new ReflectorProbe[serializedObject.targetObjects.Length];
                for (int i = 0; i < probes.Length; i++)
                {
                    probes[i] = serializedObject.targetObjects[i] as ReflectorProbe;
                }

                ReflectorProbeBaker.Bake(probes);
            }

            if (GUILayout.Button("Bake All"))
            {
                ReflectorProbeBaker.BakeReflector();
            }

            if (GUILayout.Button("Clear"))
            {
                ReflectorProbe[] probes = new ReflectorProbe[serializedObject.targetObjects.Length];
                for (int i = 0; i < probes.Length; i++)
                {
                    probes[i] = serializedObject.targetObjects[i] as ReflectorProbe;
                }

                ReflectorProbeBaker.Clear(probes);
            }

            GUILayout.EndHorizontal();

            reflectionProbes.ApplyModifiedProperties();
            serializedObject.ApplyModifiedProperties();
        }