Example #1
0
        public static IEnumerator BuildOccluderProxyGeometry(Transform parent, MeshRenderer[] staticRenderers, Action <OccluderData[]> result, Component component, string tag = "Occluder")
        {
            SimpleCulling culling = component as SimpleCulling;

            Transform           container         = NewObject(occluderContainerName, parent).transform;
            List <MeshRenderer> occluderRenderers = staticRenderers.Where(s => s.gameObject.tag == tag).ToList();

            OccluderData[] occluders = new OccluderData[occluderRenderers.Count];
            for (int i = 0; i < occluders.Length; i++)
            {
                MeshFilter meshFilter = occluderRenderers[i].GetComponent <MeshFilter>();
                if (meshFilter == null)
                {
                    continue;
                }

                GameObject   occluderObj       = occluderRenderers[i].gameObject;
                Transform    occluderTransform = occluderObj.transform;
                GameObject   proxyObj          = NewObject(occluderObj.name, container, occluderTransform.position, occluderTransform.rotation, occluderTransform.lossyScale);
                MeshCollider proxyCollider     = proxyObj.AddComponent <MeshCollider>();
                proxyCollider.sharedMesh = meshFilter.sharedMesh;
                occluders[i]             = new OccluderData(proxyCollider, occluderRenderers[i]);

#if UNITY_EDITOR
                if (culling != null)
                {
                    culling.completion = (float)(i + 1) / (float)occluders.Length;
                }
                UnityEditor.SceneView.RepaintAll();
#endif
                yield return(null);
            }
            result(occluders);
        }
Example #2
0
        private void DrawBakeTools()
        {
            EditorGUILayout.Space();
            SimpleCulling simpleCulling = (SimpleCulling)target;

            // --------------------------------------------------
            // Buttons

            EditorGUILayout.BeginHorizontal();
            bool isGenerating = simpleCulling.bakeState != SimpleCulling.BakeState.Active && simpleCulling.bakeState != SimpleCulling.BakeState.Empty;

            GUI.enabled = !isGenerating;
            if (GUILayout.Button(Styles.generateText))
            {
                simpleCulling.OnClickGenerate();
            }
            GUI.enabled = true;
            if (GUILayout.Button(isGenerating ? Styles.cancelText : Styles.clearText))
            {
                simpleCulling.OnClickCancel();
            }
            EditorGUILayout.EndHorizontal();
        }
Example #3
0
        private void DrawProgressBar()
        {
            SimpleCulling culling = (SimpleCulling)target;

            Rect   r = EditorGUILayout.BeginVertical();
            string label;
            string completion = string.Format(" {0}%", ((int)(culling.completion * 100)).ToString(), "%");

            switch (culling.bakeState)
            {
            case SimpleCulling.BakeState.Occluders:
                label = "Processing Occluders" + completion;
                break;

            case SimpleCulling.BakeState.Volumes:
                label = "Generating Volumes" + completion;
                break;

            case SimpleCulling.BakeState.Occlusion:
                label = "Baking Occlusion" + completion;
                break;

            case SimpleCulling.BakeState.Active:
                label = "Active Culling Data";
                break;

            default:
                label = "No Culling Data";
                break;
            }

            EditorGUI.ProgressBar(r, culling.completion, label);
            GUILayout.Space(16);
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }