示例#1
0
        private void CheckScene()
        {
            EditorToolUtility.ClearConsoleLogs();


            List <GameObject> allGameObjects = GetAllGameObjectsInScene();

            if (_checkMemories)
            {
                CheckMemories();
            }
            if (_checkHiddenObjects)
            {
                CheckHiddenGameObjects(allGameObjects);
            }
            if (_checkComponents)
            {
                CheckComponents(allGameObjects);
            }
            if (_checkMeshData)
            {
                CheckMeshes();
            }
        }
示例#2
0
        void OnGUI()
        {
            GUILayout.Space(5);

            EditorGUI.BeginChangeCheck();
            _genMode      = (GenMode)EditorGUILayout.EnumPopup("Mode", _genMode);
            _selectedSize = EditorGUILayout.IntPopup("Face Size", _selectedSize, _names, _sizes);
            _center       = EditorGUILayout.ObjectField("Center", _center, typeof(Transform), true) as Transform;


            GUILayout.Space(15);

            bool  hasError        = false;
            Color oldContentColor = GUI.contentColor;

            GUI.contentColor = Color.red;
            if (_center == null)
            {
                GUILayout.Label("Must set the 'Center'!");
                hasError = true;
            }
            Camera mainCam = Camera.main;

            if (mainCam == null)
            {
                GUI.contentColor = Color.red;
                GUILayout.Label("Can not find Main Camera!");
                hasError = true;
            }
            GUI.contentColor = oldContentColor;

            if (hasError)
            {
                _componentStates = null;
                return;
            }


            _layerMask = EditorToolUtility.LayerMaskField("Culling Mask", _layerMask);

            if (_componentStates == null)
            {
                _componentStates = new Dictionary <string, bool>();
                foreach (Behaviour comp in GetValidCameraComponents(mainCam))
                {
                    _componentStates.Add(comp.GetType().Name, comp.enabled);
                }
            }

            _listModified.Clear();
            EditorGUILayout.BeginVertical("box");
            foreach (KeyValuePair <string, bool> kv in _componentStates)
            {
                EditorGUI.BeginChangeCheck();
                /*bool enabled = */ EditorGUILayout.Toggle(kv.Key, kv.Value);
                if (EditorGUI.EndChangeCheck())
                {
                    _listModified.Add(kv.Key);
                }
            }
            EditorGUILayout.EndVertical();
            foreach (string comp in _listModified)
            {
                _componentStates[comp] = !_componentStates[comp];
            }


            GUILayout.Space(15);

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Bake", GUILayout.Width(100)))
            {
                if (_rtexs == null || _selectedSize != _lastSelectedSize)
                {
                    DestroyResources();
                    CreateResources();
                    _lastSelectedSize = _selectedSize;
                }


                GameObject go = GameObject.Instantiate(mainCam.gameObject);
                go.name = "__CubemapCamera__";
                Camera cam = go.GetComponent <Camera>();
                cam.enabled         = false;
                cam.backgroundColor = Camera.main.backgroundColor;
                cam.aspect          = 1;
                cam.fieldOfView     = 90;
                cam.cullingMask     = _layerMask;
                foreach (Behaviour comp in GetValidCameraComponents(cam))
                {
                    comp.enabled = _componentStates[comp.GetType().Name];
                }


                Antialiasing4Tools aape = go.AddComponent <Antialiasing4Tools>();
                aape.mode             = AAMode.FXAA1PresetA;
                go.transform.position = _center.position;

                RenderTexture oldRt = RenderTexture.active;
                for (int i = 0; i < 6; i++)
                {
                    go.transform.localEulerAngles = _cameraAngles[i];

                    RenderTexture.active = _rtexs[i];
                    cam.targetTexture    = _rtexs[i];
                    cam.Render();

                    _colorTexs[i].ReadPixels(new Rect(0, 0, _selectedSize, _selectedSize), 0, 0);
                    _colorTexs[i].Apply();
                }


                RenderTexture.active = oldRt;
                DestroyImmediate(go);

                Texture2D tex = WriteAndImportTexture();
                if (tex != null)
                {
                    Debug.Log("渲染到环境贴图完成!", tex);
                }
            }
            EditorGUILayout.EndHorizontal();
        }