Ejemplo n.º 1
0
        public void UpdateMap()
        {
            if (mpb == null)
            {
                mpb = new MaterialPropertyBlock();
            }
            mpb.Clear();
            if (rt != null)
            {
                RenderTexture.ReleaseTemporary(rt);
            }
            if (rtGAFormat != null)
            {
                RenderTexture.ReleaseTemporary(rtGAFormat);
            }
            if (heightMap2NormalMapAsset != null)
            {
                RenderTextureDescriptor rd = new RenderTextureDescriptor(heightMap2NormalMapAsset.editGenerator.DestinationWidth, heightMap2NormalMapAsset.editGenerator.DestinationHeight)
                {
                    sRGB = false
                };
                rt          = RenderTexture.GetTemporary(rd);
                rt.wrapMode = wrapMode;
                heightMap2NormalMapAsset.GenerateFromEditorGenerator(rt);
                var usedTexture = rt;
                if (toAlphaGreenNormalMapConversion)
                {
                    rtGAFormat = RenderTexture.GetTemporary(rd);
                    if (RGB2GAMat == null)
                    {
                        RGB2GAMat = new Material(Shader.Find("Hidden/NMG/RGB2GANormalMap"));
                    }
                    Graphics.Blit(rt, rtGAFormat, RGB2GAMat);
                    usedTexture = rtGAFormat;
                }
                mpb.SetTexture(normalMapShaderAttribute, usedTexture);
            }
            var r = GetComponent <Renderer>();

            if (r != null)
            {
                r.SetPropertyBlock(mpb);
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("editGenerator").FindPropertyRelative("generator"), true);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("editGenerator").FindPropertyRelative("destinationMap"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("editGenerator").FindPropertyRelative("customDestinationWidth"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("editGenerator").FindPropertyRelative("customDestinationHeight"), true);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("showPreview"));


            if (mapCreator.editGenerator.destinationMap == null)
            {
                if (GUILayout.Button("Create destination texture"))
                {
                    string targetPath = AssetDatabase.GetAssetPath(mapCreator).Substring(0, AssetDatabase.GetAssetPath(mapCreator).Length - 5) + "png";
                    mapCreator.editGenerator.destinationMap = mapCreator.editGenerator.CreateTexture(targetPath);
                    EditorUtility.SetDirty(mapCreator);
                }
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(mapCreator.generator.Equals(mapCreator.editGenerator));
            if (GUILayout.Button("Apply"))
            {
                mapCreator.ApplyEditProperty();
            }
            if (GUILayout.Button("Revert"))
            {
                mapCreator.RevertEditProperty();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            if (mapCreator.showPreview)
            {
                var s = RenderTexture.active;
                mapCreator.GenerateFromEditorGenerator(rTex);
                RenderTexture.active = s;
                GUILayout.Label(rTex);
            }
            serializedObject.ApplyModifiedProperties();
        }