UnityEditor.TerrainSplatEditor.TextureFieldGUI C# (CSharp) Method

TextureFieldGUI() private static method

private static TextureFieldGUI ( string label, Texture2D &texture, float alignmentOffset ) : void
label string
texture UnityEngine.Texture2D
alignmentOffset float
return void
        private static void TextureFieldGUI(string label, ref Texture2D texture, float alignmentOffset)
        {
            GUILayout.Space(6f);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(80f) };
            GUILayout.BeginVertical(options);
            GUILayout.Label(label, new GUILayoutOption[0]);
            Type objType = typeof(Texture2D);
            GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MaxWidth(64f) };
            Rect position = GUILayoutUtility.GetRect(64f, 64f, 64f, 64f, optionArray2);
            position.x += alignmentOffset;
            texture = EditorGUI.DoObjectField(position, position, GUIUtility.GetControlID(0x3042, FocusType.Keyboard, position), texture, objType, null, null, false) as Texture2D;
            GUILayout.EndVertical();
        }

Usage Example

        private void OnGUI()
        {
            EditorGUIUtility.labelWidth = (float)((double)this.position.width - 64.0 - 20.0);
            bool flag1 = true;

            this.m_ScrollPosition = EditorGUILayout.BeginVerticalScrollView(this.m_ScrollPosition, false, GUI.skin.verticalScrollbar, GUI.skin.scrollView);
            bool flag2 = flag1 & this.ValidateTerrain();

            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal();
            string label           = string.Empty;
            float  alignmentOffset = 0.0f;

            switch (this.m_Terrain.materialType)
            {
            case Terrain.MaterialType.BuiltInStandard:
                label           = " Albedo (RGB)\nSmoothness (A)";
                alignmentOffset = 15f;
                break;

            case Terrain.MaterialType.BuiltInLegacyDiffuse:
                label           = "\n Diffuse (RGB)";
                alignmentOffset = 15f;
                break;

            case Terrain.MaterialType.BuiltInLegacySpecular:
                label           = "Diffuse (RGB)\n   Gloss (A)";
                alignmentOffset = 12f;
                break;

            case Terrain.MaterialType.Custom:
                label           = " \n  Splat";
                alignmentOffset = 0.0f;
                break;
            }
            TerrainSplatEditor.TextureFieldGUI(label, ref this.m_Texture, alignmentOffset);
            TerrainSplatEditor.TextureFieldGUI("\nNormal", ref this.m_NormalMap, -4f);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            bool flag3 = flag2 & this.ValidateMainTexture(this.m_Texture);

            if (flag3)
            {
                if (TerrainSplatEditor.IsUsingMetallic(this.m_Terrain.materialType, this.m_Terrain.materialTemplate))
                {
                    EditorGUILayout.Space();
                    float labelWidth = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 75f;
                    this.m_Metallic             = EditorGUILayout.Slider("Metallic", this.m_Metallic, 0.0f, 1f, new GUILayoutOption[0]);
                    EditorGUIUtility.labelWidth = labelWidth;
                }
                else if (TerrainSplatEditor.IsUsingSpecular(this.m_Terrain.materialType, this.m_Terrain.materialTemplate))
                {
                    this.m_Specular = EditorGUILayout.ColorField("Specular", this.m_Specular, new GUILayoutOption[0]);
                }
                if (TerrainSplatEditor.IsUsingSmoothness(this.m_Terrain.materialType, this.m_Terrain.materialTemplate) && !TextureUtil.HasAlphaTextureFormat(this.m_Texture.format))
                {
                    EditorGUILayout.Space();
                    float labelWidth = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 75f;
                    this.m_Smoothness           = EditorGUILayout.Slider("Smoothness", this.m_Smoothness, 0.0f, 1f, new GUILayoutOption[0]);
                    EditorGUIUtility.labelWidth = labelWidth;
                }
            }
            TerrainSplatEditor.SplatSizeGUI(ref this.m_TileSize, ref this.m_TileOffset);
            bool flag4 = EditorGUI.EndChangeCheck();

            EditorGUILayout.EndScrollView();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUI.enabled = flag3;
            if (GUILayout.Button(this.m_ButtonTitle, new GUILayoutOption[1] {
                GUILayout.MinWidth(100f)
            }))
            {
                this.ApplyTerrainSplat();
                this.Close();
                GUIUtility.ExitGUI();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
            if (!flag4 || !flag3 || this.m_Index == -1)
            {
                return;
            }
            this.ApplyTerrainSplat();
        }
All Usage Examples Of UnityEditor.TerrainSplatEditor::TextureFieldGUI