Esempio n. 1
0
        void OnGUI()
        {
            // If this is the first iteration since the window is opened, do the needed initializzations
            if (firstCycle)
            {
                Start();
                firstCycle = false;
            }

            packer.DrawGUI();

            if (GUILayout.Button("Save Packed Texture"))
            {
                string path = TSFunctions.GetSelectedPathOrFallback();
                path = EditorUtility.SaveFilePanel("Save Texture", path, "Packed", "png");
                if (path.Length != 0)
                {
                    packer.PackTexture(path);
                }
            }
        }
Esempio n. 2
0
        public void DrawSection(MaterialEditor materialEditor)
        {
            EditorGUI.BeginChangeCheck();
            TSFunctions.DrawSelector(Enum.GetNames(typeof(ToonyStandardGUI.BlendMode)), _blendMode, Styles.blendMode, materialEditor);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material mat in _blendMode.targets)
                {
                    ToonyStandardGUI.SetupMaterialWithBlendMode(mat, (ToonyStandardGUI.BlendMode)_blendMode.floatValue, mat.GetFloat("_OutlineOn") > 0);
                }
            }

            //draw cull mode
            materialEditor.ShaderProperty(_Cull, Styles.cullMode);
            EditorGUILayout.Space();

            //draw main properties
            materialEditor.TexturePropertySingleLine(Styles.mainTex, _MainTex, _Color);
            if ((ToonyStandardGUI.BlendMode)_blendMode.floatValue == ToonyStandardGUI.BlendMode.Cutout)
            {
                EditorGUI.indentLevel += MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1;
                materialEditor.ShaderProperty(_Cutoff, Styles.cutOff);
                EditorGUI.indentLevel -= MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1;
            }
            materialEditor.TexturePropertySingleLine(Styles.normal, _BumpMap, _BumpScale);

            if (level == InspectorLevel.Normal)
            {
                Rect r = TSFunctions.GetControlRectForSingleLine();
                EditorGUI.BeginChangeCheck();
                materialEditor.TexturePropertyMiniThumbnail(r, _OcclusionMap, Styles.occlusion.text, Styles.occlusion.tooltip);
                if (EditorGUI.EndChangeCheck())
                {
                    gui.RegenerateMSOT(false);
                }
                TSFunctions.ProperSlider(MaterialEditor.GetRectAfterLabelWidth(r), ref _Occlusion);
            }
            else
            {
                materialEditor.ShaderProperty(_Occlusion, Styles.occlusion);
            }

            //emission
            EditorGUI.BeginChangeCheck();
            if (materialEditor.EmissionEnabledProperty())
            {
                materialEditor.TexturePropertySingleLine(Styles.emission, _Emission, _EmissionColor);
                materialEditor.LightmapEmissionProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel);
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material mat in _Emission.targets)
                {
                    MaterialEditor.FixupEmissiveFlag(mat);
                    bool shouldEmissionBeEnabled = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
                    TSFunctions.SetKeyword(mat, "_EMISSION", shouldEmissionBeEnabled);
                    if (shouldEmissionBeEnabled)
                    {
                        mat.SetOverrideTag("IsEmissive", "true");
                    }
                    else
                    {
                        mat.SetOverrideTag("IsEmissive", "false");
                    }
                }
            }
            //if in expert mode show the MSOT map and a button for the texture packer
            if (level == InspectorLevel.Expert)
            {
                EditorGUILayout.BeginHorizontal();
                materialEditor.TexturePropertySingleLine(Styles.MSOT, _MSOT);
                if (GUILayout.Button(Styles.TexturePackerButton))
                {
                    EditorGUILayout.EndHorizontal();
                    isTexturePackerOpen = !isTexturePackerOpen;
                    Styles.ToggleTexturePackerContent(isTexturePackerOpen);
                }
                else
                {
                    EditorGUILayout.EndHorizontal();
                }

                if (isTexturePackerOpen)
                {
                    EditorGUILayout.BeginVertical("box");
                    packer.DrawGUI();
                    EditorGUILayout.EndVertical();
                    if (_MSOT.textureValue != (Texture)packer.resultTex && packer.resultTex != null)
                    {
                        _MSOT.textureValue = packer.resultTex;
                        packer.resultTex   = null;
                    }
                }
            }
            EditorGUILayout.Space();
            materialEditor.TextureScaleOffsetProperty(_MainTex);
            //EditorGUILayout.Space();
            //materialEditor.RenderQueueField();

            EditorGUILayout.Space();
        }