Ejemplo n.º 1
0
            public static void BuildIcon(Material mat, ref Texture2D icon)
            {
                if (m_previewMesh == null)
                {
                    m_previewMesh = AssetDatabase.LoadAssetAtPath <Mesh>(kPreviewSpherePath);
                }

                // get target buffer
                RenderTexture newIcon = RenderTexture.GetTemporary(kImageSize, kImageSize, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

                // save old target
                RenderTexture save = m_previewUtility.m_Camera.targetTexture;

                // set new RT target
                m_previewUtility.m_Camera.targetTexture = newIcon;
                // configure camera for icon capture
                m_previewUtility.m_Camera.backgroundColor = new Color(80 / 255f, 80 / 255f, 80 / 255f, 1f);
                m_previewUtility.m_Camera.clearFlags      = CameraClearFlags.SolidColor;

                // draw the preview
                Quaternion ignore = Quaternion.identity;

                DREditorUtility.DrawPreview(m_previewUtility, mat, m_previewMesh, DREditorUtility.PreviewType.kIcon, Vector2.zero, ref ignore);

                // restore target
                m_previewUtility.m_Camera.targetTexture = save;

                if (icon != null)
                {
                    GameObject.DestroyImmediate(icon);
                }

                RenderTexture saveActiveRT = RenderTexture.active;

                try
                {
                    RenderTexture.active = newIcon;
                    icon = new Texture2D(newIcon.width, newIcon.height, TextureFormat.RGB24, false);
                    icon.ReadPixels(new Rect(0, 0, newIcon.width, newIcon.height), 0, 0);
                    icon.Apply();
                }
                finally
                {
                    // if  texture creation false always make sure we do these things
                    RenderTexture.ReleaseTemporary(newIcon);
                    RenderTexture.active = saveActiveRT;
                }
            }
        public static void DrawDaydreamLightingToggle(DaydreamRenderer renderer)
        {
            if (renderer == null)
            {
                return;
            }

            // determine lighting system in use
            const int kDaydreamLighting = 0;
            const int kUnityLighting    = 1;
            int       selectedIndex     = renderer.m_daydreamLighting ? kDaydreamLighting : kUnityLighting;

            EditorGUI.BeginChangeCheck();

            // draw section separator
            DrawSection(500, 1);
            EditorGUILayout.BeginHorizontal();
            if (selectedIndex == kDaydreamLighting)
            {
                EditorGUILayout.LabelField("Lighting System", Styles.sectionLabel, GUILayout.Width(105), GUILayout.Height(25));
                GUILayout.Button("", Styles.daydreamLightingStyle, GUILayout.Width(25), GUILayout.Height(25));
            }
            else
            {
                EditorGUILayout.LabelField("Lighting System", Styles.sectionLabel, GUILayout.Width(105), GUILayout.Height(25));
                GUILayout.Button("", Styles.unityLightingStyle, GUILayout.Width(25), GUILayout.Height(25));
            }

            EditorGUILayout.EndHorizontal();
            GUILayout.Space(5);

            EditorGUI.BeginChangeCheck();
            DREditorUtility.RadioButtonOutput selected = DREditorUtility.DrawRadioButton(selectedIndex, Styles.m_lightingSystemUI, Styles.m_buttonUnselected, Styles.m_buttonSelected, 20, 32, 150, new bool[] { true, false });
            if (EditorGUI.EndChangeCheck())
            {
                if (selected.m_selectedIndex == kDaydreamLighting)
                {
                    if (renderer.m_daydreamLighting == false)
                    {
                        renderer.m_daydreamLighting = true;
                        if (!renderer.m_enableManualLightingComponents)
                        {
                            DaydreamRendererImportManager.ApplyLightingComponents();
                        }
                        renderer.EnableEnlighten(false);
                    }
                }
                else
                {
                    if (renderer.m_daydreamLighting == true)
                    {
                        renderer.m_daydreamLighting = false;
                        if (!renderer.m_enableManualLightingComponents)
                        {
                            DaydreamRendererImportManager.RemoveAllLightingComponents();
                        }
                        renderer.EnableEnlighten(true);
                    }
                }

                // display advanced settings
                if (selected.m_dropDownSelected == kDaydreamLighting)
                {
                    LightSystemDialog.ShowDialog(null);
                }
            }
            GUILayout.Space(5);
        }
        void OnGUI()
        {
            DrawCenteredLogo(100);

            DaydreamRenderer renderer = FindObjectOfType <DaydreamRenderer>();

            if (renderer == null)
            {
                m_UIFade.target = false;

                EditorGUILayout.LabelField(Styles.ddrNotEnabled, Styles.helpText);

                GUILayout.Space(10);

                GUILayout.BeginVertical();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (DREditorUtility.FlexibleHorizButton(Styles.kAddDrToScene, Styles.boldButton, GUILayout.Width(280), GUILayout.Height(50)))
                {
                    GameObject go = GameObject.Find(kDaydreamObjectName);
                    if (go == null)
                    {
                        go = new GameObject(kDaydreamObjectName);
                    }

                    go.AddComponent <DaydreamRenderer>();
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();

                return;
            }
            else
            {
                m_UIFade.target = true;
            }

            //---------------------------------------------------------------------//
            // Daydream lighting
            if (EditorGUILayout.BeginFadeGroup(m_UIFade.faded))
            {
                EditorGUILayout.LabelField(Styles.kDaydreamEnabled, Styles.helpText);

                DrawDaydreamLightingToggle(renderer);
            }
            EditorGUILayout.EndFadeGroup();


            //---------------------------------------------------------------------//
            // Material conversion
            GUILayout.Space(10);
            DaydreamRendererImportManager.DrawSection(500, 1);
            EditorGUILayout.LabelField(Styles.kConversionWizardSegment, DaydreamRendererImportManager.Styles.sectionLabel, GUILayout.Height(25));
            GUILayout.Space(5);

            EditorGUILayout.HelpBox(Styles.kMaterialWizardInfo, MessageType.Info);

            if (GUILayout.Button(Styles.kOpenMaterialWizard))
            {
                MaterialConversionDialog.ShowDialog(null);
            }

            //---------------------------------------------------------------------//
            // Documentation
            GUILayout.Space(10);
            DaydreamRendererImportManager.DrawSection(500, 1);
            EditorGUILayout.LabelField("Documentation", DaydreamRendererImportManager.Styles.sectionLabel, GUILayout.Height(25));
            if (GUILayout.Button(Styles.kOpenDocumentation))
            {
                Application.OpenURL("https://github.com/googlevr/daydream-renderer-for-unity/blob/master/README.md");
            }
        }